blob: 3cae06e2877ffd6a574faa28d65c93db03877800 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
paul200df112005-06-01 11:17:05 +000036#include "workqueue.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "bgpd/bgpd.h"
39#include "bgpd/bgp_table.h"
40#include "bgpd/bgp_route.h"
41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_regex.h"
45#include "bgpd/bgp_community.h"
46#include "bgpd/bgp_ecommunity.h"
47#include "bgpd/bgp_clist.h"
48#include "bgpd/bgp_packet.h"
49#include "bgpd/bgp_filter.h"
50#include "bgpd/bgp_fsm.h"
51#include "bgpd/bgp_mplsvpn.h"
52#include "bgpd/bgp_nexthop.h"
53#include "bgpd/bgp_damp.h"
54#include "bgpd/bgp_advertise.h"
55#include "bgpd/bgp_zebra.h"
hasso0a486e52005-02-01 20:57:17 +000056#include "bgpd/bgp_vty.h"
paul718e3742002-12-13 20:15:29 +000057
58/* Extern from bgp_dump.c */
59extern char *bgp_origin_str[];
60extern char *bgp_origin_long_str[];
61
paul94f2b392005-06-28 12:44:16 +000062static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000063bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000064 struct prefix_rd *prd)
65{
66 struct bgp_node *rn;
67 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000068
69 assert (table);
70 if (!table)
71 return NULL;
72
paul718e3742002-12-13 20:15:29 +000073 if (safi == SAFI_MPLS_VPN)
74 {
paulfee0f4c2004-09-13 05:12:46 +000075 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000076
77 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000078 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000079 else
80 bgp_unlock_node (prn);
81 table = prn->info;
82 }
paul718e3742002-12-13 20:15:29 +000083
84 rn = bgp_node_get (table, p);
85
86 if (safi == SAFI_MPLS_VPN)
87 rn->prn = prn;
88
89 return rn;
90}
91
92/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +000093static struct bgp_info *
paul718e3742002-12-13 20:15:29 +000094bgp_info_new ()
95{
96 struct bgp_info *new;
97
98 new = XMALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
99 memset (new, 0, sizeof (struct bgp_info));
100
101 return new;
102}
103
104/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000105static void
paul718e3742002-12-13 20:15:29 +0000106bgp_info_free (struct bgp_info *binfo)
107{
108 if (binfo->attr)
109 bgp_attr_unintern (binfo->attr);
110
111 if (binfo->damp_info)
112 bgp_damp_info_free (binfo->damp_info, 0);
113
paul200df112005-06-01 11:17:05 +0000114 peer_unlock (binfo->peer); /* bgp_info peer reference */
115
paul718e3742002-12-13 20:15:29 +0000116 XFREE (MTYPE_BGP_ROUTE, binfo);
117}
118
paul200df112005-06-01 11:17:05 +0000119struct bgp_info *
120bgp_info_lock (struct bgp_info *binfo)
121{
122 binfo->lock++;
123 return binfo;
124}
125
126struct bgp_info *
127bgp_info_unlock (struct bgp_info *binfo)
128{
129 assert (binfo && binfo->lock > 0);
130 binfo->lock--;
131
132 if (binfo->lock == 0)
133 {
134#if 0
135 zlog_debug ("%s: unlocked and freeing", __func__);
136 zlog_backtrace (LOG_DEBUG);
137#endif
138 bgp_info_free (binfo);
139 return NULL;
140 }
141
142#if 0
143 if (binfo->lock == 1)
144 {
145 zlog_debug ("%s: unlocked to 1", __func__);
146 zlog_backtrace (LOG_DEBUG);
147 }
148#endif
149
150 return binfo;
151}
152
paul718e3742002-12-13 20:15:29 +0000153void
154bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
155{
156 struct bgp_info *top;
157
158 top = rn->info;
paul200df112005-06-01 11:17:05 +0000159
paul718e3742002-12-13 20:15:29 +0000160 ri->next = rn->info;
161 ri->prev = NULL;
162 if (top)
163 top->prev = ri;
164 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000165
166 bgp_info_lock (ri);
167 bgp_lock_node (rn);
168 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000169}
170
paulb40d9392005-08-22 22:34:41 +0000171/* Do the actual removal of info from RIB, for use by bgp_process
172 completion callback *only* */
173static void
174bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000175{
176 if (ri->next)
177 ri->next->prev = ri->prev;
178 if (ri->prev)
179 ri->prev->next = ri->next;
180 else
181 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000182
183 bgp_info_unlock (ri);
184 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000185}
186
paulb40d9392005-08-22 22:34:41 +0000187void
188bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
189{
Paul Jakma1a392d42006-09-07 00:24:49 +0000190 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
191 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000192 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
193}
194
Paul Jakma1a392d42006-09-07 00:24:49 +0000195/* Adjust pcount as required */
196static void
197bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
198{
Paul Jakma6f585442006-10-22 19:13:07 +0000199 assert (rn && rn->table);
200 assert (ri && ri->peer && ri->peer->bgp);
201
Paul Jakma1a392d42006-09-07 00:24:49 +0000202 /* Ignore 'pcount' for RS-client tables */
203 if (rn->table->type != BGP_TABLE_MAIN
204 || ri->peer == ri->peer->bgp->peer_self)
205 return;
206
207 if (BGP_INFO_HOLDDOWN (ri)
208 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
209 {
210
211 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
212
213 /* slight hack, but more robust against errors. */
214 if (ri->peer->pcount[rn->table->afi][rn->table->safi])
215 ri->peer->pcount[rn->table->afi][rn->table->safi]--;
216 else
217 {
218 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
219 __func__, ri->peer->host);
220 zlog_backtrace (LOG_WARNING);
221 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
222 }
223 }
224 else if (!BGP_INFO_HOLDDOWN (ri)
225 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
226 {
227 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
228 ri->peer->pcount[rn->table->afi][rn->table->safi]++;
229 }
230}
231
232
233/* Set/unset bgp_info flags, adjusting any other state as needed.
234 * This is here primarily to keep prefix-count in check.
235 */
236void
237bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
238{
239 SET_FLAG (ri->flags, flag);
240
241 /* early bath if we know it's not a flag that changes useability state */
242 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
243 return;
244
245 bgp_pcount_adjust (rn, ri);
246}
247
248void
249bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
250{
251 UNSET_FLAG (ri->flags, flag);
252
253 /* early bath if we know it's not a flag that changes useability state */
254 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
255 return;
256
257 bgp_pcount_adjust (rn, ri);
258}
259
paul718e3742002-12-13 20:15:29 +0000260/* Get MED value. If MED value is missing and "bgp bestpath
261 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000262static u_int32_t
paul718e3742002-12-13 20:15:29 +0000263bgp_med_value (struct attr *attr, struct bgp *bgp)
264{
265 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
266 return attr->med;
267 else
268 {
269 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000270 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000271 else
272 return 0;
273 }
274}
275
276/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000277static int
paul718e3742002-12-13 20:15:29 +0000278bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
279{
280 u_int32_t new_pref;
281 u_int32_t exist_pref;
282 u_int32_t new_med;
283 u_int32_t exist_med;
284 struct in_addr new_id;
285 struct in_addr exist_id;
286 int new_cluster;
287 int exist_cluster;
288 int internal_as_route = 0;
289 int confed_as_route = 0;
290 int ret;
291
292 /* 0. Null check. */
293 if (new == NULL)
294 return 0;
295 if (exist == NULL)
296 return 1;
297
298 /* 1. Weight check. */
299 if (new->attr->weight > exist->attr->weight)
300 return 1;
301 if (new->attr->weight < exist->attr->weight)
302 return 0;
303
304 /* 2. Local preference check. */
305 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
306 new_pref = new->attr->local_pref;
307 else
308 new_pref = bgp->default_local_pref;
309
310 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
311 exist_pref = exist->attr->local_pref;
312 else
313 exist_pref = bgp->default_local_pref;
314
315 if (new_pref > exist_pref)
316 return 1;
317 if (new_pref < exist_pref)
318 return 0;
319
320 /* 3. Local route check. */
321 if (new->sub_type == BGP_ROUTE_STATIC)
322 return 1;
323 if (exist->sub_type == BGP_ROUTE_STATIC)
324 return 0;
325
326 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
327 return 1;
328 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
329 return 0;
330
331 if (new->sub_type == BGP_ROUTE_AGGREGATE)
332 return 1;
333 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
334 return 0;
335
336 /* 4. AS path length check. */
337 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
338 {
paulfe69a502005-09-10 16:55:02 +0000339 int exist_hops = aspath_count_hops (exist->attr->aspath);
340 int exist_confeds = aspath_count_confeds (exist->attr->aspath);
341
hasso68118452005-04-08 15:40:36 +0000342 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
343 {
paulfe69a502005-09-10 16:55:02 +0000344 int aspath_hops;
345
346 aspath_hops = aspath_count_hops (new->attr->aspath);
347 aspath_hops += aspath_count_confeds (new->attr->aspath);
348
349 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000350 return 1;
paulfe69a502005-09-10 16:55:02 +0000351 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000352 return 0;
353 }
354 else
355 {
paulfe69a502005-09-10 16:55:02 +0000356 int newhops = aspath_count_hops (new->attr->aspath);
357
358 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000359 return 1;
paulfe69a502005-09-10 16:55:02 +0000360 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000361 return 0;
362 }
paul718e3742002-12-13 20:15:29 +0000363 }
364
365 /* 5. Origin check. */
366 if (new->attr->origin < exist->attr->origin)
367 return 1;
368 if (new->attr->origin > exist->attr->origin)
369 return 0;
370
371 /* 6. MED check. */
paulfe69a502005-09-10 16:55:02 +0000372 internal_as_route = (aspath_count_hops (new->attr->aspath) == 0
373 && aspath_count_hops (exist->attr->aspath) == 0);
374 confed_as_route = (aspath_count_confeds (new->attr->aspath) > 0
375 && aspath_count_confeds (exist->attr->aspath) > 0
376 && aspath_count_hops (new->attr->aspath) == 0
377 && aspath_count_hops (exist->attr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000378
379 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
380 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
381 && confed_as_route)
382 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
383 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
384 || internal_as_route)
385 {
386 new_med = bgp_med_value (new->attr, bgp);
387 exist_med = bgp_med_value (exist->attr, bgp);
388
389 if (new_med < exist_med)
390 return 1;
391 if (new_med > exist_med)
392 return 0;
393 }
394
395 /* 7. Peer type check. */
396 if (peer_sort (new->peer) == BGP_PEER_EBGP
397 && peer_sort (exist->peer) == BGP_PEER_IBGP)
398 return 1;
399 if (peer_sort (new->peer) == BGP_PEER_EBGP
400 && peer_sort (exist->peer) == BGP_PEER_CONFED)
401 return 1;
402 if (peer_sort (new->peer) == BGP_PEER_IBGP
403 && peer_sort (exist->peer) == BGP_PEER_EBGP)
404 return 0;
405 if (peer_sort (new->peer) == BGP_PEER_CONFED
406 && peer_sort (exist->peer) == BGP_PEER_EBGP)
407 return 0;
408
409 /* 8. IGP metric check. */
410 if (new->igpmetric < exist->igpmetric)
411 return 1;
412 if (new->igpmetric > exist->igpmetric)
413 return 0;
414
415 /* 9. Maximum path check. */
416
417 /* 10. If both paths are external, prefer the path that was received
418 first (the oldest one). This step minimizes route-flap, since a
419 newer path won't displace an older one, even if it was the
420 preferred route based on the additional decision criteria below. */
421 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
422 && peer_sort (new->peer) == BGP_PEER_EBGP
423 && peer_sort (exist->peer) == BGP_PEER_EBGP)
424 {
425 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
426 return 1;
427 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
428 return 0;
429 }
430
431 /* 11. Rourter-ID comparision. */
432 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
433 new_id.s_addr = new->attr->originator_id.s_addr;
434 else
435 new_id.s_addr = new->peer->remote_id.s_addr;
436 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
437 exist_id.s_addr = exist->attr->originator_id.s_addr;
438 else
439 exist_id.s_addr = exist->peer->remote_id.s_addr;
440
441 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
442 return 1;
443 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
444 return 0;
445
446 /* 12. Cluster length comparision. */
447 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
448 new_cluster = new->attr->cluster->length;
449 else
450 new_cluster = 0;
451 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
452 exist_cluster = exist->attr->cluster->length;
453 else
454 exist_cluster = 0;
455
456 if (new_cluster < exist_cluster)
457 return 1;
458 if (new_cluster > exist_cluster)
459 return 0;
460
461 /* 13. Neighbor address comparision. */
462 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
463
464 if (ret == 1)
465 return 0;
466 if (ret == -1)
467 return 1;
468
469 return 1;
470}
471
paul94f2b392005-06-28 12:44:16 +0000472static enum filter_type
paul718e3742002-12-13 20:15:29 +0000473bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
474 afi_t afi, safi_t safi)
475{
476 struct bgp_filter *filter;
477
478 filter = &peer->filter[afi][safi];
479
480 if (DISTRIBUTE_IN_NAME (filter))
481 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
482 return FILTER_DENY;
483
484 if (PREFIX_LIST_IN_NAME (filter))
485 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
486 return FILTER_DENY;
487
488 if (FILTER_LIST_IN_NAME (filter))
489 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
490 return FILTER_DENY;
491
492 return FILTER_PERMIT;
493}
494
paul94f2b392005-06-28 12:44:16 +0000495static enum filter_type
paul718e3742002-12-13 20:15:29 +0000496bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
497 afi_t afi, safi_t safi)
498{
499 struct bgp_filter *filter;
500
501 filter = &peer->filter[afi][safi];
502
503 if (DISTRIBUTE_OUT_NAME (filter))
504 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
505 return FILTER_DENY;
506
507 if (PREFIX_LIST_OUT_NAME (filter))
508 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
509 return FILTER_DENY;
510
511 if (FILTER_LIST_OUT_NAME (filter))
512 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
513 return FILTER_DENY;
514
515 return FILTER_PERMIT;
516}
517
518/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000519static int
paul718e3742002-12-13 20:15:29 +0000520bgp_community_filter (struct peer *peer, struct attr *attr)
521{
522 if (attr->community)
523 {
524 /* NO_ADVERTISE check. */
525 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
526 return 1;
527
528 /* NO_EXPORT check. */
529 if (peer_sort (peer) == BGP_PEER_EBGP &&
530 community_include (attr->community, COMMUNITY_NO_EXPORT))
531 return 1;
532
533 /* NO_EXPORT_SUBCONFED check. */
534 if (peer_sort (peer) == BGP_PEER_EBGP
535 || peer_sort (peer) == BGP_PEER_CONFED)
536 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
537 return 1;
538 }
539 return 0;
540}
541
542/* Route reflection loop check. */
543static int
544bgp_cluster_filter (struct peer *peer, struct attr *attr)
545{
546 struct in_addr cluster_id;
547
548 if (attr->cluster)
549 {
550 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
551 cluster_id = peer->bgp->cluster_id;
552 else
553 cluster_id = peer->bgp->router_id;
554
555 if (cluster_loop_check (attr->cluster, cluster_id))
556 return 1;
557 }
558 return 0;
559}
560
paul94f2b392005-06-28 12:44:16 +0000561static int
paul718e3742002-12-13 20:15:29 +0000562bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
563 afi_t afi, safi_t safi)
564{
565 struct bgp_filter *filter;
566 struct bgp_info info;
567 route_map_result_t ret;
568
569 filter = &peer->filter[afi][safi];
570
571 /* Apply default weight value. */
572 attr->weight = peer->weight;
573
574 /* Route map apply. */
575 if (ROUTE_MAP_IN_NAME (filter))
576 {
577 /* Duplicate current value to new strucutre for modification. */
578 info.peer = peer;
579 info.attr = attr;
580
paulac41b2a2003-08-12 05:32:27 +0000581 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
582
paul718e3742002-12-13 20:15:29 +0000583 /* Apply BGP route map to the attribute. */
584 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000585
586 peer->rmap_type = 0;
587
paul718e3742002-12-13 20:15:29 +0000588 if (ret == RMAP_DENYMATCH)
589 {
590 /* Free newly generated AS path and community by route-map. */
591 bgp_attr_flush (attr);
592 return RMAP_DENY;
593 }
594 }
595 return RMAP_PERMIT;
596}
597
paul94f2b392005-06-28 12:44:16 +0000598static int
paulfee0f4c2004-09-13 05:12:46 +0000599bgp_export_modifier (struct peer *rsclient, struct peer *peer,
600 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
601{
602 struct bgp_filter *filter;
603 struct bgp_info info;
604 route_map_result_t ret;
605
606 filter = &peer->filter[afi][safi];
607
608 /* Route map apply. */
609 if (ROUTE_MAP_EXPORT_NAME (filter))
610 {
611 /* Duplicate current value to new strucutre for modification. */
612 info.peer = rsclient;
613 info.attr = attr;
614
615 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
616
617 /* Apply BGP route map to the attribute. */
618 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
619
620 rsclient->rmap_type = 0;
621
622 if (ret == RMAP_DENYMATCH)
623 {
624 /* Free newly generated AS path and community by route-map. */
625 bgp_attr_flush (attr);
626 return RMAP_DENY;
627 }
628 }
629 return RMAP_PERMIT;
630}
631
paul94f2b392005-06-28 12:44:16 +0000632static int
paulfee0f4c2004-09-13 05:12:46 +0000633bgp_import_modifier (struct peer *rsclient, struct peer *peer,
634 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
635{
636 struct bgp_filter *filter;
637 struct bgp_info info;
638 route_map_result_t ret;
639
640 filter = &rsclient->filter[afi][safi];
641
642 /* Apply default weight value. */
643 attr->weight = peer->weight;
644
645 /* Route map apply. */
646 if (ROUTE_MAP_IMPORT_NAME (filter))
647 {
648 /* Duplicate current value to new strucutre for modification. */
649 info.peer = peer;
650 info.attr = attr;
651
652 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
653
654 /* Apply BGP route map to the attribute. */
655 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
656
657 peer->rmap_type = 0;
658
659 if (ret == RMAP_DENYMATCH)
660 {
661 /* Free newly generated AS path and community by route-map. */
662 bgp_attr_flush (attr);
663 return RMAP_DENY;
664 }
665 }
666 return RMAP_PERMIT;
667}
668
paul94f2b392005-06-28 12:44:16 +0000669static int
paul718e3742002-12-13 20:15:29 +0000670bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
671 struct attr *attr, afi_t afi, safi_t safi)
672{
673 int ret;
674 char buf[SU_ADDRSTRLEN];
675 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000676 struct peer *from;
677 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000678 int transparent;
679 int reflect;
680
681 from = ri->peer;
682 filter = &peer->filter[afi][safi];
683 bgp = peer->bgp;
684
685#ifdef DISABLE_BGP_ANNOUNCE
686 return 0;
687#endif
688
paulfee0f4c2004-09-13 05:12:46 +0000689 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
690 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
691 return 0;
692
paul718e3742002-12-13 20:15:29 +0000693 /* Do not send back route to sender. */
694 if (from == peer)
695 return 0;
696
paul35be31b2004-05-01 18:17:04 +0000697 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
698 if (p->family == AF_INET
699 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
700 return 0;
701#ifdef HAVE_IPV6
702 if (p->family == AF_INET6
703 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
704 return 0;
705#endif
706
paul718e3742002-12-13 20:15:29 +0000707 /* Aggregate-address suppress check. */
708 if (ri->suppress)
709 if (! UNSUPPRESS_MAP_NAME (filter))
710 return 0;
711
712 /* Default route check. */
713 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
714 {
715 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
716 return 0;
717#ifdef HAVE_IPV6
718 else if (p->family == AF_INET6 && p->prefixlen == 0)
719 return 0;
720#endif /* HAVE_IPV6 */
721 }
722
paul286e1e72003-08-08 00:24:31 +0000723 /* Transparency check. */
724 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
725 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
726 transparent = 1;
727 else
728 transparent = 0;
729
paul718e3742002-12-13 20:15:29 +0000730 /* If community is not disabled check the no-export and local. */
paul286e1e72003-08-08 00:24:31 +0000731 if (! transparent && bgp_community_filter (peer, ri->attr))
paul718e3742002-12-13 20:15:29 +0000732 return 0;
733
734 /* If the attribute has originator-id and it is same as remote
735 peer's id. */
736 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
737 {
738 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->originator_id))
739 {
740 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000741 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000742 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
743 peer->host,
744 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
745 p->prefixlen);
746 return 0;
747 }
748 }
749
750 /* ORF prefix-list filter check */
751 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
752 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
753 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
754 if (peer->orf_plist[afi][safi])
755 {
756 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
757 return 0;
758 }
759
760 /* Output filter check. */
761 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
762 {
763 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000764 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000765 "%s [Update:SEND] %s/%d is filtered",
766 peer->host,
767 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
768 p->prefixlen);
769 return 0;
770 }
771
772#ifdef BGP_SEND_ASPATH_CHECK
773 /* AS path loop check. */
774 if (aspath_loop_check (ri->attr->aspath, peer->as))
775 {
776 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000777 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000778 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
779 peer->host, peer->as);
780 return 0;
781 }
782#endif /* BGP_SEND_ASPATH_CHECK */
783
784 /* If we're a CONFED we need to loop check the CONFED ID too */
785 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
786 {
787 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
788 {
789 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000790 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000791 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
792 peer->host,
793 bgp->confed_id);
794 return 0;
795 }
796 }
797
798 /* Route-Reflect check. */
799 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
800 reflect = 1;
801 else
802 reflect = 0;
803
804 /* IBGP reflection check. */
805 if (reflect)
806 {
807 /* A route from a Client peer. */
808 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
809 {
810 /* Reflect to all the Non-Client peers and also to the
811 Client peers other than the originator. Originator check
812 is already done. So there is noting to do. */
813 /* no bgp client-to-client reflection check. */
814 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
815 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
816 return 0;
817 }
818 else
819 {
820 /* A route from a Non-client peer. Reflect to all other
821 clients. */
822 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
823 return 0;
824 }
825 }
826
827 /* For modify attribute, copy it to temporary structure. */
828 *attr = *ri->attr;
829
830 /* If local-preference is not set. */
831 if ((peer_sort (peer) == BGP_PEER_IBGP
832 || peer_sort (peer) == BGP_PEER_CONFED)
833 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
834 {
835 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
836 attr->local_pref = bgp->default_local_pref;
837 }
838
paul718e3742002-12-13 20:15:29 +0000839 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
840 if (peer_sort (peer) == BGP_PEER_EBGP
841 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
842 {
843 if (ri->peer != bgp->peer_self && ! transparent
844 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
845 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
846 }
847
848 /* next-hop-set */
849 if (transparent || reflect
850 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
851 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000852#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000853 || (p->family == AF_INET6 &&
854 ! IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000855#endif /* HAVE_IPV6 */
856 )))
paul718e3742002-12-13 20:15:29 +0000857 {
858 /* NEXT-HOP Unchanged. */
859 }
860 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
861 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
862#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000863 || (p->family == AF_INET6 &&
864 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000865#endif /* HAVE_IPV6 */
866 || (peer_sort (peer) == BGP_PEER_EBGP
867 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
868 {
869 /* Set IPv4 nexthop. */
870 if (p->family == AF_INET)
871 {
872 if (safi == SAFI_MPLS_VPN)
873 memcpy (&attr->mp_nexthop_global_in, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
874 else
875 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
876 }
877#ifdef HAVE_IPV6
878 /* Set IPv6 nexthop. */
879 if (p->family == AF_INET6)
880 {
881 /* IPv6 global nexthop must be included. */
882 memcpy (&attr->mp_nexthop_global, &peer->nexthop.v6_global,
883 IPV6_MAX_BYTELEN);
884 attr->mp_nexthop_len = 16;
885 }
886#endif /* HAVE_IPV6 */
887 }
888
889#ifdef HAVE_IPV6
890 if (p->family == AF_INET6)
891 {
paulfee0f4c2004-09-13 05:12:46 +0000892 /* Left nexthop_local unchanged if so configured. */
893 if ( CHECK_FLAG (peer->af_flags[afi][safi],
894 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
895 {
896 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
897 attr->mp_nexthop_len=32;
898 else
899 attr->mp_nexthop_len=16;
900 }
901
902 /* Default nexthop_local treatment for non-RS-Clients */
903 else
904 {
paul718e3742002-12-13 20:15:29 +0000905 /* Link-local address should not be transit to different peer. */
906 attr->mp_nexthop_len = 16;
907
908 /* Set link-local address for shared network peer. */
909 if (peer->shared_network
910 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
911 {
912 memcpy (&attr->mp_nexthop_local, &peer->nexthop.v6_local,
913 IPV6_MAX_BYTELEN);
914 attr->mp_nexthop_len = 32;
915 }
916
917 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
918 address.*/
919 if (reflect)
920 attr->mp_nexthop_len = 16;
921
922 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
923 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
924 attr->mp_nexthop_len = 16;
925 }
paulfee0f4c2004-09-13 05:12:46 +0000926
927 }
paul718e3742002-12-13 20:15:29 +0000928#endif /* HAVE_IPV6 */
929
930 /* If this is EBGP peer and remove-private-AS is set. */
931 if (peer_sort (peer) == BGP_PEER_EBGP
932 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
933 && aspath_private_as_check (attr->aspath))
934 attr->aspath = aspath_empty_get ();
935
936 /* Route map & unsuppress-map apply. */
937 if (ROUTE_MAP_OUT_NAME (filter)
938 || ri->suppress)
939 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +0000940 struct bgp_info info;
941 struct attr dummy_attr;
942
paul718e3742002-12-13 20:15:29 +0000943 info.peer = peer;
944 info.attr = attr;
945
946 /* The route reflector is not allowed to modify the attributes
947 of the reflected IBGP routes. */
948 if (peer_sort (from) == BGP_PEER_IBGP
949 && peer_sort (peer) == BGP_PEER_IBGP)
950 {
951 dummy_attr = *attr;
952 info.attr = &dummy_attr;
953 }
paulac41b2a2003-08-12 05:32:27 +0000954
955 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
956
paul718e3742002-12-13 20:15:29 +0000957 if (ri->suppress)
958 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
959 else
960 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
961
paulac41b2a2003-08-12 05:32:27 +0000962 peer->rmap_type = 0;
963
paul718e3742002-12-13 20:15:29 +0000964 if (ret == RMAP_DENYMATCH)
965 {
966 bgp_attr_flush (attr);
967 return 0;
968 }
969 }
970 return 1;
971}
972
paul94f2b392005-06-28 12:44:16 +0000973static int
paulfee0f4c2004-09-13 05:12:46 +0000974bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
975 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000976{
paulfee0f4c2004-09-13 05:12:46 +0000977 int ret;
978 char buf[SU_ADDRSTRLEN];
979 struct bgp_filter *filter;
980 struct bgp_info info;
981 struct peer *from;
982 struct bgp *bgp;
983
984 from = ri->peer;
985 filter = &rsclient->filter[afi][safi];
986 bgp = rsclient->bgp;
987
988#ifdef DISABLE_BGP_ANNOUNCE
989 return 0;
990#endif
991
992 /* Do not send back route to sender. */
993 if (from == rsclient)
994 return 0;
995
996 /* Aggregate-address suppress check. */
997 if (ri->suppress)
998 if (! UNSUPPRESS_MAP_NAME (filter))
999 return 0;
1000
1001 /* Default route check. */
1002 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1003 PEER_STATUS_DEFAULT_ORIGINATE))
1004 {
1005 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1006 return 0;
1007#ifdef HAVE_IPV6
1008 else if (p->family == AF_INET6 && p->prefixlen == 0)
1009 return 0;
1010#endif /* HAVE_IPV6 */
1011 }
1012
1013 /* If the attribute has originator-id and it is same as remote
1014 peer's id. */
1015 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1016 {
1017 if (IPV4_ADDR_SAME (&rsclient->remote_id, &ri->attr->originator_id))
1018 {
1019 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001020 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001021 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1022 rsclient->host,
1023 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1024 p->prefixlen);
1025 return 0;
1026 }
1027 }
1028
1029 /* ORF prefix-list filter check */
1030 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1031 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1032 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1033 if (rsclient->orf_plist[afi][safi])
1034 {
1035 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1036 return 0;
1037 }
1038
1039 /* Output filter check. */
1040 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1041 {
1042 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001043 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001044 "%s [Update:SEND] %s/%d is filtered",
1045 rsclient->host,
1046 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1047 p->prefixlen);
1048 return 0;
1049 }
1050
1051#ifdef BGP_SEND_ASPATH_CHECK
1052 /* AS path loop check. */
1053 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1054 {
1055 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001056 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001057 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
1058 rsclient->host, rsclient->as);
1059 return 0;
1060 }
1061#endif /* BGP_SEND_ASPATH_CHECK */
1062
1063 /* For modify attribute, copy it to temporary structure. */
1064 *attr = *ri->attr;
1065
1066 /* next-hop-set */
1067 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1068#ifdef HAVE_IPV6
1069 || (p->family == AF_INET6 &&
1070 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
1071#endif /* HAVE_IPV6 */
1072 )
1073 {
1074 /* Set IPv4 nexthop. */
1075 if (p->family == AF_INET)
1076 {
1077 if (safi == SAFI_MPLS_VPN)
1078 memcpy (&attr->mp_nexthop_global_in, &rsclient->nexthop.v4,
1079 IPV4_MAX_BYTELEN);
1080 else
1081 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1082 }
1083#ifdef HAVE_IPV6
1084 /* Set IPv6 nexthop. */
1085 if (p->family == AF_INET6)
1086 {
1087 /* IPv6 global nexthop must be included. */
1088 memcpy (&attr->mp_nexthop_global, &rsclient->nexthop.v6_global,
1089
1090 IPV6_MAX_BYTELEN);
1091 attr->mp_nexthop_len = 16;
1092 }
1093#endif /* HAVE_IPV6 */
1094 }
1095
1096#ifdef HAVE_IPV6
1097 if (p->family == AF_INET6)
1098 {
1099 /* Left nexthop_local unchanged if so configured. */
1100 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1101 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1102 {
1103 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1104 attr->mp_nexthop_len=32;
1105 else
1106 attr->mp_nexthop_len=16;
1107 }
1108
1109 /* Default nexthop_local treatment for RS-Clients */
1110 else
1111 {
1112 /* Announcer and RS-Client are both in the same network */
1113 if (rsclient->shared_network && from->shared_network &&
1114 (rsclient->ifindex == from->ifindex))
1115 {
1116 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1117 attr->mp_nexthop_len=32;
1118 else
1119 attr->mp_nexthop_len=16;
1120 }
1121
1122 /* Set link-local address for shared network peer. */
1123 else if (rsclient->shared_network
1124 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1125 {
1126 memcpy (&attr->mp_nexthop_local, &rsclient->nexthop.v6_local,
1127 IPV6_MAX_BYTELEN);
1128 attr->mp_nexthop_len = 32;
1129 }
1130
1131 else
1132 attr->mp_nexthop_len = 16;
1133 }
1134
1135 }
1136#endif /* HAVE_IPV6 */
1137
1138
1139 /* If this is EBGP peer and remove-private-AS is set. */
1140 if (peer_sort (rsclient) == BGP_PEER_EBGP
1141 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1142 && aspath_private_as_check (attr->aspath))
1143 attr->aspath = aspath_empty_get ();
1144
1145 /* Route map & unsuppress-map apply. */
1146 if (ROUTE_MAP_OUT_NAME (filter) || ri->suppress)
1147 {
1148 info.peer = rsclient;
1149 info.attr = attr;
1150
1151 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1152
1153 if (ri->suppress)
1154 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1155 else
1156 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1157
1158 rsclient->rmap_type = 0;
1159
1160 if (ret == RMAP_DENYMATCH)
1161 {
1162 bgp_attr_flush (attr);
1163 return 0;
1164 }
1165 }
1166
1167 return 1;
1168}
1169
1170struct bgp_info_pair
1171{
1172 struct bgp_info *old;
1173 struct bgp_info *new;
1174};
1175
paul94f2b392005-06-28 12:44:16 +00001176static void
paulfee0f4c2004-09-13 05:12:46 +00001177bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1178{
paul718e3742002-12-13 20:15:29 +00001179 struct bgp_info *new_select;
1180 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001181 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001182 struct bgp_info *ri1;
1183 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001184 struct bgp_info *nextri = NULL;
1185
paul718e3742002-12-13 20:15:29 +00001186 /* bgp deterministic-med */
1187 new_select = NULL;
1188 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1189 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1190 {
1191 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1192 continue;
1193 if (BGP_INFO_HOLDDOWN (ri1))
1194 continue;
1195
1196 new_select = ri1;
1197 if (ri1->next)
1198 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1199 {
1200 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1201 continue;
1202 if (BGP_INFO_HOLDDOWN (ri2))
1203 continue;
1204
1205 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1206 || aspath_cmp_left_confed (ri1->attr->aspath,
1207 ri2->attr->aspath))
1208 {
1209 if (bgp_info_cmp (bgp, ri2, new_select))
1210 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001211 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001212 new_select = ri2;
1213 }
1214
Paul Jakma1a392d42006-09-07 00:24:49 +00001215 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001216 }
1217 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001218 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1219 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001220 }
1221
1222 /* Check old selected route and new selected route. */
1223 old_select = NULL;
1224 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001225 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001226 {
1227 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1228 old_select = ri;
1229
1230 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001231 {
1232 /* reap REMOVED routes, if needs be
1233 * selected route must stay for a while longer though
1234 */
1235 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1236 && (ri != old_select))
1237 bgp_info_reap (rn, ri);
1238
1239 continue;
1240 }
paul718e3742002-12-13 20:15:29 +00001241
1242 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1243 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1244 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001245 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001246 continue;
1247 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001248 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1249 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001250
1251 if (bgp_info_cmp (bgp, ri, new_select))
1252 new_select = ri;
1253 }
paulb40d9392005-08-22 22:34:41 +00001254
paulfee0f4c2004-09-13 05:12:46 +00001255 result->old = old_select;
1256 result->new = new_select;
1257
1258 return;
1259}
1260
paul94f2b392005-06-28 12:44:16 +00001261static int
paulfee0f4c2004-09-13 05:12:46 +00001262bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1263 struct bgp_node *rn, struct attr *attr, afi_t afi, safi_t safi)
1264 {
1265 struct prefix *p;
1266
1267 p = &rn->p;
1268
1269 /* Announce route to Established peer. */
1270 if (peer->status != Established)
1271 return 0;
1272
1273 /* Address family configuration check. */
1274 if (! peer->afc_nego[afi][safi])
1275 return 0;
1276
1277 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1278 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1279 PEER_STATUS_ORF_WAIT_REFRESH))
1280 return 0;
1281
1282 switch (rn->table->type)
1283 {
1284 case BGP_TABLE_MAIN:
1285 /* Announcement to peer->conf. If the route is filtered,
1286 withdraw it. */
1287 if (selected && bgp_announce_check (selected, peer, p, attr, afi, safi))
1288 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1289 else
1290 bgp_adj_out_unset (rn, peer, p, afi, safi);
1291 break;
1292 case BGP_TABLE_RSCLIENT:
1293 /* Announcement to peer->conf. If the route is filtered,
1294 withdraw it. */
1295 if (selected && bgp_announce_check_rsclient
1296 (selected, peer, p, attr, afi, safi))
1297 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1298 else
1299 bgp_adj_out_unset (rn, peer, p, afi, safi);
1300 break;
1301 }
1302 return 0;
paul200df112005-06-01 11:17:05 +00001303}
paulfee0f4c2004-09-13 05:12:46 +00001304
paul200df112005-06-01 11:17:05 +00001305struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001306{
paul200df112005-06-01 11:17:05 +00001307 struct bgp *bgp;
1308 struct bgp_node *rn;
1309 afi_t afi;
1310 safi_t safi;
1311};
1312
1313static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001314bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001315{
paul0fb58d52005-11-14 14:31:49 +00001316 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001317 struct bgp *bgp = pq->bgp;
1318 struct bgp_node *rn = pq->rn;
1319 afi_t afi = pq->afi;
1320 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001321 struct bgp_info *new_select;
1322 struct bgp_info *old_select;
1323 struct bgp_info_pair old_and_new;
1324 struct attr attr;
paul1eb8ef22005-04-07 07:30:20 +00001325 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001326 struct peer *rsclient = rn->table->owner;
1327
paulfee0f4c2004-09-13 05:12:46 +00001328 /* Best path selection. */
1329 bgp_best_selection (bgp, rn, &old_and_new);
1330 new_select = old_and_new.new;
1331 old_select = old_and_new.old;
1332
paul200df112005-06-01 11:17:05 +00001333 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1334 {
1335 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1336 {
1337 /* Nothing to do. */
1338 if (old_select && old_select == new_select)
1339 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1340 continue;
paulfee0f4c2004-09-13 05:12:46 +00001341
paul200df112005-06-01 11:17:05 +00001342 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001343 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
paul200df112005-06-01 11:17:05 +00001344 if (new_select)
1345 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001346 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1347 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
paul200df112005-06-01 11:17:05 +00001348 }
paulfee0f4c2004-09-13 05:12:46 +00001349
paul200df112005-06-01 11:17:05 +00001350 bgp_process_announce_selected (rsclient, new_select, rn, &attr,
1351 afi, safi);
1352 }
1353 }
1354 else
1355 {
hassob7395792005-08-26 12:58:38 +00001356 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001357 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001358 if (new_select)
1359 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001360 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1361 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hassob7395792005-08-26 12:58:38 +00001362 }
paul200df112005-06-01 11:17:05 +00001363 bgp_process_announce_selected (rsclient, new_select, rn,
1364 &attr, afi, safi);
1365 }
paulfee0f4c2004-09-13 05:12:46 +00001366
paulb40d9392005-08-22 22:34:41 +00001367 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1368 bgp_info_reap (rn, old_select);
1369
paul200df112005-06-01 11:17:05 +00001370 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1371 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001372}
1373
paul200df112005-06-01 11:17:05 +00001374static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001375bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001376{
paul0fb58d52005-11-14 14:31:49 +00001377 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001378 struct bgp *bgp = pq->bgp;
1379 struct bgp_node *rn = pq->rn;
1380 afi_t afi = pq->afi;
1381 safi_t safi = pq->safi;
1382 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001383 struct bgp_info *new_select;
1384 struct bgp_info *old_select;
1385 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001386 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001387 struct peer *peer;
1388 struct attr attr;
paul200df112005-06-01 11:17:05 +00001389
paulfee0f4c2004-09-13 05:12:46 +00001390 /* Best path selection. */
1391 bgp_best_selection (bgp, rn, &old_and_new);
1392 old_select = old_and_new.old;
1393 new_select = old_and_new.new;
1394
1395 /* Nothing to do. */
1396 if (old_select && old_select == new_select)
1397 {
1398 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001399 {
1400 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1401 bgp_zebra_announce (p, old_select, bgp);
1402
1403 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1404 return WQ_SUCCESS;
1405 }
paulfee0f4c2004-09-13 05:12:46 +00001406 }
paul718e3742002-12-13 20:15:29 +00001407
hasso338b3422005-02-23 14:27:24 +00001408 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001409 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001410 if (new_select)
1411 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001412 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1413 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hasso338b3422005-02-23 14:27:24 +00001414 }
1415
1416
paul718e3742002-12-13 20:15:29 +00001417 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001418 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001419 {
paulfee0f4c2004-09-13 05:12:46 +00001420 bgp_process_announce_selected (peer, new_select, rn, &attr, afi, safi);
paul718e3742002-12-13 20:15:29 +00001421 }
1422
1423 /* FIB update. */
1424 if (safi == SAFI_UNICAST && ! bgp->name &&
1425 ! bgp_option_check (BGP_OPT_NO_FIB))
1426 {
1427 if (new_select
1428 && new_select->type == ZEBRA_ROUTE_BGP
1429 && new_select->sub_type == BGP_ROUTE_NORMAL)
1430 bgp_zebra_announce (p, new_select, bgp);
1431 else
1432 {
1433 /* Withdraw the route from the kernel. */
1434 if (old_select
1435 && old_select->type == ZEBRA_ROUTE_BGP
1436 && old_select->sub_type == BGP_ROUTE_NORMAL)
1437 bgp_zebra_withdraw (p, old_select);
1438 }
1439 }
paulb40d9392005-08-22 22:34:41 +00001440
1441 /* Reap old select bgp_info, it it has been removed */
1442 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1443 bgp_info_reap (rn, old_select);
1444
paul200df112005-06-01 11:17:05 +00001445 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1446 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001447}
1448
paul200df112005-06-01 11:17:05 +00001449static void
paul0fb58d52005-11-14 14:31:49 +00001450bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001451{
paul0fb58d52005-11-14 14:31:49 +00001452 struct bgp_process_queue *pq = data;
1453
paul200df112005-06-01 11:17:05 +00001454 bgp_unlock_node (pq->rn);
1455 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1456}
1457
1458static void
1459bgp_process_queue_init (void)
1460{
1461 bm->process_main_queue
1462 = work_queue_new (bm->master, "process_main_queue");
1463 bm->process_rsclient_queue
1464 = work_queue_new (bm->master, "process_rsclient_queue");
1465
1466 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1467 {
1468 zlog_err ("%s: Failed to allocate work queue", __func__);
1469 exit (1);
1470 }
1471
1472 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1473 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1474 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1475 bm->process_rsclient_queue->spec.del_item_data
1476 = bm->process_main_queue->spec.del_item_data;
1477 bm->process_main_queue->spec.max_retries
1478 = bm->process_main_queue->spec.max_retries = 0;
1479 bm->process_rsclient_queue->spec.hold
Paul Jakma09dd5612006-09-14 03:38:16 +00001480 = bm->process_main_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001481}
1482
1483void
paulfee0f4c2004-09-13 05:12:46 +00001484bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1485{
paul200df112005-06-01 11:17:05 +00001486 struct bgp_process_queue *pqnode;
1487
1488 /* already scheduled for processing? */
1489 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1490 return;
1491
1492 if ( (bm->process_main_queue == NULL) ||
1493 (bm->process_rsclient_queue == NULL) )
1494 bgp_process_queue_init ();
1495
1496 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1497 sizeof (struct bgp_process_queue));
1498 if (!pqnode)
1499 return;
1500
1501 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1502 pqnode->bgp = bgp;
1503 pqnode->afi = afi;
1504 pqnode->safi = safi;
1505
paulfee0f4c2004-09-13 05:12:46 +00001506 switch (rn->table->type)
1507 {
paul200df112005-06-01 11:17:05 +00001508 case BGP_TABLE_MAIN:
1509 work_queue_add (bm->process_main_queue, pqnode);
1510 break;
1511 case BGP_TABLE_RSCLIENT:
1512 work_queue_add (bm->process_rsclient_queue, pqnode);
1513 break;
paulfee0f4c2004-09-13 05:12:46 +00001514 }
paul200df112005-06-01 11:17:05 +00001515
1516 return;
paulfee0f4c2004-09-13 05:12:46 +00001517}
hasso0a486e52005-02-01 20:57:17 +00001518
paul94f2b392005-06-28 12:44:16 +00001519static int
hasso0a486e52005-02-01 20:57:17 +00001520bgp_maximum_prefix_restart_timer (struct thread *thread)
1521{
1522 struct peer *peer;
1523
1524 peer = THREAD_ARG (thread);
1525 peer->t_pmax_restart = NULL;
1526
1527 if (BGP_DEBUG (events, EVENTS))
1528 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1529 peer->host);
1530
1531 peer_clear (peer);
1532
1533 return 0;
1534}
1535
paulfee0f4c2004-09-13 05:12:46 +00001536int
paul5228ad22004-06-04 17:58:18 +00001537bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1538 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001539{
hassoe0701b72004-05-20 09:19:34 +00001540 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1541 return 0;
1542
1543 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001544 {
hassoe0701b72004-05-20 09:19:34 +00001545 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1546 && ! always)
1547 return 0;
paul718e3742002-12-13 20:15:29 +00001548
hassoe0701b72004-05-20 09:19:34 +00001549 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001550 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1551 "limit %ld", afi_safi_print (afi, safi), peer->host,
1552 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001553 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001554
hassoe0701b72004-05-20 09:19:34 +00001555 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1556 return 0;
paul718e3742002-12-13 20:15:29 +00001557
hassoe0701b72004-05-20 09:19:34 +00001558 {
paul5228ad22004-06-04 17:58:18 +00001559 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001560
1561 if (safi == SAFI_MPLS_VPN)
1562 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001563
1564 ndata[0] = (afi >> 8);
1565 ndata[1] = afi;
1566 ndata[2] = safi;
1567 ndata[3] = (peer->pmax[afi][safi] >> 24);
1568 ndata[4] = (peer->pmax[afi][safi] >> 16);
1569 ndata[5] = (peer->pmax[afi][safi] >> 8);
1570 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001571
1572 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1573 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1574 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1575 }
hasso0a486e52005-02-01 20:57:17 +00001576
1577 /* restart timer start */
1578 if (peer->pmax_restart[afi][safi])
1579 {
1580 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1581
1582 if (BGP_DEBUG (events, EVENTS))
1583 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1584 peer->host, peer->v_pmax_restart);
1585
1586 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1587 peer->v_pmax_restart);
1588 }
1589
hassoe0701b72004-05-20 09:19:34 +00001590 return 1;
paul718e3742002-12-13 20:15:29 +00001591 }
hassoe0701b72004-05-20 09:19:34 +00001592 else
1593 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1594
1595 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1596 {
1597 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1598 && ! always)
1599 return 0;
1600
1601 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001602 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1603 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1604 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001605 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1606 }
1607 else
1608 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001609 return 0;
1610}
1611
paulb40d9392005-08-22 22:34:41 +00001612/* Unconditionally remove the route from the RIB, without taking
1613 * damping into consideration (eg, because the session went down)
1614 */
paul94f2b392005-06-28 12:44:16 +00001615static void
paul718e3742002-12-13 20:15:29 +00001616bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1617 afi_t afi, safi_t safi)
1618{
paul902212c2006-02-05 17:51:19 +00001619 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1620
1621 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1622 bgp_info_delete (rn, ri); /* keep historical info */
1623
paulb40d9392005-08-22 22:34:41 +00001624 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001625}
1626
paul94f2b392005-06-28 12:44:16 +00001627static void
paul718e3742002-12-13 20:15:29 +00001628bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001629 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001630{
paul718e3742002-12-13 20:15:29 +00001631 int status = BGP_DAMP_NONE;
1632
paulb40d9392005-08-22 22:34:41 +00001633 /* apply dampening, if result is suppressed, we'll be retaining
1634 * the bgp_info in the RIB for historical reference.
1635 */
1636 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1637 && peer_sort (peer) == BGP_PEER_EBGP)
1638 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1639 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001640 {
paul902212c2006-02-05 17:51:19 +00001641 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1642 return;
1643 }
1644
1645 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001646}
1647
paul94f2b392005-06-28 12:44:16 +00001648static void
paulfee0f4c2004-09-13 05:12:46 +00001649bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1650 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1651 int sub_type, struct prefix_rd *prd, u_char *tag)
1652{
1653 struct bgp_node *rn;
1654 struct bgp *bgp;
1655 struct attr new_attr;
1656 struct attr *attr_new;
1657 struct attr *attr_new2;
1658 struct bgp_info *ri;
1659 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001660 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001661 char buf[SU_ADDRSTRLEN];
1662
1663 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1664 if (peer == rsclient)
1665 return;
1666
1667 bgp = peer->bgp;
1668 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1669
1670 /* Check previously received route. */
1671 for (ri = rn->info; ri; ri = ri->next)
1672 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1673 break;
1674
1675 /* AS path loop check. */
1676 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1677 {
1678 reason = "as-path contains our own AS;";
1679 goto filtered;
1680 }
1681
1682 /* Route reflector originator ID check. */
1683 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1684 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->originator_id))
1685 {
1686 reason = "originator is us;";
1687 goto filtered;
1688 }
1689
1690 new_attr = *attr;
1691
1692 /* Apply export policy. */
1693 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1694 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1695 {
1696 reason = "export-policy;";
1697 goto filtered;
1698 }
1699
1700 attr_new2 = bgp_attr_intern (&new_attr);
1701
1702 /* Apply import policy. */
1703 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1704 {
1705 bgp_attr_unintern (attr_new2);
1706
1707 reason = "import-policy;";
1708 goto filtered;
1709 }
1710
1711 attr_new = bgp_attr_intern (&new_attr);
1712 bgp_attr_unintern (attr_new2);
1713
1714 /* IPv4 unicast next hop check. */
1715 if (afi == AFI_IP && safi == SAFI_UNICAST)
1716 {
1717 /* Next hop must not be 0.0.0.0 nor Class E address. */
1718 if (new_attr.nexthop.s_addr == 0
1719 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1720 {
1721 bgp_attr_unintern (attr_new);
1722
1723 reason = "martian next-hop;";
1724 goto filtered;
1725 }
1726 }
1727
1728 /* If the update is implicit withdraw. */
1729 if (ri)
1730 {
1731 ri->uptime = time (NULL);
1732
1733 /* Same attribute comes in. */
1734 if (attrhash_cmp (ri->attr, attr_new))
1735 {
1736
Paul Jakma1a392d42006-09-07 00:24:49 +00001737 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001738
1739 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001740 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001741 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1742 peer->host,
1743 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1744 p->prefixlen, rsclient->host);
1745
1746 bgp_unlock_node (rn);
1747 bgp_attr_unintern (attr_new);
1748
1749 return;
1750 }
1751
1752 /* Received Logging. */
1753 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001754 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001755 peer->host,
1756 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1757 p->prefixlen, rsclient->host);
1758
1759 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001760 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001761
1762 /* Update to new attribute. */
1763 bgp_attr_unintern (ri->attr);
1764 ri->attr = attr_new;
1765
1766 /* Update MPLS tag. */
1767 if (safi == SAFI_MPLS_VPN)
1768 memcpy (ri->tag, tag, 3);
1769
Paul Jakma1a392d42006-09-07 00:24:49 +00001770 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001771
1772 /* Process change. */
1773 bgp_process (bgp, rn, afi, safi);
1774 bgp_unlock_node (rn);
1775
1776 return;
1777 }
1778
1779 /* Received Logging. */
1780 if (BGP_DEBUG (update, UPDATE_IN))
1781 {
ajsd2c1f162004-12-08 21:10:20 +00001782 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001783 peer->host,
1784 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1785 p->prefixlen, rsclient->host);
1786 }
1787
1788 /* Make new BGP info. */
1789 new = bgp_info_new ();
1790 new->type = type;
1791 new->sub_type = sub_type;
1792 new->peer = peer;
1793 new->attr = attr_new;
1794 new->uptime = time (NULL);
1795
1796 /* Update MPLS tag. */
1797 if (safi == SAFI_MPLS_VPN)
1798 memcpy (new->tag, tag, 3);
1799
Paul Jakma1a392d42006-09-07 00:24:49 +00001800 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001801
1802 /* Register new BGP information. */
1803 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001804
1805 /* route_node_get lock */
1806 bgp_unlock_node (rn);
1807
paulfee0f4c2004-09-13 05:12:46 +00001808 /* Process change. */
1809 bgp_process (bgp, rn, afi, safi);
1810
1811 return;
1812
1813 filtered:
1814
1815 /* This BGP update is filtered. Log the reason then update BGP entry. */
1816 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001817 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001818 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1819 peer->host,
1820 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1821 p->prefixlen, rsclient->host, reason);
1822
1823 if (ri)
paulb40d9392005-08-22 22:34:41 +00001824 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001825
1826 bgp_unlock_node (rn);
1827
1828 return;
1829}
1830
paul94f2b392005-06-28 12:44:16 +00001831static void
paulfee0f4c2004-09-13 05:12:46 +00001832bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1833 struct peer *peer, struct prefix *p, int type, int sub_type,
1834 struct prefix_rd *prd, u_char *tag)
1835 {
1836 struct bgp_node *rn;
1837 struct bgp_info *ri;
1838 char buf[SU_ADDRSTRLEN];
1839
1840 if (rsclient == peer)
1841 return;
1842
1843 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1844
1845 /* Lookup withdrawn route. */
1846 for (ri = rn->info; ri; ri = ri->next)
1847 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1848 break;
1849
1850 /* Withdraw specified route from routing table. */
1851 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001852 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001853 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001854 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001855 "%s Can't find the route %s/%d", peer->host,
1856 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1857 p->prefixlen);
1858
1859 /* Unlock bgp_node_get() lock. */
1860 bgp_unlock_node (rn);
1861 }
1862
paul94f2b392005-06-28 12:44:16 +00001863static int
paulfee0f4c2004-09-13 05:12:46 +00001864bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001865 afi_t afi, safi_t safi, int type, int sub_type,
1866 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1867{
1868 int ret;
1869 int aspath_loop_count = 0;
1870 struct bgp_node *rn;
1871 struct bgp *bgp;
1872 struct attr new_attr;
1873 struct attr *attr_new;
1874 struct bgp_info *ri;
1875 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001876 const char *reason;
paul718e3742002-12-13 20:15:29 +00001877 char buf[SU_ADDRSTRLEN];
1878
1879 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00001880 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00001881
1882 /* When peer's soft reconfiguration enabled. Record input packet in
1883 Adj-RIBs-In. */
1884 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1885 && peer != bgp->peer_self && ! soft_reconfig)
1886 bgp_adj_in_set (rn, peer, attr);
1887
1888 /* Check previously received route. */
1889 for (ri = rn->info; ri; ri = ri->next)
1890 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1891 break;
1892
1893 /* AS path local-as loop check. */
1894 if (peer->change_local_as)
1895 {
1896 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
1897 aspath_loop_count = 1;
1898
1899 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
1900 {
1901 reason = "as-path contains our own AS;";
1902 goto filtered;
1903 }
1904 }
1905
1906 /* AS path loop check. */
1907 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
1908 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
1909 && aspath_loop_check(attr->aspath, bgp->confed_id)
1910 > peer->allowas_in[afi][safi]))
1911 {
1912 reason = "as-path contains our own AS;";
1913 goto filtered;
1914 }
1915
1916 /* Route reflector originator ID check. */
1917 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1918 && IPV4_ADDR_SAME (&bgp->router_id, &attr->originator_id))
1919 {
1920 reason = "originator is us;";
1921 goto filtered;
1922 }
1923
1924 /* Route reflector cluster ID check. */
1925 if (bgp_cluster_filter (peer, attr))
1926 {
1927 reason = "reflected from the same cluster;";
1928 goto filtered;
1929 }
1930
1931 /* Apply incoming filter. */
1932 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
1933 {
1934 reason = "filter;";
1935 goto filtered;
1936 }
1937
1938 /* Apply incoming route-map. */
1939 new_attr = *attr;
1940
1941 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
1942 {
1943 reason = "route-map;";
1944 goto filtered;
1945 }
1946
1947 /* IPv4 unicast next hop check. */
1948 if (afi == AFI_IP && safi == SAFI_UNICAST)
1949 {
1950 /* If the peer is EBGP and nexthop is not on connected route,
1951 discard it. */
1952 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
1953 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00001954 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00001955 {
1956 reason = "non-connected next-hop;";
1957 goto filtered;
1958 }
1959
1960 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
1961 must not be my own address. */
1962 if (bgp_nexthop_self (afi, &new_attr)
1963 || new_attr.nexthop.s_addr == 0
1964 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1965 {
1966 reason = "martian next-hop;";
1967 goto filtered;
1968 }
1969 }
1970
1971 attr_new = bgp_attr_intern (&new_attr);
1972
1973 /* If the update is implicit withdraw. */
1974 if (ri)
1975 {
1976 ri->uptime = time (NULL);
1977
1978 /* Same attribute comes in. */
1979 if (attrhash_cmp (ri->attr, attr_new))
1980 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001981 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00001982
1983 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1984 && peer_sort (peer) == BGP_PEER_EBGP
1985 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1986 {
1987 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001988 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00001989 peer->host,
1990 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1991 p->prefixlen);
1992
paul902212c2006-02-05 17:51:19 +00001993 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
1994 {
1995 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1996 bgp_process (bgp, rn, afi, safi);
1997 }
paul718e3742002-12-13 20:15:29 +00001998 }
1999 else
2000 {
2001 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002002 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002003 "%s rcvd %s/%d...duplicate ignored",
2004 peer->host,
2005 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2006 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002007
2008 /* graceful restart STALE flag unset. */
2009 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2010 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002011 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002012 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002013 }
paul718e3742002-12-13 20:15:29 +00002014 }
2015
2016 bgp_unlock_node (rn);
2017 bgp_attr_unintern (attr_new);
2018 return 0;
2019 }
2020
2021 /* Received Logging. */
2022 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002023 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002024 peer->host,
2025 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2026 p->prefixlen);
2027
hasso93406d82005-02-02 14:40:33 +00002028 /* graceful restart STALE flag unset. */
2029 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002030 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002031
paul718e3742002-12-13 20:15:29 +00002032 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002033 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002034
2035 /* implicit withdraw, decrement aggregate and pcount here.
2036 * only if update is accepted, they'll increment below.
2037 */
paul902212c2006-02-05 17:51:19 +00002038 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2039
paul718e3742002-12-13 20:15:29 +00002040 /* Update bgp route dampening information. */
2041 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2042 && peer_sort (peer) == BGP_PEER_EBGP)
2043 {
2044 /* This is implicit withdraw so we should update dampening
2045 information. */
2046 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2047 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002048 }
2049
paul718e3742002-12-13 20:15:29 +00002050 /* Update to new attribute. */
2051 bgp_attr_unintern (ri->attr);
2052 ri->attr = attr_new;
2053
2054 /* Update MPLS tag. */
2055 if (safi == SAFI_MPLS_VPN)
2056 memcpy (ri->tag, tag, 3);
2057
2058 /* Update bgp route dampening information. */
2059 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2060 && peer_sort (peer) == BGP_PEER_EBGP)
2061 {
2062 /* Now we do normal update dampening. */
2063 ret = bgp_damp_update (ri, rn, afi, safi);
2064 if (ret == BGP_DAMP_SUPPRESSED)
2065 {
2066 bgp_unlock_node (rn);
2067 return 0;
2068 }
2069 }
2070
2071 /* Nexthop reachability check. */
2072 if ((afi == AFI_IP || afi == AFI_IP6)
2073 && safi == SAFI_UNICAST
2074 && (peer_sort (peer) == BGP_PEER_IBGP
2075 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002076 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002077 {
2078 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002079 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002080 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002081 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002082 }
2083 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002084 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002085
2086 /* Process change. */
2087 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2088
2089 bgp_process (bgp, rn, afi, safi);
2090 bgp_unlock_node (rn);
2091 return 0;
2092 }
2093
2094 /* Received Logging. */
2095 if (BGP_DEBUG (update, UPDATE_IN))
2096 {
ajsd2c1f162004-12-08 21:10:20 +00002097 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002098 peer->host,
2099 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2100 p->prefixlen);
2101 }
2102
paul718e3742002-12-13 20:15:29 +00002103 /* Make new BGP info. */
2104 new = bgp_info_new ();
2105 new->type = type;
2106 new->sub_type = sub_type;
2107 new->peer = peer;
2108 new->attr = attr_new;
2109 new->uptime = time (NULL);
2110
2111 /* Update MPLS tag. */
2112 if (safi == SAFI_MPLS_VPN)
2113 memcpy (new->tag, tag, 3);
2114
2115 /* Nexthop reachability check. */
2116 if ((afi == AFI_IP || afi == AFI_IP6)
2117 && safi == SAFI_UNICAST
2118 && (peer_sort (peer) == BGP_PEER_IBGP
2119 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002120 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002121 {
2122 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002123 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002124 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002125 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002126 }
2127 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002128 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002129
paul902212c2006-02-05 17:51:19 +00002130 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002131 bgp_aggregate_increment (bgp, p, new, afi, safi);
2132
2133 /* Register new BGP information. */
2134 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002135
2136 /* route_node_get lock */
2137 bgp_unlock_node (rn);
2138
paul718e3742002-12-13 20:15:29 +00002139 /* If maximum prefix count is configured and current prefix
2140 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002141 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2142 return -1;
paul718e3742002-12-13 20:15:29 +00002143
2144 /* Process change. */
2145 bgp_process (bgp, rn, afi, safi);
2146
2147 return 0;
2148
2149 /* This BGP update is filtered. Log the reason then update BGP
2150 entry. */
2151 filtered:
2152 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002153 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002154 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2155 peer->host,
2156 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2157 p->prefixlen, reason);
2158
2159 if (ri)
paulb40d9392005-08-22 22:34:41 +00002160 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002161
2162 bgp_unlock_node (rn);
2163
2164 return 0;
2165}
2166
2167int
paulfee0f4c2004-09-13 05:12:46 +00002168bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2169 afi_t afi, safi_t safi, int type, int sub_type,
2170 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2171{
2172 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002173 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002174 struct bgp *bgp;
2175 int ret;
2176
2177 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2178 soft_reconfig);
2179
2180 bgp = peer->bgp;
2181
2182 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002183 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002184 {
2185 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2186 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2187 sub_type, prd, tag);
2188 }
2189
2190 return ret;
2191}
2192
2193int
paul718e3742002-12-13 20:15:29 +00002194bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002195 afi_t afi, safi_t safi, int type, int sub_type,
2196 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002197{
2198 struct bgp *bgp;
2199 char buf[SU_ADDRSTRLEN];
2200 struct bgp_node *rn;
2201 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002202 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002203 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002204
2205 bgp = peer->bgp;
2206
paulfee0f4c2004-09-13 05:12:46 +00002207 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002208 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002209 {
2210 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2211 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2212 }
2213
paul718e3742002-12-13 20:15:29 +00002214 /* Logging. */
2215 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002216 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002217 peer->host,
2218 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2219 p->prefixlen);
2220
2221 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002222 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002223
2224 /* If peer is soft reconfiguration enabled. Record input packet for
2225 further calculation. */
2226 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2227 && peer != bgp->peer_self)
2228 bgp_adj_in_unset (rn, peer);
2229
2230 /* Lookup withdrawn route. */
2231 for (ri = rn->info; ri; ri = ri->next)
2232 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2233 break;
2234
2235 /* Withdraw specified route from routing table. */
2236 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002237 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002238 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002239 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002240 "%s Can't find the route %s/%d", peer->host,
2241 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2242 p->prefixlen);
2243
2244 /* Unlock bgp_node_get() lock. */
2245 bgp_unlock_node (rn);
2246
2247 return 0;
2248}
2249
2250void
2251bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2252{
2253 struct bgp *bgp;
2254 struct attr attr;
2255 struct aspath *aspath;
2256 struct prefix p;
2257 struct bgp_info binfo;
2258 struct peer *from;
2259 int ret = RMAP_DENYMATCH;
2260
2261 bgp = peer->bgp;
2262 from = bgp->peer_self;
2263
2264 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2265 aspath = attr.aspath;
2266 attr.local_pref = bgp->default_local_pref;
2267 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2268
2269 if (afi == AFI_IP)
2270 str2prefix ("0.0.0.0/0", &p);
2271#ifdef HAVE_IPV6
2272 else if (afi == AFI_IP6)
2273 {
2274 str2prefix ("::/0", &p);
2275
2276 /* IPv6 global nexthop must be included. */
2277 memcpy (&attr.mp_nexthop_global, &peer->nexthop.v6_global,
2278 IPV6_MAX_BYTELEN);
2279 attr.mp_nexthop_len = 16;
2280
2281 /* If the peer is on shared nextwork and we have link-local
2282 nexthop set it. */
2283 if (peer->shared_network
2284 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2285 {
2286 memcpy (&attr.mp_nexthop_local, &peer->nexthop.v6_local,
2287 IPV6_MAX_BYTELEN);
2288 attr.mp_nexthop_len = 32;
2289 }
2290 }
2291#endif /* HAVE_IPV6 */
2292 else
2293 return;
2294
2295 if (peer->default_rmap[afi][safi].name)
2296 {
2297 binfo.peer = bgp->peer_self;
2298 binfo.attr = &attr;
2299
paulfee0f4c2004-09-13 05:12:46 +00002300 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2301
paul718e3742002-12-13 20:15:29 +00002302 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2303 RMAP_BGP, &binfo);
2304
paulfee0f4c2004-09-13 05:12:46 +00002305 bgp->peer_self->rmap_type = 0;
2306
paul718e3742002-12-13 20:15:29 +00002307 if (ret == RMAP_DENYMATCH)
2308 {
2309 bgp_attr_flush (&attr);
2310 withdraw = 1;
2311 }
2312 }
2313
2314 if (withdraw)
2315 {
2316 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2317 bgp_default_withdraw_send (peer, afi, safi);
2318 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2319 }
2320 else
2321 {
2322 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2323 bgp_default_update_send (peer, &attr, afi, safi, from);
2324 }
2325
2326 aspath_unintern (aspath);
2327}
2328
2329static void
2330bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002331 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002332{
2333 struct bgp_node *rn;
2334 struct bgp_info *ri;
2335 struct attr attr;
2336
2337 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002338 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002339
2340 if (safi != SAFI_MPLS_VPN
2341 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2342 bgp_default_originate (peer, afi, safi, 0);
2343
2344 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2345 for (ri = rn->info; ri; ri = ri->next)
2346 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2347 {
paulfee0f4c2004-09-13 05:12:46 +00002348 if ( (rsclient) ?
2349 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2350 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002351 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2352 else
2353 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2354 }
2355}
2356
2357void
2358bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2359{
2360 struct bgp_node *rn;
2361 struct bgp_table *table;
2362
2363 if (peer->status != Established)
2364 return;
2365
2366 if (! peer->afc_nego[afi][safi])
2367 return;
2368
2369 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2370 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2371 return;
2372
2373 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002374 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002375 else
2376 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2377 rn = bgp_route_next(rn))
2378 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002379 bgp_announce_table (peer, afi, safi, table, 0);
2380
2381 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2382 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002383}
2384
2385void
2386bgp_announce_route_all (struct peer *peer)
2387{
2388 afi_t afi;
2389 safi_t safi;
2390
2391 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2392 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2393 bgp_announce_route (peer, afi, safi);
2394}
2395
2396static void
paulfee0f4c2004-09-13 05:12:46 +00002397bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2398 safi_t safi, struct bgp_table *table)
2399{
2400 struct bgp_node *rn;
2401 struct bgp_adj_in *ain;
2402
2403 if (! table)
2404 table = rsclient->bgp->rib[afi][safi];
2405
2406 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2407 for (ain = rn->adj_in; ain; ain = ain->next)
2408 {
2409 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2410 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2411 }
2412}
2413
2414void
2415bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2416{
2417 struct bgp_table *table;
2418 struct bgp_node *rn;
2419
2420 if (safi != SAFI_MPLS_VPN)
2421 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2422
2423 else
2424 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2425 rn = bgp_route_next (rn))
2426 if ((table = rn->info) != NULL)
2427 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2428}
2429
2430static void
paul718e3742002-12-13 20:15:29 +00002431bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2432 struct bgp_table *table)
2433{
2434 int ret;
2435 struct bgp_node *rn;
2436 struct bgp_adj_in *ain;
2437
2438 if (! table)
2439 table = peer->bgp->rib[afi][safi];
2440
2441 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2442 for (ain = rn->adj_in; ain; ain = ain->next)
2443 {
2444 if (ain->peer == peer)
2445 {
2446 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2447 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2448 NULL, NULL, 1);
2449 if (ret < 0)
2450 {
2451 bgp_unlock_node (rn);
2452 return;
2453 }
2454 continue;
2455 }
2456 }
2457}
2458
2459void
2460bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2461{
2462 struct bgp_node *rn;
2463 struct bgp_table *table;
2464
2465 if (peer->status != Established)
2466 return;
2467
2468 if (safi != SAFI_MPLS_VPN)
2469 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2470 else
2471 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2472 rn = bgp_route_next (rn))
2473 if ((table = rn->info) != NULL)
2474 bgp_soft_reconfig_table (peer, afi, safi, table);
2475}
2476
paul200df112005-06-01 11:17:05 +00002477static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002478bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002479{
Paul Jakma64e580a2006-02-21 01:09:01 +00002480 struct bgp_node *rn = data;
2481 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002482 struct bgp_adj_in *ain;
2483 struct bgp_adj_out *aout;
2484 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002485 afi_t afi = rn->table->afi;
2486 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002487
Paul Jakma64e580a2006-02-21 01:09:01 +00002488 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002489
Paul Jakma64e580a2006-02-21 01:09:01 +00002490 for (ri = rn->info; ri; ri = ri->next)
2491 if (ri->peer == peer)
paul200df112005-06-01 11:17:05 +00002492 {
2493 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002494 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2495 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002496 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002497 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2498 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002499 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002500 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002501 break;
2502 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002503 for (ain = rn->adj_in; ain; ain = ain->next)
2504 if (ain->peer == peer)
paul200df112005-06-01 11:17:05 +00002505 {
Paul Jakma64e580a2006-02-21 01:09:01 +00002506 bgp_adj_in_remove (rn, ain);
2507 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002508 break;
2509 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002510 for (aout = rn->adj_out; aout; aout = aout->next)
2511 if (aout->peer == peer)
paul200df112005-06-01 11:17:05 +00002512 {
Paul Jakma64e580a2006-02-21 01:09:01 +00002513 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2514 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002515 break;
2516 }
2517 return WQ_SUCCESS;
2518}
2519
2520static void
paul0fb58d52005-11-14 14:31:49 +00002521bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002522{
Paul Jakma64e580a2006-02-21 01:09:01 +00002523 struct bgp_node *rn = data;
2524
2525 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002526}
2527
2528static void
paul94f2b392005-06-28 12:44:16 +00002529bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002530{
Paul Jakma64e580a2006-02-21 01:09:01 +00002531 struct peer *peer = wq->spec.data;
2532
Paul Jakma64e580a2006-02-21 01:09:01 +00002533 peer_unlock (peer); /* bgp_clear_node_complete */
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002534
2535 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002536 BGP_EVENT_ADD (peer, Clearing_Completed);
paul200df112005-06-01 11:17:05 +00002537}
2538
2539static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002540bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002541{
Paul Jakma64e580a2006-02-21 01:09:01 +00002542#define CLEAR_QUEUE_NAME_LEN 26 /* "clear 2001:123:123:123::1" */
2543 char wname[CLEAR_QUEUE_NAME_LEN];
2544
2545 snprintf (wname, CLEAR_QUEUE_NAME_LEN, "clear %s", peer->host);
2546#undef CLEAR_QUEUE_NAME_LEN
2547
2548 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002549 {
2550 zlog_err ("%s: Failed to allocate work queue", __func__);
2551 exit (1);
2552 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002553 peer->clear_node_queue->spec.hold = 10;
2554 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2555 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2556 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2557 peer->clear_node_queue->spec.max_retries = 0;
2558
2559 /* we only 'lock' this peer reference when the queue is actually active */
2560 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002561}
2562
paul718e3742002-12-13 20:15:29 +00002563static void
2564bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002565 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002566{
2567 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002568
paul718e3742002-12-13 20:15:29 +00002569 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002570 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002571
hasso6cf159b2005-03-21 10:28:14 +00002572 /* If still no table => afi/safi isn't configured at all or smth. */
2573 if (! table)
2574 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002575
2576 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2577 {
2578 if (rn->info == NULL)
2579 continue;
2580
2581 bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2582 work_queue_add (peer->clear_node_queue, rn);
2583 }
2584 return;
2585}
2586
2587void
2588bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2589{
2590 struct bgp_node *rn;
2591 struct bgp_table *table;
2592 struct peer *rsclient;
2593 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002594
Paul Jakma64e580a2006-02-21 01:09:01 +00002595 if (peer->clear_node_queue == NULL)
2596 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002597
Paul Jakmaca058a32006-09-14 02:58:49 +00002598 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2599 * Idle until it receives a Clearing_Completed event. This protects
2600 * against peers which flap faster than we can we clear, which could
2601 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002602 *
2603 * a) race with routes from the new session being installed before
2604 * clear_route_node visits the node (to delete the route of that
2605 * peer)
2606 * b) resource exhaustion, clear_route_node likely leads to an entry
2607 * on the process_main queue. Fast-flapping could cause that queue
2608 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002609 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002610 if (!peer->clear_node_queue->thread)
2611 peer_lock (peer); /* bgp_clear_node_complete */
paul200df112005-06-01 11:17:05 +00002612
paul718e3742002-12-13 20:15:29 +00002613 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002614 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002615 else
2616 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2617 rn = bgp_route_next (rn))
2618 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002619 bgp_clear_route_table (peer, afi, safi, table, NULL);
2620
paul1eb8ef22005-04-07 07:30:20 +00002621 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002622 {
2623 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2624 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2625 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002626
Paul Jakmaca058a32006-09-14 02:58:49 +00002627 /* If no routes were cleared, nothing was added to workqueue, the
2628 * completion function won't be run by workqueue code - call it here.
2629 *
2630 * Additionally, there is a presumption in FSM that clearing is only
2631 * needed if peer state is Established - peers in pre-Established states
2632 * shouldn't have any route-update state associated with them (in or out).
2633 *
2634 * We still get here from FSM through bgp_stop->clear_route_all in
2635 * pre-Established though, so this is a useful sanity check to ensure
2636 * the assumption above holds.
2637 *
2638 * At some future point, this check could be move to the top of the
2639 * function, and do a quick early-return when state is
2640 * pre-Established, avoiding above list and table scans. Once we're
2641 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002642 */
2643 if (!peer->clear_node_queue->thread)
2644 bgp_clear_node_complete (peer->clear_node_queue);
Paul Jakmaca058a32006-09-14 02:58:49 +00002645 else
2646 {
2647 /* clearing queue scheduled. Normal if in Established state
2648 * (and about to transition out of it), but otherwise...
2649 */
2650 if (peer->status != Established)
2651 {
2652 plog_err (peer->log, "%s [Error] State %s is not Established,"
2653 " but routes were cleared - bug!",
2654 peer->host, LOOKUP (bgp_status_msg, peer->status));
2655 assert (peer->status == Established);
2656 }
2657 }
paul718e3742002-12-13 20:15:29 +00002658}
2659
2660void
2661bgp_clear_route_all (struct peer *peer)
2662{
2663 afi_t afi;
2664 safi_t safi;
2665
2666 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2667 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2668 bgp_clear_route (peer, afi, safi);
2669}
2670
2671void
2672bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2673{
2674 struct bgp_table *table;
2675 struct bgp_node *rn;
2676 struct bgp_adj_in *ain;
2677
2678 table = peer->bgp->rib[afi][safi];
2679
2680 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2681 for (ain = rn->adj_in; ain ; ain = ain->next)
2682 if (ain->peer == peer)
2683 {
2684 bgp_adj_in_remove (rn, ain);
2685 bgp_unlock_node (rn);
2686 break;
2687 }
2688}
hasso93406d82005-02-02 14:40:33 +00002689
2690void
2691bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2692{
2693 struct bgp_node *rn;
2694 struct bgp_info *ri;
2695 struct bgp_table *table;
2696
2697 table = peer->bgp->rib[afi][safi];
2698
2699 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2700 {
2701 for (ri = rn->info; ri; ri = ri->next)
2702 if (ri->peer == peer)
2703 {
2704 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2705 bgp_rib_remove (rn, ri, peer, afi, safi);
2706 break;
2707 }
2708 }
2709}
paul718e3742002-12-13 20:15:29 +00002710
2711/* Delete all kernel routes. */
2712void
paul545acaf2004-04-20 15:13:15 +00002713bgp_cleanup_routes ()
paul718e3742002-12-13 20:15:29 +00002714{
2715 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002716 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002717 struct bgp_node *rn;
2718 struct bgp_table *table;
2719 struct bgp_info *ri;
2720
paul1eb8ef22005-04-07 07:30:20 +00002721 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002722 {
2723 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2724
2725 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2726 for (ri = rn->info; ri; ri = ri->next)
2727 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2728 && ri->type == ZEBRA_ROUTE_BGP
2729 && ri->sub_type == BGP_ROUTE_NORMAL)
2730 bgp_zebra_withdraw (&rn->p, ri);
2731
2732 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2733
2734 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2735 for (ri = rn->info; ri; ri = ri->next)
2736 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2737 && ri->type == ZEBRA_ROUTE_BGP
2738 && ri->sub_type == BGP_ROUTE_NORMAL)
2739 bgp_zebra_withdraw (&rn->p, ri);
2740 }
2741}
2742
2743void
2744bgp_reset ()
2745{
2746 vty_reset ();
2747 bgp_zclient_reset ();
2748 access_list_reset ();
2749 prefix_list_reset ();
2750}
2751
2752/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2753 value. */
2754int
2755bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2756{
2757 u_char *pnt;
2758 u_char *lim;
2759 struct prefix p;
2760 int psize;
2761 int ret;
2762
2763 /* Check peer status. */
2764 if (peer->status != Established)
2765 return 0;
2766
2767 pnt = packet->nlri;
2768 lim = pnt + packet->length;
2769
2770 for (; pnt < lim; pnt += psize)
2771 {
2772 /* Clear prefix structure. */
2773 memset (&p, 0, sizeof (struct prefix));
2774
2775 /* Fetch prefix length. */
2776 p.prefixlen = *pnt++;
2777 p.family = afi2family (packet->afi);
2778
2779 /* Already checked in nlri_sanity_check(). We do double check
2780 here. */
2781 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2782 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2783 return -1;
2784
2785 /* Packet size overflow check. */
2786 psize = PSIZE (p.prefixlen);
2787
2788 /* When packet overflow occur return immediately. */
2789 if (pnt + psize > lim)
2790 return -1;
2791
2792 /* Fetch prefix from NLRI packet. */
2793 memcpy (&p.u.prefix, pnt, psize);
2794
2795 /* Check address. */
2796 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2797 {
2798 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
2799 {
paulf5ba3872004-07-09 12:11:31 +00002800 /*
2801 * From draft-ietf-idr-bgp4-22, Section 6.3:
2802 * If a BGP router receives an UPDATE message with a
2803 * semantically incorrect NLRI field, in which a prefix is
2804 * semantically incorrect (eg. an unexpected multicast IP
2805 * address), it should ignore the prefix.
2806 */
paul718e3742002-12-13 20:15:29 +00002807 zlog (peer->log, LOG_ERR,
2808 "IPv4 unicast NLRI is multicast address %s",
2809 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00002810
paul718e3742002-12-13 20:15:29 +00002811 return -1;
2812 }
2813 }
2814
2815#ifdef HAVE_IPV6
2816 /* Check address. */
2817 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
2818 {
2819 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2820 {
2821 char buf[BUFSIZ];
2822
2823 zlog (peer->log, LOG_WARNING,
2824 "IPv6 link-local NLRI received %s ignore this NLRI",
2825 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
2826
2827 continue;
2828 }
2829 }
2830#endif /* HAVE_IPV6 */
2831
2832 /* Normal process. */
2833 if (attr)
2834 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
2835 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
2836 else
2837 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
2838 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2839
2840 /* Address family configuration mismatch or maximum-prefix count
2841 overflow. */
2842 if (ret < 0)
2843 return -1;
2844 }
2845
2846 /* Packet length consistency check. */
2847 if (pnt != lim)
2848 return -1;
2849
2850 return 0;
2851}
2852
2853/* NLRI encode syntax check routine. */
2854int
2855bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
2856 bgp_size_t length)
2857{
2858 u_char *end;
2859 u_char prefixlen;
2860 int psize;
2861
2862 end = pnt + length;
2863
2864 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
2865 syntactic validity. If the field is syntactically incorrect,
2866 then the Error Subcode is set to Invalid Network Field. */
2867
2868 while (pnt < end)
2869 {
2870 prefixlen = *pnt++;
2871
2872 /* Prefix length check. */
2873 if ((afi == AFI_IP && prefixlen > 32)
2874 || (afi == AFI_IP6 && prefixlen > 128))
2875 {
2876 plog_err (peer->log,
2877 "%s [Error] Update packet error (wrong prefix length %d)",
2878 peer->host, prefixlen);
2879 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2880 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2881 return -1;
2882 }
2883
2884 /* Packet size overflow check. */
2885 psize = PSIZE (prefixlen);
2886
2887 if (pnt + psize > end)
2888 {
2889 plog_err (peer->log,
2890 "%s [Error] Update packet error"
2891 " (prefix data overflow prefix size is %d)",
2892 peer->host, psize);
2893 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2894 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2895 return -1;
2896 }
2897
2898 pnt += psize;
2899 }
2900
2901 /* Packet length consistency check. */
2902 if (pnt != end)
2903 {
2904 plog_err (peer->log,
2905 "%s [Error] Update packet error"
2906 " (prefix length mismatch with total length)",
2907 peer->host);
2908 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2909 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2910 return -1;
2911 }
2912 return 0;
2913}
2914
paul94f2b392005-06-28 12:44:16 +00002915static struct bgp_static *
paul718e3742002-12-13 20:15:29 +00002916bgp_static_new ()
2917{
2918 struct bgp_static *new;
2919 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
2920 memset (new, 0, sizeof (struct bgp_static));
2921 return new;
2922}
2923
paul94f2b392005-06-28 12:44:16 +00002924static void
paul718e3742002-12-13 20:15:29 +00002925bgp_static_free (struct bgp_static *bgp_static)
2926{
2927 if (bgp_static->rmap.name)
2928 free (bgp_static->rmap.name);
2929 XFREE (MTYPE_BGP_STATIC, bgp_static);
2930}
2931
paul94f2b392005-06-28 12:44:16 +00002932static void
paulfee0f4c2004-09-13 05:12:46 +00002933bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
2934 struct prefix *p, afi_t afi, safi_t safi)
2935{
2936 struct bgp_node *rn;
2937 struct bgp_info *ri;
2938
2939 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2940
2941 /* Check selected route and self inserted route. */
2942 for (ri = rn->info; ri; ri = ri->next)
2943 if (ri->peer == bgp->peer_self
2944 && ri->type == ZEBRA_ROUTE_BGP
2945 && ri->sub_type == BGP_ROUTE_STATIC)
2946 break;
2947
2948 /* Withdraw static BGP route from routing table. */
2949 if (ri)
2950 {
paulfee0f4c2004-09-13 05:12:46 +00002951 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00002952 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002953 }
2954
2955 /* Unlock bgp_node_lookup. */
2956 bgp_unlock_node (rn);
2957}
2958
paul94f2b392005-06-28 12:44:16 +00002959static void
paulfee0f4c2004-09-13 05:12:46 +00002960bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
2961 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
2962{
2963 struct bgp_node *rn;
2964 struct bgp_info *ri;
2965 struct bgp_info *new;
2966 struct bgp_info info;
2967 struct attr new_attr;
2968 struct attr *attr_new;
2969 struct attr attr;
2970 struct bgp *bgp;
2971 int ret;
2972 char buf[SU_ADDRSTRLEN];
2973
2974 bgp = rsclient->bgp;
2975
Paul Jakma06e110f2006-05-12 23:29:22 +00002976 assert (bgp_static);
2977 if (!bgp_static)
2978 return;
2979
paulfee0f4c2004-09-13 05:12:46 +00002980 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2981
2982 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00002983
2984 attr.nexthop = bgp_static->igpnexthop;
2985 attr.med = bgp_static->igpmetric;
2986 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paulfee0f4c2004-09-13 05:12:46 +00002987
2988 new_attr = attr;
2989
2990 /* Apply network route-map for export to this rsclient. */
2991 if (bgp_static->rmap.name)
2992 {
2993 info.peer = rsclient;
2994 info.attr = &new_attr;
2995
2996 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
2997 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
2998
2999 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3000
3001 rsclient->rmap_type = 0;
3002
3003 if (ret == RMAP_DENYMATCH)
3004 {
3005 /* Free uninterned attribute. */
3006 bgp_attr_flush (&new_attr);
3007
3008 /* Unintern original. */
3009 aspath_unintern (attr.aspath);
3010 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3011
3012 return;
3013 }
3014 attr_new = bgp_attr_intern (&new_attr);
3015 }
3016 else
3017 attr_new = bgp_attr_intern (&attr);
3018
3019 new_attr = *attr_new;
3020
3021 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3022
3023 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) == RMAP_DENY)
3024{
3025 /* This BGP update is filtered. Log the reason then update BGP entry. */
3026 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003027 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003028 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3029 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3030 p->prefixlen, rsclient->host);
3031
3032 bgp->peer_self->rmap_type = 0;
3033
3034 bgp_attr_unintern (attr_new);
3035 aspath_unintern (attr.aspath);
3036
3037 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3038
3039 return;
3040 }
3041
3042 bgp->peer_self->rmap_type = 0;
3043
3044 bgp_attr_unintern (attr_new);
3045 attr_new = bgp_attr_intern (&new_attr);
3046
3047 for (ri = rn->info; ri; ri = ri->next)
3048 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3049 && ri->sub_type == BGP_ROUTE_STATIC)
3050 break;
3051
3052 if (ri)
3053 {
3054 if (attrhash_cmp (ri->attr, attr_new))
3055 {
3056 bgp_unlock_node (rn);
3057 bgp_attr_unintern (attr_new);
3058 aspath_unintern (attr.aspath);
3059 return;
3060 }
3061 else
3062 {
3063 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003064 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003065
3066 /* Rewrite BGP route information. */
3067 bgp_attr_unintern (ri->attr);
3068 ri->attr = attr_new;
3069 ri->uptime = time (NULL);
3070
3071 /* Process change. */
3072 bgp_process (bgp, rn, afi, safi);
3073 bgp_unlock_node (rn);
3074 aspath_unintern (attr.aspath);
3075 return;
3076 }
3077}
3078
3079 /* Make new BGP info. */
3080 new = bgp_info_new ();
3081 new->type = ZEBRA_ROUTE_BGP;
3082 new->sub_type = BGP_ROUTE_STATIC;
3083 new->peer = bgp->peer_self;
3084 SET_FLAG (new->flags, BGP_INFO_VALID);
3085 new->attr = attr_new;
3086 new->uptime = time (NULL);
3087
3088 /* Register new BGP information. */
3089 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003090
3091 /* route_node_get lock */
3092 bgp_unlock_node (rn);
3093
paulfee0f4c2004-09-13 05:12:46 +00003094 /* Process change. */
3095 bgp_process (bgp, rn, afi, safi);
3096
3097 /* Unintern original. */
3098 aspath_unintern (attr.aspath);
3099}
3100
paul94f2b392005-06-28 12:44:16 +00003101static void
paulfee0f4c2004-09-13 05:12:46 +00003102bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003103 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3104{
3105 struct bgp_node *rn;
3106 struct bgp_info *ri;
3107 struct bgp_info *new;
3108 struct bgp_info info;
3109 struct attr attr;
paul286e1e72003-08-08 00:24:31 +00003110 struct attr attr_tmp;
paul718e3742002-12-13 20:15:29 +00003111 struct attr *attr_new;
3112 int ret;
3113
Paul Jakmadd8103a2006-05-12 23:27:30 +00003114 assert (bgp_static);
3115 if (!bgp_static)
3116 return;
3117
paulfee0f4c2004-09-13 05:12:46 +00003118 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003119
3120 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003121
3122 attr.nexthop = bgp_static->igpnexthop;
3123 attr.med = bgp_static->igpmetric;
3124 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003125
3126 /* Apply route-map. */
3127 if (bgp_static->rmap.name)
3128 {
paul286e1e72003-08-08 00:24:31 +00003129 attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003130 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003131 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003132
paulfee0f4c2004-09-13 05:12:46 +00003133 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3134
paul718e3742002-12-13 20:15:29 +00003135 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003136
paulfee0f4c2004-09-13 05:12:46 +00003137 bgp->peer_self->rmap_type = 0;
3138
paul718e3742002-12-13 20:15:29 +00003139 if (ret == RMAP_DENYMATCH)
3140 {
3141 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003142 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003143
3144 /* Unintern original. */
3145 aspath_unintern (attr.aspath);
3146 bgp_static_withdraw (bgp, p, afi, safi);
3147 return;
3148 }
paul286e1e72003-08-08 00:24:31 +00003149 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003150 }
paul286e1e72003-08-08 00:24:31 +00003151 else
3152 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003153
3154 for (ri = rn->info; ri; ri = ri->next)
3155 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3156 && ri->sub_type == BGP_ROUTE_STATIC)
3157 break;
3158
3159 if (ri)
3160 {
3161 if (attrhash_cmp (ri->attr, attr_new))
3162 {
3163 bgp_unlock_node (rn);
3164 bgp_attr_unintern (attr_new);
3165 aspath_unintern (attr.aspath);
3166 return;
3167 }
3168 else
3169 {
3170 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003171 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003172
3173 /* Rewrite BGP route information. */
3174 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3175 bgp_attr_unintern (ri->attr);
3176 ri->attr = attr_new;
3177 ri->uptime = time (NULL);
3178
3179 /* Process change. */
3180 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3181 bgp_process (bgp, rn, afi, safi);
3182 bgp_unlock_node (rn);
3183 aspath_unintern (attr.aspath);
3184 return;
3185 }
3186 }
3187
3188 /* Make new BGP info. */
3189 new = bgp_info_new ();
3190 new->type = ZEBRA_ROUTE_BGP;
3191 new->sub_type = BGP_ROUTE_STATIC;
3192 new->peer = bgp->peer_self;
3193 SET_FLAG (new->flags, BGP_INFO_VALID);
3194 new->attr = attr_new;
3195 new->uptime = time (NULL);
3196
3197 /* Aggregate address increment. */
3198 bgp_aggregate_increment (bgp, p, new, afi, safi);
3199
3200 /* Register new BGP information. */
3201 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003202
3203 /* route_node_get lock */
3204 bgp_unlock_node (rn);
3205
paul718e3742002-12-13 20:15:29 +00003206 /* Process change. */
3207 bgp_process (bgp, rn, afi, safi);
3208
3209 /* Unintern original. */
3210 aspath_unintern (attr.aspath);
3211}
3212
3213void
paulfee0f4c2004-09-13 05:12:46 +00003214bgp_static_update (struct bgp *bgp, struct prefix *p,
3215 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3216{
3217 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003218 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003219
3220 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3221
paul1eb8ef22005-04-07 07:30:20 +00003222 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003223 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003224 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3225 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003226 }
3227}
3228
paul94f2b392005-06-28 12:44:16 +00003229static void
paul718e3742002-12-13 20:15:29 +00003230bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3231 u_char safi, struct prefix_rd *prd, u_char *tag)
3232{
3233 struct bgp_node *rn;
3234 struct bgp_info *new;
3235
paulfee0f4c2004-09-13 05:12:46 +00003236 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003237
3238 /* Make new BGP info. */
3239 new = bgp_info_new ();
3240 new->type = ZEBRA_ROUTE_BGP;
3241 new->sub_type = BGP_ROUTE_STATIC;
3242 new->peer = bgp->peer_self;
3243 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3244 SET_FLAG (new->flags, BGP_INFO_VALID);
3245 new->uptime = time (NULL);
3246 memcpy (new->tag, tag, 3);
3247
3248 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003249 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003250
3251 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003252 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003253
paul200df112005-06-01 11:17:05 +00003254 /* route_node_get lock */
3255 bgp_unlock_node (rn);
3256
paul718e3742002-12-13 20:15:29 +00003257 /* Process change. */
3258 bgp_process (bgp, rn, afi, safi);
3259}
3260
3261void
3262bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3263 safi_t safi)
3264{
3265 struct bgp_node *rn;
3266 struct bgp_info *ri;
3267
paulfee0f4c2004-09-13 05:12:46 +00003268 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003269
3270 /* Check selected route and self inserted route. */
3271 for (ri = rn->info; ri; ri = ri->next)
3272 if (ri->peer == bgp->peer_self
3273 && ri->type == ZEBRA_ROUTE_BGP
3274 && ri->sub_type == BGP_ROUTE_STATIC)
3275 break;
3276
3277 /* Withdraw static BGP route from routing table. */
3278 if (ri)
3279 {
3280 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003281 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003282 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003283 }
3284
3285 /* Unlock bgp_node_lookup. */
3286 bgp_unlock_node (rn);
3287}
3288
3289void
paulfee0f4c2004-09-13 05:12:46 +00003290bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3291{
3292 struct bgp_static *bgp_static;
3293 struct bgp *bgp;
3294 struct bgp_node *rn;
3295 struct prefix *p;
3296
3297 bgp = rsclient->bgp;
3298
3299 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3300 if ((bgp_static = rn->info) != NULL)
3301 {
3302 p = &rn->p;
3303
3304 bgp_static_update_rsclient (rsclient, p, bgp_static,
3305 afi, safi);
3306 }
3307}
3308
paul94f2b392005-06-28 12:44:16 +00003309static void
paul718e3742002-12-13 20:15:29 +00003310bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3311 u_char safi, struct prefix_rd *prd, u_char *tag)
3312{
3313 struct bgp_node *rn;
3314 struct bgp_info *ri;
3315
paulfee0f4c2004-09-13 05:12:46 +00003316 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003317
3318 /* Check selected route and self inserted route. */
3319 for (ri = rn->info; ri; ri = ri->next)
3320 if (ri->peer == bgp->peer_self
3321 && ri->type == ZEBRA_ROUTE_BGP
3322 && ri->sub_type == BGP_ROUTE_STATIC)
3323 break;
3324
3325 /* Withdraw static BGP route from routing table. */
3326 if (ri)
3327 {
3328 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003329 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003330 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003331 }
3332
3333 /* Unlock bgp_node_lookup. */
3334 bgp_unlock_node (rn);
3335}
3336
3337/* Configure static BGP network. When user don't run zebra, static
3338 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003339static int
paulfd79ac92004-10-13 05:06:08 +00003340bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3341 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003342{
3343 int ret;
3344 struct prefix p;
3345 struct bgp_static *bgp_static;
3346 struct bgp_node *rn;
3347 int need_update = 0;
3348
3349 /* Convert IP prefix string to struct prefix. */
3350 ret = str2prefix (ip_str, &p);
3351 if (! ret)
3352 {
3353 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3354 return CMD_WARNING;
3355 }
3356#ifdef HAVE_IPV6
3357 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3358 {
3359 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3360 VTY_NEWLINE);
3361 return CMD_WARNING;
3362 }
3363#endif /* HAVE_IPV6 */
3364
3365 apply_mask (&p);
3366
3367 /* Set BGP static route configuration. */
3368 rn = bgp_node_get (bgp->route[afi][safi], &p);
3369
3370 if (rn->info)
3371 {
3372 /* Configuration change. */
3373 bgp_static = rn->info;
3374
3375 /* Check previous routes are installed into BGP. */
3376 if (! bgp_static->backdoor && bgp_static->valid)
3377 need_update = 1;
3378
3379 bgp_static->backdoor = backdoor;
3380 if (rmap)
3381 {
3382 if (bgp_static->rmap.name)
3383 free (bgp_static->rmap.name);
3384 bgp_static->rmap.name = strdup (rmap);
3385 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3386 }
3387 else
3388 {
3389 if (bgp_static->rmap.name)
3390 free (bgp_static->rmap.name);
3391 bgp_static->rmap.name = NULL;
3392 bgp_static->rmap.map = NULL;
3393 bgp_static->valid = 0;
3394 }
3395 bgp_unlock_node (rn);
3396 }
3397 else
3398 {
3399 /* New configuration. */
3400 bgp_static = bgp_static_new ();
3401 bgp_static->backdoor = backdoor;
3402 bgp_static->valid = 0;
3403 bgp_static->igpmetric = 0;
3404 bgp_static->igpnexthop.s_addr = 0;
3405 if (rmap)
3406 {
3407 if (bgp_static->rmap.name)
3408 free (bgp_static->rmap.name);
3409 bgp_static->rmap.name = strdup (rmap);
3410 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3411 }
3412 rn->info = bgp_static;
3413 }
3414
3415 /* If BGP scan is not enabled, we should install this route here. */
3416 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3417 {
3418 bgp_static->valid = 1;
3419
3420 if (need_update)
3421 bgp_static_withdraw (bgp, &p, afi, safi);
3422
3423 if (! bgp_static->backdoor)
3424 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3425 }
3426
3427 return CMD_SUCCESS;
3428}
3429
3430/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003431static int
paulfd79ac92004-10-13 05:06:08 +00003432bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003433 u_int16_t afi, u_char safi)
3434{
3435 int ret;
3436 struct prefix p;
3437 struct bgp_static *bgp_static;
3438 struct bgp_node *rn;
3439
3440 /* Convert IP prefix string to struct prefix. */
3441 ret = str2prefix (ip_str, &p);
3442 if (! ret)
3443 {
3444 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3445 return CMD_WARNING;
3446 }
3447#ifdef HAVE_IPV6
3448 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3449 {
3450 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3451 VTY_NEWLINE);
3452 return CMD_WARNING;
3453 }
3454#endif /* HAVE_IPV6 */
3455
3456 apply_mask (&p);
3457
3458 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3459 if (! rn)
3460 {
3461 vty_out (vty, "%% Can't find specified static route configuration.%s",
3462 VTY_NEWLINE);
3463 return CMD_WARNING;
3464 }
3465
3466 bgp_static = rn->info;
3467
3468 /* Update BGP RIB. */
3469 if (! bgp_static->backdoor)
3470 bgp_static_withdraw (bgp, &p, afi, safi);
3471
3472 /* Clear configuration. */
3473 bgp_static_free (bgp_static);
3474 rn->info = NULL;
3475 bgp_unlock_node (rn);
3476 bgp_unlock_node (rn);
3477
3478 return CMD_SUCCESS;
3479}
3480
3481/* Called from bgp_delete(). Delete all static routes from the BGP
3482 instance. */
3483void
3484bgp_static_delete (struct bgp *bgp)
3485{
3486 afi_t afi;
3487 safi_t safi;
3488 struct bgp_node *rn;
3489 struct bgp_node *rm;
3490 struct bgp_table *table;
3491 struct bgp_static *bgp_static;
3492
3493 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3494 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3495 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3496 if (rn->info != NULL)
3497 {
3498 if (safi == SAFI_MPLS_VPN)
3499 {
3500 table = rn->info;
3501
3502 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3503 {
3504 bgp_static = rn->info;
3505 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3506 AFI_IP, SAFI_MPLS_VPN,
3507 (struct prefix_rd *)&rn->p,
3508 bgp_static->tag);
3509 bgp_static_free (bgp_static);
3510 rn->info = NULL;
3511 bgp_unlock_node (rn);
3512 }
3513 }
3514 else
3515 {
3516 bgp_static = rn->info;
3517 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3518 bgp_static_free (bgp_static);
3519 rn->info = NULL;
3520 bgp_unlock_node (rn);
3521 }
3522 }
3523}
3524
3525int
paulfd79ac92004-10-13 05:06:08 +00003526bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3527 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003528{
3529 int ret;
3530 struct prefix p;
3531 struct prefix_rd prd;
3532 struct bgp *bgp;
3533 struct bgp_node *prn;
3534 struct bgp_node *rn;
3535 struct bgp_table *table;
3536 struct bgp_static *bgp_static;
3537 u_char tag[3];
3538
3539 bgp = vty->index;
3540
3541 ret = str2prefix (ip_str, &p);
3542 if (! ret)
3543 {
3544 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3545 return CMD_WARNING;
3546 }
3547 apply_mask (&p);
3548
3549 ret = str2prefix_rd (rd_str, &prd);
3550 if (! ret)
3551 {
3552 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3553 return CMD_WARNING;
3554 }
3555
3556 ret = str2tag (tag_str, tag);
3557 if (! ret)
3558 {
3559 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3560 return CMD_WARNING;
3561 }
3562
3563 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3564 (struct prefix *)&prd);
3565 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003566 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003567 else
3568 bgp_unlock_node (prn);
3569 table = prn->info;
3570
3571 rn = bgp_node_get (table, &p);
3572
3573 if (rn->info)
3574 {
3575 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3576 bgp_unlock_node (rn);
3577 }
3578 else
3579 {
3580 /* New configuration. */
3581 bgp_static = bgp_static_new ();
3582 bgp_static->valid = 1;
3583 memcpy (bgp_static->tag, tag, 3);
3584 rn->info = bgp_static;
3585
3586 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3587 }
3588
3589 return CMD_SUCCESS;
3590}
3591
3592/* Configure static BGP network. */
3593int
paulfd79ac92004-10-13 05:06:08 +00003594bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3595 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003596{
3597 int ret;
3598 struct bgp *bgp;
3599 struct prefix p;
3600 struct prefix_rd prd;
3601 struct bgp_node *prn;
3602 struct bgp_node *rn;
3603 struct bgp_table *table;
3604 struct bgp_static *bgp_static;
3605 u_char tag[3];
3606
3607 bgp = vty->index;
3608
3609 /* Convert IP prefix string to struct prefix. */
3610 ret = str2prefix (ip_str, &p);
3611 if (! ret)
3612 {
3613 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3614 return CMD_WARNING;
3615 }
3616 apply_mask (&p);
3617
3618 ret = str2prefix_rd (rd_str, &prd);
3619 if (! ret)
3620 {
3621 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3622 return CMD_WARNING;
3623 }
3624
3625 ret = str2tag (tag_str, tag);
3626 if (! ret)
3627 {
3628 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3629 return CMD_WARNING;
3630 }
3631
3632 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3633 (struct prefix *)&prd);
3634 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003635 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003636 else
3637 bgp_unlock_node (prn);
3638 table = prn->info;
3639
3640 rn = bgp_node_lookup (table, &p);
3641
3642 if (rn)
3643 {
3644 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3645
3646 bgp_static = rn->info;
3647 bgp_static_free (bgp_static);
3648 rn->info = NULL;
3649 bgp_unlock_node (rn);
3650 bgp_unlock_node (rn);
3651 }
3652 else
3653 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3654
3655 return CMD_SUCCESS;
3656}
3657
3658DEFUN (bgp_network,
3659 bgp_network_cmd,
3660 "network A.B.C.D/M",
3661 "Specify a network to announce via BGP\n"
3662 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3663{
3664 return bgp_static_set (vty, vty->index, argv[0],
3665 AFI_IP, bgp_node_safi (vty), NULL, 0);
3666}
3667
3668DEFUN (bgp_network_route_map,
3669 bgp_network_route_map_cmd,
3670 "network A.B.C.D/M route-map WORD",
3671 "Specify a network to announce via BGP\n"
3672 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3673 "Route-map to modify the attributes\n"
3674 "Name of the route map\n")
3675{
3676 return bgp_static_set (vty, vty->index, argv[0],
3677 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3678}
3679
3680DEFUN (bgp_network_backdoor,
3681 bgp_network_backdoor_cmd,
3682 "network A.B.C.D/M backdoor",
3683 "Specify a network to announce via BGP\n"
3684 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3685 "Specify a BGP backdoor route\n")
3686{
3687 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
3688}
3689
3690DEFUN (bgp_network_mask,
3691 bgp_network_mask_cmd,
3692 "network A.B.C.D mask A.B.C.D",
3693 "Specify a network to announce via BGP\n"
3694 "Network number\n"
3695 "Network mask\n"
3696 "Network mask\n")
3697{
3698 int ret;
3699 char prefix_str[BUFSIZ];
3700
3701 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3702 if (! ret)
3703 {
3704 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3705 return CMD_WARNING;
3706 }
3707
3708 return bgp_static_set (vty, vty->index, prefix_str,
3709 AFI_IP, bgp_node_safi (vty), NULL, 0);
3710}
3711
3712DEFUN (bgp_network_mask_route_map,
3713 bgp_network_mask_route_map_cmd,
3714 "network A.B.C.D mask A.B.C.D route-map WORD",
3715 "Specify a network to announce via BGP\n"
3716 "Network number\n"
3717 "Network mask\n"
3718 "Network mask\n"
3719 "Route-map to modify the attributes\n"
3720 "Name of the route map\n")
3721{
3722 int ret;
3723 char prefix_str[BUFSIZ];
3724
3725 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3726 if (! ret)
3727 {
3728 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3729 return CMD_WARNING;
3730 }
3731
3732 return bgp_static_set (vty, vty->index, prefix_str,
3733 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3734}
3735
3736DEFUN (bgp_network_mask_backdoor,
3737 bgp_network_mask_backdoor_cmd,
3738 "network A.B.C.D mask A.B.C.D backdoor",
3739 "Specify a network to announce via BGP\n"
3740 "Network number\n"
3741 "Network mask\n"
3742 "Network mask\n"
3743 "Specify a BGP backdoor route\n")
3744{
3745 int ret;
3746 char prefix_str[BUFSIZ];
3747
3748 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3749 if (! ret)
3750 {
3751 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3752 return CMD_WARNING;
3753 }
3754
3755 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3756}
3757
3758DEFUN (bgp_network_mask_natural,
3759 bgp_network_mask_natural_cmd,
3760 "network A.B.C.D",
3761 "Specify a network to announce via BGP\n"
3762 "Network number\n")
3763{
3764 int ret;
3765 char prefix_str[BUFSIZ];
3766
3767 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3768 if (! ret)
3769 {
3770 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3771 return CMD_WARNING;
3772 }
3773
3774 return bgp_static_set (vty, vty->index, prefix_str,
3775 AFI_IP, bgp_node_safi (vty), NULL, 0);
3776}
3777
3778DEFUN (bgp_network_mask_natural_route_map,
3779 bgp_network_mask_natural_route_map_cmd,
3780 "network A.B.C.D route-map WORD",
3781 "Specify a network to announce via BGP\n"
3782 "Network number\n"
3783 "Route-map to modify the attributes\n"
3784 "Name of the route map\n")
3785{
3786 int ret;
3787 char prefix_str[BUFSIZ];
3788
3789 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3790 if (! ret)
3791 {
3792 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3793 return CMD_WARNING;
3794 }
3795
3796 return bgp_static_set (vty, vty->index, prefix_str,
3797 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3798}
3799
3800DEFUN (bgp_network_mask_natural_backdoor,
3801 bgp_network_mask_natural_backdoor_cmd,
3802 "network A.B.C.D backdoor",
3803 "Specify a network to announce via BGP\n"
3804 "Network number\n"
3805 "Specify a BGP backdoor route\n")
3806{
3807 int ret;
3808 char prefix_str[BUFSIZ];
3809
3810 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3811 if (! ret)
3812 {
3813 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3814 return CMD_WARNING;
3815 }
3816
3817 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3818}
3819
3820DEFUN (no_bgp_network,
3821 no_bgp_network_cmd,
3822 "no network A.B.C.D/M",
3823 NO_STR
3824 "Specify a network to announce via BGP\n"
3825 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3826{
3827 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
3828 bgp_node_safi (vty));
3829}
3830
3831ALIAS (no_bgp_network,
3832 no_bgp_network_route_map_cmd,
3833 "no network A.B.C.D/M route-map WORD",
3834 NO_STR
3835 "Specify a network to announce via BGP\n"
3836 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3837 "Route-map to modify the attributes\n"
3838 "Name of the route map\n")
3839
3840ALIAS (no_bgp_network,
3841 no_bgp_network_backdoor_cmd,
3842 "no network A.B.C.D/M backdoor",
3843 NO_STR
3844 "Specify a network to announce via BGP\n"
3845 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3846 "Specify a BGP backdoor route\n")
3847
3848DEFUN (no_bgp_network_mask,
3849 no_bgp_network_mask_cmd,
3850 "no network A.B.C.D mask A.B.C.D",
3851 NO_STR
3852 "Specify a network to announce via BGP\n"
3853 "Network number\n"
3854 "Network mask\n"
3855 "Network mask\n")
3856{
3857 int ret;
3858 char prefix_str[BUFSIZ];
3859
3860 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3861 if (! ret)
3862 {
3863 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3864 return CMD_WARNING;
3865 }
3866
3867 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3868 bgp_node_safi (vty));
3869}
3870
3871ALIAS (no_bgp_network_mask,
3872 no_bgp_network_mask_route_map_cmd,
3873 "no network A.B.C.D mask A.B.C.D route-map WORD",
3874 NO_STR
3875 "Specify a network to announce via BGP\n"
3876 "Network number\n"
3877 "Network mask\n"
3878 "Network mask\n"
3879 "Route-map to modify the attributes\n"
3880 "Name of the route map\n")
3881
3882ALIAS (no_bgp_network_mask,
3883 no_bgp_network_mask_backdoor_cmd,
3884 "no network A.B.C.D mask A.B.C.D backdoor",
3885 NO_STR
3886 "Specify a network to announce via BGP\n"
3887 "Network number\n"
3888 "Network mask\n"
3889 "Network mask\n"
3890 "Specify a BGP backdoor route\n")
3891
3892DEFUN (no_bgp_network_mask_natural,
3893 no_bgp_network_mask_natural_cmd,
3894 "no network A.B.C.D",
3895 NO_STR
3896 "Specify a network to announce via BGP\n"
3897 "Network number\n")
3898{
3899 int ret;
3900 char prefix_str[BUFSIZ];
3901
3902 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3903 if (! ret)
3904 {
3905 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3906 return CMD_WARNING;
3907 }
3908
3909 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3910 bgp_node_safi (vty));
3911}
3912
3913ALIAS (no_bgp_network_mask_natural,
3914 no_bgp_network_mask_natural_route_map_cmd,
3915 "no network A.B.C.D route-map WORD",
3916 NO_STR
3917 "Specify a network to announce via BGP\n"
3918 "Network number\n"
3919 "Route-map to modify the attributes\n"
3920 "Name of the route map\n")
3921
3922ALIAS (no_bgp_network_mask_natural,
3923 no_bgp_network_mask_natural_backdoor_cmd,
3924 "no network A.B.C.D backdoor",
3925 NO_STR
3926 "Specify a network to announce via BGP\n"
3927 "Network number\n"
3928 "Specify a BGP backdoor route\n")
3929
3930#ifdef HAVE_IPV6
3931DEFUN (ipv6_bgp_network,
3932 ipv6_bgp_network_cmd,
3933 "network X:X::X:X/M",
3934 "Specify a network to announce via BGP\n"
3935 "IPv6 prefix <network>/<length>\n")
3936{
3937 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
3938}
3939
3940DEFUN (ipv6_bgp_network_route_map,
3941 ipv6_bgp_network_route_map_cmd,
3942 "network X:X::X:X/M route-map WORD",
3943 "Specify a network to announce via BGP\n"
3944 "IPv6 prefix <network>/<length>\n"
3945 "Route-map to modify the attributes\n"
3946 "Name of the route map\n")
3947{
3948 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
3949 bgp_node_safi (vty), argv[1], 0);
3950}
3951
3952DEFUN (no_ipv6_bgp_network,
3953 no_ipv6_bgp_network_cmd,
3954 "no network X:X::X:X/M",
3955 NO_STR
3956 "Specify a network to announce via BGP\n"
3957 "IPv6 prefix <network>/<length>\n")
3958{
3959 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
3960}
3961
3962ALIAS (no_ipv6_bgp_network,
3963 no_ipv6_bgp_network_route_map_cmd,
3964 "no network X:X::X:X/M route-map WORD",
3965 NO_STR
3966 "Specify a network to announce via BGP\n"
3967 "IPv6 prefix <network>/<length>\n"
3968 "Route-map to modify the attributes\n"
3969 "Name of the route map\n")
3970
3971ALIAS (ipv6_bgp_network,
3972 old_ipv6_bgp_network_cmd,
3973 "ipv6 bgp network X:X::X:X/M",
3974 IPV6_STR
3975 BGP_STR
3976 "Specify a network to announce via BGP\n"
3977 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3978
3979ALIAS (no_ipv6_bgp_network,
3980 old_no_ipv6_bgp_network_cmd,
3981 "no ipv6 bgp network X:X::X:X/M",
3982 NO_STR
3983 IPV6_STR
3984 BGP_STR
3985 "Specify a network to announce via BGP\n"
3986 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3987#endif /* HAVE_IPV6 */
3988
3989/* Aggreagete address:
3990
3991 advertise-map Set condition to advertise attribute
3992 as-set Generate AS set path information
3993 attribute-map Set attributes of aggregate
3994 route-map Set parameters of aggregate
3995 summary-only Filter more specific routes from updates
3996 suppress-map Conditionally filter more specific routes from updates
3997 <cr>
3998 */
3999struct bgp_aggregate
4000{
4001 /* Summary-only flag. */
4002 u_char summary_only;
4003
4004 /* AS set generation. */
4005 u_char as_set;
4006
4007 /* Route-map for aggregated route. */
4008 struct route_map *map;
4009
4010 /* Suppress-count. */
4011 unsigned long count;
4012
4013 /* SAFI configuration. */
4014 safi_t safi;
4015};
4016
paul94f2b392005-06-28 12:44:16 +00004017static struct bgp_aggregate *
paul718e3742002-12-13 20:15:29 +00004018bgp_aggregate_new ()
4019{
4020 struct bgp_aggregate *new;
4021 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4022 memset (new, 0, sizeof (struct bgp_aggregate));
4023 return new;
4024}
4025
paul94f2b392005-06-28 12:44:16 +00004026static void
paul718e3742002-12-13 20:15:29 +00004027bgp_aggregate_free (struct bgp_aggregate *aggregate)
4028{
4029 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4030}
4031
paul94f2b392005-06-28 12:44:16 +00004032static void
paul718e3742002-12-13 20:15:29 +00004033bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4034 afi_t afi, safi_t safi, struct bgp_info *del,
4035 struct bgp_aggregate *aggregate)
4036{
4037 struct bgp_table *table;
4038 struct bgp_node *top;
4039 struct bgp_node *rn;
4040 u_char origin;
4041 struct aspath *aspath = NULL;
4042 struct aspath *asmerge = NULL;
4043 struct community *community = NULL;
4044 struct community *commerge = NULL;
4045 struct in_addr nexthop;
4046 u_int32_t med = 0;
4047 struct bgp_info *ri;
4048 struct bgp_info *new;
4049 int first = 1;
4050 unsigned long match = 0;
4051
4052 /* Record adding route's nexthop and med. */
4053 if (rinew)
4054 {
4055 nexthop = rinew->attr->nexthop;
4056 med = rinew->attr->med;
4057 }
4058
4059 /* ORIGIN attribute: If at least one route among routes that are
4060 aggregated has ORIGIN with the value INCOMPLETE, then the
4061 aggregated route must have the ORIGIN attribute with the value
4062 INCOMPLETE. Otherwise, if at least one route among routes that
4063 are aggregated has ORIGIN with the value EGP, then the aggregated
4064 route must have the origin attribute with the value EGP. In all
4065 other case the value of the ORIGIN attribute of the aggregated
4066 route is INTERNAL. */
4067 origin = BGP_ORIGIN_IGP;
4068
4069 table = bgp->rib[afi][safi];
4070
4071 top = bgp_node_get (table, p);
4072 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4073 if (rn->p.prefixlen > p->prefixlen)
4074 {
4075 match = 0;
4076
4077 for (ri = rn->info; ri; ri = ri->next)
4078 {
4079 if (BGP_INFO_HOLDDOWN (ri))
4080 continue;
4081
4082 if (del && ri == del)
4083 continue;
4084
4085 if (! rinew && first)
4086 {
4087 nexthop = ri->attr->nexthop;
4088 med = ri->attr->med;
4089 first = 0;
4090 }
4091
4092#ifdef AGGREGATE_NEXTHOP_CHECK
4093 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4094 || ri->attr->med != med)
4095 {
4096 if (aspath)
4097 aspath_free (aspath);
4098 if (community)
4099 community_free (community);
4100 bgp_unlock_node (rn);
4101 bgp_unlock_node (top);
4102 return;
4103 }
4104#endif /* AGGREGATE_NEXTHOP_CHECK */
4105
4106 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4107 {
4108 if (aggregate->summary_only)
4109 {
4110 ri->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004111 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004112 match++;
4113 }
4114
4115 aggregate->count++;
4116
4117 if (aggregate->as_set)
4118 {
4119 if (origin < ri->attr->origin)
4120 origin = ri->attr->origin;
4121
4122 if (aspath)
4123 {
4124 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4125 aspath_free (aspath);
4126 aspath = asmerge;
4127 }
4128 else
4129 aspath = aspath_dup (ri->attr->aspath);
4130
4131 if (ri->attr->community)
4132 {
4133 if (community)
4134 {
4135 commerge = community_merge (community,
4136 ri->attr->community);
4137 community = community_uniq_sort (commerge);
4138 community_free (commerge);
4139 }
4140 else
4141 community = community_dup (ri->attr->community);
4142 }
4143 }
4144 }
4145 }
4146 if (match)
4147 bgp_process (bgp, rn, afi, safi);
4148 }
4149 bgp_unlock_node (top);
4150
4151 if (rinew)
4152 {
4153 aggregate->count++;
4154
4155 if (aggregate->summary_only)
4156 rinew->suppress++;
4157
4158 if (aggregate->as_set)
4159 {
4160 if (origin < rinew->attr->origin)
4161 origin = rinew->attr->origin;
4162
4163 if (aspath)
4164 {
4165 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4166 aspath_free (aspath);
4167 aspath = asmerge;
4168 }
4169 else
4170 aspath = aspath_dup (rinew->attr->aspath);
4171
4172 if (rinew->attr->community)
4173 {
4174 if (community)
4175 {
4176 commerge = community_merge (community,
4177 rinew->attr->community);
4178 community = community_uniq_sort (commerge);
4179 community_free (commerge);
4180 }
4181 else
4182 community = community_dup (rinew->attr->community);
4183 }
4184 }
4185 }
4186
4187 if (aggregate->count > 0)
4188 {
4189 rn = bgp_node_get (table, p);
4190 new = bgp_info_new ();
4191 new->type = ZEBRA_ROUTE_BGP;
4192 new->sub_type = BGP_ROUTE_AGGREGATE;
4193 new->peer = bgp->peer_self;
4194 SET_FLAG (new->flags, BGP_INFO_VALID);
4195 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4196 new->uptime = time (NULL);
4197
4198 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004199 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004200 bgp_process (bgp, rn, afi, safi);
4201 }
4202 else
4203 {
4204 if (aspath)
4205 aspath_free (aspath);
4206 if (community)
4207 community_free (community);
4208 }
4209}
4210
4211void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4212 struct bgp_aggregate *);
4213
4214void
4215bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4216 struct bgp_info *ri, afi_t afi, safi_t safi)
4217{
4218 struct bgp_node *child;
4219 struct bgp_node *rn;
4220 struct bgp_aggregate *aggregate;
4221
4222 /* MPLS-VPN aggregation is not yet supported. */
4223 if (safi == SAFI_MPLS_VPN)
4224 return;
4225
4226 if (p->prefixlen == 0)
4227 return;
4228
4229 if (BGP_INFO_HOLDDOWN (ri))
4230 return;
4231
4232 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4233
4234 /* Aggregate address configuration check. */
4235 for (rn = child; rn; rn = rn->parent)
4236 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4237 {
4238 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004239 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004240 }
4241 bgp_unlock_node (child);
4242}
4243
4244void
4245bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4246 struct bgp_info *del, afi_t afi, safi_t safi)
4247{
4248 struct bgp_node *child;
4249 struct bgp_node *rn;
4250 struct bgp_aggregate *aggregate;
4251
4252 /* MPLS-VPN aggregation is not yet supported. */
4253 if (safi == SAFI_MPLS_VPN)
4254 return;
4255
4256 if (p->prefixlen == 0)
4257 return;
4258
4259 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4260
4261 /* Aggregate address configuration check. */
4262 for (rn = child; rn; rn = rn->parent)
4263 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4264 {
4265 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004266 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004267 }
4268 bgp_unlock_node (child);
4269}
4270
paul94f2b392005-06-28 12:44:16 +00004271static void
paul718e3742002-12-13 20:15:29 +00004272bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4273 struct bgp_aggregate *aggregate)
4274{
4275 struct bgp_table *table;
4276 struct bgp_node *top;
4277 struct bgp_node *rn;
4278 struct bgp_info *new;
4279 struct bgp_info *ri;
4280 unsigned long match;
4281 u_char origin = BGP_ORIGIN_IGP;
4282 struct aspath *aspath = NULL;
4283 struct aspath *asmerge = NULL;
4284 struct community *community = NULL;
4285 struct community *commerge = NULL;
4286
4287 table = bgp->rib[afi][safi];
4288
4289 /* Sanity check. */
4290 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4291 return;
4292 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4293 return;
4294
4295 /* If routes exists below this node, generate aggregate routes. */
4296 top = bgp_node_get (table, p);
4297 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4298 if (rn->p.prefixlen > p->prefixlen)
4299 {
4300 match = 0;
4301
4302 for (ri = rn->info; ri; ri = ri->next)
4303 {
4304 if (BGP_INFO_HOLDDOWN (ri))
4305 continue;
4306
4307 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4308 {
4309 /* summary-only aggregate route suppress aggregated
4310 route announcement. */
4311 if (aggregate->summary_only)
4312 {
4313 ri->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004314 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004315 match++;
4316 }
4317 /* as-set aggregate route generate origin, as path,
4318 community aggregation. */
4319 if (aggregate->as_set)
4320 {
4321 if (origin < ri->attr->origin)
4322 origin = ri->attr->origin;
4323
4324 if (aspath)
4325 {
4326 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4327 aspath_free (aspath);
4328 aspath = asmerge;
4329 }
4330 else
4331 aspath = aspath_dup (ri->attr->aspath);
4332
4333 if (ri->attr->community)
4334 {
4335 if (community)
4336 {
4337 commerge = community_merge (community,
4338 ri->attr->community);
4339 community = community_uniq_sort (commerge);
4340 community_free (commerge);
4341 }
4342 else
4343 community = community_dup (ri->attr->community);
4344 }
4345 }
4346 aggregate->count++;
4347 }
4348 }
4349
4350 /* If this node is suppressed, process the change. */
4351 if (match)
4352 bgp_process (bgp, rn, afi, safi);
4353 }
4354 bgp_unlock_node (top);
4355
4356 /* Add aggregate route to BGP table. */
4357 if (aggregate->count)
4358 {
4359 rn = bgp_node_get (table, p);
4360
4361 new = bgp_info_new ();
4362 new->type = ZEBRA_ROUTE_BGP;
4363 new->sub_type = BGP_ROUTE_AGGREGATE;
4364 new->peer = bgp->peer_self;
4365 SET_FLAG (new->flags, BGP_INFO_VALID);
4366 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4367 new->uptime = time (NULL);
4368
4369 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004370 bgp_unlock_node (rn);
4371
paul718e3742002-12-13 20:15:29 +00004372 /* Process change. */
4373 bgp_process (bgp, rn, afi, safi);
4374 }
4375}
4376
4377void
4378bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4379 safi_t safi, struct bgp_aggregate *aggregate)
4380{
4381 struct bgp_table *table;
4382 struct bgp_node *top;
4383 struct bgp_node *rn;
4384 struct bgp_info *ri;
4385 unsigned long match;
4386
4387 table = bgp->rib[afi][safi];
4388
4389 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4390 return;
4391 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4392 return;
4393
4394 /* If routes exists below this node, generate aggregate routes. */
4395 top = bgp_node_get (table, p);
4396 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4397 if (rn->p.prefixlen > p->prefixlen)
4398 {
4399 match = 0;
4400
4401 for (ri = rn->info; ri; ri = ri->next)
4402 {
4403 if (BGP_INFO_HOLDDOWN (ri))
4404 continue;
4405
4406 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4407 {
4408 if (aggregate->summary_only)
4409 {
4410 ri->suppress--;
4411
4412 if (ri->suppress == 0)
4413 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004414 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004415 match++;
4416 }
4417 }
4418 aggregate->count--;
4419 }
4420 }
4421
4422 /* If this node is suppressed, process the change. */
4423 if (match)
4424 bgp_process (bgp, rn, afi, safi);
4425 }
4426 bgp_unlock_node (top);
4427
4428 /* Delete aggregate route from BGP table. */
4429 rn = bgp_node_get (table, p);
4430
4431 for (ri = rn->info; ri; ri = ri->next)
4432 if (ri->peer == bgp->peer_self
4433 && ri->type == ZEBRA_ROUTE_BGP
4434 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4435 break;
4436
4437 /* Withdraw static BGP route from routing table. */
4438 if (ri)
4439 {
paul718e3742002-12-13 20:15:29 +00004440 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004441 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004442 }
4443
4444 /* Unlock bgp_node_lookup. */
4445 bgp_unlock_node (rn);
4446}
4447
4448/* Aggregate route attribute. */
4449#define AGGREGATE_SUMMARY_ONLY 1
4450#define AGGREGATE_AS_SET 1
4451
paul94f2b392005-06-28 12:44:16 +00004452static int
paulfd79ac92004-10-13 05:06:08 +00004453bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4454 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004455 u_char summary_only, u_char as_set)
4456{
4457 int ret;
4458 struct prefix p;
4459 struct bgp_node *rn;
4460 struct bgp *bgp;
4461 struct bgp_aggregate *aggregate;
4462
4463 /* Convert string to prefix structure. */
4464 ret = str2prefix (prefix_str, &p);
4465 if (!ret)
4466 {
4467 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4468 return CMD_WARNING;
4469 }
4470 apply_mask (&p);
4471
4472 /* Get BGP structure. */
4473 bgp = vty->index;
4474
4475 /* Old configuration check. */
4476 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4477
4478 if (rn->info)
4479 {
4480 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4481 bgp_unlock_node (rn);
4482 return CMD_WARNING;
4483 }
4484
4485 /* Make aggregate address structure. */
4486 aggregate = bgp_aggregate_new ();
4487 aggregate->summary_only = summary_only;
4488 aggregate->as_set = as_set;
4489 aggregate->safi = safi;
4490 rn->info = aggregate;
4491
4492 /* Aggregate address insert into BGP routing table. */
4493 if (safi & SAFI_UNICAST)
4494 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4495 if (safi & SAFI_MULTICAST)
4496 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4497
4498 return CMD_SUCCESS;
4499}
4500
paul94f2b392005-06-28 12:44:16 +00004501static int
paulfd79ac92004-10-13 05:06:08 +00004502bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4503 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004504{
4505 int ret;
4506 struct prefix p;
4507 struct bgp_node *rn;
4508 struct bgp *bgp;
4509 struct bgp_aggregate *aggregate;
4510
4511 /* Convert string to prefix structure. */
4512 ret = str2prefix (prefix_str, &p);
4513 if (!ret)
4514 {
4515 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4516 return CMD_WARNING;
4517 }
4518 apply_mask (&p);
4519
4520 /* Get BGP structure. */
4521 bgp = vty->index;
4522
4523 /* Old configuration check. */
4524 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4525 if (! rn)
4526 {
4527 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4528 VTY_NEWLINE);
4529 return CMD_WARNING;
4530 }
4531
4532 aggregate = rn->info;
4533 if (aggregate->safi & SAFI_UNICAST)
4534 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4535 if (aggregate->safi & SAFI_MULTICAST)
4536 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4537
4538 /* Unlock aggregate address configuration. */
4539 rn->info = NULL;
4540 bgp_aggregate_free (aggregate);
4541 bgp_unlock_node (rn);
4542 bgp_unlock_node (rn);
4543
4544 return CMD_SUCCESS;
4545}
4546
4547DEFUN (aggregate_address,
4548 aggregate_address_cmd,
4549 "aggregate-address A.B.C.D/M",
4550 "Configure BGP aggregate entries\n"
4551 "Aggregate prefix\n")
4552{
4553 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4554}
4555
4556DEFUN (aggregate_address_mask,
4557 aggregate_address_mask_cmd,
4558 "aggregate-address A.B.C.D A.B.C.D",
4559 "Configure BGP aggregate entries\n"
4560 "Aggregate address\n"
4561 "Aggregate mask\n")
4562{
4563 int ret;
4564 char prefix_str[BUFSIZ];
4565
4566 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4567
4568 if (! ret)
4569 {
4570 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4571 return CMD_WARNING;
4572 }
4573
4574 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4575 0, 0);
4576}
4577
4578DEFUN (aggregate_address_summary_only,
4579 aggregate_address_summary_only_cmd,
4580 "aggregate-address A.B.C.D/M summary-only",
4581 "Configure BGP aggregate entries\n"
4582 "Aggregate prefix\n"
4583 "Filter more specific routes from updates\n")
4584{
4585 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4586 AGGREGATE_SUMMARY_ONLY, 0);
4587}
4588
4589DEFUN (aggregate_address_mask_summary_only,
4590 aggregate_address_mask_summary_only_cmd,
4591 "aggregate-address A.B.C.D A.B.C.D summary-only",
4592 "Configure BGP aggregate entries\n"
4593 "Aggregate address\n"
4594 "Aggregate mask\n"
4595 "Filter more specific routes from updates\n")
4596{
4597 int ret;
4598 char prefix_str[BUFSIZ];
4599
4600 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4601
4602 if (! ret)
4603 {
4604 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4605 return CMD_WARNING;
4606 }
4607
4608 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4609 AGGREGATE_SUMMARY_ONLY, 0);
4610}
4611
4612DEFUN (aggregate_address_as_set,
4613 aggregate_address_as_set_cmd,
4614 "aggregate-address A.B.C.D/M as-set",
4615 "Configure BGP aggregate entries\n"
4616 "Aggregate prefix\n"
4617 "Generate AS set path information\n")
4618{
4619 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4620 0, AGGREGATE_AS_SET);
4621}
4622
4623DEFUN (aggregate_address_mask_as_set,
4624 aggregate_address_mask_as_set_cmd,
4625 "aggregate-address A.B.C.D A.B.C.D as-set",
4626 "Configure BGP aggregate entries\n"
4627 "Aggregate address\n"
4628 "Aggregate mask\n"
4629 "Generate AS set path information\n")
4630{
4631 int ret;
4632 char prefix_str[BUFSIZ];
4633
4634 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4635
4636 if (! ret)
4637 {
4638 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4639 return CMD_WARNING;
4640 }
4641
4642 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4643 0, AGGREGATE_AS_SET);
4644}
4645
4646
4647DEFUN (aggregate_address_as_set_summary,
4648 aggregate_address_as_set_summary_cmd,
4649 "aggregate-address A.B.C.D/M as-set summary-only",
4650 "Configure BGP aggregate entries\n"
4651 "Aggregate prefix\n"
4652 "Generate AS set path information\n"
4653 "Filter more specific routes from updates\n")
4654{
4655 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4656 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4657}
4658
4659ALIAS (aggregate_address_as_set_summary,
4660 aggregate_address_summary_as_set_cmd,
4661 "aggregate-address A.B.C.D/M summary-only as-set",
4662 "Configure BGP aggregate entries\n"
4663 "Aggregate prefix\n"
4664 "Filter more specific routes from updates\n"
4665 "Generate AS set path information\n")
4666
4667DEFUN (aggregate_address_mask_as_set_summary,
4668 aggregate_address_mask_as_set_summary_cmd,
4669 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4670 "Configure BGP aggregate entries\n"
4671 "Aggregate address\n"
4672 "Aggregate mask\n"
4673 "Generate AS set path information\n"
4674 "Filter more specific routes from updates\n")
4675{
4676 int ret;
4677 char prefix_str[BUFSIZ];
4678
4679 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4680
4681 if (! ret)
4682 {
4683 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4684 return CMD_WARNING;
4685 }
4686
4687 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4688 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4689}
4690
4691ALIAS (aggregate_address_mask_as_set_summary,
4692 aggregate_address_mask_summary_as_set_cmd,
4693 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4694 "Configure BGP aggregate entries\n"
4695 "Aggregate address\n"
4696 "Aggregate mask\n"
4697 "Filter more specific routes from updates\n"
4698 "Generate AS set path information\n")
4699
4700DEFUN (no_aggregate_address,
4701 no_aggregate_address_cmd,
4702 "no aggregate-address A.B.C.D/M",
4703 NO_STR
4704 "Configure BGP aggregate entries\n"
4705 "Aggregate prefix\n")
4706{
4707 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4708}
4709
4710ALIAS (no_aggregate_address,
4711 no_aggregate_address_summary_only_cmd,
4712 "no aggregate-address A.B.C.D/M summary-only",
4713 NO_STR
4714 "Configure BGP aggregate entries\n"
4715 "Aggregate prefix\n"
4716 "Filter more specific routes from updates\n")
4717
4718ALIAS (no_aggregate_address,
4719 no_aggregate_address_as_set_cmd,
4720 "no aggregate-address A.B.C.D/M as-set",
4721 NO_STR
4722 "Configure BGP aggregate entries\n"
4723 "Aggregate prefix\n"
4724 "Generate AS set path information\n")
4725
4726ALIAS (no_aggregate_address,
4727 no_aggregate_address_as_set_summary_cmd,
4728 "no aggregate-address A.B.C.D/M as-set summary-only",
4729 NO_STR
4730 "Configure BGP aggregate entries\n"
4731 "Aggregate prefix\n"
4732 "Generate AS set path information\n"
4733 "Filter more specific routes from updates\n")
4734
4735ALIAS (no_aggregate_address,
4736 no_aggregate_address_summary_as_set_cmd,
4737 "no aggregate-address A.B.C.D/M summary-only as-set",
4738 NO_STR
4739 "Configure BGP aggregate entries\n"
4740 "Aggregate prefix\n"
4741 "Filter more specific routes from updates\n"
4742 "Generate AS set path information\n")
4743
4744DEFUN (no_aggregate_address_mask,
4745 no_aggregate_address_mask_cmd,
4746 "no aggregate-address A.B.C.D A.B.C.D",
4747 NO_STR
4748 "Configure BGP aggregate entries\n"
4749 "Aggregate address\n"
4750 "Aggregate mask\n")
4751{
4752 int ret;
4753 char prefix_str[BUFSIZ];
4754
4755 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4756
4757 if (! ret)
4758 {
4759 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4760 return CMD_WARNING;
4761 }
4762
4763 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4764}
4765
4766ALIAS (no_aggregate_address_mask,
4767 no_aggregate_address_mask_summary_only_cmd,
4768 "no aggregate-address A.B.C.D A.B.C.D summary-only",
4769 NO_STR
4770 "Configure BGP aggregate entries\n"
4771 "Aggregate address\n"
4772 "Aggregate mask\n"
4773 "Filter more specific routes from updates\n")
4774
4775ALIAS (no_aggregate_address_mask,
4776 no_aggregate_address_mask_as_set_cmd,
4777 "no aggregate-address A.B.C.D A.B.C.D as-set",
4778 NO_STR
4779 "Configure BGP aggregate entries\n"
4780 "Aggregate address\n"
4781 "Aggregate mask\n"
4782 "Generate AS set path information\n")
4783
4784ALIAS (no_aggregate_address_mask,
4785 no_aggregate_address_mask_as_set_summary_cmd,
4786 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4787 NO_STR
4788 "Configure BGP aggregate entries\n"
4789 "Aggregate address\n"
4790 "Aggregate mask\n"
4791 "Generate AS set path information\n"
4792 "Filter more specific routes from updates\n")
4793
4794ALIAS (no_aggregate_address_mask,
4795 no_aggregate_address_mask_summary_as_set_cmd,
4796 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4797 NO_STR
4798 "Configure BGP aggregate entries\n"
4799 "Aggregate address\n"
4800 "Aggregate mask\n"
4801 "Filter more specific routes from updates\n"
4802 "Generate AS set path information\n")
4803
4804#ifdef HAVE_IPV6
4805DEFUN (ipv6_aggregate_address,
4806 ipv6_aggregate_address_cmd,
4807 "aggregate-address X:X::X:X/M",
4808 "Configure BGP aggregate entries\n"
4809 "Aggregate prefix\n")
4810{
4811 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4812}
4813
4814DEFUN (ipv6_aggregate_address_summary_only,
4815 ipv6_aggregate_address_summary_only_cmd,
4816 "aggregate-address X:X::X:X/M summary-only",
4817 "Configure BGP aggregate entries\n"
4818 "Aggregate prefix\n"
4819 "Filter more specific routes from updates\n")
4820{
4821 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4822 AGGREGATE_SUMMARY_ONLY, 0);
4823}
4824
4825DEFUN (no_ipv6_aggregate_address,
4826 no_ipv6_aggregate_address_cmd,
4827 "no aggregate-address X:X::X:X/M",
4828 NO_STR
4829 "Configure BGP aggregate entries\n"
4830 "Aggregate prefix\n")
4831{
4832 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4833}
4834
4835DEFUN (no_ipv6_aggregate_address_summary_only,
4836 no_ipv6_aggregate_address_summary_only_cmd,
4837 "no aggregate-address X:X::X:X/M summary-only",
4838 NO_STR
4839 "Configure BGP aggregate entries\n"
4840 "Aggregate prefix\n"
4841 "Filter more specific routes from updates\n")
4842{
4843 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4844}
4845
4846ALIAS (ipv6_aggregate_address,
4847 old_ipv6_aggregate_address_cmd,
4848 "ipv6 bgp aggregate-address X:X::X:X/M",
4849 IPV6_STR
4850 BGP_STR
4851 "Configure BGP aggregate entries\n"
4852 "Aggregate prefix\n")
4853
4854ALIAS (ipv6_aggregate_address_summary_only,
4855 old_ipv6_aggregate_address_summary_only_cmd,
4856 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4857 IPV6_STR
4858 BGP_STR
4859 "Configure BGP aggregate entries\n"
4860 "Aggregate prefix\n"
4861 "Filter more specific routes from updates\n")
4862
4863ALIAS (no_ipv6_aggregate_address,
4864 old_no_ipv6_aggregate_address_cmd,
4865 "no ipv6 bgp aggregate-address X:X::X:X/M",
4866 NO_STR
4867 IPV6_STR
4868 BGP_STR
4869 "Configure BGP aggregate entries\n"
4870 "Aggregate prefix\n")
4871
4872ALIAS (no_ipv6_aggregate_address_summary_only,
4873 old_no_ipv6_aggregate_address_summary_only_cmd,
4874 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4875 NO_STR
4876 IPV6_STR
4877 BGP_STR
4878 "Configure BGP aggregate entries\n"
4879 "Aggregate prefix\n"
4880 "Filter more specific routes from updates\n")
4881#endif /* HAVE_IPV6 */
4882
4883/* Redistribute route treatment. */
4884void
4885bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4886 u_int32_t metric, u_char type)
4887{
4888 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004889 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004890 struct bgp_info *new;
4891 struct bgp_info *bi;
4892 struct bgp_info info;
4893 struct bgp_node *bn;
4894 struct attr attr;
4895 struct attr attr_new;
4896 struct attr *new_attr;
4897 afi_t afi;
4898 int ret;
4899
4900 /* Make default attribute. */
4901 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4902 if (nexthop)
4903 attr.nexthop = *nexthop;
4904
4905 attr.med = metric;
4906 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4907
paul1eb8ef22005-04-07 07:30:20 +00004908 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004909 {
4910 afi = family2afi (p->family);
4911
4912 if (bgp->redist[afi][type])
4913 {
4914 /* Copy attribute for modification. */
4915 attr_new = attr;
4916
4917 if (bgp->redist_metric_flag[afi][type])
4918 attr_new.med = bgp->redist_metric[afi][type];
4919
4920 /* Apply route-map. */
4921 if (bgp->rmap[afi][type].map)
4922 {
4923 info.peer = bgp->peer_self;
4924 info.attr = &attr_new;
4925
paulfee0f4c2004-09-13 05:12:46 +00004926 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
4927
paul718e3742002-12-13 20:15:29 +00004928 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
4929 &info);
paulfee0f4c2004-09-13 05:12:46 +00004930
4931 bgp->peer_self->rmap_type = 0;
4932
paul718e3742002-12-13 20:15:29 +00004933 if (ret == RMAP_DENYMATCH)
4934 {
4935 /* Free uninterned attribute. */
4936 bgp_attr_flush (&attr_new);
4937
4938 /* Unintern original. */
4939 aspath_unintern (attr.aspath);
4940 bgp_redistribute_delete (p, type);
4941 return;
4942 }
4943 }
4944
paulfee0f4c2004-09-13 05:12:46 +00004945 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004946 new_attr = bgp_attr_intern (&attr_new);
4947
4948 for (bi = bn->info; bi; bi = bi->next)
4949 if (bi->peer == bgp->peer_self
4950 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
4951 break;
4952
4953 if (bi)
4954 {
4955 if (attrhash_cmp (bi->attr, new_attr))
4956 {
4957 bgp_attr_unintern (new_attr);
4958 aspath_unintern (attr.aspath);
4959 bgp_unlock_node (bn);
4960 return;
4961 }
4962 else
4963 {
4964 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00004965 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004966
4967 /* Rewrite BGP route information. */
4968 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
4969 bgp_attr_unintern (bi->attr);
4970 bi->attr = new_attr;
4971 bi->uptime = time (NULL);
4972
4973 /* Process change. */
4974 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
4975 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4976 bgp_unlock_node (bn);
4977 aspath_unintern (attr.aspath);
4978 return;
4979 }
4980 }
4981
4982 new = bgp_info_new ();
4983 new->type = type;
4984 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
4985 new->peer = bgp->peer_self;
4986 SET_FLAG (new->flags, BGP_INFO_VALID);
4987 new->attr = new_attr;
4988 new->uptime = time (NULL);
4989
4990 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
4991 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00004992 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00004993 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4994 }
4995 }
4996
4997 /* Unintern original. */
4998 aspath_unintern (attr.aspath);
4999}
5000
5001void
5002bgp_redistribute_delete (struct prefix *p, u_char type)
5003{
5004 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005005 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005006 afi_t afi;
5007 struct bgp_node *rn;
5008 struct bgp_info *ri;
5009
paul1eb8ef22005-04-07 07:30:20 +00005010 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005011 {
5012 afi = family2afi (p->family);
5013
5014 if (bgp->redist[afi][type])
5015 {
paulfee0f4c2004-09-13 05:12:46 +00005016 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005017
5018 for (ri = rn->info; ri; ri = ri->next)
5019 if (ri->peer == bgp->peer_self
5020 && ri->type == type)
5021 break;
5022
5023 if (ri)
5024 {
5025 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005026 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005027 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005028 }
5029 bgp_unlock_node (rn);
5030 }
5031 }
5032}
5033
5034/* Withdraw specified route type's route. */
5035void
5036bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5037{
5038 struct bgp_node *rn;
5039 struct bgp_info *ri;
5040 struct bgp_table *table;
5041
5042 table = bgp->rib[afi][SAFI_UNICAST];
5043
5044 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5045 {
5046 for (ri = rn->info; ri; ri = ri->next)
5047 if (ri->peer == bgp->peer_self
5048 && ri->type == type)
5049 break;
5050
5051 if (ri)
5052 {
5053 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005054 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005055 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005056 }
5057 }
5058}
5059
5060/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005061static void
paul718e3742002-12-13 20:15:29 +00005062route_vty_out_route (struct prefix *p, struct vty *vty)
5063{
5064 int len;
5065 u_int32_t destination;
5066 char buf[BUFSIZ];
5067
5068 if (p->family == AF_INET)
5069 {
5070 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5071 destination = ntohl (p->u.prefix4.s_addr);
5072
5073 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5074 || (IN_CLASSB (destination) && p->prefixlen == 16)
5075 || (IN_CLASSA (destination) && p->prefixlen == 8)
5076 || p->u.prefix4.s_addr == 0)
5077 {
5078 /* When mask is natural, mask is not displayed. */
5079 }
5080 else
5081 len += vty_out (vty, "/%d", p->prefixlen);
5082 }
5083 else
5084 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5085 p->prefixlen);
5086
5087 len = 17 - len;
5088 if (len < 1)
5089 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5090 else
5091 vty_out (vty, "%*s", len, " ");
5092}
5093
paul718e3742002-12-13 20:15:29 +00005094enum bgp_display_type
5095{
5096 normal_list,
5097};
5098
paulb40d9392005-08-22 22:34:41 +00005099/* Print the short form route status for a bgp_info */
5100static void
5101route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005102{
paulb40d9392005-08-22 22:34:41 +00005103 /* Route status display. */
5104 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5105 vty_out (vty, "R");
5106 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005107 vty_out (vty, "S");
5108 else if (binfo->suppress)
paul718e3742002-12-13 20:15:29 +00005109 vty_out (vty, "s");
5110 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5111 vty_out (vty, "*");
5112 else
5113 vty_out (vty, " ");
5114
5115 /* Selected */
5116 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5117 vty_out (vty, "h");
5118 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5119 vty_out (vty, "d");
5120 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5121 vty_out (vty, ">");
5122 else
5123 vty_out (vty, " ");
5124
5125 /* Internal route. */
5126 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5127 vty_out (vty, "i");
5128 else
paulb40d9392005-08-22 22:34:41 +00005129 vty_out (vty, " ");
5130}
5131
5132/* called from terminal list command */
5133void
5134route_vty_out (struct vty *vty, struct prefix *p,
5135 struct bgp_info *binfo, int display, safi_t safi)
5136{
5137 struct attr *attr;
5138
5139 /* short status lead text */
5140 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005141
5142 /* print prefix and mask */
5143 if (! display)
5144 route_vty_out_route (p, vty);
5145 else
5146 vty_out (vty, "%*s", 17, " ");
5147
5148 /* Print attribute */
5149 attr = binfo->attr;
5150 if (attr)
5151 {
5152 if (p->family == AF_INET)
5153 {
5154 if (safi == SAFI_MPLS_VPN)
5155 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5156 else
5157 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5158 }
5159#ifdef HAVE_IPV6
5160 else if (p->family == AF_INET6)
5161 {
5162 int len;
5163 char buf[BUFSIZ];
5164
5165 len = vty_out (vty, "%s",
5166 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5167 len = 16 - len;
5168 if (len < 1)
5169 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5170 else
5171 vty_out (vty, "%*s", len, " ");
5172 }
5173#endif /* HAVE_IPV6 */
5174
5175 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5176 vty_out (vty, "%10d", attr->med);
5177 else
5178 vty_out (vty, " ");
5179
5180 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5181 vty_out (vty, "%7d", attr->local_pref);
5182 else
5183 vty_out (vty, " ");
5184
5185 vty_out (vty, "%7u ",attr->weight);
5186
Paul Jakmab2518c12006-05-12 23:48:40 +00005187 /* Print aspath */
5188 if (attr->aspath)
5189 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005190
Paul Jakmab2518c12006-05-12 23:48:40 +00005191 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005192 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005193 }
paul718e3742002-12-13 20:15:29 +00005194 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005195}
5196
5197/* called from terminal list command */
5198void
5199route_vty_out_tmp (struct vty *vty, struct prefix *p,
5200 struct attr *attr, safi_t safi)
5201{
5202 /* Route status display. */
5203 vty_out (vty, "*");
5204 vty_out (vty, ">");
5205 vty_out (vty, " ");
5206
5207 /* print prefix and mask */
5208 route_vty_out_route (p, vty);
5209
5210 /* Print attribute */
5211 if (attr)
5212 {
5213 if (p->family == AF_INET)
5214 {
5215 if (safi == SAFI_MPLS_VPN)
5216 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5217 else
5218 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5219 }
5220#ifdef HAVE_IPV6
5221 else if (p->family == AF_INET6)
5222 {
5223 int len;
5224 char buf[BUFSIZ];
5225
5226 len = vty_out (vty, "%s",
5227 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5228 len = 16 - len;
5229 if (len < 1)
5230 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5231 else
5232 vty_out (vty, "%*s", len, " ");
5233 }
5234#endif /* HAVE_IPV6 */
5235
5236 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5237 vty_out (vty, "%10d", attr->med);
5238 else
5239 vty_out (vty, " ");
5240
5241 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5242 vty_out (vty, "%7d", attr->local_pref);
5243 else
5244 vty_out (vty, " ");
5245
5246 vty_out (vty, "%7d ",attr->weight);
5247
Paul Jakmab2518c12006-05-12 23:48:40 +00005248 /* Print aspath */
5249 if (attr->aspath)
5250 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005251
Paul Jakmab2518c12006-05-12 23:48:40 +00005252 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005253 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005254 }
paul718e3742002-12-13 20:15:29 +00005255
5256 vty_out (vty, "%s", VTY_NEWLINE);
5257}
5258
ajs5a646652004-11-05 01:25:55 +00005259void
paul718e3742002-12-13 20:15:29 +00005260route_vty_out_tag (struct vty *vty, struct prefix *p,
5261 struct bgp_info *binfo, int display, safi_t safi)
5262{
5263 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005264 u_int32_t label = 0;
5265
paulb40d9392005-08-22 22:34:41 +00005266 /* short status lead text */
5267 route_vty_short_status_out (vty, binfo);
5268
paul718e3742002-12-13 20:15:29 +00005269 /* print prefix and mask */
5270 if (! display)
5271 route_vty_out_route (p, vty);
5272 else
5273 vty_out (vty, "%*s", 17, " ");
5274
5275 /* Print attribute */
5276 attr = binfo->attr;
5277 if (attr)
5278 {
5279 if (p->family == AF_INET)
5280 {
5281 if (safi == SAFI_MPLS_VPN)
5282 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5283 else
5284 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5285 }
5286#ifdef HAVE_IPV6
5287 else if (p->family == AF_INET6)
5288 {
5289 char buf[BUFSIZ];
5290 char buf1[BUFSIZ];
5291 if (attr->mp_nexthop_len == 16)
5292 vty_out (vty, "%s",
5293 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5294 else if (attr->mp_nexthop_len == 32)
5295 vty_out (vty, "%s(%s)",
5296 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
5297 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
5298
5299 }
5300#endif /* HAVE_IPV6 */
5301 }
5302
5303 label = decode_label (binfo->tag);
5304
5305 vty_out (vty, "notag/%d", label);
5306
5307 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005308}
5309
5310/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005311static void
paul718e3742002-12-13 20:15:29 +00005312damp_route_vty_out (struct vty *vty, struct prefix *p,
5313 struct bgp_info *binfo, int display, safi_t safi)
5314{
5315 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005316 int len;
5317
paulb40d9392005-08-22 22:34:41 +00005318 /* short status lead text */
5319 route_vty_short_status_out (vty, binfo);
5320
paul718e3742002-12-13 20:15:29 +00005321 /* print prefix and mask */
5322 if (! display)
5323 route_vty_out_route (p, vty);
5324 else
5325 vty_out (vty, "%*s", 17, " ");
5326
5327 len = vty_out (vty, "%s", binfo->peer->host);
5328 len = 17 - len;
5329 if (len < 1)
5330 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5331 else
5332 vty_out (vty, "%*s", len, " ");
5333
5334 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5335
5336 /* Print attribute */
5337 attr = binfo->attr;
5338 if (attr)
5339 {
5340 /* Print aspath */
5341 if (attr->aspath)
Paul Jakmab2518c12006-05-12 23:48:40 +00005342 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005343
5344 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005345 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005346 }
5347 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005348}
5349
5350#define BGP_UPTIME_LEN 25
5351
5352/* flap route */
ajs5a646652004-11-05 01:25:55 +00005353static void
paul718e3742002-12-13 20:15:29 +00005354flap_route_vty_out (struct vty *vty, struct prefix *p,
5355 struct bgp_info *binfo, int display, safi_t safi)
5356{
5357 struct attr *attr;
5358 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005359 char timebuf[BGP_UPTIME_LEN];
5360 int len;
5361
paul718e3742002-12-13 20:15:29 +00005362 bdi = binfo->damp_info;
5363
paulb40d9392005-08-22 22:34:41 +00005364 /* short status lead text */
5365 route_vty_short_status_out (vty, binfo);
5366
paul718e3742002-12-13 20:15:29 +00005367 /* print prefix and mask */
5368 if (! display)
5369 route_vty_out_route (p, vty);
5370 else
5371 vty_out (vty, "%*s", 17, " ");
5372
5373 len = vty_out (vty, "%s", binfo->peer->host);
5374 len = 16 - len;
5375 if (len < 1)
5376 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5377 else
5378 vty_out (vty, "%*s", len, " ");
5379
5380 len = vty_out (vty, "%d", bdi->flap);
5381 len = 5 - len;
5382 if (len < 1)
5383 vty_out (vty, " ");
5384 else
5385 vty_out (vty, "%*s ", len, " ");
5386
5387 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5388 timebuf, BGP_UPTIME_LEN));
5389
5390 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5391 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5392 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5393 else
5394 vty_out (vty, "%*s ", 8, " ");
5395
5396 /* Print attribute */
5397 attr = binfo->attr;
5398 if (attr)
5399 {
5400 /* Print aspath */
5401 if (attr->aspath)
Paul Jakmab2518c12006-05-12 23:48:40 +00005402 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005403
5404 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005405 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005406 }
5407 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005408}
5409
paul94f2b392005-06-28 12:44:16 +00005410static void
paul718e3742002-12-13 20:15:29 +00005411route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5412 struct bgp_info *binfo, afi_t afi, safi_t safi)
5413{
5414 char buf[INET6_ADDRSTRLEN];
5415 char buf1[BUFSIZ];
5416 struct attr *attr;
5417 int sockunion_vty_out (struct vty *, union sockunion *);
5418
5419 attr = binfo->attr;
5420
5421 if (attr)
5422 {
5423 /* Line1 display AS-path, Aggregator */
5424 if (attr->aspath)
5425 {
5426 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005427 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005428 vty_out (vty, "Local");
5429 else
Paul Jakmab2518c12006-05-12 23:48:40 +00005430 aspath_print_vty (vty, "%s", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005431 }
5432
paulb40d9392005-08-22 22:34:41 +00005433 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5434 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005435 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5436 vty_out (vty, ", (stale)");
5437 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5438 vty_out (vty, ", (aggregated by %d %s)", attr->aggregator_as,
5439 inet_ntoa (attr->aggregator_addr));
5440 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5441 vty_out (vty, ", (Received from a RR-client)");
5442 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5443 vty_out (vty, ", (Received from a RS-client)");
5444 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5445 vty_out (vty, ", (history entry)");
5446 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5447 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005448 vty_out (vty, "%s", VTY_NEWLINE);
5449
5450 /* Line2 display Next-hop, Neighbor, Router-id */
5451 if (p->family == AF_INET)
5452 {
5453 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5454 inet_ntoa (attr->mp_nexthop_global_in) :
5455 inet_ntoa (attr->nexthop));
5456 }
5457#ifdef HAVE_IPV6
5458 else
5459 {
5460 vty_out (vty, " %s",
5461 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5462 buf, INET6_ADDRSTRLEN));
5463 }
5464#endif /* HAVE_IPV6 */
5465
5466 if (binfo->peer == bgp->peer_self)
5467 {
5468 vty_out (vty, " from %s ",
5469 p->family == AF_INET ? "0.0.0.0" : "::");
5470 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5471 }
5472 else
5473 {
5474 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5475 vty_out (vty, " (inaccessible)");
5476 else if (binfo->igpmetric)
5477 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005478 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005479 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5480 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5481 else
5482 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5483 }
5484 vty_out (vty, "%s", VTY_NEWLINE);
5485
5486#ifdef HAVE_IPV6
5487 /* display nexthop local */
5488 if (attr->mp_nexthop_len == 32)
5489 {
5490 vty_out (vty, " (%s)%s",
5491 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5492 buf, INET6_ADDRSTRLEN),
5493 VTY_NEWLINE);
5494 }
5495#endif /* HAVE_IPV6 */
5496
5497 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5498 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5499
5500 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5501 vty_out (vty, ", metric %d", attr->med);
5502
5503 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5504 vty_out (vty, ", localpref %d", attr->local_pref);
5505 else
5506 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5507
5508 if (attr->weight != 0)
5509 vty_out (vty, ", weight %d", attr->weight);
5510
5511 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5512 vty_out (vty, ", valid");
5513
5514 if (binfo->peer != bgp->peer_self)
5515 {
5516 if (binfo->peer->as == binfo->peer->local_as)
5517 vty_out (vty, ", internal");
5518 else
5519 vty_out (vty, ", %s",
5520 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5521 }
5522 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5523 vty_out (vty, ", aggregated, local");
5524 else if (binfo->type != ZEBRA_ROUTE_BGP)
5525 vty_out (vty, ", sourced");
5526 else
5527 vty_out (vty, ", sourced, local");
5528
5529 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5530 vty_out (vty, ", atomic-aggregate");
5531
5532 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5533 vty_out (vty, ", best");
5534
5535 vty_out (vty, "%s", VTY_NEWLINE);
5536
5537 /* Line 4 display Community */
5538 if (attr->community)
5539 vty_out (vty, " Community: %s%s", attr->community->str,
5540 VTY_NEWLINE);
5541
5542 /* Line 5 display Extended-community */
5543 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5544 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5545 VTY_NEWLINE);
5546
5547 /* Line 6 display Originator, Cluster-id */
5548 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5549 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5550 {
5551 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5552 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5553
5554 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5555 {
5556 int i;
5557 vty_out (vty, ", Cluster list: ");
5558 for (i = 0; i < attr->cluster->length / 4; i++)
5559 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5560 }
5561 vty_out (vty, "%s", VTY_NEWLINE);
5562 }
5563
5564 if (binfo->damp_info)
5565 bgp_damp_info_vty (vty, binfo);
5566
5567 /* Line 7 display Uptime */
5568 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5569 }
5570 vty_out (vty, "%s", VTY_NEWLINE);
5571}
5572
paulb40d9392005-08-22 22:34:41 +00005573#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 +00005574#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005575#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5576#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5577#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5578
5579enum bgp_show_type
5580{
5581 bgp_show_type_normal,
5582 bgp_show_type_regexp,
5583 bgp_show_type_prefix_list,
5584 bgp_show_type_filter_list,
5585 bgp_show_type_route_map,
5586 bgp_show_type_neighbor,
5587 bgp_show_type_cidr_only,
5588 bgp_show_type_prefix_longer,
5589 bgp_show_type_community_all,
5590 bgp_show_type_community,
5591 bgp_show_type_community_exact,
5592 bgp_show_type_community_list,
5593 bgp_show_type_community_list_exact,
5594 bgp_show_type_flap_statistics,
5595 bgp_show_type_flap_address,
5596 bgp_show_type_flap_prefix,
5597 bgp_show_type_flap_cidr_only,
5598 bgp_show_type_flap_regexp,
5599 bgp_show_type_flap_filter_list,
5600 bgp_show_type_flap_prefix_list,
5601 bgp_show_type_flap_prefix_longer,
5602 bgp_show_type_flap_route_map,
5603 bgp_show_type_flap_neighbor,
5604 bgp_show_type_dampend_paths,
5605 bgp_show_type_damp_neighbor
5606};
5607
ajs5a646652004-11-05 01:25:55 +00005608static int
paulfee0f4c2004-09-13 05:12:46 +00005609bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00005610 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00005611{
paul718e3742002-12-13 20:15:29 +00005612 struct bgp_info *ri;
5613 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005614 int header = 1;
paul718e3742002-12-13 20:15:29 +00005615 int display;
ajs5a646652004-11-05 01:25:55 +00005616 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00005617
5618 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00005619 output_count = 0;
paul718e3742002-12-13 20:15:29 +00005620
paul718e3742002-12-13 20:15:29 +00005621 /* Start processing of routes. */
5622 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5623 if (rn->info != NULL)
5624 {
5625 display = 0;
5626
5627 for (ri = rn->info; ri; ri = ri->next)
5628 {
ajs5a646652004-11-05 01:25:55 +00005629 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00005630 || type == bgp_show_type_flap_address
5631 || type == bgp_show_type_flap_prefix
5632 || type == bgp_show_type_flap_cidr_only
5633 || type == bgp_show_type_flap_regexp
5634 || type == bgp_show_type_flap_filter_list
5635 || type == bgp_show_type_flap_prefix_list
5636 || type == bgp_show_type_flap_prefix_longer
5637 || type == bgp_show_type_flap_route_map
5638 || type == bgp_show_type_flap_neighbor
5639 || type == bgp_show_type_dampend_paths
5640 || type == bgp_show_type_damp_neighbor)
5641 {
5642 if (! ri->damp_info)
5643 continue;
5644 }
5645 if (type == bgp_show_type_regexp
5646 || type == bgp_show_type_flap_regexp)
5647 {
ajs5a646652004-11-05 01:25:55 +00005648 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00005649
5650 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5651 continue;
5652 }
5653 if (type == bgp_show_type_prefix_list
5654 || type == bgp_show_type_flap_prefix_list)
5655 {
ajs5a646652004-11-05 01:25:55 +00005656 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00005657
5658 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5659 continue;
5660 }
5661 if (type == bgp_show_type_filter_list
5662 || type == bgp_show_type_flap_filter_list)
5663 {
ajs5a646652004-11-05 01:25:55 +00005664 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00005665
5666 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5667 continue;
5668 }
5669 if (type == bgp_show_type_route_map
5670 || type == bgp_show_type_flap_route_map)
5671 {
ajs5a646652004-11-05 01:25:55 +00005672 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00005673 struct bgp_info binfo;
5674 struct attr dummy_attr;
5675 int ret;
5676
5677 dummy_attr = *ri->attr;
5678 binfo.peer = ri->peer;
5679 binfo.attr = &dummy_attr;
5680
5681 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5682
5683 if (ret == RMAP_DENYMATCH)
5684 continue;
5685 }
5686 if (type == bgp_show_type_neighbor
5687 || type == bgp_show_type_flap_neighbor
5688 || type == bgp_show_type_damp_neighbor)
5689 {
ajs5a646652004-11-05 01:25:55 +00005690 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00005691
5692 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5693 continue;
5694 }
5695 if (type == bgp_show_type_cidr_only
5696 || type == bgp_show_type_flap_cidr_only)
5697 {
5698 u_int32_t destination;
5699
5700 destination = ntohl (rn->p.u.prefix4.s_addr);
5701 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5702 continue;
5703 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5704 continue;
5705 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5706 continue;
5707 }
5708 if (type == bgp_show_type_prefix_longer
5709 || type == bgp_show_type_flap_prefix_longer)
5710 {
ajs5a646652004-11-05 01:25:55 +00005711 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005712
5713 if (! prefix_match (p, &rn->p))
5714 continue;
5715 }
5716 if (type == bgp_show_type_community_all)
5717 {
5718 if (! ri->attr->community)
5719 continue;
5720 }
5721 if (type == bgp_show_type_community)
5722 {
ajs5a646652004-11-05 01:25:55 +00005723 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005724
5725 if (! ri->attr->community ||
5726 ! community_match (ri->attr->community, com))
5727 continue;
5728 }
5729 if (type == bgp_show_type_community_exact)
5730 {
ajs5a646652004-11-05 01:25:55 +00005731 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005732
5733 if (! ri->attr->community ||
5734 ! community_cmp (ri->attr->community, com))
5735 continue;
5736 }
5737 if (type == bgp_show_type_community_list)
5738 {
ajs5a646652004-11-05 01:25:55 +00005739 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005740
5741 if (! community_list_match (ri->attr->community, list))
5742 continue;
5743 }
5744 if (type == bgp_show_type_community_list_exact)
5745 {
ajs5a646652004-11-05 01:25:55 +00005746 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005747
5748 if (! community_list_exact_match (ri->attr->community, list))
5749 continue;
5750 }
5751 if (type == bgp_show_type_flap_address
5752 || type == bgp_show_type_flap_prefix)
5753 {
ajs5a646652004-11-05 01:25:55 +00005754 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005755
5756 if (! prefix_match (&rn->p, p))
5757 continue;
5758
5759 if (type == bgp_show_type_flap_prefix)
5760 if (p->prefixlen != rn->p.prefixlen)
5761 continue;
5762 }
5763 if (type == bgp_show_type_dampend_paths
5764 || type == bgp_show_type_damp_neighbor)
5765 {
5766 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5767 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5768 continue;
5769 }
5770
5771 if (header)
5772 {
hasso93406d82005-02-02 14:40:33 +00005773 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
5774 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
5775 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005776 if (type == bgp_show_type_dampend_paths
5777 || type == bgp_show_type_damp_neighbor)
5778 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5779 else if (type == bgp_show_type_flap_statistics
5780 || type == bgp_show_type_flap_address
5781 || type == bgp_show_type_flap_prefix
5782 || type == bgp_show_type_flap_cidr_only
5783 || type == bgp_show_type_flap_regexp
5784 || type == bgp_show_type_flap_filter_list
5785 || type == bgp_show_type_flap_prefix_list
5786 || type == bgp_show_type_flap_prefix_longer
5787 || type == bgp_show_type_flap_route_map
5788 || type == bgp_show_type_flap_neighbor)
5789 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5790 else
5791 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005792 header = 0;
5793 }
5794
5795 if (type == bgp_show_type_dampend_paths
5796 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00005797 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005798 else if (type == bgp_show_type_flap_statistics
5799 || type == bgp_show_type_flap_address
5800 || type == bgp_show_type_flap_prefix
5801 || type == bgp_show_type_flap_cidr_only
5802 || type == bgp_show_type_flap_regexp
5803 || type == bgp_show_type_flap_filter_list
5804 || type == bgp_show_type_flap_prefix_list
5805 || type == bgp_show_type_flap_prefix_longer
5806 || type == bgp_show_type_flap_route_map
5807 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00005808 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005809 else
ajs5a646652004-11-05 01:25:55 +00005810 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005811 display++;
5812 }
5813 if (display)
ajs5a646652004-11-05 01:25:55 +00005814 output_count++;
paul718e3742002-12-13 20:15:29 +00005815 }
5816
5817 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00005818 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00005819 {
5820 if (type == bgp_show_type_normal)
5821 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5822 }
5823 else
5824 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00005825 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005826
5827 return CMD_SUCCESS;
5828}
5829
ajs5a646652004-11-05 01:25:55 +00005830static int
paulfee0f4c2004-09-13 05:12:46 +00005831bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00005832 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00005833{
5834 struct bgp_table *table;
5835
5836 if (bgp == NULL) {
5837 bgp = bgp_get_default ();
5838 }
5839
5840 if (bgp == NULL)
5841 {
5842 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5843 return CMD_WARNING;
5844 }
5845
5846
5847 table = bgp->rib[afi][safi];
5848
ajs5a646652004-11-05 01:25:55 +00005849 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00005850}
5851
paul718e3742002-12-13 20:15:29 +00005852/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00005853static void
paul718e3742002-12-13 20:15:29 +00005854route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5855 struct bgp_node *rn,
5856 struct prefix_rd *prd, afi_t afi, safi_t safi)
5857{
5858 struct bgp_info *ri;
5859 struct prefix *p;
5860 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00005861 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005862 char buf1[INET6_ADDRSTRLEN];
5863 char buf2[INET6_ADDRSTRLEN];
5864 int count = 0;
5865 int best = 0;
5866 int suppress = 0;
5867 int no_export = 0;
5868 int no_advertise = 0;
5869 int local_as = 0;
5870 int first = 0;
5871
5872 p = &rn->p;
5873 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5874 (safi == SAFI_MPLS_VPN ?
5875 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5876 safi == SAFI_MPLS_VPN ? ":" : "",
5877 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5878 p->prefixlen, VTY_NEWLINE);
5879
5880 for (ri = rn->info; ri; ri = ri->next)
5881 {
5882 count++;
5883 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5884 {
5885 best = count;
5886 if (ri->suppress)
5887 suppress = 1;
5888 if (ri->attr->community != NULL)
5889 {
5890 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5891 no_advertise = 1;
5892 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5893 no_export = 1;
5894 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5895 local_as = 1;
5896 }
5897 }
5898 }
5899
5900 vty_out (vty, "Paths: (%d available", count);
5901 if (best)
5902 {
5903 vty_out (vty, ", best #%d", best);
5904 if (safi == SAFI_UNICAST)
5905 vty_out (vty, ", table Default-IP-Routing-Table");
5906 }
5907 else
5908 vty_out (vty, ", no best path");
5909 if (no_advertise)
5910 vty_out (vty, ", not advertised to any peer");
5911 else if (no_export)
5912 vty_out (vty, ", not advertised to EBGP peer");
5913 else if (local_as)
5914 vty_out (vty, ", not advertised outside local AS");
5915 if (suppress)
5916 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5917 vty_out (vty, ")%s", VTY_NEWLINE);
5918
5919 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00005920 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00005921 {
5922 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5923 {
5924 if (! first)
5925 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5926 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5927 first = 1;
5928 }
5929 }
5930 if (! first)
5931 vty_out (vty, " Not advertised to any peer");
5932 vty_out (vty, "%s", VTY_NEWLINE);
5933}
5934
5935/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00005936static int
paulfee0f4c2004-09-13 05:12:46 +00005937bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00005938 struct bgp_table *rib, const char *ip_str,
5939 afi_t afi, safi_t safi, struct prefix_rd *prd,
5940 int prefix_check)
paul718e3742002-12-13 20:15:29 +00005941{
5942 int ret;
5943 int header;
5944 int display = 0;
5945 struct prefix match;
5946 struct bgp_node *rn;
5947 struct bgp_node *rm;
5948 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00005949 struct bgp_table *table;
5950
paul718e3742002-12-13 20:15:29 +00005951 /* Check IP address argument. */
5952 ret = str2prefix (ip_str, &match);
5953 if (! ret)
5954 {
5955 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5956 return CMD_WARNING;
5957 }
5958
5959 match.family = afi2family (afi);
5960
5961 if (safi == SAFI_MPLS_VPN)
5962 {
paulfee0f4c2004-09-13 05:12:46 +00005963 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00005964 {
5965 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5966 continue;
5967
5968 if ((table = rn->info) != NULL)
5969 {
5970 header = 1;
5971
5972 if ((rm = bgp_node_match (table, &match)) != NULL)
5973 {
5974 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5975 continue;
5976
5977 for (ri = rm->info; ri; ri = ri->next)
5978 {
5979 if (header)
5980 {
5981 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5982 AFI_IP, SAFI_MPLS_VPN);
5983
5984 header = 0;
5985 }
5986 display++;
5987 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5988 }
5989 }
5990 }
5991 }
5992 }
5993 else
5994 {
5995 header = 1;
5996
paulfee0f4c2004-09-13 05:12:46 +00005997 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00005998 {
5999 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6000 {
6001 for (ri = rn->info; ri; ri = ri->next)
6002 {
6003 if (header)
6004 {
6005 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6006 header = 0;
6007 }
6008 display++;
6009 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6010 }
6011 }
6012 }
6013 }
6014
6015 if (! display)
6016 {
6017 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6018 return CMD_WARNING;
6019 }
6020
6021 return CMD_SUCCESS;
6022}
6023
paulfee0f4c2004-09-13 05:12:46 +00006024/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006025static int
paulfd79ac92004-10-13 05:06:08 +00006026bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006027 afi_t afi, safi_t safi, struct prefix_rd *prd,
6028 int prefix_check)
6029{
6030 struct bgp *bgp;
6031
6032 /* BGP structure lookup. */
6033 if (view_name)
6034 {
6035 bgp = bgp_lookup_by_name (view_name);
6036 if (bgp == NULL)
6037 {
6038 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6039 return CMD_WARNING;
6040 }
6041 }
6042 else
6043 {
6044 bgp = bgp_get_default ();
6045 if (bgp == NULL)
6046 {
6047 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6048 return CMD_WARNING;
6049 }
6050 }
6051
6052 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6053 afi, safi, prd, prefix_check);
6054}
6055
paul718e3742002-12-13 20:15:29 +00006056/* BGP route print out function. */
6057DEFUN (show_ip_bgp,
6058 show_ip_bgp_cmd,
6059 "show ip bgp",
6060 SHOW_STR
6061 IP_STR
6062 BGP_STR)
6063{
ajs5a646652004-11-05 01:25:55 +00006064 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006065}
6066
6067DEFUN (show_ip_bgp_ipv4,
6068 show_ip_bgp_ipv4_cmd,
6069 "show ip bgp ipv4 (unicast|multicast)",
6070 SHOW_STR
6071 IP_STR
6072 BGP_STR
6073 "Address family\n"
6074 "Address Family modifier\n"
6075 "Address Family modifier\n")
6076{
6077 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006078 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6079 NULL);
paul718e3742002-12-13 20:15:29 +00006080
ajs5a646652004-11-05 01:25:55 +00006081 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006082}
6083
6084DEFUN (show_ip_bgp_route,
6085 show_ip_bgp_route_cmd,
6086 "show ip bgp A.B.C.D",
6087 SHOW_STR
6088 IP_STR
6089 BGP_STR
6090 "Network in the BGP routing table to display\n")
6091{
6092 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6093}
6094
6095DEFUN (show_ip_bgp_ipv4_route,
6096 show_ip_bgp_ipv4_route_cmd,
6097 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6098 SHOW_STR
6099 IP_STR
6100 BGP_STR
6101 "Address family\n"
6102 "Address Family modifier\n"
6103 "Address Family modifier\n"
6104 "Network in the BGP routing table to display\n")
6105{
6106 if (strncmp (argv[0], "m", 1) == 0)
6107 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6108
6109 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6110}
6111
6112DEFUN (show_ip_bgp_vpnv4_all_route,
6113 show_ip_bgp_vpnv4_all_route_cmd,
6114 "show ip bgp vpnv4 all A.B.C.D",
6115 SHOW_STR
6116 IP_STR
6117 BGP_STR
6118 "Display VPNv4 NLRI specific information\n"
6119 "Display information about all VPNv4 NLRIs\n"
6120 "Network in the BGP routing table to display\n")
6121{
6122 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6123}
6124
6125DEFUN (show_ip_bgp_vpnv4_rd_route,
6126 show_ip_bgp_vpnv4_rd_route_cmd,
6127 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6128 SHOW_STR
6129 IP_STR
6130 BGP_STR
6131 "Display VPNv4 NLRI specific information\n"
6132 "Display information for a route distinguisher\n"
6133 "VPN Route Distinguisher\n"
6134 "Network in the BGP routing table to display\n")
6135{
6136 int ret;
6137 struct prefix_rd prd;
6138
6139 ret = str2prefix_rd (argv[0], &prd);
6140 if (! ret)
6141 {
6142 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6143 return CMD_WARNING;
6144 }
6145 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6146}
6147
6148DEFUN (show_ip_bgp_prefix,
6149 show_ip_bgp_prefix_cmd,
6150 "show ip bgp A.B.C.D/M",
6151 SHOW_STR
6152 IP_STR
6153 BGP_STR
6154 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6155{
6156 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6157}
6158
6159DEFUN (show_ip_bgp_ipv4_prefix,
6160 show_ip_bgp_ipv4_prefix_cmd,
6161 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6162 SHOW_STR
6163 IP_STR
6164 BGP_STR
6165 "Address family\n"
6166 "Address Family modifier\n"
6167 "Address Family modifier\n"
6168 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6169{
6170 if (strncmp (argv[0], "m", 1) == 0)
6171 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6172
6173 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6174}
6175
6176DEFUN (show_ip_bgp_vpnv4_all_prefix,
6177 show_ip_bgp_vpnv4_all_prefix_cmd,
6178 "show ip bgp vpnv4 all A.B.C.D/M",
6179 SHOW_STR
6180 IP_STR
6181 BGP_STR
6182 "Display VPNv4 NLRI specific information\n"
6183 "Display information about all VPNv4 NLRIs\n"
6184 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6185{
6186 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6187}
6188
6189DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6190 show_ip_bgp_vpnv4_rd_prefix_cmd,
6191 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6192 SHOW_STR
6193 IP_STR
6194 BGP_STR
6195 "Display VPNv4 NLRI specific information\n"
6196 "Display information for a route distinguisher\n"
6197 "VPN Route Distinguisher\n"
6198 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6199{
6200 int ret;
6201 struct prefix_rd prd;
6202
6203 ret = str2prefix_rd (argv[0], &prd);
6204 if (! ret)
6205 {
6206 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6207 return CMD_WARNING;
6208 }
6209 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6210}
6211
6212DEFUN (show_ip_bgp_view,
6213 show_ip_bgp_view_cmd,
6214 "show ip bgp view WORD",
6215 SHOW_STR
6216 IP_STR
6217 BGP_STR
6218 "BGP view\n"
6219 "BGP view name\n")
6220{
paulbb46e942003-10-24 19:02:03 +00006221 struct bgp *bgp;
6222
6223 /* BGP structure lookup. */
6224 bgp = bgp_lookup_by_name (argv[0]);
6225 if (bgp == NULL)
6226 {
6227 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6228 return CMD_WARNING;
6229 }
6230
ajs5a646652004-11-05 01:25:55 +00006231 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006232}
6233
6234DEFUN (show_ip_bgp_view_route,
6235 show_ip_bgp_view_route_cmd,
6236 "show ip bgp view WORD A.B.C.D",
6237 SHOW_STR
6238 IP_STR
6239 BGP_STR
6240 "BGP view\n"
6241 "BGP view name\n"
6242 "Network in the BGP routing table to display\n")
6243{
6244 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6245}
6246
6247DEFUN (show_ip_bgp_view_prefix,
6248 show_ip_bgp_view_prefix_cmd,
6249 "show ip bgp view WORD A.B.C.D/M",
6250 SHOW_STR
6251 IP_STR
6252 BGP_STR
6253 "BGP view\n"
6254 "BGP view name\n"
6255 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6256{
6257 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6258}
6259
6260#ifdef HAVE_IPV6
6261DEFUN (show_bgp,
6262 show_bgp_cmd,
6263 "show bgp",
6264 SHOW_STR
6265 BGP_STR)
6266{
ajs5a646652004-11-05 01:25:55 +00006267 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6268 NULL);
paul718e3742002-12-13 20:15:29 +00006269}
6270
6271ALIAS (show_bgp,
6272 show_bgp_ipv6_cmd,
6273 "show bgp ipv6",
6274 SHOW_STR
6275 BGP_STR
6276 "Address family\n")
6277
6278/* old command */
6279DEFUN (show_ipv6_bgp,
6280 show_ipv6_bgp_cmd,
6281 "show ipv6 bgp",
6282 SHOW_STR
6283 IP_STR
6284 BGP_STR)
6285{
ajs5a646652004-11-05 01:25:55 +00006286 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6287 NULL);
paul718e3742002-12-13 20:15:29 +00006288}
6289
6290DEFUN (show_bgp_route,
6291 show_bgp_route_cmd,
6292 "show bgp X:X::X:X",
6293 SHOW_STR
6294 BGP_STR
6295 "Network in the BGP routing table to display\n")
6296{
6297 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6298}
6299
6300ALIAS (show_bgp_route,
6301 show_bgp_ipv6_route_cmd,
6302 "show bgp ipv6 X:X::X:X",
6303 SHOW_STR
6304 BGP_STR
6305 "Address family\n"
6306 "Network in the BGP routing table to display\n")
6307
6308/* old command */
6309DEFUN (show_ipv6_bgp_route,
6310 show_ipv6_bgp_route_cmd,
6311 "show ipv6 bgp X:X::X:X",
6312 SHOW_STR
6313 IP_STR
6314 BGP_STR
6315 "Network in the BGP routing table to display\n")
6316{
6317 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6318}
6319
6320DEFUN (show_bgp_prefix,
6321 show_bgp_prefix_cmd,
6322 "show bgp X:X::X:X/M",
6323 SHOW_STR
6324 BGP_STR
6325 "IPv6 prefix <network>/<length>\n")
6326{
6327 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6328}
6329
6330ALIAS (show_bgp_prefix,
6331 show_bgp_ipv6_prefix_cmd,
6332 "show bgp ipv6 X:X::X:X/M",
6333 SHOW_STR
6334 BGP_STR
6335 "Address family\n"
6336 "IPv6 prefix <network>/<length>\n")
6337
6338/* old command */
6339DEFUN (show_ipv6_bgp_prefix,
6340 show_ipv6_bgp_prefix_cmd,
6341 "show ipv6 bgp X:X::X:X/M",
6342 SHOW_STR
6343 IP_STR
6344 BGP_STR
6345 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6346{
6347 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6348}
6349
paulbb46e942003-10-24 19:02:03 +00006350DEFUN (show_bgp_view,
6351 show_bgp_view_cmd,
6352 "show bgp view WORD",
6353 SHOW_STR
6354 BGP_STR
6355 "BGP view\n"
6356 "View name\n")
6357{
6358 struct bgp *bgp;
6359
6360 /* BGP structure lookup. */
6361 bgp = bgp_lookup_by_name (argv[0]);
6362 if (bgp == NULL)
6363 {
6364 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6365 return CMD_WARNING;
6366 }
6367
ajs5a646652004-11-05 01:25:55 +00006368 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006369}
6370
6371ALIAS (show_bgp_view,
6372 show_bgp_view_ipv6_cmd,
6373 "show bgp view WORD ipv6",
6374 SHOW_STR
6375 BGP_STR
6376 "BGP view\n"
6377 "View name\n"
6378 "Address family\n")
6379
6380DEFUN (show_bgp_view_route,
6381 show_bgp_view_route_cmd,
6382 "show bgp view WORD X:X::X:X",
6383 SHOW_STR
6384 BGP_STR
6385 "BGP view\n"
6386 "View name\n"
6387 "Network in the BGP routing table to display\n")
6388{
6389 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6390}
6391
6392ALIAS (show_bgp_view_route,
6393 show_bgp_view_ipv6_route_cmd,
6394 "show bgp view WORD ipv6 X:X::X:X",
6395 SHOW_STR
6396 BGP_STR
6397 "BGP view\n"
6398 "View name\n"
6399 "Address family\n"
6400 "Network in the BGP routing table to display\n")
6401
6402DEFUN (show_bgp_view_prefix,
6403 show_bgp_view_prefix_cmd,
6404 "show bgp view WORD X:X::X:X/M",
6405 SHOW_STR
6406 BGP_STR
6407 "BGP view\n"
6408 "View name\n"
6409 "IPv6 prefix <network>/<length>\n")
6410{
6411 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6412}
6413
6414ALIAS (show_bgp_view_prefix,
6415 show_bgp_view_ipv6_prefix_cmd,
6416 "show bgp view WORD ipv6 X:X::X:X/M",
6417 SHOW_STR
6418 BGP_STR
6419 "BGP view\n"
6420 "View name\n"
6421 "Address family\n"
6422 "IPv6 prefix <network>/<length>\n")
6423
paul718e3742002-12-13 20:15:29 +00006424/* old command */
6425DEFUN (show_ipv6_mbgp,
6426 show_ipv6_mbgp_cmd,
6427 "show ipv6 mbgp",
6428 SHOW_STR
6429 IP_STR
6430 MBGP_STR)
6431{
ajs5a646652004-11-05 01:25:55 +00006432 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6433 NULL);
paul718e3742002-12-13 20:15:29 +00006434}
6435
6436/* old command */
6437DEFUN (show_ipv6_mbgp_route,
6438 show_ipv6_mbgp_route_cmd,
6439 "show ipv6 mbgp X:X::X:X",
6440 SHOW_STR
6441 IP_STR
6442 MBGP_STR
6443 "Network in the MBGP routing table to display\n")
6444{
6445 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6446}
6447
6448/* old command */
6449DEFUN (show_ipv6_mbgp_prefix,
6450 show_ipv6_mbgp_prefix_cmd,
6451 "show ipv6 mbgp X:X::X:X/M",
6452 SHOW_STR
6453 IP_STR
6454 MBGP_STR
6455 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6456{
6457 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6458}
6459#endif
6460
paul718e3742002-12-13 20:15:29 +00006461
paul94f2b392005-06-28 12:44:16 +00006462static int
paulfd79ac92004-10-13 05:06:08 +00006463bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006464 safi_t safi, enum bgp_show_type type)
6465{
6466 int i;
6467 struct buffer *b;
6468 char *regstr;
6469 int first;
6470 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006471 int rc;
paul718e3742002-12-13 20:15:29 +00006472
6473 first = 0;
6474 b = buffer_new (1024);
6475 for (i = 0; i < argc; i++)
6476 {
6477 if (first)
6478 buffer_putc (b, ' ');
6479 else
6480 {
6481 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6482 continue;
6483 first = 1;
6484 }
6485
6486 buffer_putstr (b, argv[i]);
6487 }
6488 buffer_putc (b, '\0');
6489
6490 regstr = buffer_getstr (b);
6491 buffer_free (b);
6492
6493 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006494 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006495 if (! regex)
6496 {
6497 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6498 VTY_NEWLINE);
6499 return CMD_WARNING;
6500 }
6501
ajs5a646652004-11-05 01:25:55 +00006502 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6503 bgp_regex_free (regex);
6504 return rc;
paul718e3742002-12-13 20:15:29 +00006505}
6506
6507DEFUN (show_ip_bgp_regexp,
6508 show_ip_bgp_regexp_cmd,
6509 "show ip bgp regexp .LINE",
6510 SHOW_STR
6511 IP_STR
6512 BGP_STR
6513 "Display routes matching the AS path regular expression\n"
6514 "A regular-expression to match the BGP AS paths\n")
6515{
6516 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6517 bgp_show_type_regexp);
6518}
6519
6520DEFUN (show_ip_bgp_flap_regexp,
6521 show_ip_bgp_flap_regexp_cmd,
6522 "show ip bgp flap-statistics regexp .LINE",
6523 SHOW_STR
6524 IP_STR
6525 BGP_STR
6526 "Display flap statistics of routes\n"
6527 "Display routes matching the AS path regular expression\n"
6528 "A regular-expression to match the BGP AS paths\n")
6529{
6530 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6531 bgp_show_type_flap_regexp);
6532}
6533
6534DEFUN (show_ip_bgp_ipv4_regexp,
6535 show_ip_bgp_ipv4_regexp_cmd,
6536 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6537 SHOW_STR
6538 IP_STR
6539 BGP_STR
6540 "Address family\n"
6541 "Address Family modifier\n"
6542 "Address Family modifier\n"
6543 "Display routes matching the AS path regular expression\n"
6544 "A regular-expression to match the BGP AS paths\n")
6545{
6546 if (strncmp (argv[0], "m", 1) == 0)
6547 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6548 bgp_show_type_regexp);
6549
6550 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6551 bgp_show_type_regexp);
6552}
6553
6554#ifdef HAVE_IPV6
6555DEFUN (show_bgp_regexp,
6556 show_bgp_regexp_cmd,
6557 "show bgp regexp .LINE",
6558 SHOW_STR
6559 BGP_STR
6560 "Display routes matching the AS path regular expression\n"
6561 "A regular-expression to match the BGP AS paths\n")
6562{
6563 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6564 bgp_show_type_regexp);
6565}
6566
6567ALIAS (show_bgp_regexp,
6568 show_bgp_ipv6_regexp_cmd,
6569 "show bgp ipv6 regexp .LINE",
6570 SHOW_STR
6571 BGP_STR
6572 "Address family\n"
6573 "Display routes matching the AS path regular expression\n"
6574 "A regular-expression to match the BGP AS paths\n")
6575
6576/* old command */
6577DEFUN (show_ipv6_bgp_regexp,
6578 show_ipv6_bgp_regexp_cmd,
6579 "show ipv6 bgp regexp .LINE",
6580 SHOW_STR
6581 IP_STR
6582 BGP_STR
6583 "Display routes matching the AS path regular expression\n"
6584 "A regular-expression to match the BGP AS paths\n")
6585{
6586 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6587 bgp_show_type_regexp);
6588}
6589
6590/* old command */
6591DEFUN (show_ipv6_mbgp_regexp,
6592 show_ipv6_mbgp_regexp_cmd,
6593 "show ipv6 mbgp regexp .LINE",
6594 SHOW_STR
6595 IP_STR
6596 BGP_STR
6597 "Display routes matching the AS path regular expression\n"
6598 "A regular-expression to match the MBGP AS paths\n")
6599{
6600 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6601 bgp_show_type_regexp);
6602}
6603#endif /* HAVE_IPV6 */
6604
paul94f2b392005-06-28 12:44:16 +00006605static int
paulfd79ac92004-10-13 05:06:08 +00006606bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006607 safi_t safi, enum bgp_show_type type)
6608{
6609 struct prefix_list *plist;
6610
6611 plist = prefix_list_lookup (afi, prefix_list_str);
6612 if (plist == NULL)
6613 {
6614 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6615 prefix_list_str, VTY_NEWLINE);
6616 return CMD_WARNING;
6617 }
6618
ajs5a646652004-11-05 01:25:55 +00006619 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00006620}
6621
6622DEFUN (show_ip_bgp_prefix_list,
6623 show_ip_bgp_prefix_list_cmd,
6624 "show ip bgp prefix-list WORD",
6625 SHOW_STR
6626 IP_STR
6627 BGP_STR
6628 "Display routes conforming to the prefix-list\n"
6629 "IP prefix-list name\n")
6630{
6631 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6632 bgp_show_type_prefix_list);
6633}
6634
6635DEFUN (show_ip_bgp_flap_prefix_list,
6636 show_ip_bgp_flap_prefix_list_cmd,
6637 "show ip bgp flap-statistics prefix-list WORD",
6638 SHOW_STR
6639 IP_STR
6640 BGP_STR
6641 "Display flap statistics of routes\n"
6642 "Display routes conforming to the prefix-list\n"
6643 "IP prefix-list name\n")
6644{
6645 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6646 bgp_show_type_flap_prefix_list);
6647}
6648
6649DEFUN (show_ip_bgp_ipv4_prefix_list,
6650 show_ip_bgp_ipv4_prefix_list_cmd,
6651 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6652 SHOW_STR
6653 IP_STR
6654 BGP_STR
6655 "Address family\n"
6656 "Address Family modifier\n"
6657 "Address Family modifier\n"
6658 "Display routes conforming to the prefix-list\n"
6659 "IP prefix-list name\n")
6660{
6661 if (strncmp (argv[0], "m", 1) == 0)
6662 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6663 bgp_show_type_prefix_list);
6664
6665 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6666 bgp_show_type_prefix_list);
6667}
6668
6669#ifdef HAVE_IPV6
6670DEFUN (show_bgp_prefix_list,
6671 show_bgp_prefix_list_cmd,
6672 "show bgp prefix-list WORD",
6673 SHOW_STR
6674 BGP_STR
6675 "Display routes conforming to the prefix-list\n"
6676 "IPv6 prefix-list name\n")
6677{
6678 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6679 bgp_show_type_prefix_list);
6680}
6681
6682ALIAS (show_bgp_prefix_list,
6683 show_bgp_ipv6_prefix_list_cmd,
6684 "show bgp ipv6 prefix-list WORD",
6685 SHOW_STR
6686 BGP_STR
6687 "Address family\n"
6688 "Display routes conforming to the prefix-list\n"
6689 "IPv6 prefix-list name\n")
6690
6691/* old command */
6692DEFUN (show_ipv6_bgp_prefix_list,
6693 show_ipv6_bgp_prefix_list_cmd,
6694 "show ipv6 bgp prefix-list WORD",
6695 SHOW_STR
6696 IPV6_STR
6697 BGP_STR
6698 "Display routes matching the prefix-list\n"
6699 "IPv6 prefix-list name\n")
6700{
6701 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6702 bgp_show_type_prefix_list);
6703}
6704
6705/* old command */
6706DEFUN (show_ipv6_mbgp_prefix_list,
6707 show_ipv6_mbgp_prefix_list_cmd,
6708 "show ipv6 mbgp prefix-list WORD",
6709 SHOW_STR
6710 IPV6_STR
6711 MBGP_STR
6712 "Display routes matching the prefix-list\n"
6713 "IPv6 prefix-list name\n")
6714{
6715 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6716 bgp_show_type_prefix_list);
6717}
6718#endif /* HAVE_IPV6 */
6719
paul94f2b392005-06-28 12:44:16 +00006720static int
paulfd79ac92004-10-13 05:06:08 +00006721bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006722 safi_t safi, enum bgp_show_type type)
6723{
6724 struct as_list *as_list;
6725
6726 as_list = as_list_lookup (filter);
6727 if (as_list == NULL)
6728 {
6729 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6730 return CMD_WARNING;
6731 }
6732
ajs5a646652004-11-05 01:25:55 +00006733 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00006734}
6735
6736DEFUN (show_ip_bgp_filter_list,
6737 show_ip_bgp_filter_list_cmd,
6738 "show ip bgp filter-list WORD",
6739 SHOW_STR
6740 IP_STR
6741 BGP_STR
6742 "Display routes conforming to the filter-list\n"
6743 "Regular expression access list name\n")
6744{
6745 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6746 bgp_show_type_filter_list);
6747}
6748
6749DEFUN (show_ip_bgp_flap_filter_list,
6750 show_ip_bgp_flap_filter_list_cmd,
6751 "show ip bgp flap-statistics filter-list WORD",
6752 SHOW_STR
6753 IP_STR
6754 BGP_STR
6755 "Display flap statistics of routes\n"
6756 "Display routes conforming to the filter-list\n"
6757 "Regular expression access list name\n")
6758{
6759 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6760 bgp_show_type_flap_filter_list);
6761}
6762
6763DEFUN (show_ip_bgp_ipv4_filter_list,
6764 show_ip_bgp_ipv4_filter_list_cmd,
6765 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6766 SHOW_STR
6767 IP_STR
6768 BGP_STR
6769 "Address family\n"
6770 "Address Family modifier\n"
6771 "Address Family modifier\n"
6772 "Display routes conforming to the filter-list\n"
6773 "Regular expression access list name\n")
6774{
6775 if (strncmp (argv[0], "m", 1) == 0)
6776 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6777 bgp_show_type_filter_list);
6778
6779 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6780 bgp_show_type_filter_list);
6781}
6782
6783#ifdef HAVE_IPV6
6784DEFUN (show_bgp_filter_list,
6785 show_bgp_filter_list_cmd,
6786 "show bgp filter-list WORD",
6787 SHOW_STR
6788 BGP_STR
6789 "Display routes conforming to the filter-list\n"
6790 "Regular expression access list name\n")
6791{
6792 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6793 bgp_show_type_filter_list);
6794}
6795
6796ALIAS (show_bgp_filter_list,
6797 show_bgp_ipv6_filter_list_cmd,
6798 "show bgp ipv6 filter-list WORD",
6799 SHOW_STR
6800 BGP_STR
6801 "Address family\n"
6802 "Display routes conforming to the filter-list\n"
6803 "Regular expression access list name\n")
6804
6805/* old command */
6806DEFUN (show_ipv6_bgp_filter_list,
6807 show_ipv6_bgp_filter_list_cmd,
6808 "show ipv6 bgp filter-list WORD",
6809 SHOW_STR
6810 IPV6_STR
6811 BGP_STR
6812 "Display routes conforming to the filter-list\n"
6813 "Regular expression access list name\n")
6814{
6815 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6816 bgp_show_type_filter_list);
6817}
6818
6819/* old command */
6820DEFUN (show_ipv6_mbgp_filter_list,
6821 show_ipv6_mbgp_filter_list_cmd,
6822 "show ipv6 mbgp filter-list WORD",
6823 SHOW_STR
6824 IPV6_STR
6825 MBGP_STR
6826 "Display routes conforming to the filter-list\n"
6827 "Regular expression access list name\n")
6828{
6829 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6830 bgp_show_type_filter_list);
6831}
6832#endif /* HAVE_IPV6 */
6833
paul94f2b392005-06-28 12:44:16 +00006834static int
paulfd79ac92004-10-13 05:06:08 +00006835bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006836 safi_t safi, enum bgp_show_type type)
6837{
6838 struct route_map *rmap;
6839
6840 rmap = route_map_lookup_by_name (rmap_str);
6841 if (! rmap)
6842 {
6843 vty_out (vty, "%% %s is not a valid route-map name%s",
6844 rmap_str, VTY_NEWLINE);
6845 return CMD_WARNING;
6846 }
6847
ajs5a646652004-11-05 01:25:55 +00006848 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00006849}
6850
6851DEFUN (show_ip_bgp_route_map,
6852 show_ip_bgp_route_map_cmd,
6853 "show ip bgp route-map WORD",
6854 SHOW_STR
6855 IP_STR
6856 BGP_STR
6857 "Display routes matching the route-map\n"
6858 "A route-map to match on\n")
6859{
6860 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6861 bgp_show_type_route_map);
6862}
6863
6864DEFUN (show_ip_bgp_flap_route_map,
6865 show_ip_bgp_flap_route_map_cmd,
6866 "show ip bgp flap-statistics route-map WORD",
6867 SHOW_STR
6868 IP_STR
6869 BGP_STR
6870 "Display flap statistics of routes\n"
6871 "Display routes matching the route-map\n"
6872 "A route-map to match on\n")
6873{
6874 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6875 bgp_show_type_flap_route_map);
6876}
6877
6878DEFUN (show_ip_bgp_ipv4_route_map,
6879 show_ip_bgp_ipv4_route_map_cmd,
6880 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6881 SHOW_STR
6882 IP_STR
6883 BGP_STR
6884 "Address family\n"
6885 "Address Family modifier\n"
6886 "Address Family modifier\n"
6887 "Display routes matching the route-map\n"
6888 "A route-map to match on\n")
6889{
6890 if (strncmp (argv[0], "m", 1) == 0)
6891 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6892 bgp_show_type_route_map);
6893
6894 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6895 bgp_show_type_route_map);
6896}
6897
6898DEFUN (show_bgp_route_map,
6899 show_bgp_route_map_cmd,
6900 "show bgp route-map WORD",
6901 SHOW_STR
6902 BGP_STR
6903 "Display routes matching the route-map\n"
6904 "A route-map to match on\n")
6905{
6906 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6907 bgp_show_type_route_map);
6908}
6909
6910ALIAS (show_bgp_route_map,
6911 show_bgp_ipv6_route_map_cmd,
6912 "show bgp ipv6 route-map WORD",
6913 SHOW_STR
6914 BGP_STR
6915 "Address family\n"
6916 "Display routes matching the route-map\n"
6917 "A route-map to match on\n")
6918
6919DEFUN (show_ip_bgp_cidr_only,
6920 show_ip_bgp_cidr_only_cmd,
6921 "show ip bgp cidr-only",
6922 SHOW_STR
6923 IP_STR
6924 BGP_STR
6925 "Display only routes with non-natural netmasks\n")
6926{
6927 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006928 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006929}
6930
6931DEFUN (show_ip_bgp_flap_cidr_only,
6932 show_ip_bgp_flap_cidr_only_cmd,
6933 "show ip bgp flap-statistics cidr-only",
6934 SHOW_STR
6935 IP_STR
6936 BGP_STR
6937 "Display flap statistics of routes\n"
6938 "Display only routes with non-natural netmasks\n")
6939{
6940 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006941 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006942}
6943
6944DEFUN (show_ip_bgp_ipv4_cidr_only,
6945 show_ip_bgp_ipv4_cidr_only_cmd,
6946 "show ip bgp ipv4 (unicast|multicast) cidr-only",
6947 SHOW_STR
6948 IP_STR
6949 BGP_STR
6950 "Address family\n"
6951 "Address Family modifier\n"
6952 "Address Family modifier\n"
6953 "Display only routes with non-natural netmasks\n")
6954{
6955 if (strncmp (argv[0], "m", 1) == 0)
6956 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006957 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006958
6959 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006960 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006961}
6962
6963DEFUN (show_ip_bgp_community_all,
6964 show_ip_bgp_community_all_cmd,
6965 "show ip bgp community",
6966 SHOW_STR
6967 IP_STR
6968 BGP_STR
6969 "Display routes matching the communities\n")
6970{
6971 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006972 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006973}
6974
6975DEFUN (show_ip_bgp_ipv4_community_all,
6976 show_ip_bgp_ipv4_community_all_cmd,
6977 "show ip bgp ipv4 (unicast|multicast) community",
6978 SHOW_STR
6979 IP_STR
6980 BGP_STR
6981 "Address family\n"
6982 "Address Family modifier\n"
6983 "Address Family modifier\n"
6984 "Display routes matching the communities\n")
6985{
6986 if (strncmp (argv[0], "m", 1) == 0)
6987 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006988 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006989
6990 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006991 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006992}
6993
6994#ifdef HAVE_IPV6
6995DEFUN (show_bgp_community_all,
6996 show_bgp_community_all_cmd,
6997 "show bgp community",
6998 SHOW_STR
6999 BGP_STR
7000 "Display routes matching the communities\n")
7001{
7002 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007003 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007004}
7005
7006ALIAS (show_bgp_community_all,
7007 show_bgp_ipv6_community_all_cmd,
7008 "show bgp ipv6 community",
7009 SHOW_STR
7010 BGP_STR
7011 "Address family\n"
7012 "Display routes matching the communities\n")
7013
7014/* old command */
7015DEFUN (show_ipv6_bgp_community_all,
7016 show_ipv6_bgp_community_all_cmd,
7017 "show ipv6 bgp community",
7018 SHOW_STR
7019 IPV6_STR
7020 BGP_STR
7021 "Display routes matching the communities\n")
7022{
7023 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007024 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007025}
7026
7027/* old command */
7028DEFUN (show_ipv6_mbgp_community_all,
7029 show_ipv6_mbgp_community_all_cmd,
7030 "show ipv6 mbgp community",
7031 SHOW_STR
7032 IPV6_STR
7033 MBGP_STR
7034 "Display routes matching the communities\n")
7035{
7036 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007037 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007038}
7039#endif /* HAVE_IPV6 */
7040
paul94f2b392005-06-28 12:44:16 +00007041static int
paulfd79ac92004-10-13 05:06:08 +00007042bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7043 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007044{
7045 struct community *com;
7046 struct buffer *b;
7047 int i;
7048 char *str;
7049 int first = 0;
7050
7051 b = buffer_new (1024);
7052 for (i = 0; i < argc; i++)
7053 {
7054 if (first)
7055 buffer_putc (b, ' ');
7056 else
7057 {
7058 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7059 continue;
7060 first = 1;
7061 }
7062
7063 buffer_putstr (b, argv[i]);
7064 }
7065 buffer_putc (b, '\0');
7066
7067 str = buffer_getstr (b);
7068 buffer_free (b);
7069
7070 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007071 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007072 if (! com)
7073 {
7074 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7075 return CMD_WARNING;
7076 }
7077
ajs5a646652004-11-05 01:25:55 +00007078 return bgp_show (vty, NULL, afi, safi,
7079 (exact ? bgp_show_type_community_exact :
7080 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007081}
7082
7083DEFUN (show_ip_bgp_community,
7084 show_ip_bgp_community_cmd,
7085 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7086 SHOW_STR
7087 IP_STR
7088 BGP_STR
7089 "Display routes matching the communities\n"
7090 "community number\n"
7091 "Do not send outside local AS (well-known community)\n"
7092 "Do not advertise to any peer (well-known community)\n"
7093 "Do not export to next AS (well-known community)\n")
7094{
7095 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7096}
7097
7098ALIAS (show_ip_bgp_community,
7099 show_ip_bgp_community2_cmd,
7100 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7101 SHOW_STR
7102 IP_STR
7103 BGP_STR
7104 "Display routes matching the communities\n"
7105 "community number\n"
7106 "Do not send outside local AS (well-known community)\n"
7107 "Do not advertise to any peer (well-known community)\n"
7108 "Do not export to next AS (well-known community)\n"
7109 "community number\n"
7110 "Do not send outside local AS (well-known community)\n"
7111 "Do not advertise to any peer (well-known community)\n"
7112 "Do not export to next AS (well-known community)\n")
7113
7114ALIAS (show_ip_bgp_community,
7115 show_ip_bgp_community3_cmd,
7116 "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)",
7117 SHOW_STR
7118 IP_STR
7119 BGP_STR
7120 "Display routes matching the communities\n"
7121 "community number\n"
7122 "Do not send outside local AS (well-known community)\n"
7123 "Do not advertise to any peer (well-known community)\n"
7124 "Do not export to next AS (well-known community)\n"
7125 "community number\n"
7126 "Do not send outside local AS (well-known community)\n"
7127 "Do not advertise to any peer (well-known community)\n"
7128 "Do not export to next AS (well-known community)\n"
7129 "community number\n"
7130 "Do not send outside local AS (well-known community)\n"
7131 "Do not advertise to any peer (well-known community)\n"
7132 "Do not export to next AS (well-known community)\n")
7133
7134ALIAS (show_ip_bgp_community,
7135 show_ip_bgp_community4_cmd,
7136 "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)",
7137 SHOW_STR
7138 IP_STR
7139 BGP_STR
7140 "Display routes matching the communities\n"
7141 "community number\n"
7142 "Do not send outside local AS (well-known community)\n"
7143 "Do not advertise to any peer (well-known community)\n"
7144 "Do not export to next AS (well-known community)\n"
7145 "community number\n"
7146 "Do not send outside local AS (well-known community)\n"
7147 "Do not advertise to any peer (well-known community)\n"
7148 "Do not export to next AS (well-known community)\n"
7149 "community number\n"
7150 "Do not send outside local AS (well-known community)\n"
7151 "Do not advertise to any peer (well-known community)\n"
7152 "Do not export to next AS (well-known community)\n"
7153 "community number\n"
7154 "Do not send outside local AS (well-known community)\n"
7155 "Do not advertise to any peer (well-known community)\n"
7156 "Do not export to next AS (well-known community)\n")
7157
7158DEFUN (show_ip_bgp_ipv4_community,
7159 show_ip_bgp_ipv4_community_cmd,
7160 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7161 SHOW_STR
7162 IP_STR
7163 BGP_STR
7164 "Address family\n"
7165 "Address Family modifier\n"
7166 "Address Family modifier\n"
7167 "Display routes matching the communities\n"
7168 "community number\n"
7169 "Do not send outside local AS (well-known community)\n"
7170 "Do not advertise to any peer (well-known community)\n"
7171 "Do not export to next AS (well-known community)\n")
7172{
7173 if (strncmp (argv[0], "m", 1) == 0)
7174 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7175
7176 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7177}
7178
7179ALIAS (show_ip_bgp_ipv4_community,
7180 show_ip_bgp_ipv4_community2_cmd,
7181 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7182 SHOW_STR
7183 IP_STR
7184 BGP_STR
7185 "Address family\n"
7186 "Address Family modifier\n"
7187 "Address Family modifier\n"
7188 "Display routes matching the communities\n"
7189 "community number\n"
7190 "Do not send outside local AS (well-known community)\n"
7191 "Do not advertise to any peer (well-known community)\n"
7192 "Do not export to next AS (well-known community)\n"
7193 "community number\n"
7194 "Do not send outside local AS (well-known community)\n"
7195 "Do not advertise to any peer (well-known community)\n"
7196 "Do not export to next AS (well-known community)\n")
7197
7198ALIAS (show_ip_bgp_ipv4_community,
7199 show_ip_bgp_ipv4_community3_cmd,
7200 "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)",
7201 SHOW_STR
7202 IP_STR
7203 BGP_STR
7204 "Address family\n"
7205 "Address Family modifier\n"
7206 "Address Family modifier\n"
7207 "Display routes matching the communities\n"
7208 "community number\n"
7209 "Do not send outside local AS (well-known community)\n"
7210 "Do not advertise to any peer (well-known community)\n"
7211 "Do not export to next AS (well-known community)\n"
7212 "community number\n"
7213 "Do not send outside local AS (well-known community)\n"
7214 "Do not advertise to any peer (well-known community)\n"
7215 "Do not export to next AS (well-known community)\n"
7216 "community number\n"
7217 "Do not send outside local AS (well-known community)\n"
7218 "Do not advertise to any peer (well-known community)\n"
7219 "Do not export to next AS (well-known community)\n")
7220
7221ALIAS (show_ip_bgp_ipv4_community,
7222 show_ip_bgp_ipv4_community4_cmd,
7223 "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)",
7224 SHOW_STR
7225 IP_STR
7226 BGP_STR
7227 "Address family\n"
7228 "Address Family modifier\n"
7229 "Address Family modifier\n"
7230 "Display routes matching the communities\n"
7231 "community number\n"
7232 "Do not send outside local AS (well-known community)\n"
7233 "Do not advertise to any peer (well-known community)\n"
7234 "Do not export to next AS (well-known community)\n"
7235 "community number\n"
7236 "Do not send outside local AS (well-known community)\n"
7237 "Do not advertise to any peer (well-known community)\n"
7238 "Do not export to next AS (well-known community)\n"
7239 "community number\n"
7240 "Do not send outside local AS (well-known community)\n"
7241 "Do not advertise to any peer (well-known community)\n"
7242 "Do not export to next AS (well-known community)\n"
7243 "community number\n"
7244 "Do not send outside local AS (well-known community)\n"
7245 "Do not advertise to any peer (well-known community)\n"
7246 "Do not export to next AS (well-known community)\n")
7247
7248DEFUN (show_ip_bgp_community_exact,
7249 show_ip_bgp_community_exact_cmd,
7250 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7251 SHOW_STR
7252 IP_STR
7253 BGP_STR
7254 "Display routes matching the communities\n"
7255 "community number\n"
7256 "Do not send outside local AS (well-known community)\n"
7257 "Do not advertise to any peer (well-known community)\n"
7258 "Do not export to next AS (well-known community)\n"
7259 "Exact match of the communities")
7260{
7261 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7262}
7263
7264ALIAS (show_ip_bgp_community_exact,
7265 show_ip_bgp_community2_exact_cmd,
7266 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7267 SHOW_STR
7268 IP_STR
7269 BGP_STR
7270 "Display routes matching the communities\n"
7271 "community number\n"
7272 "Do not send outside local AS (well-known community)\n"
7273 "Do not advertise to any peer (well-known community)\n"
7274 "Do not export to next AS (well-known community)\n"
7275 "community number\n"
7276 "Do not send outside local AS (well-known community)\n"
7277 "Do not advertise to any peer (well-known community)\n"
7278 "Do not export to next AS (well-known community)\n"
7279 "Exact match of the communities")
7280
7281ALIAS (show_ip_bgp_community_exact,
7282 show_ip_bgp_community3_exact_cmd,
7283 "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",
7284 SHOW_STR
7285 IP_STR
7286 BGP_STR
7287 "Display routes matching the communities\n"
7288 "community number\n"
7289 "Do not send outside local AS (well-known community)\n"
7290 "Do not advertise to any peer (well-known community)\n"
7291 "Do not export to next AS (well-known community)\n"
7292 "community number\n"
7293 "Do not send outside local AS (well-known community)\n"
7294 "Do not advertise to any peer (well-known community)\n"
7295 "Do not export to next AS (well-known community)\n"
7296 "community number\n"
7297 "Do not send outside local AS (well-known community)\n"
7298 "Do not advertise to any peer (well-known community)\n"
7299 "Do not export to next AS (well-known community)\n"
7300 "Exact match of the communities")
7301
7302ALIAS (show_ip_bgp_community_exact,
7303 show_ip_bgp_community4_exact_cmd,
7304 "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",
7305 SHOW_STR
7306 IP_STR
7307 BGP_STR
7308 "Display routes matching the communities\n"
7309 "community number\n"
7310 "Do not send outside local AS (well-known community)\n"
7311 "Do not advertise to any peer (well-known community)\n"
7312 "Do not export to next AS (well-known community)\n"
7313 "community number\n"
7314 "Do not send outside local AS (well-known community)\n"
7315 "Do not advertise to any peer (well-known community)\n"
7316 "Do not export to next AS (well-known community)\n"
7317 "community number\n"
7318 "Do not send outside local AS (well-known community)\n"
7319 "Do not advertise to any peer (well-known community)\n"
7320 "Do not export to next AS (well-known community)\n"
7321 "community number\n"
7322 "Do not send outside local AS (well-known community)\n"
7323 "Do not advertise to any peer (well-known community)\n"
7324 "Do not export to next AS (well-known community)\n"
7325 "Exact match of the communities")
7326
7327DEFUN (show_ip_bgp_ipv4_community_exact,
7328 show_ip_bgp_ipv4_community_exact_cmd,
7329 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7330 SHOW_STR
7331 IP_STR
7332 BGP_STR
7333 "Address family\n"
7334 "Address Family modifier\n"
7335 "Address Family modifier\n"
7336 "Display routes matching the communities\n"
7337 "community number\n"
7338 "Do not send outside local AS (well-known community)\n"
7339 "Do not advertise to any peer (well-known community)\n"
7340 "Do not export to next AS (well-known community)\n"
7341 "Exact match of the communities")
7342{
7343 if (strncmp (argv[0], "m", 1) == 0)
7344 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7345
7346 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7347}
7348
7349ALIAS (show_ip_bgp_ipv4_community_exact,
7350 show_ip_bgp_ipv4_community2_exact_cmd,
7351 "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",
7352 SHOW_STR
7353 IP_STR
7354 BGP_STR
7355 "Address family\n"
7356 "Address Family modifier\n"
7357 "Address Family modifier\n"
7358 "Display routes matching the communities\n"
7359 "community number\n"
7360 "Do not send outside local AS (well-known community)\n"
7361 "Do not advertise to any peer (well-known community)\n"
7362 "Do not export to next AS (well-known community)\n"
7363 "community number\n"
7364 "Do not send outside local AS (well-known community)\n"
7365 "Do not advertise to any peer (well-known community)\n"
7366 "Do not export to next AS (well-known community)\n"
7367 "Exact match of the communities")
7368
7369ALIAS (show_ip_bgp_ipv4_community_exact,
7370 show_ip_bgp_ipv4_community3_exact_cmd,
7371 "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",
7372 SHOW_STR
7373 IP_STR
7374 BGP_STR
7375 "Address family\n"
7376 "Address Family modifier\n"
7377 "Address Family modifier\n"
7378 "Display routes matching the communities\n"
7379 "community number\n"
7380 "Do not send outside local AS (well-known community)\n"
7381 "Do not advertise to any peer (well-known community)\n"
7382 "Do not export to next AS (well-known community)\n"
7383 "community number\n"
7384 "Do not send outside local AS (well-known community)\n"
7385 "Do not advertise to any peer (well-known community)\n"
7386 "Do not export to next AS (well-known community)\n"
7387 "community number\n"
7388 "Do not send outside local AS (well-known community)\n"
7389 "Do not advertise to any peer (well-known community)\n"
7390 "Do not export to next AS (well-known community)\n"
7391 "Exact match of the communities")
7392
7393ALIAS (show_ip_bgp_ipv4_community_exact,
7394 show_ip_bgp_ipv4_community4_exact_cmd,
7395 "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",
7396 SHOW_STR
7397 IP_STR
7398 BGP_STR
7399 "Address family\n"
7400 "Address Family modifier\n"
7401 "Address Family modifier\n"
7402 "Display routes matching the communities\n"
7403 "community number\n"
7404 "Do not send outside local AS (well-known community)\n"
7405 "Do not advertise to any peer (well-known community)\n"
7406 "Do not export to next AS (well-known community)\n"
7407 "community number\n"
7408 "Do not send outside local AS (well-known community)\n"
7409 "Do not advertise to any peer (well-known community)\n"
7410 "Do not export to next AS (well-known community)\n"
7411 "community number\n"
7412 "Do not send outside local AS (well-known community)\n"
7413 "Do not advertise to any peer (well-known community)\n"
7414 "Do not export to next AS (well-known community)\n"
7415 "community number\n"
7416 "Do not send outside local AS (well-known community)\n"
7417 "Do not advertise to any peer (well-known community)\n"
7418 "Do not export to next AS (well-known community)\n"
7419 "Exact match of the communities")
7420
7421#ifdef HAVE_IPV6
7422DEFUN (show_bgp_community,
7423 show_bgp_community_cmd,
7424 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7425 SHOW_STR
7426 BGP_STR
7427 "Display routes matching the communities\n"
7428 "community number\n"
7429 "Do not send outside local AS (well-known community)\n"
7430 "Do not advertise to any peer (well-known community)\n"
7431 "Do not export to next AS (well-known community)\n")
7432{
7433 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7434}
7435
7436ALIAS (show_bgp_community,
7437 show_bgp_ipv6_community_cmd,
7438 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7439 SHOW_STR
7440 BGP_STR
7441 "Address family\n"
7442 "Display routes matching the communities\n"
7443 "community number\n"
7444 "Do not send outside local AS (well-known community)\n"
7445 "Do not advertise to any peer (well-known community)\n"
7446 "Do not export to next AS (well-known community)\n")
7447
7448ALIAS (show_bgp_community,
7449 show_bgp_community2_cmd,
7450 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7451 SHOW_STR
7452 BGP_STR
7453 "Display routes matching the communities\n"
7454 "community number\n"
7455 "Do not send outside local AS (well-known community)\n"
7456 "Do not advertise to any peer (well-known community)\n"
7457 "Do not export to next AS (well-known community)\n"
7458 "community number\n"
7459 "Do not send outside local AS (well-known community)\n"
7460 "Do not advertise to any peer (well-known community)\n"
7461 "Do not export to next AS (well-known community)\n")
7462
7463ALIAS (show_bgp_community,
7464 show_bgp_ipv6_community2_cmd,
7465 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7466 SHOW_STR
7467 BGP_STR
7468 "Address family\n"
7469 "Display routes matching the communities\n"
7470 "community number\n"
7471 "Do not send outside local AS (well-known community)\n"
7472 "Do not advertise to any peer (well-known community)\n"
7473 "Do not export to next AS (well-known community)\n"
7474 "community number\n"
7475 "Do not send outside local AS (well-known community)\n"
7476 "Do not advertise to any peer (well-known community)\n"
7477 "Do not export to next AS (well-known community)\n")
7478
7479ALIAS (show_bgp_community,
7480 show_bgp_community3_cmd,
7481 "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)",
7482 SHOW_STR
7483 BGP_STR
7484 "Display routes matching the communities\n"
7485 "community number\n"
7486 "Do not send outside local AS (well-known community)\n"
7487 "Do not advertise to any peer (well-known community)\n"
7488 "Do not export to next AS (well-known community)\n"
7489 "community number\n"
7490 "Do not send outside local AS (well-known community)\n"
7491 "Do not advertise to any peer (well-known community)\n"
7492 "Do not export to next AS (well-known community)\n"
7493 "community number\n"
7494 "Do not send outside local AS (well-known community)\n"
7495 "Do not advertise to any peer (well-known community)\n"
7496 "Do not export to next AS (well-known community)\n")
7497
7498ALIAS (show_bgp_community,
7499 show_bgp_ipv6_community3_cmd,
7500 "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)",
7501 SHOW_STR
7502 BGP_STR
7503 "Address family\n"
7504 "Display routes matching the communities\n"
7505 "community number\n"
7506 "Do not send outside local AS (well-known community)\n"
7507 "Do not advertise to any peer (well-known community)\n"
7508 "Do not export to next AS (well-known community)\n"
7509 "community number\n"
7510 "Do not send outside local AS (well-known community)\n"
7511 "Do not advertise to any peer (well-known community)\n"
7512 "Do not export to next AS (well-known community)\n"
7513 "community number\n"
7514 "Do not send outside local AS (well-known community)\n"
7515 "Do not advertise to any peer (well-known community)\n"
7516 "Do not export to next AS (well-known community)\n")
7517
7518ALIAS (show_bgp_community,
7519 show_bgp_community4_cmd,
7520 "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)",
7521 SHOW_STR
7522 BGP_STR
7523 "Display routes matching the communities\n"
7524 "community number\n"
7525 "Do not send outside local AS (well-known community)\n"
7526 "Do not advertise to any peer (well-known community)\n"
7527 "Do not export to next AS (well-known community)\n"
7528 "community number\n"
7529 "Do not send outside local AS (well-known community)\n"
7530 "Do not advertise to any peer (well-known community)\n"
7531 "Do not export to next AS (well-known community)\n"
7532 "community number\n"
7533 "Do not send outside local AS (well-known community)\n"
7534 "Do not advertise to any peer (well-known community)\n"
7535 "Do not export to next AS (well-known community)\n"
7536 "community number\n"
7537 "Do not send outside local AS (well-known community)\n"
7538 "Do not advertise to any peer (well-known community)\n"
7539 "Do not export to next AS (well-known community)\n")
7540
7541ALIAS (show_bgp_community,
7542 show_bgp_ipv6_community4_cmd,
7543 "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)",
7544 SHOW_STR
7545 BGP_STR
7546 "Address family\n"
7547 "Display routes matching the communities\n"
7548 "community number\n"
7549 "Do not send outside local AS (well-known community)\n"
7550 "Do not advertise to any peer (well-known community)\n"
7551 "Do not export to next AS (well-known community)\n"
7552 "community number\n"
7553 "Do not send outside local AS (well-known community)\n"
7554 "Do not advertise to any peer (well-known community)\n"
7555 "Do not export to next AS (well-known community)\n"
7556 "community number\n"
7557 "Do not send outside local AS (well-known community)\n"
7558 "Do not advertise to any peer (well-known community)\n"
7559 "Do not export to next AS (well-known community)\n"
7560 "community number\n"
7561 "Do not send outside local AS (well-known community)\n"
7562 "Do not advertise to any peer (well-known community)\n"
7563 "Do not export to next AS (well-known community)\n")
7564
7565/* old command */
7566DEFUN (show_ipv6_bgp_community,
7567 show_ipv6_bgp_community_cmd,
7568 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7569 SHOW_STR
7570 IPV6_STR
7571 BGP_STR
7572 "Display routes matching the communities\n"
7573 "community number\n"
7574 "Do not send outside local AS (well-known community)\n"
7575 "Do not advertise to any peer (well-known community)\n"
7576 "Do not export to next AS (well-known community)\n")
7577{
7578 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7579}
7580
7581/* old command */
7582ALIAS (show_ipv6_bgp_community,
7583 show_ipv6_bgp_community2_cmd,
7584 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7585 SHOW_STR
7586 IPV6_STR
7587 BGP_STR
7588 "Display routes matching the communities\n"
7589 "community number\n"
7590 "Do not send outside local AS (well-known community)\n"
7591 "Do not advertise to any peer (well-known community)\n"
7592 "Do not export to next AS (well-known community)\n"
7593 "community number\n"
7594 "Do not send outside local AS (well-known community)\n"
7595 "Do not advertise to any peer (well-known community)\n"
7596 "Do not export to next AS (well-known community)\n")
7597
7598/* old command */
7599ALIAS (show_ipv6_bgp_community,
7600 show_ipv6_bgp_community3_cmd,
7601 "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)",
7602 SHOW_STR
7603 IPV6_STR
7604 BGP_STR
7605 "Display routes matching the communities\n"
7606 "community number\n"
7607 "Do not send outside local AS (well-known community)\n"
7608 "Do not advertise to any peer (well-known community)\n"
7609 "Do not export to next AS (well-known community)\n"
7610 "community number\n"
7611 "Do not send outside local AS (well-known community)\n"
7612 "Do not advertise to any peer (well-known community)\n"
7613 "Do not export to next AS (well-known community)\n"
7614 "community number\n"
7615 "Do not send outside local AS (well-known community)\n"
7616 "Do not advertise to any peer (well-known community)\n"
7617 "Do not export to next AS (well-known community)\n")
7618
7619/* old command */
7620ALIAS (show_ipv6_bgp_community,
7621 show_ipv6_bgp_community4_cmd,
7622 "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)",
7623 SHOW_STR
7624 IPV6_STR
7625 BGP_STR
7626 "Display routes matching the communities\n"
7627 "community number\n"
7628 "Do not send outside local AS (well-known community)\n"
7629 "Do not advertise to any peer (well-known community)\n"
7630 "Do not export to next AS (well-known community)\n"
7631 "community number\n"
7632 "Do not send outside local AS (well-known community)\n"
7633 "Do not advertise to any peer (well-known community)\n"
7634 "Do not export to next AS (well-known community)\n"
7635 "community number\n"
7636 "Do not send outside local AS (well-known community)\n"
7637 "Do not advertise to any peer (well-known community)\n"
7638 "Do not export to next AS (well-known community)\n"
7639 "community number\n"
7640 "Do not send outside local AS (well-known community)\n"
7641 "Do not advertise to any peer (well-known community)\n"
7642 "Do not export to next AS (well-known community)\n")
7643
7644DEFUN (show_bgp_community_exact,
7645 show_bgp_community_exact_cmd,
7646 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7647 SHOW_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 "Exact match of the communities")
7655{
7656 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7657}
7658
7659ALIAS (show_bgp_community_exact,
7660 show_bgp_ipv6_community_exact_cmd,
7661 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7662 SHOW_STR
7663 BGP_STR
7664 "Address family\n"
7665 "Display routes matching the communities\n"
7666 "community number\n"
7667 "Do not send outside local AS (well-known community)\n"
7668 "Do not advertise to any peer (well-known community)\n"
7669 "Do not export to next AS (well-known community)\n"
7670 "Exact match of the communities")
7671
7672ALIAS (show_bgp_community_exact,
7673 show_bgp_community2_exact_cmd,
7674 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7675 SHOW_STR
7676 BGP_STR
7677 "Display routes matching the communities\n"
7678 "community number\n"
7679 "Do not send outside local AS (well-known community)\n"
7680 "Do not advertise to any peer (well-known community)\n"
7681 "Do not export to next AS (well-known community)\n"
7682 "community number\n"
7683 "Do not send outside local AS (well-known community)\n"
7684 "Do not advertise to any peer (well-known community)\n"
7685 "Do not export to next AS (well-known community)\n"
7686 "Exact match of the communities")
7687
7688ALIAS (show_bgp_community_exact,
7689 show_bgp_ipv6_community2_exact_cmd,
7690 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7691 SHOW_STR
7692 BGP_STR
7693 "Address family\n"
7694 "Display routes matching the communities\n"
7695 "community number\n"
7696 "Do not send outside local AS (well-known community)\n"
7697 "Do not advertise to any peer (well-known community)\n"
7698 "Do not export to next AS (well-known community)\n"
7699 "community number\n"
7700 "Do not send outside local AS (well-known community)\n"
7701 "Do not advertise to any peer (well-known community)\n"
7702 "Do not export to next AS (well-known community)\n"
7703 "Exact match of the communities")
7704
7705ALIAS (show_bgp_community_exact,
7706 show_bgp_community3_exact_cmd,
7707 "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",
7708 SHOW_STR
7709 BGP_STR
7710 "Display routes matching the communities\n"
7711 "community number\n"
7712 "Do not send outside local AS (well-known community)\n"
7713 "Do not advertise to any peer (well-known community)\n"
7714 "Do not export to next AS (well-known community)\n"
7715 "community number\n"
7716 "Do not send outside local AS (well-known community)\n"
7717 "Do not advertise to any peer (well-known community)\n"
7718 "Do not export to next AS (well-known community)\n"
7719 "community number\n"
7720 "Do not send outside local AS (well-known community)\n"
7721 "Do not advertise to any peer (well-known community)\n"
7722 "Do not export to next AS (well-known community)\n"
7723 "Exact match of the communities")
7724
7725ALIAS (show_bgp_community_exact,
7726 show_bgp_ipv6_community3_exact_cmd,
7727 "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",
7728 SHOW_STR
7729 BGP_STR
7730 "Address family\n"
7731 "Display routes matching the communities\n"
7732 "community number\n"
7733 "Do not send outside local AS (well-known community)\n"
7734 "Do not advertise to any peer (well-known community)\n"
7735 "Do not export to next AS (well-known community)\n"
7736 "community number\n"
7737 "Do not send outside local AS (well-known community)\n"
7738 "Do not advertise to any peer (well-known community)\n"
7739 "Do not export to next AS (well-known community)\n"
7740 "community number\n"
7741 "Do not send outside local AS (well-known community)\n"
7742 "Do not advertise to any peer (well-known community)\n"
7743 "Do not export to next AS (well-known community)\n"
7744 "Exact match of the communities")
7745
7746ALIAS (show_bgp_community_exact,
7747 show_bgp_community4_exact_cmd,
7748 "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",
7749 SHOW_STR
7750 BGP_STR
7751 "Display routes matching the communities\n"
7752 "community number\n"
7753 "Do not send outside local AS (well-known community)\n"
7754 "Do not advertise to any peer (well-known community)\n"
7755 "Do not export to next AS (well-known community)\n"
7756 "community number\n"
7757 "Do not send outside local AS (well-known community)\n"
7758 "Do not advertise to any peer (well-known community)\n"
7759 "Do not export to next AS (well-known community)\n"
7760 "community number\n"
7761 "Do not send outside local AS (well-known community)\n"
7762 "Do not advertise to any peer (well-known community)\n"
7763 "Do not export to next AS (well-known community)\n"
7764 "community number\n"
7765 "Do not send outside local AS (well-known community)\n"
7766 "Do not advertise to any peer (well-known community)\n"
7767 "Do not export to next AS (well-known community)\n"
7768 "Exact match of the communities")
7769
7770ALIAS (show_bgp_community_exact,
7771 show_bgp_ipv6_community4_exact_cmd,
7772 "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",
7773 SHOW_STR
7774 BGP_STR
7775 "Address family\n"
7776 "Display routes matching the communities\n"
7777 "community number\n"
7778 "Do not send outside local AS (well-known community)\n"
7779 "Do not advertise to any peer (well-known community)\n"
7780 "Do not export to next AS (well-known community)\n"
7781 "community number\n"
7782 "Do not send outside local AS (well-known community)\n"
7783 "Do not advertise to any peer (well-known community)\n"
7784 "Do not export to next AS (well-known community)\n"
7785 "community number\n"
7786 "Do not send outside local AS (well-known community)\n"
7787 "Do not advertise to any peer (well-known community)\n"
7788 "Do not export to next AS (well-known community)\n"
7789 "community number\n"
7790 "Do not send outside local AS (well-known community)\n"
7791 "Do not advertise to any peer (well-known community)\n"
7792 "Do not export to next AS (well-known community)\n"
7793 "Exact match of the communities")
7794
7795/* old command */
7796DEFUN (show_ipv6_bgp_community_exact,
7797 show_ipv6_bgp_community_exact_cmd,
7798 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7799 SHOW_STR
7800 IPV6_STR
7801 BGP_STR
7802 "Display routes matching the communities\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 "Exact match of the communities")
7808{
7809 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7810}
7811
7812/* old command */
7813ALIAS (show_ipv6_bgp_community_exact,
7814 show_ipv6_bgp_community2_exact_cmd,
7815 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7816 SHOW_STR
7817 IPV6_STR
7818 BGP_STR
7819 "Display routes matching the communities\n"
7820 "community number\n"
7821 "Do not send outside local AS (well-known community)\n"
7822 "Do not advertise to any peer (well-known community)\n"
7823 "Do not export to next AS (well-known community)\n"
7824 "community number\n"
7825 "Do not send outside local AS (well-known community)\n"
7826 "Do not advertise to any peer (well-known community)\n"
7827 "Do not export to next AS (well-known community)\n"
7828 "Exact match of the communities")
7829
7830/* old command */
7831ALIAS (show_ipv6_bgp_community_exact,
7832 show_ipv6_bgp_community3_exact_cmd,
7833 "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",
7834 SHOW_STR
7835 IPV6_STR
7836 BGP_STR
7837 "Display routes matching the communities\n"
7838 "community number\n"
7839 "Do not send outside local AS (well-known community)\n"
7840 "Do not advertise to any peer (well-known community)\n"
7841 "Do not export to next AS (well-known community)\n"
7842 "community number\n"
7843 "Do not send outside local AS (well-known community)\n"
7844 "Do not advertise to any peer (well-known community)\n"
7845 "Do not export to next AS (well-known community)\n"
7846 "community number\n"
7847 "Do not send outside local AS (well-known community)\n"
7848 "Do not advertise to any peer (well-known community)\n"
7849 "Do not export to next AS (well-known community)\n"
7850 "Exact match of the communities")
7851
7852/* old command */
7853ALIAS (show_ipv6_bgp_community_exact,
7854 show_ipv6_bgp_community4_exact_cmd,
7855 "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",
7856 SHOW_STR
7857 IPV6_STR
7858 BGP_STR
7859 "Display routes matching the communities\n"
7860 "community number\n"
7861 "Do not send outside local AS (well-known community)\n"
7862 "Do not advertise to any peer (well-known community)\n"
7863 "Do not export to next AS (well-known community)\n"
7864 "community number\n"
7865 "Do not send outside local AS (well-known community)\n"
7866 "Do not advertise to any peer (well-known community)\n"
7867 "Do not export to next AS (well-known community)\n"
7868 "community number\n"
7869 "Do not send outside local AS (well-known community)\n"
7870 "Do not advertise to any peer (well-known community)\n"
7871 "Do not export to next AS (well-known community)\n"
7872 "community number\n"
7873 "Do not send outside local AS (well-known community)\n"
7874 "Do not advertise to any peer (well-known community)\n"
7875 "Do not export to next AS (well-known community)\n"
7876 "Exact match of the communities")
7877
7878/* old command */
7879DEFUN (show_ipv6_mbgp_community,
7880 show_ipv6_mbgp_community_cmd,
7881 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7882 SHOW_STR
7883 IPV6_STR
7884 MBGP_STR
7885 "Display routes matching the communities\n"
7886 "community number\n"
7887 "Do not send outside local AS (well-known community)\n"
7888 "Do not advertise to any peer (well-known community)\n"
7889 "Do not export to next AS (well-known community)\n")
7890{
7891 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7892}
7893
7894/* old command */
7895ALIAS (show_ipv6_mbgp_community,
7896 show_ipv6_mbgp_community2_cmd,
7897 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7898 SHOW_STR
7899 IPV6_STR
7900 MBGP_STR
7901 "Display routes matching the communities\n"
7902 "community number\n"
7903 "Do not send outside local AS (well-known community)\n"
7904 "Do not advertise to any peer (well-known community)\n"
7905 "Do not export to next AS (well-known community)\n"
7906 "community number\n"
7907 "Do not send outside local AS (well-known community)\n"
7908 "Do not advertise to any peer (well-known community)\n"
7909 "Do not export to next AS (well-known community)\n")
7910
7911/* old command */
7912ALIAS (show_ipv6_mbgp_community,
7913 show_ipv6_mbgp_community3_cmd,
7914 "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)",
7915 SHOW_STR
7916 IPV6_STR
7917 MBGP_STR
7918 "Display routes matching the communities\n"
7919 "community number\n"
7920 "Do not send outside local AS (well-known community)\n"
7921 "Do not advertise to any peer (well-known community)\n"
7922 "Do not export to next AS (well-known community)\n"
7923 "community number\n"
7924 "Do not send outside local AS (well-known community)\n"
7925 "Do not advertise to any peer (well-known community)\n"
7926 "Do not export to next AS (well-known community)\n"
7927 "community number\n"
7928 "Do not send outside local AS (well-known community)\n"
7929 "Do not advertise to any peer (well-known community)\n"
7930 "Do not export to next AS (well-known community)\n")
7931
7932/* old command */
7933ALIAS (show_ipv6_mbgp_community,
7934 show_ipv6_mbgp_community4_cmd,
7935 "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)",
7936 SHOW_STR
7937 IPV6_STR
7938 MBGP_STR
7939 "Display routes matching the communities\n"
7940 "community number\n"
7941 "Do not send outside local AS (well-known community)\n"
7942 "Do not advertise to any peer (well-known community)\n"
7943 "Do not export to next AS (well-known community)\n"
7944 "community number\n"
7945 "Do not send outside local AS (well-known community)\n"
7946 "Do not advertise to any peer (well-known community)\n"
7947 "Do not export to next AS (well-known community)\n"
7948 "community number\n"
7949 "Do not send outside local AS (well-known community)\n"
7950 "Do not advertise to any peer (well-known community)\n"
7951 "Do not export to next AS (well-known community)\n"
7952 "community number\n"
7953 "Do not send outside local AS (well-known community)\n"
7954 "Do not advertise to any peer (well-known community)\n"
7955 "Do not export to next AS (well-known community)\n")
7956
7957/* old command */
7958DEFUN (show_ipv6_mbgp_community_exact,
7959 show_ipv6_mbgp_community_exact_cmd,
7960 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7961 SHOW_STR
7962 IPV6_STR
7963 MBGP_STR
7964 "Display routes matching the communities\n"
7965 "community number\n"
7966 "Do not send outside local AS (well-known community)\n"
7967 "Do not advertise to any peer (well-known community)\n"
7968 "Do not export to next AS (well-known community)\n"
7969 "Exact match of the communities")
7970{
7971 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7972}
7973
7974/* old command */
7975ALIAS (show_ipv6_mbgp_community_exact,
7976 show_ipv6_mbgp_community2_exact_cmd,
7977 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7978 SHOW_STR
7979 IPV6_STR
7980 MBGP_STR
7981 "Display routes matching the communities\n"
7982 "community number\n"
7983 "Do not send outside local AS (well-known community)\n"
7984 "Do not advertise to any peer (well-known community)\n"
7985 "Do not export to next AS (well-known community)\n"
7986 "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
7992/* old command */
7993ALIAS (show_ipv6_mbgp_community_exact,
7994 show_ipv6_mbgp_community3_exact_cmd,
7995 "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",
7996 SHOW_STR
7997 IPV6_STR
7998 MBGP_STR
7999 "Display routes matching the communities\n"
8000 "community number\n"
8001 "Do not send outside local AS (well-known community)\n"
8002 "Do not advertise to any peer (well-known community)\n"
8003 "Do not export to next AS (well-known community)\n"
8004 "community number\n"
8005 "Do not send outside local AS (well-known community)\n"
8006 "Do not advertise to any peer (well-known community)\n"
8007 "Do not export to next AS (well-known community)\n"
8008 "community number\n"
8009 "Do not send outside local AS (well-known community)\n"
8010 "Do not advertise to any peer (well-known community)\n"
8011 "Do not export to next AS (well-known community)\n"
8012 "Exact match of the communities")
8013
8014/* old command */
8015ALIAS (show_ipv6_mbgp_community_exact,
8016 show_ipv6_mbgp_community4_exact_cmd,
8017 "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",
8018 SHOW_STR
8019 IPV6_STR
8020 MBGP_STR
8021 "Display routes matching the communities\n"
8022 "community number\n"
8023 "Do not send outside local AS (well-known community)\n"
8024 "Do not advertise to any peer (well-known community)\n"
8025 "Do not export to next AS (well-known community)\n"
8026 "community number\n"
8027 "Do not send outside local AS (well-known community)\n"
8028 "Do not advertise to any peer (well-known community)\n"
8029 "Do not export to next AS (well-known community)\n"
8030 "community number\n"
8031 "Do not send outside local AS (well-known community)\n"
8032 "Do not advertise to any peer (well-known community)\n"
8033 "Do not export to next AS (well-known community)\n"
8034 "community number\n"
8035 "Do not send outside local AS (well-known community)\n"
8036 "Do not advertise to any peer (well-known community)\n"
8037 "Do not export to next AS (well-known community)\n"
8038 "Exact match of the communities")
8039#endif /* HAVE_IPV6 */
8040
paul94f2b392005-06-28 12:44:16 +00008041static int
paulfd79ac92004-10-13 05:06:08 +00008042bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008043 u_int16_t afi, u_char safi)
8044{
8045 struct community_list *list;
8046
hassofee6e4e2005-02-02 16:29:31 +00008047 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008048 if (list == NULL)
8049 {
8050 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8051 VTY_NEWLINE);
8052 return CMD_WARNING;
8053 }
8054
ajs5a646652004-11-05 01:25:55 +00008055 return bgp_show (vty, NULL, afi, safi,
8056 (exact ? bgp_show_type_community_list_exact :
8057 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008058}
8059
8060DEFUN (show_ip_bgp_community_list,
8061 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008062 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008063 SHOW_STR
8064 IP_STR
8065 BGP_STR
8066 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008067 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008068 "community-list name\n")
8069{
8070 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8071}
8072
8073DEFUN (show_ip_bgp_ipv4_community_list,
8074 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008075 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008076 SHOW_STR
8077 IP_STR
8078 BGP_STR
8079 "Address family\n"
8080 "Address Family modifier\n"
8081 "Address Family modifier\n"
8082 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008083 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008084 "community-list name\n")
8085{
8086 if (strncmp (argv[0], "m", 1) == 0)
8087 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8088
8089 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8090}
8091
8092DEFUN (show_ip_bgp_community_list_exact,
8093 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008094 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008095 SHOW_STR
8096 IP_STR
8097 BGP_STR
8098 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008099 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008100 "community-list name\n"
8101 "Exact match of the communities\n")
8102{
8103 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8104}
8105
8106DEFUN (show_ip_bgp_ipv4_community_list_exact,
8107 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008108 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008109 SHOW_STR
8110 IP_STR
8111 BGP_STR
8112 "Address family\n"
8113 "Address Family modifier\n"
8114 "Address Family modifier\n"
8115 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008116 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008117 "community-list name\n"
8118 "Exact match of the communities\n")
8119{
8120 if (strncmp (argv[0], "m", 1) == 0)
8121 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8122
8123 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8124}
8125
8126#ifdef HAVE_IPV6
8127DEFUN (show_bgp_community_list,
8128 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008129 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008130 SHOW_STR
8131 BGP_STR
8132 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008133 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008134 "community-list name\n")
8135{
8136 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8137}
8138
8139ALIAS (show_bgp_community_list,
8140 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008141 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008142 SHOW_STR
8143 BGP_STR
8144 "Address family\n"
8145 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008146 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008147 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008148
8149/* old command */
8150DEFUN (show_ipv6_bgp_community_list,
8151 show_ipv6_bgp_community_list_cmd,
8152 "show ipv6 bgp community-list WORD",
8153 SHOW_STR
8154 IPV6_STR
8155 BGP_STR
8156 "Display routes matching the community-list\n"
8157 "community-list name\n")
8158{
8159 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8160}
8161
8162/* old command */
8163DEFUN (show_ipv6_mbgp_community_list,
8164 show_ipv6_mbgp_community_list_cmd,
8165 "show ipv6 mbgp community-list WORD",
8166 SHOW_STR
8167 IPV6_STR
8168 MBGP_STR
8169 "Display routes matching the community-list\n"
8170 "community-list name\n")
8171{
8172 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8173}
8174
8175DEFUN (show_bgp_community_list_exact,
8176 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008177 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008178 SHOW_STR
8179 BGP_STR
8180 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008181 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008182 "community-list name\n"
8183 "Exact match of the communities\n")
8184{
8185 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8186}
8187
8188ALIAS (show_bgp_community_list_exact,
8189 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008190 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008191 SHOW_STR
8192 BGP_STR
8193 "Address family\n"
8194 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008195 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008196 "community-list name\n"
8197 "Exact match of the communities\n")
8198
8199/* old command */
8200DEFUN (show_ipv6_bgp_community_list_exact,
8201 show_ipv6_bgp_community_list_exact_cmd,
8202 "show ipv6 bgp community-list WORD exact-match",
8203 SHOW_STR
8204 IPV6_STR
8205 BGP_STR
8206 "Display routes matching the community-list\n"
8207 "community-list name\n"
8208 "Exact match of the communities\n")
8209{
8210 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8211}
8212
8213/* old command */
8214DEFUN (show_ipv6_mbgp_community_list_exact,
8215 show_ipv6_mbgp_community_list_exact_cmd,
8216 "show ipv6 mbgp community-list WORD exact-match",
8217 SHOW_STR
8218 IPV6_STR
8219 MBGP_STR
8220 "Display routes matching the community-list\n"
8221 "community-list name\n"
8222 "Exact match of the communities\n")
8223{
8224 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8225}
8226#endif /* HAVE_IPV6 */
8227
paul94f2b392005-06-28 12:44:16 +00008228static int
paulfd79ac92004-10-13 05:06:08 +00008229bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008230 safi_t safi, enum bgp_show_type type)
8231{
8232 int ret;
8233 struct prefix *p;
8234
8235 p = prefix_new();
8236
8237 ret = str2prefix (prefix, p);
8238 if (! ret)
8239 {
8240 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8241 return CMD_WARNING;
8242 }
8243
ajs5a646652004-11-05 01:25:55 +00008244 ret = bgp_show (vty, NULL, afi, safi, type, p);
8245 prefix_free(p);
8246 return ret;
paul718e3742002-12-13 20:15:29 +00008247}
8248
8249DEFUN (show_ip_bgp_prefix_longer,
8250 show_ip_bgp_prefix_longer_cmd,
8251 "show ip bgp A.B.C.D/M longer-prefixes",
8252 SHOW_STR
8253 IP_STR
8254 BGP_STR
8255 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8256 "Display route and more specific routes\n")
8257{
8258 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8259 bgp_show_type_prefix_longer);
8260}
8261
8262DEFUN (show_ip_bgp_flap_prefix_longer,
8263 show_ip_bgp_flap_prefix_longer_cmd,
8264 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8265 SHOW_STR
8266 IP_STR
8267 BGP_STR
8268 "Display flap statistics of routes\n"
8269 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8270 "Display route and more specific routes\n")
8271{
8272 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8273 bgp_show_type_flap_prefix_longer);
8274}
8275
8276DEFUN (show_ip_bgp_ipv4_prefix_longer,
8277 show_ip_bgp_ipv4_prefix_longer_cmd,
8278 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8279 SHOW_STR
8280 IP_STR
8281 BGP_STR
8282 "Address family\n"
8283 "Address Family modifier\n"
8284 "Address Family modifier\n"
8285 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8286 "Display route and more specific routes\n")
8287{
8288 if (strncmp (argv[0], "m", 1) == 0)
8289 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8290 bgp_show_type_prefix_longer);
8291
8292 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8293 bgp_show_type_prefix_longer);
8294}
8295
8296DEFUN (show_ip_bgp_flap_address,
8297 show_ip_bgp_flap_address_cmd,
8298 "show ip bgp flap-statistics A.B.C.D",
8299 SHOW_STR
8300 IP_STR
8301 BGP_STR
8302 "Display flap statistics of routes\n"
8303 "Network in the BGP routing table to display\n")
8304{
8305 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8306 bgp_show_type_flap_address);
8307}
8308
8309DEFUN (show_ip_bgp_flap_prefix,
8310 show_ip_bgp_flap_prefix_cmd,
8311 "show ip bgp flap-statistics A.B.C.D/M",
8312 SHOW_STR
8313 IP_STR
8314 BGP_STR
8315 "Display flap statistics of routes\n"
8316 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8317{
8318 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8319 bgp_show_type_flap_prefix);
8320}
8321#ifdef HAVE_IPV6
8322DEFUN (show_bgp_prefix_longer,
8323 show_bgp_prefix_longer_cmd,
8324 "show bgp X:X::X:X/M longer-prefixes",
8325 SHOW_STR
8326 BGP_STR
8327 "IPv6 prefix <network>/<length>\n"
8328 "Display route and more specific routes\n")
8329{
8330 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8331 bgp_show_type_prefix_longer);
8332}
8333
8334ALIAS (show_bgp_prefix_longer,
8335 show_bgp_ipv6_prefix_longer_cmd,
8336 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8337 SHOW_STR
8338 BGP_STR
8339 "Address family\n"
8340 "IPv6 prefix <network>/<length>\n"
8341 "Display route and more specific routes\n")
8342
8343/* old command */
8344DEFUN (show_ipv6_bgp_prefix_longer,
8345 show_ipv6_bgp_prefix_longer_cmd,
8346 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8347 SHOW_STR
8348 IPV6_STR
8349 BGP_STR
8350 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8351 "Display route and more specific routes\n")
8352{
8353 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8354 bgp_show_type_prefix_longer);
8355}
8356
8357/* old command */
8358DEFUN (show_ipv6_mbgp_prefix_longer,
8359 show_ipv6_mbgp_prefix_longer_cmd,
8360 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8361 SHOW_STR
8362 IPV6_STR
8363 MBGP_STR
8364 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8365 "Display route and more specific routes\n")
8366{
8367 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8368 bgp_show_type_prefix_longer);
8369}
8370#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008371
paul94f2b392005-06-28 12:44:16 +00008372static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008373peer_lookup_in_view (struct vty *vty, const char *view_name,
8374 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008375{
8376 int ret;
8377 struct bgp *bgp;
8378 struct peer *peer;
8379 union sockunion su;
8380
8381 /* BGP structure lookup. */
8382 if (view_name)
8383 {
8384 bgp = bgp_lookup_by_name (view_name);
8385 if (! bgp)
8386 {
8387 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8388 return NULL;
8389 }
8390 }
paul5228ad22004-06-04 17:58:18 +00008391 else
paulbb46e942003-10-24 19:02:03 +00008392 {
8393 bgp = bgp_get_default ();
8394 if (! bgp)
8395 {
8396 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8397 return NULL;
8398 }
8399 }
8400
8401 /* Get peer sockunion. */
8402 ret = str2sockunion (ip_str, &su);
8403 if (ret < 0)
8404 {
8405 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8406 return NULL;
8407 }
8408
8409 /* Peer structure lookup. */
8410 peer = peer_lookup (bgp, &su);
8411 if (! peer)
8412 {
8413 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8414 return NULL;
8415 }
8416
8417 return peer;
8418}
Paul Jakma2815e612006-09-14 02:56:07 +00008419
8420enum bgp_stats
8421{
8422 BGP_STATS_MAXBITLEN = 0,
8423 BGP_STATS_RIB,
8424 BGP_STATS_PREFIXES,
8425 BGP_STATS_TOTPLEN,
8426 BGP_STATS_UNAGGREGATEABLE,
8427 BGP_STATS_MAX_AGGREGATEABLE,
8428 BGP_STATS_AGGREGATES,
8429 BGP_STATS_SPACE,
8430 BGP_STATS_ASPATH_COUNT,
8431 BGP_STATS_ASPATH_MAXHOPS,
8432 BGP_STATS_ASPATH_TOTHOPS,
8433 BGP_STATS_ASPATH_MAXSIZE,
8434 BGP_STATS_ASPATH_TOTSIZE,
8435 BGP_STATS_ASN_HIGHEST,
8436 BGP_STATS_MAX,
8437};
paulbb46e942003-10-24 19:02:03 +00008438
Paul Jakma2815e612006-09-14 02:56:07 +00008439static const char *table_stats_strs[] =
8440{
8441 [BGP_STATS_PREFIXES] = "Total Prefixes",
8442 [BGP_STATS_TOTPLEN] = "Average prefix length",
8443 [BGP_STATS_RIB] = "Total Advertisements",
8444 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8445 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8446 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8447 [BGP_STATS_SPACE] = "Address space advertised",
8448 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8449 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8450 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8451 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
8452 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
8453 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
8454 [BGP_STATS_MAX] = NULL,
8455};
8456
8457struct bgp_table_stats
8458{
8459 struct bgp_table *table;
8460 unsigned long long counts[BGP_STATS_MAX];
8461};
8462
8463#if 0
8464#define TALLY_SIGFIG 100000
8465static unsigned long
8466ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
8467{
8468 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
8469 unsigned long res = (newtot * TALLY_SIGFIG) / count;
8470 unsigned long ret = newtot / count;
8471
8472 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
8473 return ret + 1;
8474 else
8475 return ret;
8476}
8477#endif
8478
8479static int
8480bgp_table_stats_walker (struct thread *t)
8481{
8482 struct bgp_node *rn;
8483 struct bgp_node *top;
8484 struct bgp_table_stats *ts = THREAD_ARG (t);
8485 unsigned int space = 0;
8486
Paul Jakma53d9f672006-10-15 23:41:16 +00008487 if (!(top = bgp_table_top (ts->table)))
8488 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00008489
8490 switch (top->p.family)
8491 {
8492 case AF_INET:
8493 space = IPV4_MAX_BITLEN;
8494 break;
8495 case AF_INET6:
8496 space = IPV6_MAX_BITLEN;
8497 break;
8498 }
8499
8500 ts->counts[BGP_STATS_MAXBITLEN] = space;
8501
8502 for (rn = top; rn; rn = bgp_route_next (rn))
8503 {
8504 struct bgp_info *ri;
8505 struct bgp_node *prn = rn->parent;
8506 unsigned int rinum = 0;
8507
8508 if (rn == top)
8509 continue;
8510
8511 if (!rn->info)
8512 continue;
8513
8514 ts->counts[BGP_STATS_PREFIXES]++;
8515 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
8516
8517#if 0
8518 ts->counts[BGP_STATS_AVGPLEN]
8519 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
8520 ts->counts[BGP_STATS_AVGPLEN],
8521 rn->p.prefixlen);
8522#endif
8523
8524 /* check if the prefix is included by any other announcements */
8525 while (prn && !prn->info)
8526 prn = prn->parent;
8527
8528 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00008529 {
8530 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
8531 /* announced address space */
8532 if (space)
8533 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
8534 }
Paul Jakma2815e612006-09-14 02:56:07 +00008535 else if (prn->info)
8536 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
8537
Paul Jakma2815e612006-09-14 02:56:07 +00008538 for (ri = rn->info; ri; ri = ri->next)
8539 {
8540 rinum++;
8541 ts->counts[BGP_STATS_RIB]++;
8542
8543 if (ri->attr &&
8544 (CHECK_FLAG (ri->attr->flag,
8545 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
8546 ts->counts[BGP_STATS_AGGREGATES]++;
8547
8548 /* as-path stats */
8549 if (ri->attr && ri->attr->aspath)
8550 {
8551 unsigned int hops = aspath_count_hops (ri->attr->aspath);
8552 unsigned int size = aspath_size (ri->attr->aspath);
8553 as_t highest = aspath_highest (ri->attr->aspath);
8554
8555 ts->counts[BGP_STATS_ASPATH_COUNT]++;
8556
8557 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
8558 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
8559
8560 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
8561 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
8562
8563 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
8564 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
8565#if 0
8566 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
8567 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8568 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
8569 hops);
8570 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
8571 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8572 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
8573 size);
8574#endif
8575 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
8576 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
8577 }
8578 }
8579 }
8580 return 0;
8581}
8582
8583static int
8584bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
8585{
8586 struct bgp_table_stats ts;
8587 unsigned int i;
8588
8589 if (!bgp->rib[afi][safi])
8590 {
8591 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
8592 return CMD_WARNING;
8593 }
8594
8595 memset (&ts, 0, sizeof (ts));
8596 ts.table = bgp->rib[afi][safi];
8597 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
8598
8599 vty_out (vty, "BGP %s RIB statistics%s%s",
8600 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
8601
8602 for (i = 0; i < BGP_STATS_MAX; i++)
8603 {
8604 if (!table_stats_strs[i])
8605 continue;
8606
8607 switch (i)
8608 {
8609#if 0
8610 case BGP_STATS_ASPATH_AVGHOPS:
8611 case BGP_STATS_ASPATH_AVGSIZE:
8612 case BGP_STATS_AVGPLEN:
8613 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8614 vty_out (vty, "%12.2f",
8615 (float)ts.counts[i] / (float)TALLY_SIGFIG);
8616 break;
8617#endif
8618 case BGP_STATS_ASPATH_TOTHOPS:
8619 case BGP_STATS_ASPATH_TOTSIZE:
8620 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8621 vty_out (vty, "%12.2f",
8622 ts.counts[i] ?
8623 (float)ts.counts[i] /
8624 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
8625 : 0);
8626 break;
8627 case BGP_STATS_TOTPLEN:
8628 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8629 vty_out (vty, "%12.2f",
8630 ts.counts[i] ?
8631 (float)ts.counts[i] /
8632 (float)ts.counts[BGP_STATS_PREFIXES]
8633 : 0);
8634 break;
8635 case BGP_STATS_SPACE:
8636 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8637 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
8638 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
8639 break;
8640 vty_out (vty, "%30s: ", "\% announced ");
8641 vty_out (vty, "%12.2f%s",
8642 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00008643 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00008644 VTY_NEWLINE);
8645 vty_out (vty, "%30s: ", "/8 equivalent ");
8646 vty_out (vty, "%12.2f%s",
8647 (float)ts.counts[BGP_STATS_SPACE] /
8648 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
8649 VTY_NEWLINE);
8650 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
8651 break;
8652 vty_out (vty, "%30s: ", "/24 equivalent ");
8653 vty_out (vty, "%12.2f",
8654 (float)ts.counts[BGP_STATS_SPACE] /
8655 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
8656 break;
8657 default:
8658 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8659 vty_out (vty, "%12llu", ts.counts[i]);
8660 }
8661
8662 vty_out (vty, "%s", VTY_NEWLINE);
8663 }
8664 return CMD_SUCCESS;
8665}
8666
8667static int
8668bgp_table_stats_vty (struct vty *vty, const char *name,
8669 const char *afi_str, const char *safi_str)
8670{
8671 struct bgp *bgp;
8672 afi_t afi;
8673 safi_t safi;
8674
8675 if (name)
8676 bgp = bgp_lookup_by_name (name);
8677 else
8678 bgp = bgp_get_default ();
8679
8680 if (!bgp)
8681 {
8682 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
8683 return CMD_WARNING;
8684 }
8685 if (strncmp (afi_str, "ipv", 3) == 0)
8686 {
8687 if (strncmp (afi_str, "ipv4", 4) == 0)
8688 afi = AFI_IP;
8689 else if (strncmp (afi_str, "ipv6", 4) == 0)
8690 afi = AFI_IP6;
8691 else
8692 {
8693 vty_out (vty, "%% Invalid address family %s%s",
8694 afi_str, VTY_NEWLINE);
8695 return CMD_WARNING;
8696 }
8697 if (strncmp (safi_str, "m", 1) == 0)
8698 safi = SAFI_MULTICAST;
8699 else if (strncmp (safi_str, "u", 1) == 0)
8700 safi = SAFI_UNICAST;
8701 else if (strncmp (safi_str, "vpnv4", 5) == 0)
8702 safi = BGP_SAFI_VPNV4;
8703 else if (strncmp (safi_str, "vpnv6", 6) == 0)
8704 safi = BGP_SAFI_VPNV6;
8705 else
8706 {
8707 vty_out (vty, "%% Invalid subsequent address family %s%s",
8708 safi_str, VTY_NEWLINE);
8709 return CMD_WARNING;
8710 }
8711 }
8712 else
8713 {
8714 vty_out (vty, "%% Invalid address family %s%s",
8715 afi_str, VTY_NEWLINE);
8716 return CMD_WARNING;
8717 }
8718
8719 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
8720 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
8721 {
8722 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
8723 afi_str, safi_str, VTY_NEWLINE);
8724 return CMD_WARNING;
8725 }
8726 return bgp_table_stats (vty, bgp, afi, safi);
8727}
8728
8729DEFUN (show_bgp_statistics,
8730 show_bgp_statistics_cmd,
8731 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
8732 SHOW_STR
8733 BGP_STR
8734 "Address family\n"
8735 "Address family\n"
8736 "Address Family modifier\n"
8737 "Address Family modifier\n"
8738 "BGP RIB advertisement statistics\n")
8739{
8740 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
8741}
8742
8743ALIAS (show_bgp_statistics,
8744 show_bgp_statistics_vpnv4_cmd,
8745 "show bgp (ipv4) (vpnv4) statistics",
8746 SHOW_STR
8747 BGP_STR
8748 "Address family\n"
8749 "Address Family modifier\n"
8750 "BGP RIB advertisement statistics\n")
8751
8752DEFUN (show_bgp_statistics_view,
8753 show_bgp_statistics_view_cmd,
8754 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
8755 SHOW_STR
8756 BGP_STR
8757 "BGP view\n"
8758 "Address family\n"
8759 "Address family\n"
8760 "Address Family modifier\n"
8761 "Address Family modifier\n"
8762 "BGP RIB advertisement statistics\n")
8763{
8764 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
8765}
8766
8767ALIAS (show_bgp_statistics_view,
8768 show_bgp_statistics_view_vpnv4_cmd,
8769 "show bgp view WORD (ipv4) (vpnv4) statistics",
8770 SHOW_STR
8771 BGP_STR
8772 "BGP view\n"
8773 "Address family\n"
8774 "Address Family modifier\n"
8775 "BGP RIB advertisement statistics\n")
8776
Paul Jakmaff7924f2006-09-04 01:10:36 +00008777enum bgp_pcounts
8778{
8779 PCOUNT_ADJ_IN = 0,
8780 PCOUNT_DAMPED,
8781 PCOUNT_REMOVED,
8782 PCOUNT_HISTORY,
8783 PCOUNT_STALE,
8784 PCOUNT_VALID,
8785 PCOUNT_ALL,
8786 PCOUNT_COUNTED,
8787 PCOUNT_PFCNT, /* the figure we display to users */
8788 PCOUNT_MAX,
8789};
8790
8791static const char *pcount_strs[] =
8792{
8793 [PCOUNT_ADJ_IN] = "Adj-in",
8794 [PCOUNT_DAMPED] = "Damped",
8795 [PCOUNT_REMOVED] = "Removed",
8796 [PCOUNT_HISTORY] = "History",
8797 [PCOUNT_STALE] = "Stale",
8798 [PCOUNT_VALID] = "Valid",
8799 [PCOUNT_ALL] = "All RIB",
8800 [PCOUNT_COUNTED] = "PfxCt counted",
8801 [PCOUNT_PFCNT] = "Useable",
8802 [PCOUNT_MAX] = NULL,
8803};
8804
Paul Jakma2815e612006-09-14 02:56:07 +00008805struct peer_pcounts
8806{
8807 unsigned int count[PCOUNT_MAX];
8808 const struct peer *peer;
8809 const struct bgp_table *table;
8810};
8811
Paul Jakmaff7924f2006-09-04 01:10:36 +00008812static int
Paul Jakma2815e612006-09-14 02:56:07 +00008813bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00008814{
8815 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00008816 struct peer_pcounts *pc = THREAD_ARG (t);
8817 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008818
Paul Jakma2815e612006-09-14 02:56:07 +00008819 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00008820 {
8821 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00008822 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008823
8824 for (ain = rn->adj_in; ain; ain = ain->next)
8825 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00008826 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008827
Paul Jakmaff7924f2006-09-04 01:10:36 +00008828 for (ri = rn->info; ri; ri = ri->next)
8829 {
8830 char buf[SU_ADDRSTRLEN];
8831
8832 if (ri->peer != peer)
8833 continue;
8834
Paul Jakma2815e612006-09-14 02:56:07 +00008835 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008836
8837 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00008838 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008839 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00008840 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008841 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00008842 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008843 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00008844 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008845 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00008846 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00008847 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00008848 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008849
8850 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
8851 {
Paul Jakma2815e612006-09-14 02:56:07 +00008852 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00008853 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00008854 plog_warn (peer->log,
8855 "%s [pcount] %s/%d is counted but flags 0x%x",
8856 peer->host,
8857 inet_ntop(rn->p.family, &rn->p.u.prefix,
8858 buf, SU_ADDRSTRLEN),
8859 rn->p.prefixlen,
8860 ri->flags);
8861 }
8862 else
8863 {
Paul Jakma1a392d42006-09-07 00:24:49 +00008864 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00008865 plog_warn (peer->log,
8866 "%s [pcount] %s/%d not counted but flags 0x%x",
8867 peer->host,
8868 inet_ntop(rn->p.family, &rn->p.u.prefix,
8869 buf, SU_ADDRSTRLEN),
8870 rn->p.prefixlen,
8871 ri->flags);
8872 }
8873 }
8874 }
Paul Jakma2815e612006-09-14 02:56:07 +00008875 return 0;
8876}
Paul Jakmaff7924f2006-09-04 01:10:36 +00008877
Paul Jakma2815e612006-09-14 02:56:07 +00008878static int
8879bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
8880{
8881 struct peer_pcounts pcounts = { .peer = peer };
8882 unsigned int i;
8883
8884 if (!peer || !peer->bgp || !peer->afc[afi][safi]
8885 || !peer->bgp->rib[afi][safi])
8886 {
8887 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8888 return CMD_WARNING;
8889 }
8890
8891 memset (&pcounts, 0, sizeof(pcounts));
8892 pcounts.peer = peer;
8893 pcounts.table = peer->bgp->rib[afi][safi];
8894
8895 /* in-place call via thread subsystem so as to record execution time
8896 * stats for the thread-walk (i.e. ensure this can't be blamed on
8897 * on just vty_read()).
8898 */
8899 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
8900
Paul Jakmaff7924f2006-09-04 01:10:36 +00008901 vty_out (vty, "Prefix counts for %s, %s%s",
8902 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
8903 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
8904 vty_out (vty, "%sCounts from RIB table walk:%s%s",
8905 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8906
8907 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00008908 vty_out (vty, "%20s: %-10d%s",
8909 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00008910
Paul Jakma2815e612006-09-14 02:56:07 +00008911 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00008912 {
8913 vty_out (vty, "%s [pcount] PfxCt drift!%s",
8914 peer->host, VTY_NEWLINE);
8915 vty_out (vty, "Please report this bug, with the above command output%s",
8916 VTY_NEWLINE);
8917 }
8918
8919 return CMD_SUCCESS;
8920}
8921
8922DEFUN (show_ip_bgp_neighbor_prefix_counts,
8923 show_ip_bgp_neighbor_prefix_counts_cmd,
8924 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8925 SHOW_STR
8926 IP_STR
8927 BGP_STR
8928 "Detailed information on TCP and BGP neighbor connections\n"
8929 "Neighbor to display information about\n"
8930 "Neighbor to display information about\n"
8931 "Display detailed prefix count information\n")
8932{
8933 struct peer *peer;
8934
8935 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8936 if (! peer)
8937 return CMD_WARNING;
8938
8939 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
8940}
8941
8942DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
8943 show_bgp_ipv6_neighbor_prefix_counts_cmd,
8944 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8945 SHOW_STR
8946 BGP_STR
8947 "Address family\n"
8948 "Detailed information on TCP and BGP neighbor connections\n"
8949 "Neighbor to display information about\n"
8950 "Neighbor to display information about\n"
8951 "Display detailed prefix count information\n")
8952{
8953 struct peer *peer;
8954
8955 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8956 if (! peer)
8957 return CMD_WARNING;
8958
8959 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
8960}
8961
8962DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
8963 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
8964 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8965 SHOW_STR
8966 IP_STR
8967 BGP_STR
8968 "Address family\n"
8969 "Address Family modifier\n"
8970 "Address Family modifier\n"
8971 "Detailed information on TCP and BGP neighbor connections\n"
8972 "Neighbor to display information about\n"
8973 "Neighbor to display information about\n"
8974 "Display detailed prefix count information\n")
8975{
8976 struct peer *peer;
8977
8978 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8979 if (! peer)
8980 return CMD_WARNING;
8981
8982 if (strncmp (argv[0], "m", 1) == 0)
8983 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
8984
8985 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
8986}
8987
8988DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
8989 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
8990 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8991 SHOW_STR
8992 IP_STR
8993 BGP_STR
8994 "Address family\n"
8995 "Address Family modifier\n"
8996 "Address Family modifier\n"
8997 "Detailed information on TCP and BGP neighbor connections\n"
8998 "Neighbor to display information about\n"
8999 "Neighbor to display information about\n"
9000 "Display detailed prefix count information\n")
9001{
9002 struct peer *peer;
9003
9004 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9005 if (! peer)
9006 return CMD_WARNING;
9007
9008 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9009}
9010
9011
paul94f2b392005-06-28 12:44:16 +00009012static void
paul718e3742002-12-13 20:15:29 +00009013show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9014 int in)
9015{
9016 struct bgp_table *table;
9017 struct bgp_adj_in *ain;
9018 struct bgp_adj_out *adj;
9019 unsigned long output_count;
9020 struct bgp_node *rn;
9021 int header1 = 1;
9022 struct bgp *bgp;
9023 int header2 = 1;
9024
paulbb46e942003-10-24 19:02:03 +00009025 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009026
9027 if (! bgp)
9028 return;
9029
9030 table = bgp->rib[afi][safi];
9031
9032 output_count = 0;
9033
9034 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9035 PEER_STATUS_DEFAULT_ORIGINATE))
9036 {
9037 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 +00009038 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9039 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009040
9041 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9042 VTY_NEWLINE, VTY_NEWLINE);
9043 header1 = 0;
9044 }
9045
9046 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9047 if (in)
9048 {
9049 for (ain = rn->adj_in; ain; ain = ain->next)
9050 if (ain->peer == peer)
9051 {
9052 if (header1)
9053 {
9054 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 +00009055 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9056 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009057 header1 = 0;
9058 }
9059 if (header2)
9060 {
9061 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9062 header2 = 0;
9063 }
9064 if (ain->attr)
9065 {
9066 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9067 output_count++;
9068 }
9069 }
9070 }
9071 else
9072 {
9073 for (adj = rn->adj_out; adj; adj = adj->next)
9074 if (adj->peer == peer)
9075 {
9076 if (header1)
9077 {
9078 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 +00009079 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9080 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009081 header1 = 0;
9082 }
9083 if (header2)
9084 {
9085 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9086 header2 = 0;
9087 }
9088 if (adj->attr)
9089 {
9090 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9091 output_count++;
9092 }
9093 }
9094 }
9095
9096 if (output_count != 0)
9097 vty_out (vty, "%sTotal number of prefixes %ld%s",
9098 VTY_NEWLINE, output_count, VTY_NEWLINE);
9099}
9100
paul94f2b392005-06-28 12:44:16 +00009101static int
paulbb46e942003-10-24 19:02:03 +00009102peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9103{
paul718e3742002-12-13 20:15:29 +00009104 if (! peer || ! peer->afc[afi][safi])
9105 {
9106 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9107 return CMD_WARNING;
9108 }
9109
9110 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9111 {
9112 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9113 VTY_NEWLINE);
9114 return CMD_WARNING;
9115 }
9116
9117 show_adj_route (vty, peer, afi, safi, in);
9118
9119 return CMD_SUCCESS;
9120}
9121
9122DEFUN (show_ip_bgp_neighbor_advertised_route,
9123 show_ip_bgp_neighbor_advertised_route_cmd,
9124 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9125 SHOW_STR
9126 IP_STR
9127 BGP_STR
9128 "Detailed information on TCP and BGP neighbor connections\n"
9129 "Neighbor to display information about\n"
9130 "Neighbor to display information about\n"
9131 "Display the routes advertised to a BGP neighbor\n")
9132{
paulbb46e942003-10-24 19:02:03 +00009133 struct peer *peer;
9134
9135 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9136 if (! peer)
9137 return CMD_WARNING;
9138
9139 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009140}
9141
9142DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9143 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9144 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9145 SHOW_STR
9146 IP_STR
9147 BGP_STR
9148 "Address family\n"
9149 "Address Family modifier\n"
9150 "Address Family modifier\n"
9151 "Detailed information on TCP and BGP neighbor connections\n"
9152 "Neighbor to display information about\n"
9153 "Neighbor to display information about\n"
9154 "Display the routes advertised to a BGP neighbor\n")
9155{
paulbb46e942003-10-24 19:02:03 +00009156 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009157
paulbb46e942003-10-24 19:02:03 +00009158 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9159 if (! peer)
9160 return CMD_WARNING;
9161
9162 if (strncmp (argv[0], "m", 1) == 0)
9163 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9164
9165 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009166}
9167
9168#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009169DEFUN (show_bgp_view_neighbor_advertised_route,
9170 show_bgp_view_neighbor_advertised_route_cmd,
9171 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9172 SHOW_STR
9173 BGP_STR
9174 "BGP view\n"
9175 "View name\n"
9176 "Detailed information on TCP and BGP neighbor connections\n"
9177 "Neighbor to display information about\n"
9178 "Neighbor to display information about\n"
9179 "Display the routes advertised to a BGP neighbor\n")
9180{
9181 struct peer *peer;
9182
9183 if (argc == 2)
9184 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9185 else
9186 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9187
9188 if (! peer)
9189 return CMD_WARNING;
9190
9191 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9192}
9193
9194ALIAS (show_bgp_view_neighbor_advertised_route,
9195 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9196 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9197 SHOW_STR
9198 BGP_STR
9199 "BGP view\n"
9200 "View name\n"
9201 "Address family\n"
9202 "Detailed information on TCP and BGP neighbor connections\n"
9203 "Neighbor to display information about\n"
9204 "Neighbor to display information about\n"
9205 "Display the routes advertised to a BGP neighbor\n")
9206
9207DEFUN (show_bgp_view_neighbor_received_routes,
9208 show_bgp_view_neighbor_received_routes_cmd,
9209 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9210 SHOW_STR
9211 BGP_STR
9212 "BGP view\n"
9213 "View name\n"
9214 "Detailed information on TCP and BGP neighbor connections\n"
9215 "Neighbor to display information about\n"
9216 "Neighbor to display information about\n"
9217 "Display the received routes from neighbor\n")
9218{
9219 struct peer *peer;
9220
9221 if (argc == 2)
9222 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9223 else
9224 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9225
9226 if (! peer)
9227 return CMD_WARNING;
9228
9229 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9230}
9231
9232ALIAS (show_bgp_view_neighbor_received_routes,
9233 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9234 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9235 SHOW_STR
9236 BGP_STR
9237 "BGP view\n"
9238 "View name\n"
9239 "Address family\n"
9240 "Detailed information on TCP and BGP neighbor connections\n"
9241 "Neighbor to display information about\n"
9242 "Neighbor to display information about\n"
9243 "Display the received routes from neighbor\n")
9244
9245ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009246 show_bgp_neighbor_advertised_route_cmd,
9247 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9248 SHOW_STR
9249 BGP_STR
9250 "Detailed information on TCP and BGP neighbor connections\n"
9251 "Neighbor to display information about\n"
9252 "Neighbor to display information about\n"
9253 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009254
9255ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009256 show_bgp_ipv6_neighbor_advertised_route_cmd,
9257 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9258 SHOW_STR
9259 BGP_STR
9260 "Address family\n"
9261 "Detailed information on TCP and BGP neighbor connections\n"
9262 "Neighbor to display information about\n"
9263 "Neighbor to display information about\n"
9264 "Display the routes advertised to a BGP neighbor\n")
9265
9266/* old command */
paulbb46e942003-10-24 19:02:03 +00009267ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009268 ipv6_bgp_neighbor_advertised_route_cmd,
9269 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9270 SHOW_STR
9271 IPV6_STR
9272 BGP_STR
9273 "Detailed information on TCP and BGP neighbor connections\n"
9274 "Neighbor to display information about\n"
9275 "Neighbor to display information about\n"
9276 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009277
paul718e3742002-12-13 20:15:29 +00009278/* old command */
9279DEFUN (ipv6_mbgp_neighbor_advertised_route,
9280 ipv6_mbgp_neighbor_advertised_route_cmd,
9281 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9282 SHOW_STR
9283 IPV6_STR
9284 MBGP_STR
9285 "Detailed information on TCP and BGP neighbor connections\n"
9286 "Neighbor to display information about\n"
9287 "Neighbor to display information about\n"
9288 "Display the routes advertised to a BGP neighbor\n")
9289{
paulbb46e942003-10-24 19:02:03 +00009290 struct peer *peer;
9291
9292 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9293 if (! peer)
9294 return CMD_WARNING;
9295
9296 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009297}
9298#endif /* HAVE_IPV6 */
9299
9300DEFUN (show_ip_bgp_neighbor_received_routes,
9301 show_ip_bgp_neighbor_received_routes_cmd,
9302 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9303 SHOW_STR
9304 IP_STR
9305 BGP_STR
9306 "Detailed information on TCP and BGP neighbor connections\n"
9307 "Neighbor to display information about\n"
9308 "Neighbor to display information about\n"
9309 "Display the received routes from neighbor\n")
9310{
paulbb46e942003-10-24 19:02:03 +00009311 struct peer *peer;
9312
9313 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9314 if (! peer)
9315 return CMD_WARNING;
9316
9317 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009318}
9319
9320DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9321 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9322 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9323 SHOW_STR
9324 IP_STR
9325 BGP_STR
9326 "Address family\n"
9327 "Address Family modifier\n"
9328 "Address Family modifier\n"
9329 "Detailed information on TCP and BGP neighbor connections\n"
9330 "Neighbor to display information about\n"
9331 "Neighbor to display information about\n"
9332 "Display the received routes from neighbor\n")
9333{
paulbb46e942003-10-24 19:02:03 +00009334 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009335
paulbb46e942003-10-24 19:02:03 +00009336 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9337 if (! peer)
9338 return CMD_WARNING;
9339
9340 if (strncmp (argv[0], "m", 1) == 0)
9341 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9342
9343 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009344}
9345
9346DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9347 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9348 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9349 SHOW_STR
9350 IP_STR
9351 BGP_STR
9352 "Detailed information on TCP and BGP neighbor connections\n"
9353 "Neighbor to display information about\n"
9354 "Neighbor to display information about\n"
9355 "Display information received from a BGP neighbor\n"
9356 "Display the prefixlist filter\n")
9357{
9358 char name[BUFSIZ];
9359 union sockunion *su;
9360 struct peer *peer;
9361 int count;
9362
9363 su = sockunion_str2su (argv[0]);
9364 if (su == NULL)
9365 return CMD_WARNING;
9366
9367 peer = peer_lookup (NULL, su);
9368 if (! peer)
9369 return CMD_WARNING;
9370
9371 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9372 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9373 if (count)
9374 {
9375 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9376 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9377 }
9378
9379 return CMD_SUCCESS;
9380}
9381
9382DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9383 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9384 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9385 SHOW_STR
9386 IP_STR
9387 BGP_STR
9388 "Address family\n"
9389 "Address Family modifier\n"
9390 "Address Family modifier\n"
9391 "Detailed information on TCP and BGP neighbor connections\n"
9392 "Neighbor to display information about\n"
9393 "Neighbor to display information about\n"
9394 "Display information received from a BGP neighbor\n"
9395 "Display the prefixlist filter\n")
9396{
9397 char name[BUFSIZ];
9398 union sockunion *su;
9399 struct peer *peer;
9400 int count;
9401
9402 su = sockunion_str2su (argv[1]);
9403 if (su == NULL)
9404 return CMD_WARNING;
9405
9406 peer = peer_lookup (NULL, su);
9407 if (! peer)
9408 return CMD_WARNING;
9409
9410 if (strncmp (argv[0], "m", 1) == 0)
9411 {
9412 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9413 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9414 if (count)
9415 {
9416 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9417 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9418 }
9419 }
9420 else
9421 {
9422 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9423 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9424 if (count)
9425 {
9426 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9427 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9428 }
9429 }
9430
9431 return CMD_SUCCESS;
9432}
9433
9434
9435#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009436ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009437 show_bgp_neighbor_received_routes_cmd,
9438 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9439 SHOW_STR
9440 BGP_STR
9441 "Detailed information on TCP and BGP neighbor connections\n"
9442 "Neighbor to display information about\n"
9443 "Neighbor to display information about\n"
9444 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009445
paulbb46e942003-10-24 19:02:03 +00009446ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009447 show_bgp_ipv6_neighbor_received_routes_cmd,
9448 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9449 SHOW_STR
9450 BGP_STR
9451 "Address family\n"
9452 "Detailed information on TCP and BGP neighbor connections\n"
9453 "Neighbor to display information about\n"
9454 "Neighbor to display information about\n"
9455 "Display the received routes from neighbor\n")
9456
9457DEFUN (show_bgp_neighbor_received_prefix_filter,
9458 show_bgp_neighbor_received_prefix_filter_cmd,
9459 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9460 SHOW_STR
9461 BGP_STR
9462 "Detailed information on TCP and BGP neighbor connections\n"
9463 "Neighbor to display information about\n"
9464 "Neighbor to display information about\n"
9465 "Display information received from a BGP neighbor\n"
9466 "Display the prefixlist filter\n")
9467{
9468 char name[BUFSIZ];
9469 union sockunion *su;
9470 struct peer *peer;
9471 int count;
9472
9473 su = sockunion_str2su (argv[0]);
9474 if (su == NULL)
9475 return CMD_WARNING;
9476
9477 peer = peer_lookup (NULL, su);
9478 if (! peer)
9479 return CMD_WARNING;
9480
9481 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9482 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9483 if (count)
9484 {
9485 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
9486 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
9487 }
9488
9489 return CMD_SUCCESS;
9490}
9491
9492ALIAS (show_bgp_neighbor_received_prefix_filter,
9493 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
9494 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9495 SHOW_STR
9496 BGP_STR
9497 "Address family\n"
9498 "Detailed information on TCP and BGP neighbor connections\n"
9499 "Neighbor to display information about\n"
9500 "Neighbor to display information about\n"
9501 "Display information received from a BGP neighbor\n"
9502 "Display the prefixlist filter\n")
9503
9504/* old command */
paulbb46e942003-10-24 19:02:03 +00009505ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009506 ipv6_bgp_neighbor_received_routes_cmd,
9507 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9508 SHOW_STR
9509 IPV6_STR
9510 BGP_STR
9511 "Detailed information on TCP and BGP neighbor connections\n"
9512 "Neighbor to display information about\n"
9513 "Neighbor to display information about\n"
9514 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009515
9516/* old command */
9517DEFUN (ipv6_mbgp_neighbor_received_routes,
9518 ipv6_mbgp_neighbor_received_routes_cmd,
9519 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9520 SHOW_STR
9521 IPV6_STR
9522 MBGP_STR
9523 "Detailed information on TCP and BGP neighbor connections\n"
9524 "Neighbor to display information about\n"
9525 "Neighbor to display information about\n"
9526 "Display the received routes from neighbor\n")
9527{
paulbb46e942003-10-24 19:02:03 +00009528 struct peer *peer;
9529
9530 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9531 if (! peer)
9532 return CMD_WARNING;
9533
9534 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00009535}
paulbb46e942003-10-24 19:02:03 +00009536
9537DEFUN (show_bgp_view_neighbor_received_prefix_filter,
9538 show_bgp_view_neighbor_received_prefix_filter_cmd,
9539 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9540 SHOW_STR
9541 BGP_STR
9542 "BGP view\n"
9543 "View name\n"
9544 "Detailed information on TCP and BGP neighbor connections\n"
9545 "Neighbor to display information about\n"
9546 "Neighbor to display information about\n"
9547 "Display information received from a BGP neighbor\n"
9548 "Display the prefixlist filter\n")
9549{
9550 char name[BUFSIZ];
9551 union sockunion *su;
9552 struct peer *peer;
9553 struct bgp *bgp;
9554 int count;
9555
9556 /* BGP structure lookup. */
9557 bgp = bgp_lookup_by_name (argv[0]);
9558 if (bgp == NULL)
9559 {
9560 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9561 return CMD_WARNING;
9562 }
9563
9564 su = sockunion_str2su (argv[1]);
9565 if (su == NULL)
9566 return CMD_WARNING;
9567
9568 peer = peer_lookup (bgp, su);
9569 if (! peer)
9570 return CMD_WARNING;
9571
9572 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9573 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9574 if (count)
9575 {
9576 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
9577 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
9578 }
9579
9580 return CMD_SUCCESS;
9581}
9582
9583ALIAS (show_bgp_view_neighbor_received_prefix_filter,
9584 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
9585 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9586 SHOW_STR
9587 BGP_STR
9588 "BGP view\n"
9589 "View name\n"
9590 "Address family\n"
9591 "Detailed information on TCP and BGP neighbor connections\n"
9592 "Neighbor to display information about\n"
9593 "Neighbor to display information about\n"
9594 "Display information received from a BGP neighbor\n"
9595 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00009596#endif /* HAVE_IPV6 */
9597
paul94f2b392005-06-28 12:44:16 +00009598static int
paulbb46e942003-10-24 19:02:03 +00009599bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009600 safi_t safi, enum bgp_show_type type)
9601{
paul718e3742002-12-13 20:15:29 +00009602 if (! peer || ! peer->afc[afi][safi])
9603 {
9604 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009605 return CMD_WARNING;
9606 }
9607
ajs5a646652004-11-05 01:25:55 +00009608 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +00009609}
9610
9611DEFUN (show_ip_bgp_neighbor_routes,
9612 show_ip_bgp_neighbor_routes_cmd,
9613 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
9614 SHOW_STR
9615 IP_STR
9616 BGP_STR
9617 "Detailed information on TCP and BGP neighbor connections\n"
9618 "Neighbor to display information about\n"
9619 "Neighbor to display information about\n"
9620 "Display routes learned from neighbor\n")
9621{
paulbb46e942003-10-24 19:02:03 +00009622 struct peer *peer;
9623
9624 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9625 if (! peer)
9626 return CMD_WARNING;
9627
9628 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009629 bgp_show_type_neighbor);
9630}
9631
9632DEFUN (show_ip_bgp_neighbor_flap,
9633 show_ip_bgp_neighbor_flap_cmd,
9634 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9635 SHOW_STR
9636 IP_STR
9637 BGP_STR
9638 "Detailed information on TCP and BGP neighbor connections\n"
9639 "Neighbor to display information about\n"
9640 "Neighbor to display information about\n"
9641 "Display flap statistics of the routes learned from neighbor\n")
9642{
paulbb46e942003-10-24 19:02:03 +00009643 struct peer *peer;
9644
9645 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9646 if (! peer)
9647 return CMD_WARNING;
9648
9649 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009650 bgp_show_type_flap_neighbor);
9651}
9652
9653DEFUN (show_ip_bgp_neighbor_damp,
9654 show_ip_bgp_neighbor_damp_cmd,
9655 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
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 the dampened routes received from neighbor\n")
9663{
paulbb46e942003-10-24 19:02:03 +00009664 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_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009671 bgp_show_type_damp_neighbor);
9672}
9673
9674DEFUN (show_ip_bgp_ipv4_neighbor_routes,
9675 show_ip_bgp_ipv4_neighbor_routes_cmd,
9676 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
9677 SHOW_STR
9678 IP_STR
9679 BGP_STR
9680 "Address family\n"
9681 "Address Family modifier\n"
9682 "Address Family modifier\n"
9683 "Detailed information on TCP and BGP neighbor connections\n"
9684 "Neighbor to display information about\n"
9685 "Neighbor to display information about\n"
9686 "Display routes learned from neighbor\n")
9687{
paulbb46e942003-10-24 19:02:03 +00009688 struct peer *peer;
9689
9690 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9691 if (! peer)
9692 return CMD_WARNING;
9693
paul718e3742002-12-13 20:15:29 +00009694 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00009695 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009696 bgp_show_type_neighbor);
9697
paulbb46e942003-10-24 19:02:03 +00009698 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009699 bgp_show_type_neighbor);
9700}
paulbb46e942003-10-24 19:02:03 +00009701
paulfee0f4c2004-09-13 05:12:46 +00009702DEFUN (show_ip_bgp_view_rsclient,
9703 show_ip_bgp_view_rsclient_cmd,
9704 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9705 SHOW_STR
9706 IP_STR
9707 BGP_STR
9708 "BGP view\n"
9709 "BGP view name\n"
9710 "Information about Route Server Client\n"
9711 NEIGHBOR_ADDR_STR)
9712{
9713 struct bgp_table *table;
9714 struct peer *peer;
9715
9716 if (argc == 2)
9717 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9718 else
9719 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9720
9721 if (! peer)
9722 return CMD_WARNING;
9723
9724 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9725 {
9726 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9727 VTY_NEWLINE);
9728 return CMD_WARNING;
9729 }
9730
9731 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9732 PEER_FLAG_RSERVER_CLIENT))
9733 {
9734 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9735 VTY_NEWLINE);
9736 return CMD_WARNING;
9737 }
9738
9739 table = peer->rib[AFI_IP][SAFI_UNICAST];
9740
ajs5a646652004-11-05 01:25:55 +00009741 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009742}
9743
9744ALIAS (show_ip_bgp_view_rsclient,
9745 show_ip_bgp_rsclient_cmd,
9746 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
9747 SHOW_STR
9748 IP_STR
9749 BGP_STR
9750 "Information about Route Server Client\n"
9751 NEIGHBOR_ADDR_STR)
9752
9753DEFUN (show_ip_bgp_view_rsclient_route,
9754 show_ip_bgp_view_rsclient_route_cmd,
9755 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9756 SHOW_STR
9757 IP_STR
9758 BGP_STR
9759 "BGP view\n"
9760 "BGP view name\n"
9761 "Information about Route Server Client\n"
9762 NEIGHBOR_ADDR_STR
9763 "Network in the BGP routing table to display\n")
9764{
9765 struct bgp *bgp;
9766 struct peer *peer;
9767
9768 /* BGP structure lookup. */
9769 if (argc == 3)
9770 {
9771 bgp = bgp_lookup_by_name (argv[0]);
9772 if (bgp == NULL)
9773 {
9774 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9775 return CMD_WARNING;
9776 }
9777 }
9778 else
9779 {
9780 bgp = bgp_get_default ();
9781 if (bgp == NULL)
9782 {
9783 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9784 return CMD_WARNING;
9785 }
9786 }
9787
9788 if (argc == 3)
9789 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9790 else
9791 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9792
9793 if (! peer)
9794 return CMD_WARNING;
9795
9796 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9797 {
9798 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9799 VTY_NEWLINE);
9800 return CMD_WARNING;
9801}
9802
9803 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9804 PEER_FLAG_RSERVER_CLIENT))
9805 {
9806 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9807 VTY_NEWLINE);
9808 return CMD_WARNING;
9809 }
9810
9811 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9812 (argc == 3) ? argv[2] : argv[1],
9813 AFI_IP, SAFI_UNICAST, NULL, 0);
9814}
9815
9816ALIAS (show_ip_bgp_view_rsclient_route,
9817 show_ip_bgp_rsclient_route_cmd,
9818 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9819 SHOW_STR
9820 IP_STR
9821 BGP_STR
9822 "Information about Route Server Client\n"
9823 NEIGHBOR_ADDR_STR
9824 "Network in the BGP routing table to display\n")
9825
9826DEFUN (show_ip_bgp_view_rsclient_prefix,
9827 show_ip_bgp_view_rsclient_prefix_cmd,
9828 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9829 SHOW_STR
9830 IP_STR
9831 BGP_STR
9832 "BGP view\n"
9833 "BGP view name\n"
9834 "Information about Route Server Client\n"
9835 NEIGHBOR_ADDR_STR
9836 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9837{
9838 struct bgp *bgp;
9839 struct peer *peer;
9840
9841 /* BGP structure lookup. */
9842 if (argc == 3)
9843 {
9844 bgp = bgp_lookup_by_name (argv[0]);
9845 if (bgp == NULL)
9846 {
9847 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9848 return CMD_WARNING;
9849 }
9850 }
9851 else
9852 {
9853 bgp = bgp_get_default ();
9854 if (bgp == NULL)
9855 {
9856 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9857 return CMD_WARNING;
9858 }
9859 }
9860
9861 if (argc == 3)
9862 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9863 else
9864 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9865
9866 if (! peer)
9867 return CMD_WARNING;
9868
9869 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9870 {
9871 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9872 VTY_NEWLINE);
9873 return CMD_WARNING;
9874}
9875
9876 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9877 PEER_FLAG_RSERVER_CLIENT))
9878{
9879 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9880 VTY_NEWLINE);
9881 return CMD_WARNING;
9882 }
9883
9884 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9885 (argc == 3) ? argv[2] : argv[1],
9886 AFI_IP, SAFI_UNICAST, NULL, 1);
9887}
9888
9889ALIAS (show_ip_bgp_view_rsclient_prefix,
9890 show_ip_bgp_rsclient_prefix_cmd,
9891 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9892 SHOW_STR
9893 IP_STR
9894 BGP_STR
9895 "Information about Route Server Client\n"
9896 NEIGHBOR_ADDR_STR
9897 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9898
9899
paul718e3742002-12-13 20:15:29 +00009900#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009901DEFUN (show_bgp_view_neighbor_routes,
9902 show_bgp_view_neighbor_routes_cmd,
9903 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
9904 SHOW_STR
9905 BGP_STR
9906 "BGP view\n"
9907 "BGP view name\n"
9908 "Detailed information on TCP and BGP neighbor connections\n"
9909 "Neighbor to display information about\n"
9910 "Neighbor to display information about\n"
9911 "Display routes learned from neighbor\n")
9912{
9913 struct peer *peer;
9914
9915 if (argc == 2)
9916 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9917 else
9918 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9919
9920 if (! peer)
9921 return CMD_WARNING;
9922
9923 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9924 bgp_show_type_neighbor);
9925}
9926
9927ALIAS (show_bgp_view_neighbor_routes,
9928 show_bgp_view_ipv6_neighbor_routes_cmd,
9929 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9930 SHOW_STR
9931 BGP_STR
9932 "BGP view\n"
9933 "BGP view name\n"
9934 "Address family\n"
9935 "Detailed information on TCP and BGP neighbor connections\n"
9936 "Neighbor to display information about\n"
9937 "Neighbor to display information about\n"
9938 "Display routes learned from neighbor\n")
9939
9940DEFUN (show_bgp_view_neighbor_damp,
9941 show_bgp_view_neighbor_damp_cmd,
9942 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9943 SHOW_STR
9944 BGP_STR
9945 "BGP view\n"
9946 "BGP view name\n"
9947 "Detailed information on TCP and BGP neighbor connections\n"
9948 "Neighbor to display information about\n"
9949 "Neighbor to display information about\n"
9950 "Display the dampened routes received from neighbor\n")
9951{
9952 struct peer *peer;
9953
9954 if (argc == 2)
9955 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9956 else
9957 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9958
9959 if (! peer)
9960 return CMD_WARNING;
9961
9962 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9963 bgp_show_type_damp_neighbor);
9964}
9965
9966ALIAS (show_bgp_view_neighbor_damp,
9967 show_bgp_view_ipv6_neighbor_damp_cmd,
9968 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9969 SHOW_STR
9970 BGP_STR
9971 "BGP view\n"
9972 "BGP view name\n"
9973 "Address family\n"
9974 "Detailed information on TCP and BGP neighbor connections\n"
9975 "Neighbor to display information about\n"
9976 "Neighbor to display information about\n"
9977 "Display the dampened routes received from neighbor\n")
9978
9979DEFUN (show_bgp_view_neighbor_flap,
9980 show_bgp_view_neighbor_flap_cmd,
9981 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9982 SHOW_STR
9983 BGP_STR
9984 "BGP view\n"
9985 "BGP view name\n"
9986 "Detailed information on TCP and BGP neighbor connections\n"
9987 "Neighbor to display information about\n"
9988 "Neighbor to display information about\n"
9989 "Display flap statistics of the routes learned from neighbor\n")
9990{
9991 struct peer *peer;
9992
9993 if (argc == 2)
9994 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9995 else
9996 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9997
9998 if (! peer)
9999 return CMD_WARNING;
10000
10001 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10002 bgp_show_type_flap_neighbor);
10003}
10004
10005ALIAS (show_bgp_view_neighbor_flap,
10006 show_bgp_view_ipv6_neighbor_flap_cmd,
10007 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10008 SHOW_STR
10009 BGP_STR
10010 "BGP view\n"
10011 "BGP view name\n"
10012 "Address family\n"
10013 "Detailed information on TCP and BGP neighbor connections\n"
10014 "Neighbor to display information about\n"
10015 "Neighbor to display information about\n"
10016 "Display flap statistics of the routes learned from neighbor\n")
10017
10018ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010019 show_bgp_neighbor_routes_cmd,
10020 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10021 SHOW_STR
10022 BGP_STR
10023 "Detailed information on TCP and BGP neighbor connections\n"
10024 "Neighbor to display information about\n"
10025 "Neighbor to display information about\n"
10026 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010027
paulbb46e942003-10-24 19:02:03 +000010028
10029ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010030 show_bgp_ipv6_neighbor_routes_cmd,
10031 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10032 SHOW_STR
10033 BGP_STR
10034 "Address family\n"
10035 "Detailed information on TCP and BGP neighbor connections\n"
10036 "Neighbor to display information about\n"
10037 "Neighbor to display information about\n"
10038 "Display routes learned from neighbor\n")
10039
10040/* old command */
paulbb46e942003-10-24 19:02:03 +000010041ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010042 ipv6_bgp_neighbor_routes_cmd,
10043 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10044 SHOW_STR
10045 IPV6_STR
10046 BGP_STR
10047 "Detailed information on TCP and BGP neighbor connections\n"
10048 "Neighbor to display information about\n"
10049 "Neighbor to display information about\n"
10050 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010051
10052/* old command */
10053DEFUN (ipv6_mbgp_neighbor_routes,
10054 ipv6_mbgp_neighbor_routes_cmd,
10055 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10056 SHOW_STR
10057 IPV6_STR
10058 MBGP_STR
10059 "Detailed information on TCP and BGP neighbor connections\n"
10060 "Neighbor to display information about\n"
10061 "Neighbor to display information about\n"
10062 "Display routes learned from neighbor\n")
10063{
paulbb46e942003-10-24 19:02:03 +000010064 struct peer *peer;
10065
10066 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10067 if (! peer)
10068 return CMD_WARNING;
10069
10070 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010071 bgp_show_type_neighbor);
10072}
paulbb46e942003-10-24 19:02:03 +000010073
10074ALIAS (show_bgp_view_neighbor_flap,
10075 show_bgp_neighbor_flap_cmd,
10076 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10077 SHOW_STR
10078 BGP_STR
10079 "Detailed information on TCP and BGP neighbor connections\n"
10080 "Neighbor to display information about\n"
10081 "Neighbor to display information about\n"
10082 "Display flap statistics of the routes learned from neighbor\n")
10083
10084ALIAS (show_bgp_view_neighbor_flap,
10085 show_bgp_ipv6_neighbor_flap_cmd,
10086 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10087 SHOW_STR
10088 BGP_STR
10089 "Address family\n"
10090 "Detailed information on TCP and BGP neighbor connections\n"
10091 "Neighbor to display information about\n"
10092 "Neighbor to display information about\n"
10093 "Display flap statistics of the routes learned from neighbor\n")
10094
10095ALIAS (show_bgp_view_neighbor_damp,
10096 show_bgp_neighbor_damp_cmd,
10097 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10098 SHOW_STR
10099 BGP_STR
10100 "Detailed information on TCP and BGP neighbor connections\n"
10101 "Neighbor to display information about\n"
10102 "Neighbor to display information about\n"
10103 "Display the dampened routes received from neighbor\n")
10104
10105ALIAS (show_bgp_view_neighbor_damp,
10106 show_bgp_ipv6_neighbor_damp_cmd,
10107 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10108 SHOW_STR
10109 BGP_STR
10110 "Address family\n"
10111 "Detailed information on TCP and BGP neighbor connections\n"
10112 "Neighbor to display information about\n"
10113 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010114 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010115
10116DEFUN (show_bgp_view_rsclient,
10117 show_bgp_view_rsclient_cmd,
10118 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10119 SHOW_STR
10120 BGP_STR
10121 "BGP view\n"
10122 "BGP view name\n"
10123 "Information about Route Server Client\n"
10124 NEIGHBOR_ADDR_STR)
10125{
10126 struct bgp_table *table;
10127 struct peer *peer;
10128
10129 if (argc == 2)
10130 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10131 else
10132 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10133
10134 if (! peer)
10135 return CMD_WARNING;
10136
10137 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10138 {
10139 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10140 VTY_NEWLINE);
10141 return CMD_WARNING;
10142 }
10143
10144 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10145 PEER_FLAG_RSERVER_CLIENT))
10146 {
10147 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10148 VTY_NEWLINE);
10149 return CMD_WARNING;
10150 }
10151
10152 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10153
ajs5a646652004-11-05 01:25:55 +000010154 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010155}
10156
10157ALIAS (show_bgp_view_rsclient,
10158 show_bgp_rsclient_cmd,
10159 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10160 SHOW_STR
10161 BGP_STR
10162 "Information about Route Server Client\n"
10163 NEIGHBOR_ADDR_STR)
10164
10165DEFUN (show_bgp_view_rsclient_route,
10166 show_bgp_view_rsclient_route_cmd,
10167 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10168 SHOW_STR
10169 BGP_STR
10170 "BGP view\n"
10171 "BGP view name\n"
10172 "Information about Route Server Client\n"
10173 NEIGHBOR_ADDR_STR
10174 "Network in the BGP routing table to display\n")
10175{
10176 struct bgp *bgp;
10177 struct peer *peer;
10178
10179 /* BGP structure lookup. */
10180 if (argc == 3)
10181 {
10182 bgp = bgp_lookup_by_name (argv[0]);
10183 if (bgp == NULL)
10184 {
10185 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10186 return CMD_WARNING;
10187 }
10188 }
10189 else
10190 {
10191 bgp = bgp_get_default ();
10192 if (bgp == NULL)
10193 {
10194 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10195 return CMD_WARNING;
10196 }
10197 }
10198
10199 if (argc == 3)
10200 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10201 else
10202 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10203
10204 if (! peer)
10205 return CMD_WARNING;
10206
10207 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10208 {
10209 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10210 VTY_NEWLINE);
10211 return CMD_WARNING;
10212 }
10213
10214 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10215 PEER_FLAG_RSERVER_CLIENT))
10216 {
10217 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10218 VTY_NEWLINE);
10219 return CMD_WARNING;
10220 }
10221
10222 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10223 (argc == 3) ? argv[2] : argv[1],
10224 AFI_IP6, SAFI_UNICAST, NULL, 0);
10225}
10226
10227ALIAS (show_bgp_view_rsclient_route,
10228 show_bgp_rsclient_route_cmd,
10229 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10230 SHOW_STR
10231 BGP_STR
10232 "Information about Route Server Client\n"
10233 NEIGHBOR_ADDR_STR
10234 "Network in the BGP routing table to display\n")
10235
10236DEFUN (show_bgp_view_rsclient_prefix,
10237 show_bgp_view_rsclient_prefix_cmd,
10238 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10239 SHOW_STR
10240 BGP_STR
10241 "BGP view\n"
10242 "BGP view name\n"
10243 "Information about Route Server Client\n"
10244 NEIGHBOR_ADDR_STR
10245 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10246{
10247 struct bgp *bgp;
10248 struct peer *peer;
10249
10250 /* BGP structure lookup. */
10251 if (argc == 3)
10252 {
10253 bgp = bgp_lookup_by_name (argv[0]);
10254 if (bgp == NULL)
10255 {
10256 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10257 return CMD_WARNING;
10258 }
10259 }
10260 else
10261 {
10262 bgp = bgp_get_default ();
10263 if (bgp == NULL)
10264 {
10265 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10266 return CMD_WARNING;
10267 }
10268 }
10269
10270 if (argc == 3)
10271 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10272 else
10273 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10274
10275 if (! peer)
10276 return CMD_WARNING;
10277
10278 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10279 {
10280 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10281 VTY_NEWLINE);
10282 return CMD_WARNING;
10283 }
10284
10285 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10286 PEER_FLAG_RSERVER_CLIENT))
10287 {
10288 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10289 VTY_NEWLINE);
10290 return CMD_WARNING;
10291 }
10292
10293 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10294 (argc == 3) ? argv[2] : argv[1],
10295 AFI_IP6, SAFI_UNICAST, NULL, 1);
10296}
10297
10298ALIAS (show_bgp_view_rsclient_prefix,
10299 show_bgp_rsclient_prefix_cmd,
10300 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10301 SHOW_STR
10302 BGP_STR
10303 "Information about Route Server Client\n"
10304 NEIGHBOR_ADDR_STR
10305 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10306
paul718e3742002-12-13 20:15:29 +000010307#endif /* HAVE_IPV6 */
10308
10309struct bgp_table *bgp_distance_table;
10310
10311struct bgp_distance
10312{
10313 /* Distance value for the IP source prefix. */
10314 u_char distance;
10315
10316 /* Name of the access-list to be matched. */
10317 char *access_list;
10318};
10319
paul94f2b392005-06-28 12:44:16 +000010320static struct bgp_distance *
paul718e3742002-12-13 20:15:29 +000010321bgp_distance_new ()
10322{
10323 struct bgp_distance *new;
10324 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
10325 memset (new, 0, sizeof (struct bgp_distance));
10326 return new;
10327}
10328
paul94f2b392005-06-28 12:44:16 +000010329static void
paul718e3742002-12-13 20:15:29 +000010330bgp_distance_free (struct bgp_distance *bdistance)
10331{
10332 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10333}
10334
paul94f2b392005-06-28 12:44:16 +000010335static int
paulfd79ac92004-10-13 05:06:08 +000010336bgp_distance_set (struct vty *vty, const char *distance_str,
10337 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010338{
10339 int ret;
10340 struct prefix_ipv4 p;
10341 u_char distance;
10342 struct bgp_node *rn;
10343 struct bgp_distance *bdistance;
10344
10345 ret = str2prefix_ipv4 (ip_str, &p);
10346 if (ret == 0)
10347 {
10348 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10349 return CMD_WARNING;
10350 }
10351
10352 distance = atoi (distance_str);
10353
10354 /* Get BGP distance node. */
10355 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10356 if (rn->info)
10357 {
10358 bdistance = rn->info;
10359 bgp_unlock_node (rn);
10360 }
10361 else
10362 {
10363 bdistance = bgp_distance_new ();
10364 rn->info = bdistance;
10365 }
10366
10367 /* Set distance value. */
10368 bdistance->distance = distance;
10369
10370 /* Reset access-list configuration. */
10371 if (bdistance->access_list)
10372 {
10373 free (bdistance->access_list);
10374 bdistance->access_list = NULL;
10375 }
10376 if (access_list_str)
10377 bdistance->access_list = strdup (access_list_str);
10378
10379 return CMD_SUCCESS;
10380}
10381
paul94f2b392005-06-28 12:44:16 +000010382static int
paulfd79ac92004-10-13 05:06:08 +000010383bgp_distance_unset (struct vty *vty, const char *distance_str,
10384 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010385{
10386 int ret;
10387 struct prefix_ipv4 p;
10388 u_char distance;
10389 struct bgp_node *rn;
10390 struct bgp_distance *bdistance;
10391
10392 ret = str2prefix_ipv4 (ip_str, &p);
10393 if (ret == 0)
10394 {
10395 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10396 return CMD_WARNING;
10397 }
10398
10399 distance = atoi (distance_str);
10400
10401 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10402 if (! rn)
10403 {
10404 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10405 return CMD_WARNING;
10406 }
10407
10408 bdistance = rn->info;
10409
10410 if (bdistance->access_list)
10411 free (bdistance->access_list);
10412 bgp_distance_free (bdistance);
10413
10414 rn->info = NULL;
10415 bgp_unlock_node (rn);
10416 bgp_unlock_node (rn);
10417
10418 return CMD_SUCCESS;
10419}
10420
paul94f2b392005-06-28 12:44:16 +000010421static void
paul718e3742002-12-13 20:15:29 +000010422bgp_distance_reset ()
10423{
10424 struct bgp_node *rn;
10425 struct bgp_distance *bdistance;
10426
10427 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10428 if ((bdistance = rn->info) != NULL)
10429 {
10430 if (bdistance->access_list)
10431 free (bdistance->access_list);
10432 bgp_distance_free (bdistance);
10433 rn->info = NULL;
10434 bgp_unlock_node (rn);
10435 }
10436}
10437
10438/* Apply BGP information to distance method. */
10439u_char
10440bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10441{
10442 struct bgp_node *rn;
10443 struct prefix_ipv4 q;
10444 struct peer *peer;
10445 struct bgp_distance *bdistance;
10446 struct access_list *alist;
10447 struct bgp_static *bgp_static;
10448
10449 if (! bgp)
10450 return 0;
10451
10452 if (p->family != AF_INET)
10453 return 0;
10454
10455 peer = rinfo->peer;
10456
10457 if (peer->su.sa.sa_family != AF_INET)
10458 return 0;
10459
10460 memset (&q, 0, sizeof (struct prefix_ipv4));
10461 q.family = AF_INET;
10462 q.prefix = peer->su.sin.sin_addr;
10463 q.prefixlen = IPV4_MAX_BITLEN;
10464
10465 /* Check source address. */
10466 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
10467 if (rn)
10468 {
10469 bdistance = rn->info;
10470 bgp_unlock_node (rn);
10471
10472 if (bdistance->access_list)
10473 {
10474 alist = access_list_lookup (AFI_IP, bdistance->access_list);
10475 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
10476 return bdistance->distance;
10477 }
10478 else
10479 return bdistance->distance;
10480 }
10481
10482 /* Backdoor check. */
10483 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
10484 if (rn)
10485 {
10486 bgp_static = rn->info;
10487 bgp_unlock_node (rn);
10488
10489 if (bgp_static->backdoor)
10490 {
10491 if (bgp->distance_local)
10492 return bgp->distance_local;
10493 else
10494 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10495 }
10496 }
10497
10498 if (peer_sort (peer) == BGP_PEER_EBGP)
10499 {
10500 if (bgp->distance_ebgp)
10501 return bgp->distance_ebgp;
10502 return ZEBRA_EBGP_DISTANCE_DEFAULT;
10503 }
10504 else
10505 {
10506 if (bgp->distance_ibgp)
10507 return bgp->distance_ibgp;
10508 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10509 }
10510}
10511
10512DEFUN (bgp_distance,
10513 bgp_distance_cmd,
10514 "distance bgp <1-255> <1-255> <1-255>",
10515 "Define an administrative distance\n"
10516 "BGP distance\n"
10517 "Distance for routes external to the AS\n"
10518 "Distance for routes internal to the AS\n"
10519 "Distance for local routes\n")
10520{
10521 struct bgp *bgp;
10522
10523 bgp = vty->index;
10524
10525 bgp->distance_ebgp = atoi (argv[0]);
10526 bgp->distance_ibgp = atoi (argv[1]);
10527 bgp->distance_local = atoi (argv[2]);
10528 return CMD_SUCCESS;
10529}
10530
10531DEFUN (no_bgp_distance,
10532 no_bgp_distance_cmd,
10533 "no distance bgp <1-255> <1-255> <1-255>",
10534 NO_STR
10535 "Define an administrative distance\n"
10536 "BGP distance\n"
10537 "Distance for routes external to the AS\n"
10538 "Distance for routes internal to the AS\n"
10539 "Distance for local routes\n")
10540{
10541 struct bgp *bgp;
10542
10543 bgp = vty->index;
10544
10545 bgp->distance_ebgp= 0;
10546 bgp->distance_ibgp = 0;
10547 bgp->distance_local = 0;
10548 return CMD_SUCCESS;
10549}
10550
10551ALIAS (no_bgp_distance,
10552 no_bgp_distance2_cmd,
10553 "no distance bgp",
10554 NO_STR
10555 "Define an administrative distance\n"
10556 "BGP distance\n")
10557
10558DEFUN (bgp_distance_source,
10559 bgp_distance_source_cmd,
10560 "distance <1-255> A.B.C.D/M",
10561 "Define an administrative distance\n"
10562 "Administrative distance\n"
10563 "IP source prefix\n")
10564{
10565 bgp_distance_set (vty, argv[0], argv[1], NULL);
10566 return CMD_SUCCESS;
10567}
10568
10569DEFUN (no_bgp_distance_source,
10570 no_bgp_distance_source_cmd,
10571 "no distance <1-255> A.B.C.D/M",
10572 NO_STR
10573 "Define an administrative distance\n"
10574 "Administrative distance\n"
10575 "IP source prefix\n")
10576{
10577 bgp_distance_unset (vty, argv[0], argv[1], NULL);
10578 return CMD_SUCCESS;
10579}
10580
10581DEFUN (bgp_distance_source_access_list,
10582 bgp_distance_source_access_list_cmd,
10583 "distance <1-255> A.B.C.D/M WORD",
10584 "Define an administrative distance\n"
10585 "Administrative distance\n"
10586 "IP source prefix\n"
10587 "Access list name\n")
10588{
10589 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
10590 return CMD_SUCCESS;
10591}
10592
10593DEFUN (no_bgp_distance_source_access_list,
10594 no_bgp_distance_source_access_list_cmd,
10595 "no distance <1-255> A.B.C.D/M WORD",
10596 NO_STR
10597 "Define an administrative distance\n"
10598 "Administrative distance\n"
10599 "IP source prefix\n"
10600 "Access list name\n")
10601{
10602 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
10603 return CMD_SUCCESS;
10604}
10605
10606DEFUN (bgp_damp_set,
10607 bgp_damp_set_cmd,
10608 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10609 "BGP Specific commands\n"
10610 "Enable route-flap dampening\n"
10611 "Half-life time for the penalty\n"
10612 "Value to start reusing a route\n"
10613 "Value to start suppressing a route\n"
10614 "Maximum duration to suppress a stable route\n")
10615{
10616 struct bgp *bgp;
10617 int half = DEFAULT_HALF_LIFE * 60;
10618 int reuse = DEFAULT_REUSE;
10619 int suppress = DEFAULT_SUPPRESS;
10620 int max = 4 * half;
10621
10622 if (argc == 4)
10623 {
10624 half = atoi (argv[0]) * 60;
10625 reuse = atoi (argv[1]);
10626 suppress = atoi (argv[2]);
10627 max = atoi (argv[3]) * 60;
10628 }
10629 else if (argc == 1)
10630 {
10631 half = atoi (argv[0]) * 60;
10632 max = 4 * half;
10633 }
10634
10635 bgp = vty->index;
10636 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
10637 half, reuse, suppress, max);
10638}
10639
10640ALIAS (bgp_damp_set,
10641 bgp_damp_set2_cmd,
10642 "bgp dampening <1-45>",
10643 "BGP Specific commands\n"
10644 "Enable route-flap dampening\n"
10645 "Half-life time for the penalty\n")
10646
10647ALIAS (bgp_damp_set,
10648 bgp_damp_set3_cmd,
10649 "bgp dampening",
10650 "BGP Specific commands\n"
10651 "Enable route-flap dampening\n")
10652
10653DEFUN (bgp_damp_unset,
10654 bgp_damp_unset_cmd,
10655 "no bgp dampening",
10656 NO_STR
10657 "BGP Specific commands\n"
10658 "Enable route-flap dampening\n")
10659{
10660 struct bgp *bgp;
10661
10662 bgp = vty->index;
10663 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
10664}
10665
10666ALIAS (bgp_damp_unset,
10667 bgp_damp_unset2_cmd,
10668 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10669 NO_STR
10670 "BGP Specific commands\n"
10671 "Enable route-flap dampening\n"
10672 "Half-life time for the penalty\n"
10673 "Value to start reusing a route\n"
10674 "Value to start suppressing a route\n"
10675 "Maximum duration to suppress a stable route\n")
10676
10677DEFUN (show_ip_bgp_dampened_paths,
10678 show_ip_bgp_dampened_paths_cmd,
10679 "show ip bgp dampened-paths",
10680 SHOW_STR
10681 IP_STR
10682 BGP_STR
10683 "Display paths suppressed due to dampening\n")
10684{
ajs5a646652004-11-05 01:25:55 +000010685 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
10686 NULL);
paul718e3742002-12-13 20:15:29 +000010687}
10688
10689DEFUN (show_ip_bgp_flap_statistics,
10690 show_ip_bgp_flap_statistics_cmd,
10691 "show ip bgp flap-statistics",
10692 SHOW_STR
10693 IP_STR
10694 BGP_STR
10695 "Display flap statistics of routes\n")
10696{
ajs5a646652004-11-05 01:25:55 +000010697 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10698 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000010699}
10700
10701/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000010702static int
paulfd79ac92004-10-13 05:06:08 +000010703bgp_clear_damp_route (struct vty *vty, const char *view_name,
10704 const char *ip_str, afi_t afi, safi_t safi,
10705 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000010706{
10707 int ret;
10708 struct prefix match;
10709 struct bgp_node *rn;
10710 struct bgp_node *rm;
10711 struct bgp_info *ri;
10712 struct bgp_info *ri_temp;
10713 struct bgp *bgp;
10714 struct bgp_table *table;
10715
10716 /* BGP structure lookup. */
10717 if (view_name)
10718 {
10719 bgp = bgp_lookup_by_name (view_name);
10720 if (bgp == NULL)
10721 {
10722 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10723 return CMD_WARNING;
10724 }
10725 }
10726 else
10727 {
10728 bgp = bgp_get_default ();
10729 if (bgp == NULL)
10730 {
10731 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
10732 return CMD_WARNING;
10733 }
10734 }
10735
10736 /* Check IP address argument. */
10737 ret = str2prefix (ip_str, &match);
10738 if (! ret)
10739 {
10740 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
10741 return CMD_WARNING;
10742 }
10743
10744 match.family = afi2family (afi);
10745
10746 if (safi == SAFI_MPLS_VPN)
10747 {
10748 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
10749 {
10750 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
10751 continue;
10752
10753 if ((table = rn->info) != NULL)
10754 if ((rm = bgp_node_match (table, &match)) != NULL)
10755 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
10756 {
10757 ri = rm->info;
10758 while (ri)
10759 {
10760 if (ri->damp_info)
10761 {
10762 ri_temp = ri->next;
10763 bgp_damp_info_free (ri->damp_info, 1);
10764 ri = ri_temp;
10765 }
10766 else
10767 ri = ri->next;
10768 }
10769 }
10770 }
10771 }
10772 else
10773 {
10774 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
10775 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
10776 {
10777 ri = rn->info;
10778 while (ri)
10779 {
10780 if (ri->damp_info)
10781 {
10782 ri_temp = ri->next;
10783 bgp_damp_info_free (ri->damp_info, 1);
10784 ri = ri_temp;
10785 }
10786 else
10787 ri = ri->next;
10788 }
10789 }
10790 }
10791
10792 return CMD_SUCCESS;
10793}
10794
10795DEFUN (clear_ip_bgp_dampening,
10796 clear_ip_bgp_dampening_cmd,
10797 "clear ip bgp dampening",
10798 CLEAR_STR
10799 IP_STR
10800 BGP_STR
10801 "Clear route flap dampening information\n")
10802{
10803 bgp_damp_info_clean ();
10804 return CMD_SUCCESS;
10805}
10806
10807DEFUN (clear_ip_bgp_dampening_prefix,
10808 clear_ip_bgp_dampening_prefix_cmd,
10809 "clear ip bgp dampening A.B.C.D/M",
10810 CLEAR_STR
10811 IP_STR
10812 BGP_STR
10813 "Clear route flap dampening information\n"
10814 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10815{
10816 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10817 SAFI_UNICAST, NULL, 1);
10818}
10819
10820DEFUN (clear_ip_bgp_dampening_address,
10821 clear_ip_bgp_dampening_address_cmd,
10822 "clear ip bgp dampening A.B.C.D",
10823 CLEAR_STR
10824 IP_STR
10825 BGP_STR
10826 "Clear route flap dampening information\n"
10827 "Network to clear damping information\n")
10828{
10829 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10830 SAFI_UNICAST, NULL, 0);
10831}
10832
10833DEFUN (clear_ip_bgp_dampening_address_mask,
10834 clear_ip_bgp_dampening_address_mask_cmd,
10835 "clear ip bgp dampening A.B.C.D A.B.C.D",
10836 CLEAR_STR
10837 IP_STR
10838 BGP_STR
10839 "Clear route flap dampening information\n"
10840 "Network to clear damping information\n"
10841 "Network mask\n")
10842{
10843 int ret;
10844 char prefix_str[BUFSIZ];
10845
10846 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
10847 if (! ret)
10848 {
10849 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
10850 return CMD_WARNING;
10851 }
10852
10853 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
10854 SAFI_UNICAST, NULL, 0);
10855}
10856
paul94f2b392005-06-28 12:44:16 +000010857static int
paul718e3742002-12-13 20:15:29 +000010858bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
10859 afi_t afi, safi_t safi, int *write)
10860{
10861 struct bgp_node *prn;
10862 struct bgp_node *rn;
10863 struct bgp_table *table;
10864 struct prefix *p;
10865 struct prefix_rd *prd;
10866 struct bgp_static *bgp_static;
10867 u_int32_t label;
10868 char buf[SU_ADDRSTRLEN];
10869 char rdbuf[RD_ADDRSTRLEN];
10870
10871 /* Network configuration. */
10872 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
10873 if ((table = prn->info) != NULL)
10874 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10875 if ((bgp_static = rn->info) != NULL)
10876 {
10877 p = &rn->p;
10878 prd = (struct prefix_rd *) &prn->p;
10879
10880 /* "address-family" display. */
10881 bgp_config_write_family_header (vty, afi, safi, write);
10882
10883 /* "network" configuration display. */
10884 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
10885 label = decode_label (bgp_static->tag);
10886
10887 vty_out (vty, " network %s/%d rd %s tag %d",
10888 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10889 p->prefixlen,
10890 rdbuf, label);
10891 vty_out (vty, "%s", VTY_NEWLINE);
10892 }
10893 return 0;
10894}
10895
10896/* Configuration of static route announcement and aggregate
10897 information. */
10898int
10899bgp_config_write_network (struct vty *vty, struct bgp *bgp,
10900 afi_t afi, safi_t safi, int *write)
10901{
10902 struct bgp_node *rn;
10903 struct prefix *p;
10904 struct bgp_static *bgp_static;
10905 struct bgp_aggregate *bgp_aggregate;
10906 char buf[SU_ADDRSTRLEN];
10907
10908 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
10909 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
10910
10911 /* Network configuration. */
10912 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
10913 if ((bgp_static = rn->info) != NULL)
10914 {
10915 p = &rn->p;
10916
10917 /* "address-family" display. */
10918 bgp_config_write_family_header (vty, afi, safi, write);
10919
10920 /* "network" configuration display. */
10921 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10922 {
10923 u_int32_t destination;
10924 struct in_addr netmask;
10925
10926 destination = ntohl (p->u.prefix4.s_addr);
10927 masklen2ip (p->prefixlen, &netmask);
10928 vty_out (vty, " network %s",
10929 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
10930
10931 if ((IN_CLASSC (destination) && p->prefixlen == 24)
10932 || (IN_CLASSB (destination) && p->prefixlen == 16)
10933 || (IN_CLASSA (destination) && p->prefixlen == 8)
10934 || p->u.prefix4.s_addr == 0)
10935 {
10936 /* Natural mask is not display. */
10937 }
10938 else
10939 vty_out (vty, " mask %s", inet_ntoa (netmask));
10940 }
10941 else
10942 {
10943 vty_out (vty, " network %s/%d",
10944 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10945 p->prefixlen);
10946 }
10947
10948 if (bgp_static->rmap.name)
10949 vty_out (vty, " route-map %s", bgp_static->rmap.name);
10950 else if (bgp_static->backdoor)
10951 vty_out (vty, " backdoor");
10952
10953 vty_out (vty, "%s", VTY_NEWLINE);
10954 }
10955
10956 /* Aggregate-address configuration. */
10957 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
10958 if ((bgp_aggregate = rn->info) != NULL)
10959 {
10960 p = &rn->p;
10961
10962 /* "address-family" display. */
10963 bgp_config_write_family_header (vty, afi, safi, write);
10964
10965 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10966 {
10967 struct in_addr netmask;
10968
10969 masklen2ip (p->prefixlen, &netmask);
10970 vty_out (vty, " aggregate-address %s %s",
10971 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10972 inet_ntoa (netmask));
10973 }
10974 else
10975 {
10976 vty_out (vty, " aggregate-address %s/%d",
10977 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10978 p->prefixlen);
10979 }
10980
10981 if (bgp_aggregate->as_set)
10982 vty_out (vty, " as-set");
10983
10984 if (bgp_aggregate->summary_only)
10985 vty_out (vty, " summary-only");
10986
10987 vty_out (vty, "%s", VTY_NEWLINE);
10988 }
10989
10990 return 0;
10991}
10992
10993int
10994bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
10995{
10996 struct bgp_node *rn;
10997 struct bgp_distance *bdistance;
10998
10999 /* Distance configuration. */
11000 if (bgp->distance_ebgp
11001 && bgp->distance_ibgp
11002 && bgp->distance_local
11003 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11004 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11005 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11006 vty_out (vty, " distance bgp %d %d %d%s",
11007 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11008 VTY_NEWLINE);
11009
11010 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11011 if ((bdistance = rn->info) != NULL)
11012 {
11013 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11014 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11015 bdistance->access_list ? bdistance->access_list : "",
11016 VTY_NEWLINE);
11017 }
11018
11019 return 0;
11020}
11021
11022/* Allocate routing table structure and install commands. */
11023void
11024bgp_route_init ()
11025{
11026 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011027 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011028
11029 /* IPv4 BGP commands. */
11030 install_element (BGP_NODE, &bgp_network_cmd);
11031 install_element (BGP_NODE, &bgp_network_mask_cmd);
11032 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11033 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11034 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11035 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11036 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11037 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11038 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
11039 install_element (BGP_NODE, &no_bgp_network_cmd);
11040 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11041 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11042 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11043 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11044 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11045 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11046 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11047 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
11048
11049 install_element (BGP_NODE, &aggregate_address_cmd);
11050 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11051 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11052 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11053 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11054 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11055 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11056 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11057 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11058 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11059 install_element (BGP_NODE, &no_aggregate_address_cmd);
11060 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11061 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11062 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11063 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11064 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11065 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11066 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11067 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11068 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11069
11070 /* IPv4 unicast configuration. */
11071 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11072 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11073 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11074 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11075 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11076 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
11077 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
11078 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11079 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11080 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11081 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11082 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11083 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11084 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11085 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11086 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11087 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11088 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11089 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11090 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11091 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11092 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11093 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11094 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11095 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11096 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11097 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11098 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11099 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11100 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11101 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11102 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11103
11104 /* IPv4 multicast configuration. */
11105 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11106 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11107 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11108 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11109 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11110 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
11111 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11112 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11113 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11114 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11115 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11116 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11117 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11118 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11119 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11120 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11121 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11122 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11123 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11124 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11125 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11126 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11127 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11128 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11129 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11130 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11131 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11132 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11133 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11134 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11135 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11136 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11137
11138 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11139 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11140 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11141 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11142 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11143 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11144 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11145 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11146 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11147 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11148 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11149 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11150 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11151 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11152 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11153 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11154 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11155 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11156 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11157 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11158 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11159 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11160 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11161 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11162 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11163 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11164 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11165 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11166 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11167 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11168 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11169 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11170 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11171 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11172 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11173 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11174 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11175 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11176 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11177 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11178 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11179 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11180 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11181 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11182 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11183 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11184 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11185 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11186 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11187 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11188 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11189 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11190 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11191 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11192 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11193 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11194 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11195 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11196 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11197 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11198 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11199 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11200 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11201 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11202 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11203 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11204 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011205 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11206 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11207 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11208 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11209 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11210 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011211
11212 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11213 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11214 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11215 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11216 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11217 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11218 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11219 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11220 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11221 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11222 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11223 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11224 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11225 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11226 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11227 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11228 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11229 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11230 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11231 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11232 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11233 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11234 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11235 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11236 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11237 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11238 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11239 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11240 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11241 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11242 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11243 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11244 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11245 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11246 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11247 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11248 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11249 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11250 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11251 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11252 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11253 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11254 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11255 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11256 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11257 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11258 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11259 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11260 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11261 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11262 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11263 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11264 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11265 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11266 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11267 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11268 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11269 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11270 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11271 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11272 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11273 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11274 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11275 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11276 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11277 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11278 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011279 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11280 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11281 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11282 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11283 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11284 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011285
11286 /* BGP dampening clear commands */
11287 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11288 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11289 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11290 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11291
Paul Jakmaff7924f2006-09-04 01:10:36 +000011292 /* prefix count */
11293 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11294 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11295 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011296#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011297 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11298
paul718e3742002-12-13 20:15:29 +000011299 /* New config IPv6 BGP commands. */
11300 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11301 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
11302 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11303 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
11304
11305 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11306 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11307 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11308 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11309
11310 /* Old config IPv6 BGP commands. */
11311 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11312 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11313
11314 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11315 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11316 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11317 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11318
11319 install_element (VIEW_NODE, &show_bgp_cmd);
11320 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11321 install_element (VIEW_NODE, &show_bgp_route_cmd);
11322 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11323 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11324 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11325 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11326 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11327 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11328 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11329 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11330 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11331 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11332 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11333 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11334 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11335 install_element (VIEW_NODE, &show_bgp_community_cmd);
11336 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11337 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11338 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11339 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11340 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11341 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11342 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11343 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
11344 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
11345 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
11346 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
11347 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
11348 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
11349 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
11350 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
11351 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
11352 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
11353 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
11354 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11355 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
11356 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11357 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
11358 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11359 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
11360 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11361 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
11362 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11363 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11364 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011365 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
11366 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11367 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
11368 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011369 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
11370 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
11371 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011372 install_element (VIEW_NODE, &show_bgp_view_cmd);
11373 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
11374 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
11375 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
11376 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
11377 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
11378 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11379 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11380 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11381 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11382 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
11383 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11384 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11385 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11386 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
11387 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11388 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
11389 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011390 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
11391 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
11392 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011393
11394 install_element (ENABLE_NODE, &show_bgp_cmd);
11395 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
11396 install_element (ENABLE_NODE, &show_bgp_route_cmd);
11397 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
11398 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
11399 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
11400 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
11401 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
11402 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
11403 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
11404 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
11405 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
11406 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
11407 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
11408 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
11409 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
11410 install_element (ENABLE_NODE, &show_bgp_community_cmd);
11411 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
11412 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
11413 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
11414 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
11415 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
11416 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
11417 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
11418 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
11419 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
11420 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
11421 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
11422 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
11423 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
11424 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
11425 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
11426 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
11427 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
11428 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
11429 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11430 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
11431 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11432 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
11433 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11434 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
11435 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11436 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
11437 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11438 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11439 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011440 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
11441 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11442 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
11443 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011444 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
11445 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
11446 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011447 install_element (ENABLE_NODE, &show_bgp_view_cmd);
11448 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
11449 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
11450 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
11451 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
11452 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
11453 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11454 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11455 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11456 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11457 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
11458 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11459 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11460 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11461 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
11462 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11463 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
11464 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011465 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
11466 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
11467 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000011468
11469 /* Statistics */
11470 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
11471 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
11472 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
11473 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
11474
paul718e3742002-12-13 20:15:29 +000011475 /* old command */
11476 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
11477 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
11478 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
11479 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
11480 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
11481 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
11482 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
11483 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
11484 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
11485 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
11486 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
11487 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
11488 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
11489 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
11490 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
11491 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
11492 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
11493 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
11494 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
11495 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
11496 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
11497 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
11498 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
11499 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
11500 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
11501 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
11502 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
11503 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
11504 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
11505 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
11506 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
11507 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
11508 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
11509 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
11510 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
11511 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000011512
paul718e3742002-12-13 20:15:29 +000011513 /* old command */
11514 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
11515 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
11516 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
11517 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
11518 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
11519 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
11520 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
11521 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
11522 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
11523 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
11524 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
11525 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
11526 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
11527 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
11528 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
11529 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
11530 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
11531 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
11532 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
11533 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
11534 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
11535 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
11536 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
11537 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
11538 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
11539 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
11540 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
11541 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
11542 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
11543 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
11544 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
11545 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
11546 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
11547 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
11548 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
11549 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
11550
11551 /* old command */
11552 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
11553 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
11554 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
11555 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
11556
11557 /* old command */
11558 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
11559 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
11560 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
11561 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
11562
11563 /* old command */
11564 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
11565 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
11566 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
11567 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
11568#endif /* HAVE_IPV6 */
11569
11570 install_element (BGP_NODE, &bgp_distance_cmd);
11571 install_element (BGP_NODE, &no_bgp_distance_cmd);
11572 install_element (BGP_NODE, &no_bgp_distance2_cmd);
11573 install_element (BGP_NODE, &bgp_distance_source_cmd);
11574 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
11575 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
11576 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
11577
11578 install_element (BGP_NODE, &bgp_damp_set_cmd);
11579 install_element (BGP_NODE, &bgp_damp_set2_cmd);
11580 install_element (BGP_NODE, &bgp_damp_set3_cmd);
11581 install_element (BGP_NODE, &bgp_damp_unset_cmd);
11582 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
11583 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
11584 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
11585 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
11586 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
11587 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
11588}