blob: 40534a1477ffa31db4e10aa324120a0c07caae33 [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{
190 /* leave info in place for now in place for now,
191 * bgp_process will reap it later. */
192 SET_FLAG (ri->flags, BGP_INFO_REMOVED);
193 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
194}
195
paul718e3742002-12-13 20:15:29 +0000196/* Get MED value. If MED value is missing and "bgp bestpath
197 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000198static u_int32_t
paul718e3742002-12-13 20:15:29 +0000199bgp_med_value (struct attr *attr, struct bgp *bgp)
200{
201 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
202 return attr->med;
203 else
204 {
205 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000206 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000207 else
208 return 0;
209 }
210}
211
212/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000213static int
paul718e3742002-12-13 20:15:29 +0000214bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
215{
216 u_int32_t new_pref;
217 u_int32_t exist_pref;
218 u_int32_t new_med;
219 u_int32_t exist_med;
220 struct in_addr new_id;
221 struct in_addr exist_id;
222 int new_cluster;
223 int exist_cluster;
224 int internal_as_route = 0;
225 int confed_as_route = 0;
226 int ret;
227
228 /* 0. Null check. */
229 if (new == NULL)
230 return 0;
231 if (exist == NULL)
232 return 1;
233
234 /* 1. Weight check. */
235 if (new->attr->weight > exist->attr->weight)
236 return 1;
237 if (new->attr->weight < exist->attr->weight)
238 return 0;
239
240 /* 2. Local preference check. */
241 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
242 new_pref = new->attr->local_pref;
243 else
244 new_pref = bgp->default_local_pref;
245
246 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
247 exist_pref = exist->attr->local_pref;
248 else
249 exist_pref = bgp->default_local_pref;
250
251 if (new_pref > exist_pref)
252 return 1;
253 if (new_pref < exist_pref)
254 return 0;
255
256 /* 3. Local route check. */
257 if (new->sub_type == BGP_ROUTE_STATIC)
258 return 1;
259 if (exist->sub_type == BGP_ROUTE_STATIC)
260 return 0;
261
262 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
263 return 1;
264 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
265 return 0;
266
267 if (new->sub_type == BGP_ROUTE_AGGREGATE)
268 return 1;
269 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
270 return 0;
271
272 /* 4. AS path length check. */
273 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
274 {
paulfe69a502005-09-10 16:55:02 +0000275 int exist_hops = aspath_count_hops (exist->attr->aspath);
276 int exist_confeds = aspath_count_confeds (exist->attr->aspath);
277
hasso68118452005-04-08 15:40:36 +0000278 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
279 {
paulfe69a502005-09-10 16:55:02 +0000280 int aspath_hops;
281
282 aspath_hops = aspath_count_hops (new->attr->aspath);
283 aspath_hops += aspath_count_confeds (new->attr->aspath);
284
285 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000286 return 1;
paulfe69a502005-09-10 16:55:02 +0000287 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000288 return 0;
289 }
290 else
291 {
paulfe69a502005-09-10 16:55:02 +0000292 int newhops = aspath_count_hops (new->attr->aspath);
293
294 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000295 return 1;
paulfe69a502005-09-10 16:55:02 +0000296 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000297 return 0;
298 }
paul718e3742002-12-13 20:15:29 +0000299 }
300
301 /* 5. Origin check. */
302 if (new->attr->origin < exist->attr->origin)
303 return 1;
304 if (new->attr->origin > exist->attr->origin)
305 return 0;
306
307 /* 6. MED check. */
paulfe69a502005-09-10 16:55:02 +0000308 internal_as_route = (aspath_count_hops (new->attr->aspath) == 0
309 && aspath_count_hops (exist->attr->aspath) == 0);
310 confed_as_route = (aspath_count_confeds (new->attr->aspath) > 0
311 && aspath_count_confeds (exist->attr->aspath) > 0
312 && aspath_count_hops (new->attr->aspath) == 0
313 && aspath_count_hops (exist->attr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000314
315 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
316 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
317 && confed_as_route)
318 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
319 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
320 || internal_as_route)
321 {
322 new_med = bgp_med_value (new->attr, bgp);
323 exist_med = bgp_med_value (exist->attr, bgp);
324
325 if (new_med < exist_med)
326 return 1;
327 if (new_med > exist_med)
328 return 0;
329 }
330
331 /* 7. Peer type check. */
332 if (peer_sort (new->peer) == BGP_PEER_EBGP
333 && peer_sort (exist->peer) == BGP_PEER_IBGP)
334 return 1;
335 if (peer_sort (new->peer) == BGP_PEER_EBGP
336 && peer_sort (exist->peer) == BGP_PEER_CONFED)
337 return 1;
338 if (peer_sort (new->peer) == BGP_PEER_IBGP
339 && peer_sort (exist->peer) == BGP_PEER_EBGP)
340 return 0;
341 if (peer_sort (new->peer) == BGP_PEER_CONFED
342 && peer_sort (exist->peer) == BGP_PEER_EBGP)
343 return 0;
344
345 /* 8. IGP metric check. */
346 if (new->igpmetric < exist->igpmetric)
347 return 1;
348 if (new->igpmetric > exist->igpmetric)
349 return 0;
350
351 /* 9. Maximum path check. */
352
353 /* 10. If both paths are external, prefer the path that was received
354 first (the oldest one). This step minimizes route-flap, since a
355 newer path won't displace an older one, even if it was the
356 preferred route based on the additional decision criteria below. */
357 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
358 && peer_sort (new->peer) == BGP_PEER_EBGP
359 && peer_sort (exist->peer) == BGP_PEER_EBGP)
360 {
361 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
362 return 1;
363 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
364 return 0;
365 }
366
367 /* 11. Rourter-ID comparision. */
368 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
369 new_id.s_addr = new->attr->originator_id.s_addr;
370 else
371 new_id.s_addr = new->peer->remote_id.s_addr;
372 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
373 exist_id.s_addr = exist->attr->originator_id.s_addr;
374 else
375 exist_id.s_addr = exist->peer->remote_id.s_addr;
376
377 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
378 return 1;
379 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
380 return 0;
381
382 /* 12. Cluster length comparision. */
383 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
384 new_cluster = new->attr->cluster->length;
385 else
386 new_cluster = 0;
387 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
388 exist_cluster = exist->attr->cluster->length;
389 else
390 exist_cluster = 0;
391
392 if (new_cluster < exist_cluster)
393 return 1;
394 if (new_cluster > exist_cluster)
395 return 0;
396
397 /* 13. Neighbor address comparision. */
398 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
399
400 if (ret == 1)
401 return 0;
402 if (ret == -1)
403 return 1;
404
405 return 1;
406}
407
paul94f2b392005-06-28 12:44:16 +0000408static enum filter_type
paul718e3742002-12-13 20:15:29 +0000409bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
410 afi_t afi, safi_t safi)
411{
412 struct bgp_filter *filter;
413
414 filter = &peer->filter[afi][safi];
415
416 if (DISTRIBUTE_IN_NAME (filter))
417 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
418 return FILTER_DENY;
419
420 if (PREFIX_LIST_IN_NAME (filter))
421 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
422 return FILTER_DENY;
423
424 if (FILTER_LIST_IN_NAME (filter))
425 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
426 return FILTER_DENY;
427
428 return FILTER_PERMIT;
429}
430
paul94f2b392005-06-28 12:44:16 +0000431static enum filter_type
paul718e3742002-12-13 20:15:29 +0000432bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
433 afi_t afi, safi_t safi)
434{
435 struct bgp_filter *filter;
436
437 filter = &peer->filter[afi][safi];
438
439 if (DISTRIBUTE_OUT_NAME (filter))
440 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
441 return FILTER_DENY;
442
443 if (PREFIX_LIST_OUT_NAME (filter))
444 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
445 return FILTER_DENY;
446
447 if (FILTER_LIST_OUT_NAME (filter))
448 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
449 return FILTER_DENY;
450
451 return FILTER_PERMIT;
452}
453
454/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000455static int
paul718e3742002-12-13 20:15:29 +0000456bgp_community_filter (struct peer *peer, struct attr *attr)
457{
458 if (attr->community)
459 {
460 /* NO_ADVERTISE check. */
461 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
462 return 1;
463
464 /* NO_EXPORT check. */
465 if (peer_sort (peer) == BGP_PEER_EBGP &&
466 community_include (attr->community, COMMUNITY_NO_EXPORT))
467 return 1;
468
469 /* NO_EXPORT_SUBCONFED check. */
470 if (peer_sort (peer) == BGP_PEER_EBGP
471 || peer_sort (peer) == BGP_PEER_CONFED)
472 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
473 return 1;
474 }
475 return 0;
476}
477
478/* Route reflection loop check. */
479static int
480bgp_cluster_filter (struct peer *peer, struct attr *attr)
481{
482 struct in_addr cluster_id;
483
484 if (attr->cluster)
485 {
486 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
487 cluster_id = peer->bgp->cluster_id;
488 else
489 cluster_id = peer->bgp->router_id;
490
491 if (cluster_loop_check (attr->cluster, cluster_id))
492 return 1;
493 }
494 return 0;
495}
496
paul94f2b392005-06-28 12:44:16 +0000497static int
paul718e3742002-12-13 20:15:29 +0000498bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
499 afi_t afi, safi_t safi)
500{
501 struct bgp_filter *filter;
502 struct bgp_info info;
503 route_map_result_t ret;
504
505 filter = &peer->filter[afi][safi];
506
507 /* Apply default weight value. */
508 attr->weight = peer->weight;
509
510 /* Route map apply. */
511 if (ROUTE_MAP_IN_NAME (filter))
512 {
513 /* Duplicate current value to new strucutre for modification. */
514 info.peer = peer;
515 info.attr = attr;
516
paulac41b2a2003-08-12 05:32:27 +0000517 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
518
paul718e3742002-12-13 20:15:29 +0000519 /* Apply BGP route map to the attribute. */
520 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000521
522 peer->rmap_type = 0;
523
paul718e3742002-12-13 20:15:29 +0000524 if (ret == RMAP_DENYMATCH)
525 {
526 /* Free newly generated AS path and community by route-map. */
527 bgp_attr_flush (attr);
528 return RMAP_DENY;
529 }
530 }
531 return RMAP_PERMIT;
532}
533
paul94f2b392005-06-28 12:44:16 +0000534static int
paulfee0f4c2004-09-13 05:12:46 +0000535bgp_export_modifier (struct peer *rsclient, struct peer *peer,
536 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
537{
538 struct bgp_filter *filter;
539 struct bgp_info info;
540 route_map_result_t ret;
541
542 filter = &peer->filter[afi][safi];
543
544 /* Route map apply. */
545 if (ROUTE_MAP_EXPORT_NAME (filter))
546 {
547 /* Duplicate current value to new strucutre for modification. */
548 info.peer = rsclient;
549 info.attr = attr;
550
551 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
552
553 /* Apply BGP route map to the attribute. */
554 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
555
556 rsclient->rmap_type = 0;
557
558 if (ret == RMAP_DENYMATCH)
559 {
560 /* Free newly generated AS path and community by route-map. */
561 bgp_attr_flush (attr);
562 return RMAP_DENY;
563 }
564 }
565 return RMAP_PERMIT;
566}
567
paul94f2b392005-06-28 12:44:16 +0000568static int
paulfee0f4c2004-09-13 05:12:46 +0000569bgp_import_modifier (struct peer *rsclient, struct peer *peer,
570 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
571{
572 struct bgp_filter *filter;
573 struct bgp_info info;
574 route_map_result_t ret;
575
576 filter = &rsclient->filter[afi][safi];
577
578 /* Apply default weight value. */
579 attr->weight = peer->weight;
580
581 /* Route map apply. */
582 if (ROUTE_MAP_IMPORT_NAME (filter))
583 {
584 /* Duplicate current value to new strucutre for modification. */
585 info.peer = peer;
586 info.attr = attr;
587
588 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
589
590 /* Apply BGP route map to the attribute. */
591 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
592
593 peer->rmap_type = 0;
594
595 if (ret == RMAP_DENYMATCH)
596 {
597 /* Free newly generated AS path and community by route-map. */
598 bgp_attr_flush (attr);
599 return RMAP_DENY;
600 }
601 }
602 return RMAP_PERMIT;
603}
604
paul94f2b392005-06-28 12:44:16 +0000605static int
paul718e3742002-12-13 20:15:29 +0000606bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
607 struct attr *attr, afi_t afi, safi_t safi)
608{
609 int ret;
610 char buf[SU_ADDRSTRLEN];
611 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000612 struct peer *from;
613 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000614 int transparent;
615 int reflect;
616
617 from = ri->peer;
618 filter = &peer->filter[afi][safi];
619 bgp = peer->bgp;
620
621#ifdef DISABLE_BGP_ANNOUNCE
622 return 0;
623#endif
624
paulfee0f4c2004-09-13 05:12:46 +0000625 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
626 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
627 return 0;
628
paul718e3742002-12-13 20:15:29 +0000629 /* Do not send back route to sender. */
630 if (from == peer)
631 return 0;
632
paul35be31b2004-05-01 18:17:04 +0000633 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
634 if (p->family == AF_INET
635 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
636 return 0;
637#ifdef HAVE_IPV6
638 if (p->family == AF_INET6
639 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
640 return 0;
641#endif
642
paul718e3742002-12-13 20:15:29 +0000643 /* Aggregate-address suppress check. */
644 if (ri->suppress)
645 if (! UNSUPPRESS_MAP_NAME (filter))
646 return 0;
647
648 /* Default route check. */
649 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
650 {
651 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
652 return 0;
653#ifdef HAVE_IPV6
654 else if (p->family == AF_INET6 && p->prefixlen == 0)
655 return 0;
656#endif /* HAVE_IPV6 */
657 }
658
paul286e1e72003-08-08 00:24:31 +0000659 /* Transparency check. */
660 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
661 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
662 transparent = 1;
663 else
664 transparent = 0;
665
paul718e3742002-12-13 20:15:29 +0000666 /* If community is not disabled check the no-export and local. */
paul286e1e72003-08-08 00:24:31 +0000667 if (! transparent && bgp_community_filter (peer, ri->attr))
paul718e3742002-12-13 20:15:29 +0000668 return 0;
669
670 /* If the attribute has originator-id and it is same as remote
671 peer's id. */
672 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
673 {
674 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->originator_id))
675 {
676 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000677 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000678 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
679 peer->host,
680 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
681 p->prefixlen);
682 return 0;
683 }
684 }
685
686 /* ORF prefix-list filter check */
687 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
688 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
689 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
690 if (peer->orf_plist[afi][safi])
691 {
692 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
693 return 0;
694 }
695
696 /* Output filter check. */
697 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
698 {
699 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000700 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000701 "%s [Update:SEND] %s/%d is filtered",
702 peer->host,
703 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
704 p->prefixlen);
705 return 0;
706 }
707
708#ifdef BGP_SEND_ASPATH_CHECK
709 /* AS path loop check. */
710 if (aspath_loop_check (ri->attr->aspath, peer->as))
711 {
712 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000713 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000714 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
715 peer->host, peer->as);
716 return 0;
717 }
718#endif /* BGP_SEND_ASPATH_CHECK */
719
720 /* If we're a CONFED we need to loop check the CONFED ID too */
721 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
722 {
723 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
724 {
725 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000726 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000727 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
728 peer->host,
729 bgp->confed_id);
730 return 0;
731 }
732 }
733
734 /* Route-Reflect check. */
735 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
736 reflect = 1;
737 else
738 reflect = 0;
739
740 /* IBGP reflection check. */
741 if (reflect)
742 {
743 /* A route from a Client peer. */
744 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
745 {
746 /* Reflect to all the Non-Client peers and also to the
747 Client peers other than the originator. Originator check
748 is already done. So there is noting to do. */
749 /* no bgp client-to-client reflection check. */
750 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
751 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
752 return 0;
753 }
754 else
755 {
756 /* A route from a Non-client peer. Reflect to all other
757 clients. */
758 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
759 return 0;
760 }
761 }
762
763 /* For modify attribute, copy it to temporary structure. */
764 *attr = *ri->attr;
765
766 /* If local-preference is not set. */
767 if ((peer_sort (peer) == BGP_PEER_IBGP
768 || peer_sort (peer) == BGP_PEER_CONFED)
769 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
770 {
771 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
772 attr->local_pref = bgp->default_local_pref;
773 }
774
paul718e3742002-12-13 20:15:29 +0000775 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
776 if (peer_sort (peer) == BGP_PEER_EBGP
777 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
778 {
779 if (ri->peer != bgp->peer_self && ! transparent
780 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
781 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
782 }
783
784 /* next-hop-set */
785 if (transparent || reflect
786 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
787 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000788#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000789 || (p->family == AF_INET6 &&
790 ! IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000791#endif /* HAVE_IPV6 */
792 )))
paul718e3742002-12-13 20:15:29 +0000793 {
794 /* NEXT-HOP Unchanged. */
795 }
796 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
797 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
798#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000799 || (p->family == AF_INET6 &&
800 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000801#endif /* HAVE_IPV6 */
802 || (peer_sort (peer) == BGP_PEER_EBGP
803 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
804 {
805 /* Set IPv4 nexthop. */
806 if (p->family == AF_INET)
807 {
808 if (safi == SAFI_MPLS_VPN)
809 memcpy (&attr->mp_nexthop_global_in, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
810 else
811 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
812 }
813#ifdef HAVE_IPV6
814 /* Set IPv6 nexthop. */
815 if (p->family == AF_INET6)
816 {
817 /* IPv6 global nexthop must be included. */
818 memcpy (&attr->mp_nexthop_global, &peer->nexthop.v6_global,
819 IPV6_MAX_BYTELEN);
820 attr->mp_nexthop_len = 16;
821 }
822#endif /* HAVE_IPV6 */
823 }
824
825#ifdef HAVE_IPV6
826 if (p->family == AF_INET6)
827 {
paulfee0f4c2004-09-13 05:12:46 +0000828 /* Left nexthop_local unchanged if so configured. */
829 if ( CHECK_FLAG (peer->af_flags[afi][safi],
830 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
831 {
832 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
833 attr->mp_nexthop_len=32;
834 else
835 attr->mp_nexthop_len=16;
836 }
837
838 /* Default nexthop_local treatment for non-RS-Clients */
839 else
840 {
paul718e3742002-12-13 20:15:29 +0000841 /* Link-local address should not be transit to different peer. */
842 attr->mp_nexthop_len = 16;
843
844 /* Set link-local address for shared network peer. */
845 if (peer->shared_network
846 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
847 {
848 memcpy (&attr->mp_nexthop_local, &peer->nexthop.v6_local,
849 IPV6_MAX_BYTELEN);
850 attr->mp_nexthop_len = 32;
851 }
852
853 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
854 address.*/
855 if (reflect)
856 attr->mp_nexthop_len = 16;
857
858 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
859 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
860 attr->mp_nexthop_len = 16;
861 }
paulfee0f4c2004-09-13 05:12:46 +0000862
863 }
paul718e3742002-12-13 20:15:29 +0000864#endif /* HAVE_IPV6 */
865
866 /* If this is EBGP peer and remove-private-AS is set. */
867 if (peer_sort (peer) == BGP_PEER_EBGP
868 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
869 && aspath_private_as_check (attr->aspath))
870 attr->aspath = aspath_empty_get ();
871
872 /* Route map & unsuppress-map apply. */
873 if (ROUTE_MAP_OUT_NAME (filter)
874 || ri->suppress)
875 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +0000876 struct bgp_info info;
877 struct attr dummy_attr;
878
paul718e3742002-12-13 20:15:29 +0000879 info.peer = peer;
880 info.attr = attr;
881
882 /* The route reflector is not allowed to modify the attributes
883 of the reflected IBGP routes. */
884 if (peer_sort (from) == BGP_PEER_IBGP
885 && peer_sort (peer) == BGP_PEER_IBGP)
886 {
887 dummy_attr = *attr;
888 info.attr = &dummy_attr;
889 }
paulac41b2a2003-08-12 05:32:27 +0000890
891 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
892
paul718e3742002-12-13 20:15:29 +0000893 if (ri->suppress)
894 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
895 else
896 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
897
paulac41b2a2003-08-12 05:32:27 +0000898 peer->rmap_type = 0;
899
paul718e3742002-12-13 20:15:29 +0000900 if (ret == RMAP_DENYMATCH)
901 {
902 bgp_attr_flush (attr);
903 return 0;
904 }
905 }
906 return 1;
907}
908
paul94f2b392005-06-28 12:44:16 +0000909static int
paulfee0f4c2004-09-13 05:12:46 +0000910bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
911 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000912{
paulfee0f4c2004-09-13 05:12:46 +0000913 int ret;
914 char buf[SU_ADDRSTRLEN];
915 struct bgp_filter *filter;
916 struct bgp_info info;
917 struct peer *from;
918 struct bgp *bgp;
919
920 from = ri->peer;
921 filter = &rsclient->filter[afi][safi];
922 bgp = rsclient->bgp;
923
924#ifdef DISABLE_BGP_ANNOUNCE
925 return 0;
926#endif
927
928 /* Do not send back route to sender. */
929 if (from == rsclient)
930 return 0;
931
932 /* Aggregate-address suppress check. */
933 if (ri->suppress)
934 if (! UNSUPPRESS_MAP_NAME (filter))
935 return 0;
936
937 /* Default route check. */
938 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
939 PEER_STATUS_DEFAULT_ORIGINATE))
940 {
941 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
942 return 0;
943#ifdef HAVE_IPV6
944 else if (p->family == AF_INET6 && p->prefixlen == 0)
945 return 0;
946#endif /* HAVE_IPV6 */
947 }
948
949 /* If the attribute has originator-id and it is same as remote
950 peer's id. */
951 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
952 {
953 if (IPV4_ADDR_SAME (&rsclient->remote_id, &ri->attr->originator_id))
954 {
955 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000956 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000957 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
958 rsclient->host,
959 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
960 p->prefixlen);
961 return 0;
962 }
963 }
964
965 /* ORF prefix-list filter check */
966 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
967 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
968 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
969 if (rsclient->orf_plist[afi][safi])
970 {
971 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
972 return 0;
973 }
974
975 /* Output filter check. */
976 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
977 {
978 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000979 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000980 "%s [Update:SEND] %s/%d is filtered",
981 rsclient->host,
982 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
983 p->prefixlen);
984 return 0;
985 }
986
987#ifdef BGP_SEND_ASPATH_CHECK
988 /* AS path loop check. */
989 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
990 {
991 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000992 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000993 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
994 rsclient->host, rsclient->as);
995 return 0;
996 }
997#endif /* BGP_SEND_ASPATH_CHECK */
998
999 /* For modify attribute, copy it to temporary structure. */
1000 *attr = *ri->attr;
1001
1002 /* next-hop-set */
1003 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1004#ifdef HAVE_IPV6
1005 || (p->family == AF_INET6 &&
1006 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
1007#endif /* HAVE_IPV6 */
1008 )
1009 {
1010 /* Set IPv4 nexthop. */
1011 if (p->family == AF_INET)
1012 {
1013 if (safi == SAFI_MPLS_VPN)
1014 memcpy (&attr->mp_nexthop_global_in, &rsclient->nexthop.v4,
1015 IPV4_MAX_BYTELEN);
1016 else
1017 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1018 }
1019#ifdef HAVE_IPV6
1020 /* Set IPv6 nexthop. */
1021 if (p->family == AF_INET6)
1022 {
1023 /* IPv6 global nexthop must be included. */
1024 memcpy (&attr->mp_nexthop_global, &rsclient->nexthop.v6_global,
1025
1026 IPV6_MAX_BYTELEN);
1027 attr->mp_nexthop_len = 16;
1028 }
1029#endif /* HAVE_IPV6 */
1030 }
1031
1032#ifdef HAVE_IPV6
1033 if (p->family == AF_INET6)
1034 {
1035 /* Left nexthop_local unchanged if so configured. */
1036 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1037 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1038 {
1039 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1040 attr->mp_nexthop_len=32;
1041 else
1042 attr->mp_nexthop_len=16;
1043 }
1044
1045 /* Default nexthop_local treatment for RS-Clients */
1046 else
1047 {
1048 /* Announcer and RS-Client are both in the same network */
1049 if (rsclient->shared_network && from->shared_network &&
1050 (rsclient->ifindex == from->ifindex))
1051 {
1052 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1053 attr->mp_nexthop_len=32;
1054 else
1055 attr->mp_nexthop_len=16;
1056 }
1057
1058 /* Set link-local address for shared network peer. */
1059 else if (rsclient->shared_network
1060 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1061 {
1062 memcpy (&attr->mp_nexthop_local, &rsclient->nexthop.v6_local,
1063 IPV6_MAX_BYTELEN);
1064 attr->mp_nexthop_len = 32;
1065 }
1066
1067 else
1068 attr->mp_nexthop_len = 16;
1069 }
1070
1071 }
1072#endif /* HAVE_IPV6 */
1073
1074
1075 /* If this is EBGP peer and remove-private-AS is set. */
1076 if (peer_sort (rsclient) == BGP_PEER_EBGP
1077 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1078 && aspath_private_as_check (attr->aspath))
1079 attr->aspath = aspath_empty_get ();
1080
1081 /* Route map & unsuppress-map apply. */
1082 if (ROUTE_MAP_OUT_NAME (filter) || ri->suppress)
1083 {
1084 info.peer = rsclient;
1085 info.attr = attr;
1086
1087 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1088
1089 if (ri->suppress)
1090 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1091 else
1092 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1093
1094 rsclient->rmap_type = 0;
1095
1096 if (ret == RMAP_DENYMATCH)
1097 {
1098 bgp_attr_flush (attr);
1099 return 0;
1100 }
1101 }
1102
1103 return 1;
1104}
1105
1106struct bgp_info_pair
1107{
1108 struct bgp_info *old;
1109 struct bgp_info *new;
1110};
1111
paul94f2b392005-06-28 12:44:16 +00001112static void
paulfee0f4c2004-09-13 05:12:46 +00001113bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1114{
paul718e3742002-12-13 20:15:29 +00001115 struct bgp_info *new_select;
1116 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001117 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001118 struct bgp_info *ri1;
1119 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001120 struct bgp_info *nextri = NULL;
1121
paul718e3742002-12-13 20:15:29 +00001122 /* bgp deterministic-med */
1123 new_select = NULL;
1124 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1125 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1126 {
1127 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1128 continue;
1129 if (BGP_INFO_HOLDDOWN (ri1))
1130 continue;
1131
1132 new_select = ri1;
1133 if (ri1->next)
1134 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1135 {
1136 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1137 continue;
1138 if (BGP_INFO_HOLDDOWN (ri2))
1139 continue;
1140
1141 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1142 || aspath_cmp_left_confed (ri1->attr->aspath,
1143 ri2->attr->aspath))
1144 {
1145 if (bgp_info_cmp (bgp, ri2, new_select))
1146 {
1147 UNSET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
1148 new_select = ri2;
1149 }
1150
1151 SET_FLAG (ri2->flags, BGP_INFO_DMED_CHECK);
1152 }
1153 }
1154 SET_FLAG (new_select->flags, BGP_INFO_DMED_CHECK);
1155 SET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
1156 }
1157
1158 /* Check old selected route and new selected route. */
1159 old_select = NULL;
1160 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001161 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001162 {
1163 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1164 old_select = ri;
1165
1166 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001167 {
1168 /* reap REMOVED routes, if needs be
1169 * selected route must stay for a while longer though
1170 */
1171 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1172 && (ri != old_select))
1173 bgp_info_reap (rn, ri);
1174
1175 continue;
1176 }
paul718e3742002-12-13 20:15:29 +00001177
1178 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1179 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1180 {
1181 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
1182 continue;
1183 }
1184 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
1185 UNSET_FLAG (ri->flags, BGP_INFO_DMED_SELECTED);
1186
1187 if (bgp_info_cmp (bgp, ri, new_select))
1188 new_select = ri;
1189 }
paulb40d9392005-08-22 22:34:41 +00001190
paulfee0f4c2004-09-13 05:12:46 +00001191 result->old = old_select;
1192 result->new = new_select;
1193
1194 return;
1195}
1196
paul94f2b392005-06-28 12:44:16 +00001197static int
paulfee0f4c2004-09-13 05:12:46 +00001198bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1199 struct bgp_node *rn, struct attr *attr, afi_t afi, safi_t safi)
1200 {
1201 struct prefix *p;
1202
1203 p = &rn->p;
1204
1205 /* Announce route to Established peer. */
1206 if (peer->status != Established)
1207 return 0;
1208
1209 /* Address family configuration check. */
1210 if (! peer->afc_nego[afi][safi])
1211 return 0;
1212
1213 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1214 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1215 PEER_STATUS_ORF_WAIT_REFRESH))
1216 return 0;
1217
1218 switch (rn->table->type)
1219 {
1220 case BGP_TABLE_MAIN:
1221 /* Announcement to peer->conf. If the route is filtered,
1222 withdraw it. */
1223 if (selected && bgp_announce_check (selected, peer, p, attr, afi, safi))
1224 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1225 else
1226 bgp_adj_out_unset (rn, peer, p, afi, safi);
1227 break;
1228 case BGP_TABLE_RSCLIENT:
1229 /* Announcement to peer->conf. If the route is filtered,
1230 withdraw it. */
1231 if (selected && bgp_announce_check_rsclient
1232 (selected, peer, p, attr, afi, safi))
1233 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1234 else
1235 bgp_adj_out_unset (rn, peer, p, afi, safi);
1236 break;
1237 }
1238 return 0;
paul200df112005-06-01 11:17:05 +00001239}
paulfee0f4c2004-09-13 05:12:46 +00001240
paul200df112005-06-01 11:17:05 +00001241struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001242{
paul200df112005-06-01 11:17:05 +00001243 struct bgp *bgp;
1244 struct bgp_node *rn;
1245 afi_t afi;
1246 safi_t safi;
1247};
1248
1249static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001250bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001251{
paul0fb58d52005-11-14 14:31:49 +00001252 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001253 struct bgp *bgp = pq->bgp;
1254 struct bgp_node *rn = pq->rn;
1255 afi_t afi = pq->afi;
1256 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001257 struct bgp_info *new_select;
1258 struct bgp_info *old_select;
1259 struct bgp_info_pair old_and_new;
1260 struct attr attr;
paul1eb8ef22005-04-07 07:30:20 +00001261 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001262 struct peer *rsclient = rn->table->owner;
1263
paulfee0f4c2004-09-13 05:12:46 +00001264 /* Best path selection. */
1265 bgp_best_selection (bgp, rn, &old_and_new);
1266 new_select = old_and_new.new;
1267 old_select = old_and_new.old;
1268
paul200df112005-06-01 11:17:05 +00001269 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1270 {
1271 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1272 {
1273 /* Nothing to do. */
1274 if (old_select && old_select == new_select)
1275 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1276 continue;
paulfee0f4c2004-09-13 05:12:46 +00001277
paul200df112005-06-01 11:17:05 +00001278 if (old_select)
1279 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1280 if (new_select)
1281 {
1282 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1283 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1284 }
paulfee0f4c2004-09-13 05:12:46 +00001285
paul200df112005-06-01 11:17:05 +00001286 bgp_process_announce_selected (rsclient, new_select, rn, &attr,
1287 afi, safi);
1288 }
1289 }
1290 else
1291 {
hassob7395792005-08-26 12:58:38 +00001292 if (old_select)
1293 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1294 if (new_select)
1295 {
1296 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1297 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1298 }
paul200df112005-06-01 11:17:05 +00001299 bgp_process_announce_selected (rsclient, new_select, rn,
1300 &attr, afi, safi);
1301 }
paulfee0f4c2004-09-13 05:12:46 +00001302
paulb40d9392005-08-22 22:34:41 +00001303 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1304 bgp_info_reap (rn, old_select);
1305
paul200df112005-06-01 11:17:05 +00001306 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1307 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001308}
1309
paul200df112005-06-01 11:17:05 +00001310static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001311bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001312{
paul0fb58d52005-11-14 14:31:49 +00001313 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001314 struct bgp *bgp = pq->bgp;
1315 struct bgp_node *rn = pq->rn;
1316 afi_t afi = pq->afi;
1317 safi_t safi = pq->safi;
1318 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001319 struct bgp_info *new_select;
1320 struct bgp_info *old_select;
1321 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001322 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001323 struct peer *peer;
1324 struct attr attr;
paul200df112005-06-01 11:17:05 +00001325
paulfee0f4c2004-09-13 05:12:46 +00001326 /* Best path selection. */
1327 bgp_best_selection (bgp, rn, &old_and_new);
1328 old_select = old_and_new.old;
1329 new_select = old_and_new.new;
1330
1331 /* Nothing to do. */
1332 if (old_select && old_select == new_select)
1333 {
1334 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001335 {
1336 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1337 bgp_zebra_announce (p, old_select, bgp);
1338
1339 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1340 return WQ_SUCCESS;
1341 }
paulfee0f4c2004-09-13 05:12:46 +00001342 }
paul718e3742002-12-13 20:15:29 +00001343
hasso338b3422005-02-23 14:27:24 +00001344 if (old_select)
1345 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1346 if (new_select)
1347 {
1348 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1349 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1350 }
1351
1352
paul718e3742002-12-13 20:15:29 +00001353 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001354 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001355 {
paulfee0f4c2004-09-13 05:12:46 +00001356 bgp_process_announce_selected (peer, new_select, rn, &attr, afi, safi);
paul718e3742002-12-13 20:15:29 +00001357 }
1358
1359 /* FIB update. */
1360 if (safi == SAFI_UNICAST && ! bgp->name &&
1361 ! bgp_option_check (BGP_OPT_NO_FIB))
1362 {
1363 if (new_select
1364 && new_select->type == ZEBRA_ROUTE_BGP
1365 && new_select->sub_type == BGP_ROUTE_NORMAL)
1366 bgp_zebra_announce (p, new_select, bgp);
1367 else
1368 {
1369 /* Withdraw the route from the kernel. */
1370 if (old_select
1371 && old_select->type == ZEBRA_ROUTE_BGP
1372 && old_select->sub_type == BGP_ROUTE_NORMAL)
1373 bgp_zebra_withdraw (p, old_select);
1374 }
1375 }
paulb40d9392005-08-22 22:34:41 +00001376
1377 /* Reap old select bgp_info, it it has been removed */
1378 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1379 bgp_info_reap (rn, old_select);
1380
paul200df112005-06-01 11:17:05 +00001381 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1382 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001383}
1384
paul200df112005-06-01 11:17:05 +00001385static void
paul0fb58d52005-11-14 14:31:49 +00001386bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001387{
paul0fb58d52005-11-14 14:31:49 +00001388 struct bgp_process_queue *pq = data;
1389
paul200df112005-06-01 11:17:05 +00001390 bgp_unlock_node (pq->rn);
1391 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1392}
1393
1394static void
1395bgp_process_queue_init (void)
1396{
1397 bm->process_main_queue
1398 = work_queue_new (bm->master, "process_main_queue");
1399 bm->process_rsclient_queue
1400 = work_queue_new (bm->master, "process_rsclient_queue");
1401
1402 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1403 {
1404 zlog_err ("%s: Failed to allocate work queue", __func__);
1405 exit (1);
1406 }
1407
1408 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1409 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1410 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1411 bm->process_rsclient_queue->spec.del_item_data
1412 = bm->process_main_queue->spec.del_item_data;
1413 bm->process_main_queue->spec.max_retries
1414 = bm->process_main_queue->spec.max_retries = 0;
1415 bm->process_rsclient_queue->spec.hold
1416 = bm->process_main_queue->spec.hold = 500;
paul200df112005-06-01 11:17:05 +00001417}
1418
1419void
paulfee0f4c2004-09-13 05:12:46 +00001420bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1421{
paul200df112005-06-01 11:17:05 +00001422 struct bgp_process_queue *pqnode;
1423
1424 /* already scheduled for processing? */
1425 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1426 return;
1427
1428 if ( (bm->process_main_queue == NULL) ||
1429 (bm->process_rsclient_queue == NULL) )
1430 bgp_process_queue_init ();
1431
1432 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1433 sizeof (struct bgp_process_queue));
1434 if (!pqnode)
1435 return;
1436
1437 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1438 pqnode->bgp = bgp;
1439 pqnode->afi = afi;
1440 pqnode->safi = safi;
1441
paulfee0f4c2004-09-13 05:12:46 +00001442 switch (rn->table->type)
1443 {
paul200df112005-06-01 11:17:05 +00001444 case BGP_TABLE_MAIN:
1445 work_queue_add (bm->process_main_queue, pqnode);
1446 break;
1447 case BGP_TABLE_RSCLIENT:
1448 work_queue_add (bm->process_rsclient_queue, pqnode);
1449 break;
paulfee0f4c2004-09-13 05:12:46 +00001450 }
paul200df112005-06-01 11:17:05 +00001451
1452 return;
paulfee0f4c2004-09-13 05:12:46 +00001453}
hasso0a486e52005-02-01 20:57:17 +00001454
paul94f2b392005-06-28 12:44:16 +00001455static int
hasso0a486e52005-02-01 20:57:17 +00001456bgp_maximum_prefix_restart_timer (struct thread *thread)
1457{
1458 struct peer *peer;
1459
1460 peer = THREAD_ARG (thread);
1461 peer->t_pmax_restart = NULL;
1462
1463 if (BGP_DEBUG (events, EVENTS))
1464 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1465 peer->host);
1466
1467 peer_clear (peer);
1468
1469 return 0;
1470}
1471
paulfee0f4c2004-09-13 05:12:46 +00001472int
paul5228ad22004-06-04 17:58:18 +00001473bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1474 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001475{
hassoe0701b72004-05-20 09:19:34 +00001476 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1477 return 0;
1478
1479 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001480 {
hassoe0701b72004-05-20 09:19:34 +00001481 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1482 && ! always)
1483 return 0;
paul718e3742002-12-13 20:15:29 +00001484
hassoe0701b72004-05-20 09:19:34 +00001485 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001486 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1487 "limit %ld", afi_safi_print (afi, safi), peer->host,
1488 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001489 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001490
hassoe0701b72004-05-20 09:19:34 +00001491 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1492 return 0;
paul718e3742002-12-13 20:15:29 +00001493
hassoe0701b72004-05-20 09:19:34 +00001494 {
paul5228ad22004-06-04 17:58:18 +00001495 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001496
1497 if (safi == SAFI_MPLS_VPN)
1498 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001499
1500 ndata[0] = (afi >> 8);
1501 ndata[1] = afi;
1502 ndata[2] = safi;
1503 ndata[3] = (peer->pmax[afi][safi] >> 24);
1504 ndata[4] = (peer->pmax[afi][safi] >> 16);
1505 ndata[5] = (peer->pmax[afi][safi] >> 8);
1506 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001507
1508 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1509 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1510 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1511 }
hasso0a486e52005-02-01 20:57:17 +00001512
1513 /* restart timer start */
1514 if (peer->pmax_restart[afi][safi])
1515 {
1516 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1517
1518 if (BGP_DEBUG (events, EVENTS))
1519 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1520 peer->host, peer->v_pmax_restart);
1521
1522 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1523 peer->v_pmax_restart);
1524 }
1525
hassoe0701b72004-05-20 09:19:34 +00001526 return 1;
paul718e3742002-12-13 20:15:29 +00001527 }
hassoe0701b72004-05-20 09:19:34 +00001528 else
1529 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1530
1531 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1532 {
1533 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1534 && ! always)
1535 return 0;
1536
1537 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001538 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1539 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1540 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001541 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1542 }
1543 else
1544 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001545 return 0;
1546}
1547
paul902212c2006-02-05 17:51:19 +00001548static void
1549bgp_pcount_increment (struct bgp_node *rn, struct bgp_info *ri,
1550 afi_t afi, safi_t safi)
1551{
1552 assert (ri && rn);
1553
1554 if (!CHECK_FLAG (ri->flags, BGP_INFO_COUNTED)
1555 && rn->table->type == BGP_TABLE_MAIN)
1556 {
1557 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
1558 ri->peer->pcount[afi][safi]++;
1559 }
1560}
1561
1562static void
1563bgp_pcount_decrement (struct bgp_node *rn, struct bgp_info *ri,
1564 afi_t afi, safi_t safi)
1565{
1566 /* Ignore 'pcount' for RS-client tables */
1567 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED)
1568 && rn->table->type == BGP_TABLE_MAIN)
1569 {
1570 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
1571
1572 /* slight hack, but more robust against errors. */
1573 if (ri->peer->pcount[afi][safi])
1574 ri->peer->pcount[afi][safi]--;
1575 else
1576 {
1577 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
1578 __func__, ri->peer->host);
1579 zlog_backtrace (LOG_WARNING);
1580 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
1581 }
1582 }
1583}
1584
paulb40d9392005-08-22 22:34:41 +00001585/* Unconditionally remove the route from the RIB, without taking
1586 * damping into consideration (eg, because the session went down)
1587 */
paul94f2b392005-06-28 12:44:16 +00001588static void
paul718e3742002-12-13 20:15:29 +00001589bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1590 afi_t afi, safi_t safi)
1591{
paul902212c2006-02-05 17:51:19 +00001592 bgp_pcount_decrement (rn, ri, afi, safi);
1593 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1594
1595 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1596 bgp_info_delete (rn, ri); /* keep historical info */
1597
paulb40d9392005-08-22 22:34:41 +00001598 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001599}
1600
paul94f2b392005-06-28 12:44:16 +00001601static void
paul718e3742002-12-13 20:15:29 +00001602bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001603 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001604{
paul718e3742002-12-13 20:15:29 +00001605 int status = BGP_DAMP_NONE;
1606
paulb40d9392005-08-22 22:34:41 +00001607 /* apply dampening, if result is suppressed, we'll be retaining
1608 * the bgp_info in the RIB for historical reference.
1609 */
1610 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1611 && peer_sort (peer) == BGP_PEER_EBGP)
1612 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1613 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001614 {
1615 bgp_pcount_decrement (rn, ri, afi, safi);
1616 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1617 return;
1618 }
1619
1620 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001621}
1622
paul94f2b392005-06-28 12:44:16 +00001623static void
paulfee0f4c2004-09-13 05:12:46 +00001624bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1625 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1626 int sub_type, struct prefix_rd *prd, u_char *tag)
1627{
1628 struct bgp_node *rn;
1629 struct bgp *bgp;
1630 struct attr new_attr;
1631 struct attr *attr_new;
1632 struct attr *attr_new2;
1633 struct bgp_info *ri;
1634 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001635 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001636 char buf[SU_ADDRSTRLEN];
1637
1638 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1639 if (peer == rsclient)
1640 return;
1641
1642 bgp = peer->bgp;
1643 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1644
1645 /* Check previously received route. */
1646 for (ri = rn->info; ri; ri = ri->next)
1647 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1648 break;
1649
1650 /* AS path loop check. */
1651 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1652 {
1653 reason = "as-path contains our own AS;";
1654 goto filtered;
1655 }
1656
1657 /* Route reflector originator ID check. */
1658 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1659 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->originator_id))
1660 {
1661 reason = "originator is us;";
1662 goto filtered;
1663 }
1664
1665 new_attr = *attr;
1666
1667 /* Apply export policy. */
1668 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1669 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1670 {
1671 reason = "export-policy;";
1672 goto filtered;
1673 }
1674
1675 attr_new2 = bgp_attr_intern (&new_attr);
1676
1677 /* Apply import policy. */
1678 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1679 {
1680 bgp_attr_unintern (attr_new2);
1681
1682 reason = "import-policy;";
1683 goto filtered;
1684 }
1685
1686 attr_new = bgp_attr_intern (&new_attr);
1687 bgp_attr_unintern (attr_new2);
1688
1689 /* IPv4 unicast next hop check. */
1690 if (afi == AFI_IP && safi == SAFI_UNICAST)
1691 {
1692 /* Next hop must not be 0.0.0.0 nor Class E address. */
1693 if (new_attr.nexthop.s_addr == 0
1694 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1695 {
1696 bgp_attr_unintern (attr_new);
1697
1698 reason = "martian next-hop;";
1699 goto filtered;
1700 }
1701 }
1702
1703 /* If the update is implicit withdraw. */
1704 if (ri)
1705 {
1706 ri->uptime = time (NULL);
1707
1708 /* Same attribute comes in. */
1709 if (attrhash_cmp (ri->attr, attr_new))
1710 {
1711
1712 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1713
1714 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001715 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001716 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1717 peer->host,
1718 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1719 p->prefixlen, rsclient->host);
1720
1721 bgp_unlock_node (rn);
1722 bgp_attr_unintern (attr_new);
1723
1724 return;
1725 }
1726
1727 /* Received Logging. */
1728 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001729 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001730 peer->host,
1731 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1732 p->prefixlen, rsclient->host);
1733
1734 /* The attribute is changed. */
1735 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1736
1737 /* Update to new attribute. */
1738 bgp_attr_unintern (ri->attr);
1739 ri->attr = attr_new;
1740
1741 /* Update MPLS tag. */
1742 if (safi == SAFI_MPLS_VPN)
1743 memcpy (ri->tag, tag, 3);
1744
1745 SET_FLAG (ri->flags, BGP_INFO_VALID);
1746
1747 /* Process change. */
1748 bgp_process (bgp, rn, afi, safi);
1749 bgp_unlock_node (rn);
1750
1751 return;
1752 }
1753
1754 /* Received Logging. */
1755 if (BGP_DEBUG (update, UPDATE_IN))
1756 {
ajsd2c1f162004-12-08 21:10:20 +00001757 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001758 peer->host,
1759 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1760 p->prefixlen, rsclient->host);
1761 }
1762
1763 /* Make new BGP info. */
1764 new = bgp_info_new ();
1765 new->type = type;
1766 new->sub_type = sub_type;
1767 new->peer = peer;
1768 new->attr = attr_new;
1769 new->uptime = time (NULL);
1770
1771 /* Update MPLS tag. */
1772 if (safi == SAFI_MPLS_VPN)
1773 memcpy (new->tag, tag, 3);
1774
1775 SET_FLAG (new->flags, BGP_INFO_VALID);
1776
1777 /* Register new BGP information. */
1778 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001779
1780 /* route_node_get lock */
1781 bgp_unlock_node (rn);
1782
paulfee0f4c2004-09-13 05:12:46 +00001783 /* Process change. */
1784 bgp_process (bgp, rn, afi, safi);
1785
1786 return;
1787
1788 filtered:
1789
1790 /* This BGP update is filtered. Log the reason then update BGP entry. */
1791 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001792 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001793 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1794 peer->host,
1795 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1796 p->prefixlen, rsclient->host, reason);
1797
1798 if (ri)
paulb40d9392005-08-22 22:34:41 +00001799 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001800
1801 bgp_unlock_node (rn);
1802
1803 return;
1804}
1805
paul94f2b392005-06-28 12:44:16 +00001806static void
paulfee0f4c2004-09-13 05:12:46 +00001807bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1808 struct peer *peer, struct prefix *p, int type, int sub_type,
1809 struct prefix_rd *prd, u_char *tag)
1810 {
1811 struct bgp_node *rn;
1812 struct bgp_info *ri;
1813 char buf[SU_ADDRSTRLEN];
1814
1815 if (rsclient == peer)
1816 return;
1817
1818 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1819
1820 /* Lookup withdrawn route. */
1821 for (ri = rn->info; ri; ri = ri->next)
1822 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1823 break;
1824
1825 /* Withdraw specified route from routing table. */
1826 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001827 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001828 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001829 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001830 "%s Can't find the route %s/%d", peer->host,
1831 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1832 p->prefixlen);
1833
1834 /* Unlock bgp_node_get() lock. */
1835 bgp_unlock_node (rn);
1836 }
1837
paul94f2b392005-06-28 12:44:16 +00001838static int
paulfee0f4c2004-09-13 05:12:46 +00001839bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001840 afi_t afi, safi_t safi, int type, int sub_type,
1841 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1842{
1843 int ret;
1844 int aspath_loop_count = 0;
1845 struct bgp_node *rn;
1846 struct bgp *bgp;
1847 struct attr new_attr;
1848 struct attr *attr_new;
1849 struct bgp_info *ri;
1850 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001851 const char *reason;
paul718e3742002-12-13 20:15:29 +00001852 char buf[SU_ADDRSTRLEN];
1853
1854 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00001855 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00001856
1857 /* When peer's soft reconfiguration enabled. Record input packet in
1858 Adj-RIBs-In. */
1859 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1860 && peer != bgp->peer_self && ! soft_reconfig)
1861 bgp_adj_in_set (rn, peer, attr);
1862
1863 /* Check previously received route. */
1864 for (ri = rn->info; ri; ri = ri->next)
1865 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1866 break;
1867
1868 /* AS path local-as loop check. */
1869 if (peer->change_local_as)
1870 {
1871 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
1872 aspath_loop_count = 1;
1873
1874 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
1875 {
1876 reason = "as-path contains our own AS;";
1877 goto filtered;
1878 }
1879 }
1880
1881 /* AS path loop check. */
1882 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
1883 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
1884 && aspath_loop_check(attr->aspath, bgp->confed_id)
1885 > peer->allowas_in[afi][safi]))
1886 {
1887 reason = "as-path contains our own AS;";
1888 goto filtered;
1889 }
1890
1891 /* Route reflector originator ID check. */
1892 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1893 && IPV4_ADDR_SAME (&bgp->router_id, &attr->originator_id))
1894 {
1895 reason = "originator is us;";
1896 goto filtered;
1897 }
1898
1899 /* Route reflector cluster ID check. */
1900 if (bgp_cluster_filter (peer, attr))
1901 {
1902 reason = "reflected from the same cluster;";
1903 goto filtered;
1904 }
1905
1906 /* Apply incoming filter. */
1907 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
1908 {
1909 reason = "filter;";
1910 goto filtered;
1911 }
1912
1913 /* Apply incoming route-map. */
1914 new_attr = *attr;
1915
1916 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
1917 {
1918 reason = "route-map;";
1919 goto filtered;
1920 }
1921
1922 /* IPv4 unicast next hop check. */
1923 if (afi == AFI_IP && safi == SAFI_UNICAST)
1924 {
1925 /* If the peer is EBGP and nexthop is not on connected route,
1926 discard it. */
1927 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
1928 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00001929 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00001930 {
1931 reason = "non-connected next-hop;";
1932 goto filtered;
1933 }
1934
1935 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
1936 must not be my own address. */
1937 if (bgp_nexthop_self (afi, &new_attr)
1938 || new_attr.nexthop.s_addr == 0
1939 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1940 {
1941 reason = "martian next-hop;";
1942 goto filtered;
1943 }
1944 }
1945
1946 attr_new = bgp_attr_intern (&new_attr);
1947
1948 /* If the update is implicit withdraw. */
1949 if (ri)
1950 {
1951 ri->uptime = time (NULL);
1952
1953 /* Same attribute comes in. */
1954 if (attrhash_cmp (ri->attr, attr_new))
1955 {
1956 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1957
1958 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1959 && peer_sort (peer) == BGP_PEER_EBGP
1960 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1961 {
1962 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001963 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00001964 peer->host,
1965 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1966 p->prefixlen);
1967
paul902212c2006-02-05 17:51:19 +00001968 bgp_pcount_increment (rn, ri, afi, safi);
1969
1970 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
1971 {
1972 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1973 bgp_process (bgp, rn, afi, safi);
1974 }
paul718e3742002-12-13 20:15:29 +00001975 }
1976 else
1977 {
1978 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001979 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00001980 "%s rcvd %s/%d...duplicate ignored",
1981 peer->host,
1982 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1983 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00001984
1985 /* graceful restart STALE flag unset. */
1986 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1987 {
1988 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00001989 bgp_pcount_increment (rn, ri, afi, safi);
1990 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00001991 }
paul718e3742002-12-13 20:15:29 +00001992 }
1993
1994 bgp_unlock_node (rn);
1995 bgp_attr_unintern (attr_new);
1996 return 0;
1997 }
1998
1999 /* Received Logging. */
2000 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002001 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002002 peer->host,
2003 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2004 p->prefixlen);
2005
hasso93406d82005-02-02 14:40:33 +00002006 /* graceful restart STALE flag unset. */
2007 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
paul902212c2006-02-05 17:51:19 +00002008 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002009
paul718e3742002-12-13 20:15:29 +00002010 /* The attribute is changed. */
2011 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002012
2013 /* implicit withdraw, decrement aggregate and pcount here.
2014 * only if update is accepted, they'll increment below.
2015 */
2016 bgp_pcount_decrement (rn, ri, afi, safi);
2017 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2018
paul718e3742002-12-13 20:15:29 +00002019 /* Update bgp route dampening information. */
2020 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2021 && peer_sort (peer) == BGP_PEER_EBGP)
2022 {
2023 /* This is implicit withdraw so we should update dampening
2024 information. */
2025 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2026 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002027 }
2028
paul718e3742002-12-13 20:15:29 +00002029 /* Update to new attribute. */
2030 bgp_attr_unintern (ri->attr);
2031 ri->attr = attr_new;
2032
2033 /* Update MPLS tag. */
2034 if (safi == SAFI_MPLS_VPN)
2035 memcpy (ri->tag, tag, 3);
2036
2037 /* Update bgp route dampening information. */
2038 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2039 && peer_sort (peer) == BGP_PEER_EBGP)
2040 {
2041 /* Now we do normal update dampening. */
2042 ret = bgp_damp_update (ri, rn, afi, safi);
2043 if (ret == BGP_DAMP_SUPPRESSED)
2044 {
2045 bgp_unlock_node (rn);
2046 return 0;
2047 }
2048 }
2049
2050 /* Nexthop reachability check. */
2051 if ((afi == AFI_IP || afi == AFI_IP6)
2052 && safi == SAFI_UNICAST
2053 && (peer_sort (peer) == BGP_PEER_IBGP
2054 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002055 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002056 {
2057 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
2058 SET_FLAG (ri->flags, BGP_INFO_VALID);
2059 else
2060 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2061 }
2062 else
2063 SET_FLAG (ri->flags, BGP_INFO_VALID);
2064
2065 /* Process change. */
paul902212c2006-02-05 17:51:19 +00002066 bgp_pcount_increment (rn, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00002067 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2068
2069 bgp_process (bgp, rn, afi, safi);
2070 bgp_unlock_node (rn);
2071 return 0;
2072 }
2073
2074 /* Received Logging. */
2075 if (BGP_DEBUG (update, UPDATE_IN))
2076 {
ajsd2c1f162004-12-08 21:10:20 +00002077 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002078 peer->host,
2079 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2080 p->prefixlen);
2081 }
2082
paul718e3742002-12-13 20:15:29 +00002083 /* Make new BGP info. */
2084 new = bgp_info_new ();
2085 new->type = type;
2086 new->sub_type = sub_type;
2087 new->peer = peer;
2088 new->attr = attr_new;
2089 new->uptime = time (NULL);
2090
2091 /* Update MPLS tag. */
2092 if (safi == SAFI_MPLS_VPN)
2093 memcpy (new->tag, tag, 3);
2094
2095 /* Nexthop reachability check. */
2096 if ((afi == AFI_IP || afi == AFI_IP6)
2097 && safi == SAFI_UNICAST
2098 && (peer_sort (peer) == BGP_PEER_IBGP
2099 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002100 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002101 {
2102 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
2103 SET_FLAG (new->flags, BGP_INFO_VALID);
2104 else
2105 UNSET_FLAG (new->flags, BGP_INFO_VALID);
2106 }
2107 else
2108 SET_FLAG (new->flags, BGP_INFO_VALID);
2109
paul902212c2006-02-05 17:51:19 +00002110 /* Increment prefix */
2111 bgp_pcount_increment (rn, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00002112 bgp_aggregate_increment (bgp, p, new, afi, safi);
2113
2114 /* Register new BGP information. */
2115 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002116
2117 /* route_node_get lock */
2118 bgp_unlock_node (rn);
2119
paul718e3742002-12-13 20:15:29 +00002120 /* If maximum prefix count is configured and current prefix
2121 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002122 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2123 return -1;
paul718e3742002-12-13 20:15:29 +00002124
2125 /* Process change. */
2126 bgp_process (bgp, rn, afi, safi);
2127
2128 return 0;
2129
2130 /* This BGP update is filtered. Log the reason then update BGP
2131 entry. */
2132 filtered:
2133 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002134 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002135 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2136 peer->host,
2137 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2138 p->prefixlen, reason);
2139
2140 if (ri)
paulb40d9392005-08-22 22:34:41 +00002141 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002142
2143 bgp_unlock_node (rn);
2144
2145 return 0;
2146}
2147
2148int
paulfee0f4c2004-09-13 05:12:46 +00002149bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2150 afi_t afi, safi_t safi, int type, int sub_type,
2151 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2152{
2153 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002154 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002155 struct bgp *bgp;
2156 int ret;
2157
2158 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2159 soft_reconfig);
2160
2161 bgp = peer->bgp;
2162
2163 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002164 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002165 {
2166 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2167 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2168 sub_type, prd, tag);
2169 }
2170
2171 return ret;
2172}
2173
2174int
paul718e3742002-12-13 20:15:29 +00002175bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002176 afi_t afi, safi_t safi, int type, int sub_type,
2177 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002178{
2179 struct bgp *bgp;
2180 char buf[SU_ADDRSTRLEN];
2181 struct bgp_node *rn;
2182 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002183 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002184 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002185
2186 bgp = peer->bgp;
2187
paulfee0f4c2004-09-13 05:12:46 +00002188 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002189 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002190 {
2191 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2192 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2193 }
2194
paul718e3742002-12-13 20:15:29 +00002195 /* Logging. */
2196 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002197 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002198 peer->host,
2199 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2200 p->prefixlen);
2201
2202 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002203 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002204
2205 /* If peer is soft reconfiguration enabled. Record input packet for
2206 further calculation. */
2207 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2208 && peer != bgp->peer_self)
2209 bgp_adj_in_unset (rn, peer);
2210
2211 /* Lookup withdrawn route. */
2212 for (ri = rn->info; ri; ri = ri->next)
2213 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2214 break;
2215
2216 /* Withdraw specified route from routing table. */
2217 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002218 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002219 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002220 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002221 "%s Can't find the route %s/%d", peer->host,
2222 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2223 p->prefixlen);
2224
2225 /* Unlock bgp_node_get() lock. */
2226 bgp_unlock_node (rn);
2227
2228 return 0;
2229}
2230
2231void
2232bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2233{
2234 struct bgp *bgp;
2235 struct attr attr;
2236 struct aspath *aspath;
2237 struct prefix p;
2238 struct bgp_info binfo;
2239 struct peer *from;
2240 int ret = RMAP_DENYMATCH;
2241
2242 bgp = peer->bgp;
2243 from = bgp->peer_self;
2244
2245 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2246 aspath = attr.aspath;
2247 attr.local_pref = bgp->default_local_pref;
2248 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2249
2250 if (afi == AFI_IP)
2251 str2prefix ("0.0.0.0/0", &p);
2252#ifdef HAVE_IPV6
2253 else if (afi == AFI_IP6)
2254 {
2255 str2prefix ("::/0", &p);
2256
2257 /* IPv6 global nexthop must be included. */
2258 memcpy (&attr.mp_nexthop_global, &peer->nexthop.v6_global,
2259 IPV6_MAX_BYTELEN);
2260 attr.mp_nexthop_len = 16;
2261
2262 /* If the peer is on shared nextwork and we have link-local
2263 nexthop set it. */
2264 if (peer->shared_network
2265 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2266 {
2267 memcpy (&attr.mp_nexthop_local, &peer->nexthop.v6_local,
2268 IPV6_MAX_BYTELEN);
2269 attr.mp_nexthop_len = 32;
2270 }
2271 }
2272#endif /* HAVE_IPV6 */
2273 else
2274 return;
2275
2276 if (peer->default_rmap[afi][safi].name)
2277 {
2278 binfo.peer = bgp->peer_self;
2279 binfo.attr = &attr;
2280
paulfee0f4c2004-09-13 05:12:46 +00002281 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2282
paul718e3742002-12-13 20:15:29 +00002283 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2284 RMAP_BGP, &binfo);
2285
paulfee0f4c2004-09-13 05:12:46 +00002286 bgp->peer_self->rmap_type = 0;
2287
paul718e3742002-12-13 20:15:29 +00002288 if (ret == RMAP_DENYMATCH)
2289 {
2290 bgp_attr_flush (&attr);
2291 withdraw = 1;
2292 }
2293 }
2294
2295 if (withdraw)
2296 {
2297 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2298 bgp_default_withdraw_send (peer, afi, safi);
2299 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2300 }
2301 else
2302 {
2303 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2304 bgp_default_update_send (peer, &attr, afi, safi, from);
2305 }
2306
2307 aspath_unintern (aspath);
2308}
2309
2310static void
2311bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002312 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002313{
2314 struct bgp_node *rn;
2315 struct bgp_info *ri;
2316 struct attr attr;
2317
2318 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002319 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002320
2321 if (safi != SAFI_MPLS_VPN
2322 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2323 bgp_default_originate (peer, afi, safi, 0);
2324
2325 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2326 for (ri = rn->info; ri; ri = ri->next)
2327 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2328 {
paulfee0f4c2004-09-13 05:12:46 +00002329 if ( (rsclient) ?
2330 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2331 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002332 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2333 else
2334 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2335 }
2336}
2337
2338void
2339bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2340{
2341 struct bgp_node *rn;
2342 struct bgp_table *table;
2343
2344 if (peer->status != Established)
2345 return;
2346
2347 if (! peer->afc_nego[afi][safi])
2348 return;
2349
2350 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2351 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2352 return;
2353
2354 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002355 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002356 else
2357 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2358 rn = bgp_route_next(rn))
2359 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002360 bgp_announce_table (peer, afi, safi, table, 0);
2361
2362 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2363 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002364}
2365
2366void
2367bgp_announce_route_all (struct peer *peer)
2368{
2369 afi_t afi;
2370 safi_t safi;
2371
2372 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2373 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2374 bgp_announce_route (peer, afi, safi);
2375}
2376
2377static void
paulfee0f4c2004-09-13 05:12:46 +00002378bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2379 safi_t safi, struct bgp_table *table)
2380{
2381 struct bgp_node *rn;
2382 struct bgp_adj_in *ain;
2383
2384 if (! table)
2385 table = rsclient->bgp->rib[afi][safi];
2386
2387 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2388 for (ain = rn->adj_in; ain; ain = ain->next)
2389 {
2390 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2391 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2392 }
2393}
2394
2395void
2396bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2397{
2398 struct bgp_table *table;
2399 struct bgp_node *rn;
2400
2401 if (safi != SAFI_MPLS_VPN)
2402 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2403
2404 else
2405 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2406 rn = bgp_route_next (rn))
2407 if ((table = rn->info) != NULL)
2408 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2409}
2410
2411static void
paul718e3742002-12-13 20:15:29 +00002412bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2413 struct bgp_table *table)
2414{
2415 int ret;
2416 struct bgp_node *rn;
2417 struct bgp_adj_in *ain;
2418
2419 if (! table)
2420 table = peer->bgp->rib[afi][safi];
2421
2422 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2423 for (ain = rn->adj_in; ain; ain = ain->next)
2424 {
2425 if (ain->peer == peer)
2426 {
2427 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2428 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2429 NULL, NULL, 1);
2430 if (ret < 0)
2431 {
2432 bgp_unlock_node (rn);
2433 return;
2434 }
2435 continue;
2436 }
2437 }
2438}
2439
2440void
2441bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2442{
2443 struct bgp_node *rn;
2444 struct bgp_table *table;
2445
2446 if (peer->status != Established)
2447 return;
2448
2449 if (safi != SAFI_MPLS_VPN)
2450 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2451 else
2452 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2453 rn = bgp_route_next (rn))
2454 if ((table = rn->info) != NULL)
2455 bgp_soft_reconfig_table (peer, afi, safi, table);
2456}
2457
paul200df112005-06-01 11:17:05 +00002458static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002459bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002460{
Paul Jakma64e580a2006-02-21 01:09:01 +00002461 struct bgp_node *rn = data;
2462 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002463 struct bgp_adj_in *ain;
2464 struct bgp_adj_out *aout;
2465 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002466 afi_t afi = rn->table->afi;
2467 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002468
Paul Jakma64e580a2006-02-21 01:09:01 +00002469 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002470
Paul Jakma64e580a2006-02-21 01:09:01 +00002471 for (ri = rn->info; ri; ri = ri->next)
2472 if (ri->peer == peer)
paul200df112005-06-01 11:17:05 +00002473 {
2474 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002475 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2476 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002477 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2478 && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
paul902212c2006-02-05 17:51:19 +00002479 && ! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
2480 && ! CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
paul200df112005-06-01 11:17:05 +00002481 {
Paul Jakma64e580a2006-02-21 01:09:01 +00002482 bgp_pcount_decrement (rn, ri, afi, safi);
paul200df112005-06-01 11:17:05 +00002483 SET_FLAG (ri->flags, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002484 }
2485 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002486 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002487 break;
2488 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002489 for (ain = rn->adj_in; ain; ain = ain->next)
2490 if (ain->peer == peer)
paul200df112005-06-01 11:17:05 +00002491 {
Paul Jakma64e580a2006-02-21 01:09:01 +00002492 bgp_adj_in_remove (rn, ain);
2493 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002494 break;
2495 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002496 for (aout = rn->adj_out; aout; aout = aout->next)
2497 if (aout->peer == peer)
paul200df112005-06-01 11:17:05 +00002498 {
Paul Jakma64e580a2006-02-21 01:09:01 +00002499 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2500 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002501 break;
2502 }
2503 return WQ_SUCCESS;
2504}
2505
2506static void
paul0fb58d52005-11-14 14:31:49 +00002507bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002508{
Paul Jakma64e580a2006-02-21 01:09:01 +00002509 struct bgp_node *rn = data;
2510
2511 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002512}
2513
2514static void
paul94f2b392005-06-28 12:44:16 +00002515bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002516{
Paul Jakma64e580a2006-02-21 01:09:01 +00002517 struct peer *peer = wq->spec.data;
2518
2519 UNSET_FLAG (peer->sflags, PEER_STATUS_CLEARING);
2520 peer_unlock (peer); /* bgp_clear_node_complete */
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002521
2522 /* Tickle FSM to start moving again */
2523 BGP_EVENT_ADD (peer, BGP_Start);
paul200df112005-06-01 11:17:05 +00002524}
2525
2526static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002527bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002528{
Paul Jakma64e580a2006-02-21 01:09:01 +00002529#define CLEAR_QUEUE_NAME_LEN 26 /* "clear 2001:123:123:123::1" */
2530 char wname[CLEAR_QUEUE_NAME_LEN];
2531
2532 snprintf (wname, CLEAR_QUEUE_NAME_LEN, "clear %s", peer->host);
2533#undef CLEAR_QUEUE_NAME_LEN
2534
2535 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002536 {
2537 zlog_err ("%s: Failed to allocate work queue", __func__);
2538 exit (1);
2539 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002540 peer->clear_node_queue->spec.hold = 10;
2541 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2542 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2543 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2544 peer->clear_node_queue->spec.max_retries = 0;
2545
2546 /* we only 'lock' this peer reference when the queue is actually active */
2547 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002548}
2549
paul718e3742002-12-13 20:15:29 +00002550static void
2551bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002552 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002553{
2554 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002555
paul718e3742002-12-13 20:15:29 +00002556 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002557 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002558
hasso6cf159b2005-03-21 10:28:14 +00002559 /* If still no table => afi/safi isn't configured at all or smth. */
2560 if (! table)
2561 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002562
2563 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2564 {
2565 if (rn->info == NULL)
2566 continue;
2567
2568 bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2569 work_queue_add (peer->clear_node_queue, rn);
2570 }
2571 return;
2572}
2573
2574void
2575bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2576{
2577 struct bgp_node *rn;
2578 struct bgp_table *table;
2579 struct peer *rsclient;
2580 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002581
Paul Jakma64e580a2006-02-21 01:09:01 +00002582 if (peer->clear_node_queue == NULL)
2583 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002584
Paul Jakma64e580a2006-02-21 01:09:01 +00002585 /* bgp_fsm.c will not bring CLEARING sessions out of Idle this
2586 * protects against peers which flap faster than we can we clear,
2587 * which could lead to:
2588 *
2589 * a) race with routes from the new session being installed before
2590 * clear_route_node visits the node (to delete the route of that
2591 * peer)
2592 * b) resource exhaustion, clear_route_node likely leads to an entry
2593 * on the process_main queue. Fast-flapping could cause that queue
2594 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002595 */
Paul Jakma64e580a2006-02-21 01:09:01 +00002596 if (!CHECK_FLAG (peer->sflags, PEER_STATUS_CLEARING))
2597 {
2598 SET_FLAG (peer->sflags, PEER_STATUS_CLEARING);
2599 peer_lock (peer); /* bgp_clear_node_complete */
2600 }
paul200df112005-06-01 11:17:05 +00002601
paul718e3742002-12-13 20:15:29 +00002602 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002603 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002604 else
2605 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2606 rn = bgp_route_next (rn))
2607 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002608 bgp_clear_route_table (peer, afi, safi, table, NULL);
2609
paul1eb8ef22005-04-07 07:30:20 +00002610 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002611 {
2612 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2613 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2614 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002615
2616 /* If no routes were cleared, nothing was added to workqueue, run the
2617 * completion function now.
2618 */
2619 if (!peer->clear_node_queue->thread)
2620 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002621}
2622
2623void
2624bgp_clear_route_all (struct peer *peer)
2625{
2626 afi_t afi;
2627 safi_t safi;
2628
2629 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2630 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2631 bgp_clear_route (peer, afi, safi);
2632}
2633
2634void
2635bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2636{
2637 struct bgp_table *table;
2638 struct bgp_node *rn;
2639 struct bgp_adj_in *ain;
2640
2641 table = peer->bgp->rib[afi][safi];
2642
2643 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2644 for (ain = rn->adj_in; ain ; ain = ain->next)
2645 if (ain->peer == peer)
2646 {
2647 bgp_adj_in_remove (rn, ain);
2648 bgp_unlock_node (rn);
2649 break;
2650 }
2651}
hasso93406d82005-02-02 14:40:33 +00002652
2653void
2654bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2655{
2656 struct bgp_node *rn;
2657 struct bgp_info *ri;
2658 struct bgp_table *table;
2659
2660 table = peer->bgp->rib[afi][safi];
2661
2662 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2663 {
2664 for (ri = rn->info; ri; ri = ri->next)
2665 if (ri->peer == peer)
2666 {
2667 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2668 bgp_rib_remove (rn, ri, peer, afi, safi);
2669 break;
2670 }
2671 }
2672}
paul718e3742002-12-13 20:15:29 +00002673
2674/* Delete all kernel routes. */
2675void
paul545acaf2004-04-20 15:13:15 +00002676bgp_cleanup_routes ()
paul718e3742002-12-13 20:15:29 +00002677{
2678 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002679 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002680 struct bgp_node *rn;
2681 struct bgp_table *table;
2682 struct bgp_info *ri;
2683
paul1eb8ef22005-04-07 07:30:20 +00002684 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002685 {
2686 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2687
2688 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2689 for (ri = rn->info; ri; ri = ri->next)
2690 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2691 && ri->type == ZEBRA_ROUTE_BGP
2692 && ri->sub_type == BGP_ROUTE_NORMAL)
2693 bgp_zebra_withdraw (&rn->p, ri);
2694
2695 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2696
2697 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2698 for (ri = rn->info; ri; ri = ri->next)
2699 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2700 && ri->type == ZEBRA_ROUTE_BGP
2701 && ri->sub_type == BGP_ROUTE_NORMAL)
2702 bgp_zebra_withdraw (&rn->p, ri);
2703 }
2704}
2705
2706void
2707bgp_reset ()
2708{
2709 vty_reset ();
2710 bgp_zclient_reset ();
2711 access_list_reset ();
2712 prefix_list_reset ();
2713}
2714
2715/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2716 value. */
2717int
2718bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2719{
2720 u_char *pnt;
2721 u_char *lim;
2722 struct prefix p;
2723 int psize;
2724 int ret;
2725
2726 /* Check peer status. */
2727 if (peer->status != Established)
2728 return 0;
2729
2730 pnt = packet->nlri;
2731 lim = pnt + packet->length;
2732
2733 for (; pnt < lim; pnt += psize)
2734 {
2735 /* Clear prefix structure. */
2736 memset (&p, 0, sizeof (struct prefix));
2737
2738 /* Fetch prefix length. */
2739 p.prefixlen = *pnt++;
2740 p.family = afi2family (packet->afi);
2741
2742 /* Already checked in nlri_sanity_check(). We do double check
2743 here. */
2744 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2745 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2746 return -1;
2747
2748 /* Packet size overflow check. */
2749 psize = PSIZE (p.prefixlen);
2750
2751 /* When packet overflow occur return immediately. */
2752 if (pnt + psize > lim)
2753 return -1;
2754
2755 /* Fetch prefix from NLRI packet. */
2756 memcpy (&p.u.prefix, pnt, psize);
2757
2758 /* Check address. */
2759 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2760 {
2761 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
2762 {
paulf5ba3872004-07-09 12:11:31 +00002763 /*
2764 * From draft-ietf-idr-bgp4-22, Section 6.3:
2765 * If a BGP router receives an UPDATE message with a
2766 * semantically incorrect NLRI field, in which a prefix is
2767 * semantically incorrect (eg. an unexpected multicast IP
2768 * address), it should ignore the prefix.
2769 */
paul718e3742002-12-13 20:15:29 +00002770 zlog (peer->log, LOG_ERR,
2771 "IPv4 unicast NLRI is multicast address %s",
2772 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00002773
paul718e3742002-12-13 20:15:29 +00002774 return -1;
2775 }
2776 }
2777
2778#ifdef HAVE_IPV6
2779 /* Check address. */
2780 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
2781 {
2782 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2783 {
2784 char buf[BUFSIZ];
2785
2786 zlog (peer->log, LOG_WARNING,
2787 "IPv6 link-local NLRI received %s ignore this NLRI",
2788 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
2789
2790 continue;
2791 }
2792 }
2793#endif /* HAVE_IPV6 */
2794
2795 /* Normal process. */
2796 if (attr)
2797 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
2798 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
2799 else
2800 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
2801 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2802
2803 /* Address family configuration mismatch or maximum-prefix count
2804 overflow. */
2805 if (ret < 0)
2806 return -1;
2807 }
2808
2809 /* Packet length consistency check. */
2810 if (pnt != lim)
2811 return -1;
2812
2813 return 0;
2814}
2815
2816/* NLRI encode syntax check routine. */
2817int
2818bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
2819 bgp_size_t length)
2820{
2821 u_char *end;
2822 u_char prefixlen;
2823 int psize;
2824
2825 end = pnt + length;
2826
2827 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
2828 syntactic validity. If the field is syntactically incorrect,
2829 then the Error Subcode is set to Invalid Network Field. */
2830
2831 while (pnt < end)
2832 {
2833 prefixlen = *pnt++;
2834
2835 /* Prefix length check. */
2836 if ((afi == AFI_IP && prefixlen > 32)
2837 || (afi == AFI_IP6 && prefixlen > 128))
2838 {
2839 plog_err (peer->log,
2840 "%s [Error] Update packet error (wrong prefix length %d)",
2841 peer->host, prefixlen);
2842 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2843 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2844 return -1;
2845 }
2846
2847 /* Packet size overflow check. */
2848 psize = PSIZE (prefixlen);
2849
2850 if (pnt + psize > end)
2851 {
2852 plog_err (peer->log,
2853 "%s [Error] Update packet error"
2854 " (prefix data overflow prefix size is %d)",
2855 peer->host, psize);
2856 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2857 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2858 return -1;
2859 }
2860
2861 pnt += psize;
2862 }
2863
2864 /* Packet length consistency check. */
2865 if (pnt != end)
2866 {
2867 plog_err (peer->log,
2868 "%s [Error] Update packet error"
2869 " (prefix length mismatch with total length)",
2870 peer->host);
2871 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2872 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2873 return -1;
2874 }
2875 return 0;
2876}
2877
paul94f2b392005-06-28 12:44:16 +00002878static struct bgp_static *
paul718e3742002-12-13 20:15:29 +00002879bgp_static_new ()
2880{
2881 struct bgp_static *new;
2882 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
2883 memset (new, 0, sizeof (struct bgp_static));
2884 return new;
2885}
2886
paul94f2b392005-06-28 12:44:16 +00002887static void
paul718e3742002-12-13 20:15:29 +00002888bgp_static_free (struct bgp_static *bgp_static)
2889{
2890 if (bgp_static->rmap.name)
2891 free (bgp_static->rmap.name);
2892 XFREE (MTYPE_BGP_STATIC, bgp_static);
2893}
2894
paul94f2b392005-06-28 12:44:16 +00002895static void
paulfee0f4c2004-09-13 05:12:46 +00002896bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
2897 struct prefix *p, afi_t afi, safi_t safi)
2898{
2899 struct bgp_node *rn;
2900 struct bgp_info *ri;
2901
2902 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2903
2904 /* Check selected route and self inserted route. */
2905 for (ri = rn->info; ri; ri = ri->next)
2906 if (ri->peer == bgp->peer_self
2907 && ri->type == ZEBRA_ROUTE_BGP
2908 && ri->sub_type == BGP_ROUTE_STATIC)
2909 break;
2910
2911 /* Withdraw static BGP route from routing table. */
2912 if (ri)
2913 {
2914 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2915 bgp_process (bgp, rn, afi, safi);
2916 bgp_info_delete (rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00002917 }
2918
2919 /* Unlock bgp_node_lookup. */
2920 bgp_unlock_node (rn);
2921}
2922
paul94f2b392005-06-28 12:44:16 +00002923static void
paulfee0f4c2004-09-13 05:12:46 +00002924bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
2925 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
2926{
2927 struct bgp_node *rn;
2928 struct bgp_info *ri;
2929 struct bgp_info *new;
2930 struct bgp_info info;
2931 struct attr new_attr;
2932 struct attr *attr_new;
2933 struct attr attr;
2934 struct bgp *bgp;
2935 int ret;
2936 char buf[SU_ADDRSTRLEN];
2937
2938 bgp = rsclient->bgp;
2939
Paul Jakma06e110f2006-05-12 23:29:22 +00002940 assert (bgp_static);
2941 if (!bgp_static)
2942 return;
2943
paulfee0f4c2004-09-13 05:12:46 +00002944 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2945
2946 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00002947
2948 attr.nexthop = bgp_static->igpnexthop;
2949 attr.med = bgp_static->igpmetric;
2950 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paulfee0f4c2004-09-13 05:12:46 +00002951
2952 new_attr = attr;
2953
2954 /* Apply network route-map for export to this rsclient. */
2955 if (bgp_static->rmap.name)
2956 {
2957 info.peer = rsclient;
2958 info.attr = &new_attr;
2959
2960 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
2961 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
2962
2963 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
2964
2965 rsclient->rmap_type = 0;
2966
2967 if (ret == RMAP_DENYMATCH)
2968 {
2969 /* Free uninterned attribute. */
2970 bgp_attr_flush (&new_attr);
2971
2972 /* Unintern original. */
2973 aspath_unintern (attr.aspath);
2974 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2975
2976 return;
2977 }
2978 attr_new = bgp_attr_intern (&new_attr);
2979 }
2980 else
2981 attr_new = bgp_attr_intern (&attr);
2982
2983 new_attr = *attr_new;
2984
2985 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
2986
2987 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) == RMAP_DENY)
2988{
2989 /* This BGP update is filtered. Log the reason then update BGP entry. */
2990 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002991 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002992 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
2993 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2994 p->prefixlen, rsclient->host);
2995
2996 bgp->peer_self->rmap_type = 0;
2997
2998 bgp_attr_unintern (attr_new);
2999 aspath_unintern (attr.aspath);
3000
3001 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3002
3003 return;
3004 }
3005
3006 bgp->peer_self->rmap_type = 0;
3007
3008 bgp_attr_unintern (attr_new);
3009 attr_new = bgp_attr_intern (&new_attr);
3010
3011 for (ri = rn->info; ri; ri = ri->next)
3012 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3013 && ri->sub_type == BGP_ROUTE_STATIC)
3014 break;
3015
3016 if (ri)
3017 {
3018 if (attrhash_cmp (ri->attr, attr_new))
3019 {
3020 bgp_unlock_node (rn);
3021 bgp_attr_unintern (attr_new);
3022 aspath_unintern (attr.aspath);
3023 return;
3024 }
3025 else
3026 {
3027 /* The attribute is changed. */
3028 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3029
3030 /* Rewrite BGP route information. */
3031 bgp_attr_unintern (ri->attr);
3032 ri->attr = attr_new;
3033 ri->uptime = time (NULL);
3034
3035 /* Process change. */
3036 bgp_process (bgp, rn, afi, safi);
3037 bgp_unlock_node (rn);
3038 aspath_unintern (attr.aspath);
3039 return;
3040 }
3041}
3042
3043 /* Make new BGP info. */
3044 new = bgp_info_new ();
3045 new->type = ZEBRA_ROUTE_BGP;
3046 new->sub_type = BGP_ROUTE_STATIC;
3047 new->peer = bgp->peer_self;
3048 SET_FLAG (new->flags, BGP_INFO_VALID);
3049 new->attr = attr_new;
3050 new->uptime = time (NULL);
3051
3052 /* Register new BGP information. */
3053 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003054
3055 /* route_node_get lock */
3056 bgp_unlock_node (rn);
3057
paulfee0f4c2004-09-13 05:12:46 +00003058 /* Process change. */
3059 bgp_process (bgp, rn, afi, safi);
3060
3061 /* Unintern original. */
3062 aspath_unintern (attr.aspath);
3063}
3064
paul94f2b392005-06-28 12:44:16 +00003065static void
paulfee0f4c2004-09-13 05:12:46 +00003066bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003067 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3068{
3069 struct bgp_node *rn;
3070 struct bgp_info *ri;
3071 struct bgp_info *new;
3072 struct bgp_info info;
3073 struct attr attr;
paul286e1e72003-08-08 00:24:31 +00003074 struct attr attr_tmp;
paul718e3742002-12-13 20:15:29 +00003075 struct attr *attr_new;
3076 int ret;
3077
Paul Jakmadd8103a2006-05-12 23:27:30 +00003078 assert (bgp_static);
3079 if (!bgp_static)
3080 return;
3081
paulfee0f4c2004-09-13 05:12:46 +00003082 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003083
3084 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003085
3086 attr.nexthop = bgp_static->igpnexthop;
3087 attr.med = bgp_static->igpmetric;
3088 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003089
3090 /* Apply route-map. */
3091 if (bgp_static->rmap.name)
3092 {
paul286e1e72003-08-08 00:24:31 +00003093 attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003094 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003095 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003096
paulfee0f4c2004-09-13 05:12:46 +00003097 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3098
paul718e3742002-12-13 20:15:29 +00003099 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003100
paulfee0f4c2004-09-13 05:12:46 +00003101 bgp->peer_self->rmap_type = 0;
3102
paul718e3742002-12-13 20:15:29 +00003103 if (ret == RMAP_DENYMATCH)
3104 {
3105 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003106 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003107
3108 /* Unintern original. */
3109 aspath_unintern (attr.aspath);
3110 bgp_static_withdraw (bgp, p, afi, safi);
3111 return;
3112 }
paul286e1e72003-08-08 00:24:31 +00003113 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003114 }
paul286e1e72003-08-08 00:24:31 +00003115 else
3116 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003117
3118 for (ri = rn->info; ri; ri = ri->next)
3119 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3120 && ri->sub_type == BGP_ROUTE_STATIC)
3121 break;
3122
3123 if (ri)
3124 {
3125 if (attrhash_cmp (ri->attr, attr_new))
3126 {
3127 bgp_unlock_node (rn);
3128 bgp_attr_unintern (attr_new);
3129 aspath_unintern (attr.aspath);
3130 return;
3131 }
3132 else
3133 {
3134 /* The attribute is changed. */
3135 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3136
3137 /* Rewrite BGP route information. */
3138 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3139 bgp_attr_unintern (ri->attr);
3140 ri->attr = attr_new;
3141 ri->uptime = time (NULL);
3142
3143 /* Process change. */
3144 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3145 bgp_process (bgp, rn, afi, safi);
3146 bgp_unlock_node (rn);
3147 aspath_unintern (attr.aspath);
3148 return;
3149 }
3150 }
3151
3152 /* Make new BGP info. */
3153 new = bgp_info_new ();
3154 new->type = ZEBRA_ROUTE_BGP;
3155 new->sub_type = BGP_ROUTE_STATIC;
3156 new->peer = bgp->peer_self;
3157 SET_FLAG (new->flags, BGP_INFO_VALID);
3158 new->attr = attr_new;
3159 new->uptime = time (NULL);
3160
3161 /* Aggregate address increment. */
3162 bgp_aggregate_increment (bgp, p, new, afi, safi);
3163
3164 /* Register new BGP information. */
3165 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003166
3167 /* route_node_get lock */
3168 bgp_unlock_node (rn);
3169
paul718e3742002-12-13 20:15:29 +00003170 /* Process change. */
3171 bgp_process (bgp, rn, afi, safi);
3172
3173 /* Unintern original. */
3174 aspath_unintern (attr.aspath);
3175}
3176
3177void
paulfee0f4c2004-09-13 05:12:46 +00003178bgp_static_update (struct bgp *bgp, struct prefix *p,
3179 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3180{
3181 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003182 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003183
3184 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3185
paul1eb8ef22005-04-07 07:30:20 +00003186 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003187 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003188 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3189 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003190 }
3191}
3192
paul94f2b392005-06-28 12:44:16 +00003193static void
paul718e3742002-12-13 20:15:29 +00003194bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3195 u_char safi, struct prefix_rd *prd, u_char *tag)
3196{
3197 struct bgp_node *rn;
3198 struct bgp_info *new;
3199
paulfee0f4c2004-09-13 05:12:46 +00003200 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003201
3202 /* Make new BGP info. */
3203 new = bgp_info_new ();
3204 new->type = ZEBRA_ROUTE_BGP;
3205 new->sub_type = BGP_ROUTE_STATIC;
3206 new->peer = bgp->peer_self;
3207 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3208 SET_FLAG (new->flags, BGP_INFO_VALID);
3209 new->uptime = time (NULL);
3210 memcpy (new->tag, tag, 3);
3211
3212 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003213 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003214
3215 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003216 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003217
paul200df112005-06-01 11:17:05 +00003218 /* route_node_get lock */
3219 bgp_unlock_node (rn);
3220
paul718e3742002-12-13 20:15:29 +00003221 /* Process change. */
3222 bgp_process (bgp, rn, afi, safi);
3223}
3224
3225void
3226bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3227 safi_t safi)
3228{
3229 struct bgp_node *rn;
3230 struct bgp_info *ri;
3231
paulfee0f4c2004-09-13 05:12:46 +00003232 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003233
3234 /* Check selected route and self inserted route. */
3235 for (ri = rn->info; ri; ri = ri->next)
3236 if (ri->peer == bgp->peer_self
3237 && ri->type == ZEBRA_ROUTE_BGP
3238 && ri->sub_type == BGP_ROUTE_STATIC)
3239 break;
3240
3241 /* Withdraw static BGP route from routing table. */
3242 if (ri)
3243 {
3244 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3245 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3246 bgp_process (bgp, rn, afi, safi);
3247 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003248 }
3249
3250 /* Unlock bgp_node_lookup. */
3251 bgp_unlock_node (rn);
3252}
3253
3254void
paulfee0f4c2004-09-13 05:12:46 +00003255bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3256{
3257 struct bgp_static *bgp_static;
3258 struct bgp *bgp;
3259 struct bgp_node *rn;
3260 struct prefix *p;
3261
3262 bgp = rsclient->bgp;
3263
3264 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3265 if ((bgp_static = rn->info) != NULL)
3266 {
3267 p = &rn->p;
3268
3269 bgp_static_update_rsclient (rsclient, p, bgp_static,
3270 afi, safi);
3271 }
3272}
3273
paul94f2b392005-06-28 12:44:16 +00003274static void
paul718e3742002-12-13 20:15:29 +00003275bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3276 u_char safi, struct prefix_rd *prd, u_char *tag)
3277{
3278 struct bgp_node *rn;
3279 struct bgp_info *ri;
3280
paulfee0f4c2004-09-13 05:12:46 +00003281 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003282
3283 /* Check selected route and self inserted route. */
3284 for (ri = rn->info; ri; ri = ri->next)
3285 if (ri->peer == bgp->peer_self
3286 && ri->type == ZEBRA_ROUTE_BGP
3287 && ri->sub_type == BGP_ROUTE_STATIC)
3288 break;
3289
3290 /* Withdraw static BGP route from routing table. */
3291 if (ri)
3292 {
3293 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3294 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3295 bgp_process (bgp, rn, afi, safi);
3296 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003297 }
3298
3299 /* Unlock bgp_node_lookup. */
3300 bgp_unlock_node (rn);
3301}
3302
3303/* Configure static BGP network. When user don't run zebra, static
3304 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003305static int
paulfd79ac92004-10-13 05:06:08 +00003306bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3307 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003308{
3309 int ret;
3310 struct prefix p;
3311 struct bgp_static *bgp_static;
3312 struct bgp_node *rn;
3313 int need_update = 0;
3314
3315 /* Convert IP prefix string to struct prefix. */
3316 ret = str2prefix (ip_str, &p);
3317 if (! ret)
3318 {
3319 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3320 return CMD_WARNING;
3321 }
3322#ifdef HAVE_IPV6
3323 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3324 {
3325 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3326 VTY_NEWLINE);
3327 return CMD_WARNING;
3328 }
3329#endif /* HAVE_IPV6 */
3330
3331 apply_mask (&p);
3332
3333 /* Set BGP static route configuration. */
3334 rn = bgp_node_get (bgp->route[afi][safi], &p);
3335
3336 if (rn->info)
3337 {
3338 /* Configuration change. */
3339 bgp_static = rn->info;
3340
3341 /* Check previous routes are installed into BGP. */
3342 if (! bgp_static->backdoor && bgp_static->valid)
3343 need_update = 1;
3344
3345 bgp_static->backdoor = backdoor;
3346 if (rmap)
3347 {
3348 if (bgp_static->rmap.name)
3349 free (bgp_static->rmap.name);
3350 bgp_static->rmap.name = strdup (rmap);
3351 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3352 }
3353 else
3354 {
3355 if (bgp_static->rmap.name)
3356 free (bgp_static->rmap.name);
3357 bgp_static->rmap.name = NULL;
3358 bgp_static->rmap.map = NULL;
3359 bgp_static->valid = 0;
3360 }
3361 bgp_unlock_node (rn);
3362 }
3363 else
3364 {
3365 /* New configuration. */
3366 bgp_static = bgp_static_new ();
3367 bgp_static->backdoor = backdoor;
3368 bgp_static->valid = 0;
3369 bgp_static->igpmetric = 0;
3370 bgp_static->igpnexthop.s_addr = 0;
3371 if (rmap)
3372 {
3373 if (bgp_static->rmap.name)
3374 free (bgp_static->rmap.name);
3375 bgp_static->rmap.name = strdup (rmap);
3376 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3377 }
3378 rn->info = bgp_static;
3379 }
3380
3381 /* If BGP scan is not enabled, we should install this route here. */
3382 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3383 {
3384 bgp_static->valid = 1;
3385
3386 if (need_update)
3387 bgp_static_withdraw (bgp, &p, afi, safi);
3388
3389 if (! bgp_static->backdoor)
3390 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3391 }
3392
3393 return CMD_SUCCESS;
3394}
3395
3396/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003397static int
paulfd79ac92004-10-13 05:06:08 +00003398bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003399 u_int16_t afi, u_char safi)
3400{
3401 int ret;
3402 struct prefix p;
3403 struct bgp_static *bgp_static;
3404 struct bgp_node *rn;
3405
3406 /* Convert IP prefix string to struct prefix. */
3407 ret = str2prefix (ip_str, &p);
3408 if (! ret)
3409 {
3410 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3411 return CMD_WARNING;
3412 }
3413#ifdef HAVE_IPV6
3414 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3415 {
3416 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3417 VTY_NEWLINE);
3418 return CMD_WARNING;
3419 }
3420#endif /* HAVE_IPV6 */
3421
3422 apply_mask (&p);
3423
3424 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3425 if (! rn)
3426 {
3427 vty_out (vty, "%% Can't find specified static route configuration.%s",
3428 VTY_NEWLINE);
3429 return CMD_WARNING;
3430 }
3431
3432 bgp_static = rn->info;
3433
3434 /* Update BGP RIB. */
3435 if (! bgp_static->backdoor)
3436 bgp_static_withdraw (bgp, &p, afi, safi);
3437
3438 /* Clear configuration. */
3439 bgp_static_free (bgp_static);
3440 rn->info = NULL;
3441 bgp_unlock_node (rn);
3442 bgp_unlock_node (rn);
3443
3444 return CMD_SUCCESS;
3445}
3446
3447/* Called from bgp_delete(). Delete all static routes from the BGP
3448 instance. */
3449void
3450bgp_static_delete (struct bgp *bgp)
3451{
3452 afi_t afi;
3453 safi_t safi;
3454 struct bgp_node *rn;
3455 struct bgp_node *rm;
3456 struct bgp_table *table;
3457 struct bgp_static *bgp_static;
3458
3459 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3460 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3461 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3462 if (rn->info != NULL)
3463 {
3464 if (safi == SAFI_MPLS_VPN)
3465 {
3466 table = rn->info;
3467
3468 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3469 {
3470 bgp_static = rn->info;
3471 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3472 AFI_IP, SAFI_MPLS_VPN,
3473 (struct prefix_rd *)&rn->p,
3474 bgp_static->tag);
3475 bgp_static_free (bgp_static);
3476 rn->info = NULL;
3477 bgp_unlock_node (rn);
3478 }
3479 }
3480 else
3481 {
3482 bgp_static = rn->info;
3483 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3484 bgp_static_free (bgp_static);
3485 rn->info = NULL;
3486 bgp_unlock_node (rn);
3487 }
3488 }
3489}
3490
3491int
paulfd79ac92004-10-13 05:06:08 +00003492bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3493 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003494{
3495 int ret;
3496 struct prefix p;
3497 struct prefix_rd prd;
3498 struct bgp *bgp;
3499 struct bgp_node *prn;
3500 struct bgp_node *rn;
3501 struct bgp_table *table;
3502 struct bgp_static *bgp_static;
3503 u_char tag[3];
3504
3505 bgp = vty->index;
3506
3507 ret = str2prefix (ip_str, &p);
3508 if (! ret)
3509 {
3510 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3511 return CMD_WARNING;
3512 }
3513 apply_mask (&p);
3514
3515 ret = str2prefix_rd (rd_str, &prd);
3516 if (! ret)
3517 {
3518 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3519 return CMD_WARNING;
3520 }
3521
3522 ret = str2tag (tag_str, tag);
3523 if (! ret)
3524 {
3525 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3526 return CMD_WARNING;
3527 }
3528
3529 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3530 (struct prefix *)&prd);
3531 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003532 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003533 else
3534 bgp_unlock_node (prn);
3535 table = prn->info;
3536
3537 rn = bgp_node_get (table, &p);
3538
3539 if (rn->info)
3540 {
3541 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3542 bgp_unlock_node (rn);
3543 }
3544 else
3545 {
3546 /* New configuration. */
3547 bgp_static = bgp_static_new ();
3548 bgp_static->valid = 1;
3549 memcpy (bgp_static->tag, tag, 3);
3550 rn->info = bgp_static;
3551
3552 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3553 }
3554
3555 return CMD_SUCCESS;
3556}
3557
3558/* Configure static BGP network. */
3559int
paulfd79ac92004-10-13 05:06:08 +00003560bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3561 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003562{
3563 int ret;
3564 struct bgp *bgp;
3565 struct prefix p;
3566 struct prefix_rd prd;
3567 struct bgp_node *prn;
3568 struct bgp_node *rn;
3569 struct bgp_table *table;
3570 struct bgp_static *bgp_static;
3571 u_char tag[3];
3572
3573 bgp = vty->index;
3574
3575 /* Convert IP prefix string to struct prefix. */
3576 ret = str2prefix (ip_str, &p);
3577 if (! ret)
3578 {
3579 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3580 return CMD_WARNING;
3581 }
3582 apply_mask (&p);
3583
3584 ret = str2prefix_rd (rd_str, &prd);
3585 if (! ret)
3586 {
3587 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3588 return CMD_WARNING;
3589 }
3590
3591 ret = str2tag (tag_str, tag);
3592 if (! ret)
3593 {
3594 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3595 return CMD_WARNING;
3596 }
3597
3598 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3599 (struct prefix *)&prd);
3600 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003601 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003602 else
3603 bgp_unlock_node (prn);
3604 table = prn->info;
3605
3606 rn = bgp_node_lookup (table, &p);
3607
3608 if (rn)
3609 {
3610 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3611
3612 bgp_static = rn->info;
3613 bgp_static_free (bgp_static);
3614 rn->info = NULL;
3615 bgp_unlock_node (rn);
3616 bgp_unlock_node (rn);
3617 }
3618 else
3619 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3620
3621 return CMD_SUCCESS;
3622}
3623
3624DEFUN (bgp_network,
3625 bgp_network_cmd,
3626 "network A.B.C.D/M",
3627 "Specify a network to announce via BGP\n"
3628 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3629{
3630 return bgp_static_set (vty, vty->index, argv[0],
3631 AFI_IP, bgp_node_safi (vty), NULL, 0);
3632}
3633
3634DEFUN (bgp_network_route_map,
3635 bgp_network_route_map_cmd,
3636 "network A.B.C.D/M route-map WORD",
3637 "Specify a network to announce via BGP\n"
3638 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3639 "Route-map to modify the attributes\n"
3640 "Name of the route map\n")
3641{
3642 return bgp_static_set (vty, vty->index, argv[0],
3643 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3644}
3645
3646DEFUN (bgp_network_backdoor,
3647 bgp_network_backdoor_cmd,
3648 "network A.B.C.D/M backdoor",
3649 "Specify a network to announce via BGP\n"
3650 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3651 "Specify a BGP backdoor route\n")
3652{
3653 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
3654}
3655
3656DEFUN (bgp_network_mask,
3657 bgp_network_mask_cmd,
3658 "network A.B.C.D mask A.B.C.D",
3659 "Specify a network to announce via BGP\n"
3660 "Network number\n"
3661 "Network mask\n"
3662 "Network mask\n")
3663{
3664 int ret;
3665 char prefix_str[BUFSIZ];
3666
3667 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3668 if (! ret)
3669 {
3670 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3671 return CMD_WARNING;
3672 }
3673
3674 return bgp_static_set (vty, vty->index, prefix_str,
3675 AFI_IP, bgp_node_safi (vty), NULL, 0);
3676}
3677
3678DEFUN (bgp_network_mask_route_map,
3679 bgp_network_mask_route_map_cmd,
3680 "network A.B.C.D mask A.B.C.D route-map WORD",
3681 "Specify a network to announce via BGP\n"
3682 "Network number\n"
3683 "Network mask\n"
3684 "Network mask\n"
3685 "Route-map to modify the attributes\n"
3686 "Name of the route map\n")
3687{
3688 int ret;
3689 char prefix_str[BUFSIZ];
3690
3691 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3692 if (! ret)
3693 {
3694 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3695 return CMD_WARNING;
3696 }
3697
3698 return bgp_static_set (vty, vty->index, prefix_str,
3699 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3700}
3701
3702DEFUN (bgp_network_mask_backdoor,
3703 bgp_network_mask_backdoor_cmd,
3704 "network A.B.C.D mask A.B.C.D backdoor",
3705 "Specify a network to announce via BGP\n"
3706 "Network number\n"
3707 "Network mask\n"
3708 "Network mask\n"
3709 "Specify a BGP backdoor route\n")
3710{
3711 int ret;
3712 char prefix_str[BUFSIZ];
3713
3714 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3715 if (! ret)
3716 {
3717 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3718 return CMD_WARNING;
3719 }
3720
3721 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3722}
3723
3724DEFUN (bgp_network_mask_natural,
3725 bgp_network_mask_natural_cmd,
3726 "network A.B.C.D",
3727 "Specify a network to announce via BGP\n"
3728 "Network number\n")
3729{
3730 int ret;
3731 char prefix_str[BUFSIZ];
3732
3733 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3734 if (! ret)
3735 {
3736 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3737 return CMD_WARNING;
3738 }
3739
3740 return bgp_static_set (vty, vty->index, prefix_str,
3741 AFI_IP, bgp_node_safi (vty), NULL, 0);
3742}
3743
3744DEFUN (bgp_network_mask_natural_route_map,
3745 bgp_network_mask_natural_route_map_cmd,
3746 "network A.B.C.D route-map WORD",
3747 "Specify a network to announce via BGP\n"
3748 "Network number\n"
3749 "Route-map to modify the attributes\n"
3750 "Name of the route map\n")
3751{
3752 int ret;
3753 char prefix_str[BUFSIZ];
3754
3755 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3756 if (! ret)
3757 {
3758 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3759 return CMD_WARNING;
3760 }
3761
3762 return bgp_static_set (vty, vty->index, prefix_str,
3763 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3764}
3765
3766DEFUN (bgp_network_mask_natural_backdoor,
3767 bgp_network_mask_natural_backdoor_cmd,
3768 "network A.B.C.D backdoor",
3769 "Specify a network to announce via BGP\n"
3770 "Network number\n"
3771 "Specify a BGP backdoor route\n")
3772{
3773 int ret;
3774 char prefix_str[BUFSIZ];
3775
3776 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3777 if (! ret)
3778 {
3779 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3780 return CMD_WARNING;
3781 }
3782
3783 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3784}
3785
3786DEFUN (no_bgp_network,
3787 no_bgp_network_cmd,
3788 "no network A.B.C.D/M",
3789 NO_STR
3790 "Specify a network to announce via BGP\n"
3791 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3792{
3793 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
3794 bgp_node_safi (vty));
3795}
3796
3797ALIAS (no_bgp_network,
3798 no_bgp_network_route_map_cmd,
3799 "no network A.B.C.D/M route-map WORD",
3800 NO_STR
3801 "Specify a network to announce via BGP\n"
3802 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3803 "Route-map to modify the attributes\n"
3804 "Name of the route map\n")
3805
3806ALIAS (no_bgp_network,
3807 no_bgp_network_backdoor_cmd,
3808 "no network A.B.C.D/M backdoor",
3809 NO_STR
3810 "Specify a network to announce via BGP\n"
3811 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3812 "Specify a BGP backdoor route\n")
3813
3814DEFUN (no_bgp_network_mask,
3815 no_bgp_network_mask_cmd,
3816 "no network A.B.C.D mask A.B.C.D",
3817 NO_STR
3818 "Specify a network to announce via BGP\n"
3819 "Network number\n"
3820 "Network mask\n"
3821 "Network mask\n")
3822{
3823 int ret;
3824 char prefix_str[BUFSIZ];
3825
3826 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3827 if (! ret)
3828 {
3829 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3830 return CMD_WARNING;
3831 }
3832
3833 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3834 bgp_node_safi (vty));
3835}
3836
3837ALIAS (no_bgp_network_mask,
3838 no_bgp_network_mask_route_map_cmd,
3839 "no network A.B.C.D mask A.B.C.D route-map WORD",
3840 NO_STR
3841 "Specify a network to announce via BGP\n"
3842 "Network number\n"
3843 "Network mask\n"
3844 "Network mask\n"
3845 "Route-map to modify the attributes\n"
3846 "Name of the route map\n")
3847
3848ALIAS (no_bgp_network_mask,
3849 no_bgp_network_mask_backdoor_cmd,
3850 "no network A.B.C.D mask A.B.C.D backdoor",
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 "Specify a BGP backdoor route\n")
3857
3858DEFUN (no_bgp_network_mask_natural,
3859 no_bgp_network_mask_natural_cmd,
3860 "no network A.B.C.D",
3861 NO_STR
3862 "Specify a network to announce via BGP\n"
3863 "Network number\n")
3864{
3865 int ret;
3866 char prefix_str[BUFSIZ];
3867
3868 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3869 if (! ret)
3870 {
3871 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3872 return CMD_WARNING;
3873 }
3874
3875 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3876 bgp_node_safi (vty));
3877}
3878
3879ALIAS (no_bgp_network_mask_natural,
3880 no_bgp_network_mask_natural_route_map_cmd,
3881 "no network A.B.C.D route-map WORD",
3882 NO_STR
3883 "Specify a network to announce via BGP\n"
3884 "Network number\n"
3885 "Route-map to modify the attributes\n"
3886 "Name of the route map\n")
3887
3888ALIAS (no_bgp_network_mask_natural,
3889 no_bgp_network_mask_natural_backdoor_cmd,
3890 "no network A.B.C.D backdoor",
3891 NO_STR
3892 "Specify a network to announce via BGP\n"
3893 "Network number\n"
3894 "Specify a BGP backdoor route\n")
3895
3896#ifdef HAVE_IPV6
3897DEFUN (ipv6_bgp_network,
3898 ipv6_bgp_network_cmd,
3899 "network X:X::X:X/M",
3900 "Specify a network to announce via BGP\n"
3901 "IPv6 prefix <network>/<length>\n")
3902{
3903 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
3904}
3905
3906DEFUN (ipv6_bgp_network_route_map,
3907 ipv6_bgp_network_route_map_cmd,
3908 "network X:X::X:X/M route-map WORD",
3909 "Specify a network to announce via BGP\n"
3910 "IPv6 prefix <network>/<length>\n"
3911 "Route-map to modify the attributes\n"
3912 "Name of the route map\n")
3913{
3914 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
3915 bgp_node_safi (vty), argv[1], 0);
3916}
3917
3918DEFUN (no_ipv6_bgp_network,
3919 no_ipv6_bgp_network_cmd,
3920 "no network X:X::X:X/M",
3921 NO_STR
3922 "Specify a network to announce via BGP\n"
3923 "IPv6 prefix <network>/<length>\n")
3924{
3925 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
3926}
3927
3928ALIAS (no_ipv6_bgp_network,
3929 no_ipv6_bgp_network_route_map_cmd,
3930 "no network X:X::X:X/M route-map WORD",
3931 NO_STR
3932 "Specify a network to announce via BGP\n"
3933 "IPv6 prefix <network>/<length>\n"
3934 "Route-map to modify the attributes\n"
3935 "Name of the route map\n")
3936
3937ALIAS (ipv6_bgp_network,
3938 old_ipv6_bgp_network_cmd,
3939 "ipv6 bgp network X:X::X:X/M",
3940 IPV6_STR
3941 BGP_STR
3942 "Specify a network to announce via BGP\n"
3943 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3944
3945ALIAS (no_ipv6_bgp_network,
3946 old_no_ipv6_bgp_network_cmd,
3947 "no ipv6 bgp network X:X::X:X/M",
3948 NO_STR
3949 IPV6_STR
3950 BGP_STR
3951 "Specify a network to announce via BGP\n"
3952 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3953#endif /* HAVE_IPV6 */
3954
3955/* Aggreagete address:
3956
3957 advertise-map Set condition to advertise attribute
3958 as-set Generate AS set path information
3959 attribute-map Set attributes of aggregate
3960 route-map Set parameters of aggregate
3961 summary-only Filter more specific routes from updates
3962 suppress-map Conditionally filter more specific routes from updates
3963 <cr>
3964 */
3965struct bgp_aggregate
3966{
3967 /* Summary-only flag. */
3968 u_char summary_only;
3969
3970 /* AS set generation. */
3971 u_char as_set;
3972
3973 /* Route-map for aggregated route. */
3974 struct route_map *map;
3975
3976 /* Suppress-count. */
3977 unsigned long count;
3978
3979 /* SAFI configuration. */
3980 safi_t safi;
3981};
3982
paul94f2b392005-06-28 12:44:16 +00003983static struct bgp_aggregate *
paul718e3742002-12-13 20:15:29 +00003984bgp_aggregate_new ()
3985{
3986 struct bgp_aggregate *new;
3987 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
3988 memset (new, 0, sizeof (struct bgp_aggregate));
3989 return new;
3990}
3991
paul94f2b392005-06-28 12:44:16 +00003992static void
paul718e3742002-12-13 20:15:29 +00003993bgp_aggregate_free (struct bgp_aggregate *aggregate)
3994{
3995 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
3996}
3997
paul94f2b392005-06-28 12:44:16 +00003998static void
paul718e3742002-12-13 20:15:29 +00003999bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4000 afi_t afi, safi_t safi, struct bgp_info *del,
4001 struct bgp_aggregate *aggregate)
4002{
4003 struct bgp_table *table;
4004 struct bgp_node *top;
4005 struct bgp_node *rn;
4006 u_char origin;
4007 struct aspath *aspath = NULL;
4008 struct aspath *asmerge = NULL;
4009 struct community *community = NULL;
4010 struct community *commerge = NULL;
4011 struct in_addr nexthop;
4012 u_int32_t med = 0;
4013 struct bgp_info *ri;
4014 struct bgp_info *new;
4015 int first = 1;
4016 unsigned long match = 0;
4017
4018 /* Record adding route's nexthop and med. */
4019 if (rinew)
4020 {
4021 nexthop = rinew->attr->nexthop;
4022 med = rinew->attr->med;
4023 }
4024
4025 /* ORIGIN attribute: If at least one route among routes that are
4026 aggregated has ORIGIN with the value INCOMPLETE, then the
4027 aggregated route must have the ORIGIN attribute with the value
4028 INCOMPLETE. Otherwise, if at least one route among routes that
4029 are aggregated has ORIGIN with the value EGP, then the aggregated
4030 route must have the origin attribute with the value EGP. In all
4031 other case the value of the ORIGIN attribute of the aggregated
4032 route is INTERNAL. */
4033 origin = BGP_ORIGIN_IGP;
4034
4035 table = bgp->rib[afi][safi];
4036
4037 top = bgp_node_get (table, p);
4038 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4039 if (rn->p.prefixlen > p->prefixlen)
4040 {
4041 match = 0;
4042
4043 for (ri = rn->info; ri; ri = ri->next)
4044 {
4045 if (BGP_INFO_HOLDDOWN (ri))
4046 continue;
4047
4048 if (del && ri == del)
4049 continue;
4050
4051 if (! rinew && first)
4052 {
4053 nexthop = ri->attr->nexthop;
4054 med = ri->attr->med;
4055 first = 0;
4056 }
4057
4058#ifdef AGGREGATE_NEXTHOP_CHECK
4059 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4060 || ri->attr->med != med)
4061 {
4062 if (aspath)
4063 aspath_free (aspath);
4064 if (community)
4065 community_free (community);
4066 bgp_unlock_node (rn);
4067 bgp_unlock_node (top);
4068 return;
4069 }
4070#endif /* AGGREGATE_NEXTHOP_CHECK */
4071
4072 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4073 {
4074 if (aggregate->summary_only)
4075 {
4076 ri->suppress++;
4077 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4078 match++;
4079 }
4080
4081 aggregate->count++;
4082
4083 if (aggregate->as_set)
4084 {
4085 if (origin < ri->attr->origin)
4086 origin = ri->attr->origin;
4087
4088 if (aspath)
4089 {
4090 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4091 aspath_free (aspath);
4092 aspath = asmerge;
4093 }
4094 else
4095 aspath = aspath_dup (ri->attr->aspath);
4096
4097 if (ri->attr->community)
4098 {
4099 if (community)
4100 {
4101 commerge = community_merge (community,
4102 ri->attr->community);
4103 community = community_uniq_sort (commerge);
4104 community_free (commerge);
4105 }
4106 else
4107 community = community_dup (ri->attr->community);
4108 }
4109 }
4110 }
4111 }
4112 if (match)
4113 bgp_process (bgp, rn, afi, safi);
4114 }
4115 bgp_unlock_node (top);
4116
4117 if (rinew)
4118 {
4119 aggregate->count++;
4120
4121 if (aggregate->summary_only)
4122 rinew->suppress++;
4123
4124 if (aggregate->as_set)
4125 {
4126 if (origin < rinew->attr->origin)
4127 origin = rinew->attr->origin;
4128
4129 if (aspath)
4130 {
4131 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4132 aspath_free (aspath);
4133 aspath = asmerge;
4134 }
4135 else
4136 aspath = aspath_dup (rinew->attr->aspath);
4137
4138 if (rinew->attr->community)
4139 {
4140 if (community)
4141 {
4142 commerge = community_merge (community,
4143 rinew->attr->community);
4144 community = community_uniq_sort (commerge);
4145 community_free (commerge);
4146 }
4147 else
4148 community = community_dup (rinew->attr->community);
4149 }
4150 }
4151 }
4152
4153 if (aggregate->count > 0)
4154 {
4155 rn = bgp_node_get (table, p);
4156 new = bgp_info_new ();
4157 new->type = ZEBRA_ROUTE_BGP;
4158 new->sub_type = BGP_ROUTE_AGGREGATE;
4159 new->peer = bgp->peer_self;
4160 SET_FLAG (new->flags, BGP_INFO_VALID);
4161 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4162 new->uptime = time (NULL);
4163
4164 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004165 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004166 bgp_process (bgp, rn, afi, safi);
4167 }
4168 else
4169 {
4170 if (aspath)
4171 aspath_free (aspath);
4172 if (community)
4173 community_free (community);
4174 }
4175}
4176
4177void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4178 struct bgp_aggregate *);
4179
4180void
4181bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4182 struct bgp_info *ri, afi_t afi, safi_t safi)
4183{
4184 struct bgp_node *child;
4185 struct bgp_node *rn;
4186 struct bgp_aggregate *aggregate;
4187
4188 /* MPLS-VPN aggregation is not yet supported. */
4189 if (safi == SAFI_MPLS_VPN)
4190 return;
4191
4192 if (p->prefixlen == 0)
4193 return;
4194
4195 if (BGP_INFO_HOLDDOWN (ri))
4196 return;
4197
4198 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4199
4200 /* Aggregate address configuration check. */
4201 for (rn = child; rn; rn = rn->parent)
4202 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4203 {
4204 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004205 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004206 }
4207 bgp_unlock_node (child);
4208}
4209
4210void
4211bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4212 struct bgp_info *del, afi_t afi, safi_t safi)
4213{
4214 struct bgp_node *child;
4215 struct bgp_node *rn;
4216 struct bgp_aggregate *aggregate;
4217
4218 /* MPLS-VPN aggregation is not yet supported. */
4219 if (safi == SAFI_MPLS_VPN)
4220 return;
4221
4222 if (p->prefixlen == 0)
4223 return;
4224
4225 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4226
4227 /* Aggregate address configuration check. */
4228 for (rn = child; rn; rn = rn->parent)
4229 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4230 {
4231 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004232 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004233 }
4234 bgp_unlock_node (child);
4235}
4236
paul94f2b392005-06-28 12:44:16 +00004237static void
paul718e3742002-12-13 20:15:29 +00004238bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4239 struct bgp_aggregate *aggregate)
4240{
4241 struct bgp_table *table;
4242 struct bgp_node *top;
4243 struct bgp_node *rn;
4244 struct bgp_info *new;
4245 struct bgp_info *ri;
4246 unsigned long match;
4247 u_char origin = BGP_ORIGIN_IGP;
4248 struct aspath *aspath = NULL;
4249 struct aspath *asmerge = NULL;
4250 struct community *community = NULL;
4251 struct community *commerge = NULL;
4252
4253 table = bgp->rib[afi][safi];
4254
4255 /* Sanity check. */
4256 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4257 return;
4258 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4259 return;
4260
4261 /* If routes exists below this node, generate aggregate routes. */
4262 top = bgp_node_get (table, p);
4263 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4264 if (rn->p.prefixlen > p->prefixlen)
4265 {
4266 match = 0;
4267
4268 for (ri = rn->info; ri; ri = ri->next)
4269 {
4270 if (BGP_INFO_HOLDDOWN (ri))
4271 continue;
4272
4273 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4274 {
4275 /* summary-only aggregate route suppress aggregated
4276 route announcement. */
4277 if (aggregate->summary_only)
4278 {
4279 ri->suppress++;
4280 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4281 match++;
4282 }
4283 /* as-set aggregate route generate origin, as path,
4284 community aggregation. */
4285 if (aggregate->as_set)
4286 {
4287 if (origin < ri->attr->origin)
4288 origin = ri->attr->origin;
4289
4290 if (aspath)
4291 {
4292 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4293 aspath_free (aspath);
4294 aspath = asmerge;
4295 }
4296 else
4297 aspath = aspath_dup (ri->attr->aspath);
4298
4299 if (ri->attr->community)
4300 {
4301 if (community)
4302 {
4303 commerge = community_merge (community,
4304 ri->attr->community);
4305 community = community_uniq_sort (commerge);
4306 community_free (commerge);
4307 }
4308 else
4309 community = community_dup (ri->attr->community);
4310 }
4311 }
4312 aggregate->count++;
4313 }
4314 }
4315
4316 /* If this node is suppressed, process the change. */
4317 if (match)
4318 bgp_process (bgp, rn, afi, safi);
4319 }
4320 bgp_unlock_node (top);
4321
4322 /* Add aggregate route to BGP table. */
4323 if (aggregate->count)
4324 {
4325 rn = bgp_node_get (table, p);
4326
4327 new = bgp_info_new ();
4328 new->type = ZEBRA_ROUTE_BGP;
4329 new->sub_type = BGP_ROUTE_AGGREGATE;
4330 new->peer = bgp->peer_self;
4331 SET_FLAG (new->flags, BGP_INFO_VALID);
4332 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4333 new->uptime = time (NULL);
4334
4335 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004336 bgp_unlock_node (rn);
4337
paul718e3742002-12-13 20:15:29 +00004338 /* Process change. */
4339 bgp_process (bgp, rn, afi, safi);
4340 }
4341}
4342
4343void
4344bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4345 safi_t safi, struct bgp_aggregate *aggregate)
4346{
4347 struct bgp_table *table;
4348 struct bgp_node *top;
4349 struct bgp_node *rn;
4350 struct bgp_info *ri;
4351 unsigned long match;
4352
4353 table = bgp->rib[afi][safi];
4354
4355 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4356 return;
4357 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4358 return;
4359
4360 /* If routes exists below this node, generate aggregate routes. */
4361 top = bgp_node_get (table, p);
4362 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4363 if (rn->p.prefixlen > p->prefixlen)
4364 {
4365 match = 0;
4366
4367 for (ri = rn->info; ri; ri = ri->next)
4368 {
4369 if (BGP_INFO_HOLDDOWN (ri))
4370 continue;
4371
4372 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4373 {
4374 if (aggregate->summary_only)
4375 {
4376 ri->suppress--;
4377
4378 if (ri->suppress == 0)
4379 {
4380 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4381 match++;
4382 }
4383 }
4384 aggregate->count--;
4385 }
4386 }
4387
4388 /* If this node is suppressed, process the change. */
4389 if (match)
4390 bgp_process (bgp, rn, afi, safi);
4391 }
4392 bgp_unlock_node (top);
4393
4394 /* Delete aggregate route from BGP table. */
4395 rn = bgp_node_get (table, p);
4396
4397 for (ri = rn->info; ri; ri = ri->next)
4398 if (ri->peer == bgp->peer_self
4399 && ri->type == ZEBRA_ROUTE_BGP
4400 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4401 break;
4402
4403 /* Withdraw static BGP route from routing table. */
4404 if (ri)
4405 {
4406 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4407 bgp_process (bgp, rn, afi, safi);
4408 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004409 }
4410
4411 /* Unlock bgp_node_lookup. */
4412 bgp_unlock_node (rn);
4413}
4414
4415/* Aggregate route attribute. */
4416#define AGGREGATE_SUMMARY_ONLY 1
4417#define AGGREGATE_AS_SET 1
4418
paul94f2b392005-06-28 12:44:16 +00004419static int
paulfd79ac92004-10-13 05:06:08 +00004420bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4421 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004422 u_char summary_only, u_char as_set)
4423{
4424 int ret;
4425 struct prefix p;
4426 struct bgp_node *rn;
4427 struct bgp *bgp;
4428 struct bgp_aggregate *aggregate;
4429
4430 /* Convert string to prefix structure. */
4431 ret = str2prefix (prefix_str, &p);
4432 if (!ret)
4433 {
4434 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4435 return CMD_WARNING;
4436 }
4437 apply_mask (&p);
4438
4439 /* Get BGP structure. */
4440 bgp = vty->index;
4441
4442 /* Old configuration check. */
4443 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4444
4445 if (rn->info)
4446 {
4447 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4448 bgp_unlock_node (rn);
4449 return CMD_WARNING;
4450 }
4451
4452 /* Make aggregate address structure. */
4453 aggregate = bgp_aggregate_new ();
4454 aggregate->summary_only = summary_only;
4455 aggregate->as_set = as_set;
4456 aggregate->safi = safi;
4457 rn->info = aggregate;
4458
4459 /* Aggregate address insert into BGP routing table. */
4460 if (safi & SAFI_UNICAST)
4461 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4462 if (safi & SAFI_MULTICAST)
4463 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4464
4465 return CMD_SUCCESS;
4466}
4467
paul94f2b392005-06-28 12:44:16 +00004468static int
paulfd79ac92004-10-13 05:06:08 +00004469bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4470 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004471{
4472 int ret;
4473 struct prefix p;
4474 struct bgp_node *rn;
4475 struct bgp *bgp;
4476 struct bgp_aggregate *aggregate;
4477
4478 /* Convert string to prefix structure. */
4479 ret = str2prefix (prefix_str, &p);
4480 if (!ret)
4481 {
4482 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4483 return CMD_WARNING;
4484 }
4485 apply_mask (&p);
4486
4487 /* Get BGP structure. */
4488 bgp = vty->index;
4489
4490 /* Old configuration check. */
4491 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4492 if (! rn)
4493 {
4494 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4495 VTY_NEWLINE);
4496 return CMD_WARNING;
4497 }
4498
4499 aggregate = rn->info;
4500 if (aggregate->safi & SAFI_UNICAST)
4501 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4502 if (aggregate->safi & SAFI_MULTICAST)
4503 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4504
4505 /* Unlock aggregate address configuration. */
4506 rn->info = NULL;
4507 bgp_aggregate_free (aggregate);
4508 bgp_unlock_node (rn);
4509 bgp_unlock_node (rn);
4510
4511 return CMD_SUCCESS;
4512}
4513
4514DEFUN (aggregate_address,
4515 aggregate_address_cmd,
4516 "aggregate-address A.B.C.D/M",
4517 "Configure BGP aggregate entries\n"
4518 "Aggregate prefix\n")
4519{
4520 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4521}
4522
4523DEFUN (aggregate_address_mask,
4524 aggregate_address_mask_cmd,
4525 "aggregate-address A.B.C.D A.B.C.D",
4526 "Configure BGP aggregate entries\n"
4527 "Aggregate address\n"
4528 "Aggregate mask\n")
4529{
4530 int ret;
4531 char prefix_str[BUFSIZ];
4532
4533 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4534
4535 if (! ret)
4536 {
4537 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4538 return CMD_WARNING;
4539 }
4540
4541 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4542 0, 0);
4543}
4544
4545DEFUN (aggregate_address_summary_only,
4546 aggregate_address_summary_only_cmd,
4547 "aggregate-address A.B.C.D/M summary-only",
4548 "Configure BGP aggregate entries\n"
4549 "Aggregate prefix\n"
4550 "Filter more specific routes from updates\n")
4551{
4552 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4553 AGGREGATE_SUMMARY_ONLY, 0);
4554}
4555
4556DEFUN (aggregate_address_mask_summary_only,
4557 aggregate_address_mask_summary_only_cmd,
4558 "aggregate-address A.B.C.D A.B.C.D summary-only",
4559 "Configure BGP aggregate entries\n"
4560 "Aggregate address\n"
4561 "Aggregate mask\n"
4562 "Filter more specific routes from updates\n")
4563{
4564 int ret;
4565 char prefix_str[BUFSIZ];
4566
4567 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4568
4569 if (! ret)
4570 {
4571 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4572 return CMD_WARNING;
4573 }
4574
4575 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4576 AGGREGATE_SUMMARY_ONLY, 0);
4577}
4578
4579DEFUN (aggregate_address_as_set,
4580 aggregate_address_as_set_cmd,
4581 "aggregate-address A.B.C.D/M as-set",
4582 "Configure BGP aggregate entries\n"
4583 "Aggregate prefix\n"
4584 "Generate AS set path information\n")
4585{
4586 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4587 0, AGGREGATE_AS_SET);
4588}
4589
4590DEFUN (aggregate_address_mask_as_set,
4591 aggregate_address_mask_as_set_cmd,
4592 "aggregate-address A.B.C.D A.B.C.D as-set",
4593 "Configure BGP aggregate entries\n"
4594 "Aggregate address\n"
4595 "Aggregate mask\n"
4596 "Generate AS set path information\n")
4597{
4598 int ret;
4599 char prefix_str[BUFSIZ];
4600
4601 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4602
4603 if (! ret)
4604 {
4605 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4606 return CMD_WARNING;
4607 }
4608
4609 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4610 0, AGGREGATE_AS_SET);
4611}
4612
4613
4614DEFUN (aggregate_address_as_set_summary,
4615 aggregate_address_as_set_summary_cmd,
4616 "aggregate-address A.B.C.D/M as-set summary-only",
4617 "Configure BGP aggregate entries\n"
4618 "Aggregate prefix\n"
4619 "Generate AS set path information\n"
4620 "Filter more specific routes from updates\n")
4621{
4622 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4623 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4624}
4625
4626ALIAS (aggregate_address_as_set_summary,
4627 aggregate_address_summary_as_set_cmd,
4628 "aggregate-address A.B.C.D/M summary-only as-set",
4629 "Configure BGP aggregate entries\n"
4630 "Aggregate prefix\n"
4631 "Filter more specific routes from updates\n"
4632 "Generate AS set path information\n")
4633
4634DEFUN (aggregate_address_mask_as_set_summary,
4635 aggregate_address_mask_as_set_summary_cmd,
4636 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4637 "Configure BGP aggregate entries\n"
4638 "Aggregate address\n"
4639 "Aggregate mask\n"
4640 "Generate AS set path information\n"
4641 "Filter more specific routes from updates\n")
4642{
4643 int ret;
4644 char prefix_str[BUFSIZ];
4645
4646 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4647
4648 if (! ret)
4649 {
4650 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4651 return CMD_WARNING;
4652 }
4653
4654 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4655 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4656}
4657
4658ALIAS (aggregate_address_mask_as_set_summary,
4659 aggregate_address_mask_summary_as_set_cmd,
4660 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4661 "Configure BGP aggregate entries\n"
4662 "Aggregate address\n"
4663 "Aggregate mask\n"
4664 "Filter more specific routes from updates\n"
4665 "Generate AS set path information\n")
4666
4667DEFUN (no_aggregate_address,
4668 no_aggregate_address_cmd,
4669 "no aggregate-address A.B.C.D/M",
4670 NO_STR
4671 "Configure BGP aggregate entries\n"
4672 "Aggregate prefix\n")
4673{
4674 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4675}
4676
4677ALIAS (no_aggregate_address,
4678 no_aggregate_address_summary_only_cmd,
4679 "no aggregate-address A.B.C.D/M summary-only",
4680 NO_STR
4681 "Configure BGP aggregate entries\n"
4682 "Aggregate prefix\n"
4683 "Filter more specific routes from updates\n")
4684
4685ALIAS (no_aggregate_address,
4686 no_aggregate_address_as_set_cmd,
4687 "no aggregate-address A.B.C.D/M as-set",
4688 NO_STR
4689 "Configure BGP aggregate entries\n"
4690 "Aggregate prefix\n"
4691 "Generate AS set path information\n")
4692
4693ALIAS (no_aggregate_address,
4694 no_aggregate_address_as_set_summary_cmd,
4695 "no aggregate-address A.B.C.D/M as-set summary-only",
4696 NO_STR
4697 "Configure BGP aggregate entries\n"
4698 "Aggregate prefix\n"
4699 "Generate AS set path information\n"
4700 "Filter more specific routes from updates\n")
4701
4702ALIAS (no_aggregate_address,
4703 no_aggregate_address_summary_as_set_cmd,
4704 "no aggregate-address A.B.C.D/M summary-only as-set",
4705 NO_STR
4706 "Configure BGP aggregate entries\n"
4707 "Aggregate prefix\n"
4708 "Filter more specific routes from updates\n"
4709 "Generate AS set path information\n")
4710
4711DEFUN (no_aggregate_address_mask,
4712 no_aggregate_address_mask_cmd,
4713 "no aggregate-address A.B.C.D A.B.C.D",
4714 NO_STR
4715 "Configure BGP aggregate entries\n"
4716 "Aggregate address\n"
4717 "Aggregate mask\n")
4718{
4719 int ret;
4720 char prefix_str[BUFSIZ];
4721
4722 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4723
4724 if (! ret)
4725 {
4726 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4727 return CMD_WARNING;
4728 }
4729
4730 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4731}
4732
4733ALIAS (no_aggregate_address_mask,
4734 no_aggregate_address_mask_summary_only_cmd,
4735 "no aggregate-address A.B.C.D A.B.C.D summary-only",
4736 NO_STR
4737 "Configure BGP aggregate entries\n"
4738 "Aggregate address\n"
4739 "Aggregate mask\n"
4740 "Filter more specific routes from updates\n")
4741
4742ALIAS (no_aggregate_address_mask,
4743 no_aggregate_address_mask_as_set_cmd,
4744 "no aggregate-address A.B.C.D A.B.C.D as-set",
4745 NO_STR
4746 "Configure BGP aggregate entries\n"
4747 "Aggregate address\n"
4748 "Aggregate mask\n"
4749 "Generate AS set path information\n")
4750
4751ALIAS (no_aggregate_address_mask,
4752 no_aggregate_address_mask_as_set_summary_cmd,
4753 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4754 NO_STR
4755 "Configure BGP aggregate entries\n"
4756 "Aggregate address\n"
4757 "Aggregate mask\n"
4758 "Generate AS set path information\n"
4759 "Filter more specific routes from updates\n")
4760
4761ALIAS (no_aggregate_address_mask,
4762 no_aggregate_address_mask_summary_as_set_cmd,
4763 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4764 NO_STR
4765 "Configure BGP aggregate entries\n"
4766 "Aggregate address\n"
4767 "Aggregate mask\n"
4768 "Filter more specific routes from updates\n"
4769 "Generate AS set path information\n")
4770
4771#ifdef HAVE_IPV6
4772DEFUN (ipv6_aggregate_address,
4773 ipv6_aggregate_address_cmd,
4774 "aggregate-address X:X::X:X/M",
4775 "Configure BGP aggregate entries\n"
4776 "Aggregate prefix\n")
4777{
4778 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4779}
4780
4781DEFUN (ipv6_aggregate_address_summary_only,
4782 ipv6_aggregate_address_summary_only_cmd,
4783 "aggregate-address X:X::X:X/M summary-only",
4784 "Configure BGP aggregate entries\n"
4785 "Aggregate prefix\n"
4786 "Filter more specific routes from updates\n")
4787{
4788 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4789 AGGREGATE_SUMMARY_ONLY, 0);
4790}
4791
4792DEFUN (no_ipv6_aggregate_address,
4793 no_ipv6_aggregate_address_cmd,
4794 "no aggregate-address X:X::X:X/M",
4795 NO_STR
4796 "Configure BGP aggregate entries\n"
4797 "Aggregate prefix\n")
4798{
4799 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4800}
4801
4802DEFUN (no_ipv6_aggregate_address_summary_only,
4803 no_ipv6_aggregate_address_summary_only_cmd,
4804 "no aggregate-address X:X::X:X/M summary-only",
4805 NO_STR
4806 "Configure BGP aggregate entries\n"
4807 "Aggregate prefix\n"
4808 "Filter more specific routes from updates\n")
4809{
4810 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4811}
4812
4813ALIAS (ipv6_aggregate_address,
4814 old_ipv6_aggregate_address_cmd,
4815 "ipv6 bgp aggregate-address X:X::X:X/M",
4816 IPV6_STR
4817 BGP_STR
4818 "Configure BGP aggregate entries\n"
4819 "Aggregate prefix\n")
4820
4821ALIAS (ipv6_aggregate_address_summary_only,
4822 old_ipv6_aggregate_address_summary_only_cmd,
4823 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4824 IPV6_STR
4825 BGP_STR
4826 "Configure BGP aggregate entries\n"
4827 "Aggregate prefix\n"
4828 "Filter more specific routes from updates\n")
4829
4830ALIAS (no_ipv6_aggregate_address,
4831 old_no_ipv6_aggregate_address_cmd,
4832 "no ipv6 bgp aggregate-address X:X::X:X/M",
4833 NO_STR
4834 IPV6_STR
4835 BGP_STR
4836 "Configure BGP aggregate entries\n"
4837 "Aggregate prefix\n")
4838
4839ALIAS (no_ipv6_aggregate_address_summary_only,
4840 old_no_ipv6_aggregate_address_summary_only_cmd,
4841 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4842 NO_STR
4843 IPV6_STR
4844 BGP_STR
4845 "Configure BGP aggregate entries\n"
4846 "Aggregate prefix\n"
4847 "Filter more specific routes from updates\n")
4848#endif /* HAVE_IPV6 */
4849
4850/* Redistribute route treatment. */
4851void
4852bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4853 u_int32_t metric, u_char type)
4854{
4855 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004856 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004857 struct bgp_info *new;
4858 struct bgp_info *bi;
4859 struct bgp_info info;
4860 struct bgp_node *bn;
4861 struct attr attr;
4862 struct attr attr_new;
4863 struct attr *new_attr;
4864 afi_t afi;
4865 int ret;
4866
4867 /* Make default attribute. */
4868 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4869 if (nexthop)
4870 attr.nexthop = *nexthop;
4871
4872 attr.med = metric;
4873 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4874
paul1eb8ef22005-04-07 07:30:20 +00004875 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004876 {
4877 afi = family2afi (p->family);
4878
4879 if (bgp->redist[afi][type])
4880 {
4881 /* Copy attribute for modification. */
4882 attr_new = attr;
4883
4884 if (bgp->redist_metric_flag[afi][type])
4885 attr_new.med = bgp->redist_metric[afi][type];
4886
4887 /* Apply route-map. */
4888 if (bgp->rmap[afi][type].map)
4889 {
4890 info.peer = bgp->peer_self;
4891 info.attr = &attr_new;
4892
paulfee0f4c2004-09-13 05:12:46 +00004893 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
4894
paul718e3742002-12-13 20:15:29 +00004895 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
4896 &info);
paulfee0f4c2004-09-13 05:12:46 +00004897
4898 bgp->peer_self->rmap_type = 0;
4899
paul718e3742002-12-13 20:15:29 +00004900 if (ret == RMAP_DENYMATCH)
4901 {
4902 /* Free uninterned attribute. */
4903 bgp_attr_flush (&attr_new);
4904
4905 /* Unintern original. */
4906 aspath_unintern (attr.aspath);
4907 bgp_redistribute_delete (p, type);
4908 return;
4909 }
4910 }
4911
paulfee0f4c2004-09-13 05:12:46 +00004912 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004913 new_attr = bgp_attr_intern (&attr_new);
4914
4915 for (bi = bn->info; bi; bi = bi->next)
4916 if (bi->peer == bgp->peer_self
4917 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
4918 break;
4919
4920 if (bi)
4921 {
4922 if (attrhash_cmp (bi->attr, new_attr))
4923 {
4924 bgp_attr_unintern (new_attr);
4925 aspath_unintern (attr.aspath);
4926 bgp_unlock_node (bn);
4927 return;
4928 }
4929 else
4930 {
4931 /* The attribute is changed. */
4932 SET_FLAG (bi->flags, BGP_INFO_ATTR_CHANGED);
4933
4934 /* Rewrite BGP route information. */
4935 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
4936 bgp_attr_unintern (bi->attr);
4937 bi->attr = new_attr;
4938 bi->uptime = time (NULL);
4939
4940 /* Process change. */
4941 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
4942 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4943 bgp_unlock_node (bn);
4944 aspath_unintern (attr.aspath);
4945 return;
4946 }
4947 }
4948
4949 new = bgp_info_new ();
4950 new->type = type;
4951 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
4952 new->peer = bgp->peer_self;
4953 SET_FLAG (new->flags, BGP_INFO_VALID);
4954 new->attr = new_attr;
4955 new->uptime = time (NULL);
4956
4957 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
4958 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00004959 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00004960 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4961 }
4962 }
4963
4964 /* Unintern original. */
4965 aspath_unintern (attr.aspath);
4966}
4967
4968void
4969bgp_redistribute_delete (struct prefix *p, u_char type)
4970{
4971 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004972 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004973 afi_t afi;
4974 struct bgp_node *rn;
4975 struct bgp_info *ri;
4976
paul1eb8ef22005-04-07 07:30:20 +00004977 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004978 {
4979 afi = family2afi (p->family);
4980
4981 if (bgp->redist[afi][type])
4982 {
paulfee0f4c2004-09-13 05:12:46 +00004983 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004984
4985 for (ri = rn->info; ri; ri = ri->next)
4986 if (ri->peer == bgp->peer_self
4987 && ri->type == type)
4988 break;
4989
4990 if (ri)
4991 {
4992 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
4993 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4994 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4995 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004996 }
4997 bgp_unlock_node (rn);
4998 }
4999 }
5000}
5001
5002/* Withdraw specified route type's route. */
5003void
5004bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5005{
5006 struct bgp_node *rn;
5007 struct bgp_info *ri;
5008 struct bgp_table *table;
5009
5010 table = bgp->rib[afi][SAFI_UNICAST];
5011
5012 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5013 {
5014 for (ri = rn->info; ri; ri = ri->next)
5015 if (ri->peer == bgp->peer_self
5016 && ri->type == type)
5017 break;
5018
5019 if (ri)
5020 {
5021 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
5022 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
5023 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5024 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00005025 }
5026 }
5027}
5028
5029/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005030static void
paul718e3742002-12-13 20:15:29 +00005031route_vty_out_route (struct prefix *p, struct vty *vty)
5032{
5033 int len;
5034 u_int32_t destination;
5035 char buf[BUFSIZ];
5036
5037 if (p->family == AF_INET)
5038 {
5039 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5040 destination = ntohl (p->u.prefix4.s_addr);
5041
5042 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5043 || (IN_CLASSB (destination) && p->prefixlen == 16)
5044 || (IN_CLASSA (destination) && p->prefixlen == 8)
5045 || p->u.prefix4.s_addr == 0)
5046 {
5047 /* When mask is natural, mask is not displayed. */
5048 }
5049 else
5050 len += vty_out (vty, "/%d", p->prefixlen);
5051 }
5052 else
5053 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5054 p->prefixlen);
5055
5056 len = 17 - len;
5057 if (len < 1)
5058 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5059 else
5060 vty_out (vty, "%*s", len, " ");
5061}
5062
paul718e3742002-12-13 20:15:29 +00005063enum bgp_display_type
5064{
5065 normal_list,
5066};
5067
paulb40d9392005-08-22 22:34:41 +00005068/* Print the short form route status for a bgp_info */
5069static void
5070route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005071{
paulb40d9392005-08-22 22:34:41 +00005072 /* Route status display. */
5073 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5074 vty_out (vty, "R");
5075 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005076 vty_out (vty, "S");
5077 else if (binfo->suppress)
paul718e3742002-12-13 20:15:29 +00005078 vty_out (vty, "s");
5079 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5080 vty_out (vty, "*");
5081 else
5082 vty_out (vty, " ");
5083
5084 /* Selected */
5085 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5086 vty_out (vty, "h");
5087 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5088 vty_out (vty, "d");
5089 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5090 vty_out (vty, ">");
5091 else
5092 vty_out (vty, " ");
5093
5094 /* Internal route. */
5095 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5096 vty_out (vty, "i");
5097 else
paulb40d9392005-08-22 22:34:41 +00005098 vty_out (vty, " ");
5099}
5100
5101/* called from terminal list command */
5102void
5103route_vty_out (struct vty *vty, struct prefix *p,
5104 struct bgp_info *binfo, int display, safi_t safi)
5105{
5106 struct attr *attr;
5107
5108 /* short status lead text */
5109 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005110
5111 /* print prefix and mask */
5112 if (! display)
5113 route_vty_out_route (p, vty);
5114 else
5115 vty_out (vty, "%*s", 17, " ");
5116
5117 /* Print attribute */
5118 attr = binfo->attr;
5119 if (attr)
5120 {
5121 if (p->family == AF_INET)
5122 {
5123 if (safi == SAFI_MPLS_VPN)
5124 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5125 else
5126 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5127 }
5128#ifdef HAVE_IPV6
5129 else if (p->family == AF_INET6)
5130 {
5131 int len;
5132 char buf[BUFSIZ];
5133
5134 len = vty_out (vty, "%s",
5135 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5136 len = 16 - len;
5137 if (len < 1)
5138 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5139 else
5140 vty_out (vty, "%*s", len, " ");
5141 }
5142#endif /* HAVE_IPV6 */
5143
5144 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5145 vty_out (vty, "%10d", attr->med);
5146 else
5147 vty_out (vty, " ");
5148
5149 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5150 vty_out (vty, "%7d", attr->local_pref);
5151 else
5152 vty_out (vty, " ");
5153
5154 vty_out (vty, "%7u ",attr->weight);
5155
Paul Jakmab2518c12006-05-12 23:48:40 +00005156 /* Print aspath */
5157 if (attr->aspath)
5158 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005159
Paul Jakmab2518c12006-05-12 23:48:40 +00005160 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005161 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005162 }
paul718e3742002-12-13 20:15:29 +00005163 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005164}
5165
5166/* called from terminal list command */
5167void
5168route_vty_out_tmp (struct vty *vty, struct prefix *p,
5169 struct attr *attr, safi_t safi)
5170{
5171 /* Route status display. */
5172 vty_out (vty, "*");
5173 vty_out (vty, ">");
5174 vty_out (vty, " ");
5175
5176 /* print prefix and mask */
5177 route_vty_out_route (p, vty);
5178
5179 /* Print attribute */
5180 if (attr)
5181 {
5182 if (p->family == AF_INET)
5183 {
5184 if (safi == SAFI_MPLS_VPN)
5185 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5186 else
5187 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5188 }
5189#ifdef HAVE_IPV6
5190 else if (p->family == AF_INET6)
5191 {
5192 int len;
5193 char buf[BUFSIZ];
5194
5195 len = vty_out (vty, "%s",
5196 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5197 len = 16 - len;
5198 if (len < 1)
5199 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5200 else
5201 vty_out (vty, "%*s", len, " ");
5202 }
5203#endif /* HAVE_IPV6 */
5204
5205 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5206 vty_out (vty, "%10d", attr->med);
5207 else
5208 vty_out (vty, " ");
5209
5210 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5211 vty_out (vty, "%7d", attr->local_pref);
5212 else
5213 vty_out (vty, " ");
5214
5215 vty_out (vty, "%7d ",attr->weight);
5216
Paul Jakmab2518c12006-05-12 23:48:40 +00005217 /* Print aspath */
5218 if (attr->aspath)
5219 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005220
Paul Jakmab2518c12006-05-12 23:48:40 +00005221 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005222 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005223 }
paul718e3742002-12-13 20:15:29 +00005224
5225 vty_out (vty, "%s", VTY_NEWLINE);
5226}
5227
ajs5a646652004-11-05 01:25:55 +00005228void
paul718e3742002-12-13 20:15:29 +00005229route_vty_out_tag (struct vty *vty, struct prefix *p,
5230 struct bgp_info *binfo, int display, safi_t safi)
5231{
5232 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005233 u_int32_t label = 0;
5234
paulb40d9392005-08-22 22:34:41 +00005235 /* short status lead text */
5236 route_vty_short_status_out (vty, binfo);
5237
paul718e3742002-12-13 20:15:29 +00005238 /* print prefix and mask */
5239 if (! display)
5240 route_vty_out_route (p, vty);
5241 else
5242 vty_out (vty, "%*s", 17, " ");
5243
5244 /* Print attribute */
5245 attr = binfo->attr;
5246 if (attr)
5247 {
5248 if (p->family == AF_INET)
5249 {
5250 if (safi == SAFI_MPLS_VPN)
5251 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5252 else
5253 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5254 }
5255#ifdef HAVE_IPV6
5256 else if (p->family == AF_INET6)
5257 {
5258 char buf[BUFSIZ];
5259 char buf1[BUFSIZ];
5260 if (attr->mp_nexthop_len == 16)
5261 vty_out (vty, "%s",
5262 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5263 else if (attr->mp_nexthop_len == 32)
5264 vty_out (vty, "%s(%s)",
5265 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
5266 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
5267
5268 }
5269#endif /* HAVE_IPV6 */
5270 }
5271
5272 label = decode_label (binfo->tag);
5273
5274 vty_out (vty, "notag/%d", label);
5275
5276 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005277}
5278
5279/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005280static void
paul718e3742002-12-13 20:15:29 +00005281damp_route_vty_out (struct vty *vty, struct prefix *p,
5282 struct bgp_info *binfo, int display, safi_t safi)
5283{
5284 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005285 int len;
5286
paulb40d9392005-08-22 22:34:41 +00005287 /* short status lead text */
5288 route_vty_short_status_out (vty, binfo);
5289
paul718e3742002-12-13 20:15:29 +00005290 /* print prefix and mask */
5291 if (! display)
5292 route_vty_out_route (p, vty);
5293 else
5294 vty_out (vty, "%*s", 17, " ");
5295
5296 len = vty_out (vty, "%s", binfo->peer->host);
5297 len = 17 - len;
5298 if (len < 1)
5299 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5300 else
5301 vty_out (vty, "%*s", len, " ");
5302
5303 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5304
5305 /* Print attribute */
5306 attr = binfo->attr;
5307 if (attr)
5308 {
5309 /* Print aspath */
5310 if (attr->aspath)
Paul Jakmab2518c12006-05-12 23:48:40 +00005311 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005312
5313 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005314 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005315 }
5316 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005317}
5318
5319#define BGP_UPTIME_LEN 25
5320
5321/* flap route */
ajs5a646652004-11-05 01:25:55 +00005322static void
paul718e3742002-12-13 20:15:29 +00005323flap_route_vty_out (struct vty *vty, struct prefix *p,
5324 struct bgp_info *binfo, int display, safi_t safi)
5325{
5326 struct attr *attr;
5327 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005328 char timebuf[BGP_UPTIME_LEN];
5329 int len;
5330
paul718e3742002-12-13 20:15:29 +00005331 bdi = binfo->damp_info;
5332
paulb40d9392005-08-22 22:34:41 +00005333 /* short status lead text */
5334 route_vty_short_status_out (vty, binfo);
5335
paul718e3742002-12-13 20:15:29 +00005336 /* print prefix and mask */
5337 if (! display)
5338 route_vty_out_route (p, vty);
5339 else
5340 vty_out (vty, "%*s", 17, " ");
5341
5342 len = vty_out (vty, "%s", binfo->peer->host);
5343 len = 16 - len;
5344 if (len < 1)
5345 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5346 else
5347 vty_out (vty, "%*s", len, " ");
5348
5349 len = vty_out (vty, "%d", bdi->flap);
5350 len = 5 - len;
5351 if (len < 1)
5352 vty_out (vty, " ");
5353 else
5354 vty_out (vty, "%*s ", len, " ");
5355
5356 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5357 timebuf, BGP_UPTIME_LEN));
5358
5359 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5360 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5361 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5362 else
5363 vty_out (vty, "%*s ", 8, " ");
5364
5365 /* Print attribute */
5366 attr = binfo->attr;
5367 if (attr)
5368 {
5369 /* Print aspath */
5370 if (attr->aspath)
Paul Jakmab2518c12006-05-12 23:48:40 +00005371 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005372
5373 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005374 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005375 }
5376 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005377}
5378
paul94f2b392005-06-28 12:44:16 +00005379static void
paul718e3742002-12-13 20:15:29 +00005380route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5381 struct bgp_info *binfo, afi_t afi, safi_t safi)
5382{
5383 char buf[INET6_ADDRSTRLEN];
5384 char buf1[BUFSIZ];
5385 struct attr *attr;
5386 int sockunion_vty_out (struct vty *, union sockunion *);
5387
5388 attr = binfo->attr;
5389
5390 if (attr)
5391 {
5392 /* Line1 display AS-path, Aggregator */
5393 if (attr->aspath)
5394 {
5395 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005396 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005397 vty_out (vty, "Local");
5398 else
Paul Jakmab2518c12006-05-12 23:48:40 +00005399 aspath_print_vty (vty, "%s", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005400 }
5401
paulb40d9392005-08-22 22:34:41 +00005402 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5403 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005404 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5405 vty_out (vty, ", (stale)");
5406 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5407 vty_out (vty, ", (aggregated by %d %s)", attr->aggregator_as,
5408 inet_ntoa (attr->aggregator_addr));
5409 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5410 vty_out (vty, ", (Received from a RR-client)");
5411 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5412 vty_out (vty, ", (Received from a RS-client)");
5413 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5414 vty_out (vty, ", (history entry)");
5415 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5416 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005417 vty_out (vty, "%s", VTY_NEWLINE);
5418
5419 /* Line2 display Next-hop, Neighbor, Router-id */
5420 if (p->family == AF_INET)
5421 {
5422 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5423 inet_ntoa (attr->mp_nexthop_global_in) :
5424 inet_ntoa (attr->nexthop));
5425 }
5426#ifdef HAVE_IPV6
5427 else
5428 {
5429 vty_out (vty, " %s",
5430 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5431 buf, INET6_ADDRSTRLEN));
5432 }
5433#endif /* HAVE_IPV6 */
5434
5435 if (binfo->peer == bgp->peer_self)
5436 {
5437 vty_out (vty, " from %s ",
5438 p->family == AF_INET ? "0.0.0.0" : "::");
5439 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5440 }
5441 else
5442 {
5443 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5444 vty_out (vty, " (inaccessible)");
5445 else if (binfo->igpmetric)
5446 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005447 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005448 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5449 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5450 else
5451 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5452 }
5453 vty_out (vty, "%s", VTY_NEWLINE);
5454
5455#ifdef HAVE_IPV6
5456 /* display nexthop local */
5457 if (attr->mp_nexthop_len == 32)
5458 {
5459 vty_out (vty, " (%s)%s",
5460 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5461 buf, INET6_ADDRSTRLEN),
5462 VTY_NEWLINE);
5463 }
5464#endif /* HAVE_IPV6 */
5465
5466 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5467 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5468
5469 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5470 vty_out (vty, ", metric %d", attr->med);
5471
5472 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5473 vty_out (vty, ", localpref %d", attr->local_pref);
5474 else
5475 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5476
5477 if (attr->weight != 0)
5478 vty_out (vty, ", weight %d", attr->weight);
5479
5480 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5481 vty_out (vty, ", valid");
5482
5483 if (binfo->peer != bgp->peer_self)
5484 {
5485 if (binfo->peer->as == binfo->peer->local_as)
5486 vty_out (vty, ", internal");
5487 else
5488 vty_out (vty, ", %s",
5489 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5490 }
5491 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5492 vty_out (vty, ", aggregated, local");
5493 else if (binfo->type != ZEBRA_ROUTE_BGP)
5494 vty_out (vty, ", sourced");
5495 else
5496 vty_out (vty, ", sourced, local");
5497
5498 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5499 vty_out (vty, ", atomic-aggregate");
5500
5501 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5502 vty_out (vty, ", best");
5503
5504 vty_out (vty, "%s", VTY_NEWLINE);
5505
5506 /* Line 4 display Community */
5507 if (attr->community)
5508 vty_out (vty, " Community: %s%s", attr->community->str,
5509 VTY_NEWLINE);
5510
5511 /* Line 5 display Extended-community */
5512 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5513 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5514 VTY_NEWLINE);
5515
5516 /* Line 6 display Originator, Cluster-id */
5517 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5518 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5519 {
5520 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5521 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5522
5523 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5524 {
5525 int i;
5526 vty_out (vty, ", Cluster list: ");
5527 for (i = 0; i < attr->cluster->length / 4; i++)
5528 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5529 }
5530 vty_out (vty, "%s", VTY_NEWLINE);
5531 }
5532
5533 if (binfo->damp_info)
5534 bgp_damp_info_vty (vty, binfo);
5535
5536 /* Line 7 display Uptime */
5537 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5538 }
5539 vty_out (vty, "%s", VTY_NEWLINE);
5540}
5541
paulb40d9392005-08-22 22:34:41 +00005542#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 +00005543#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005544#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5545#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5546#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5547
5548enum bgp_show_type
5549{
5550 bgp_show_type_normal,
5551 bgp_show_type_regexp,
5552 bgp_show_type_prefix_list,
5553 bgp_show_type_filter_list,
5554 bgp_show_type_route_map,
5555 bgp_show_type_neighbor,
5556 bgp_show_type_cidr_only,
5557 bgp_show_type_prefix_longer,
5558 bgp_show_type_community_all,
5559 bgp_show_type_community,
5560 bgp_show_type_community_exact,
5561 bgp_show_type_community_list,
5562 bgp_show_type_community_list_exact,
5563 bgp_show_type_flap_statistics,
5564 bgp_show_type_flap_address,
5565 bgp_show_type_flap_prefix,
5566 bgp_show_type_flap_cidr_only,
5567 bgp_show_type_flap_regexp,
5568 bgp_show_type_flap_filter_list,
5569 bgp_show_type_flap_prefix_list,
5570 bgp_show_type_flap_prefix_longer,
5571 bgp_show_type_flap_route_map,
5572 bgp_show_type_flap_neighbor,
5573 bgp_show_type_dampend_paths,
5574 bgp_show_type_damp_neighbor
5575};
5576
ajs5a646652004-11-05 01:25:55 +00005577static int
paulfee0f4c2004-09-13 05:12:46 +00005578bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00005579 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00005580{
paul718e3742002-12-13 20:15:29 +00005581 struct bgp_info *ri;
5582 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005583 int header = 1;
paul718e3742002-12-13 20:15:29 +00005584 int display;
ajs5a646652004-11-05 01:25:55 +00005585 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00005586
5587 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00005588 output_count = 0;
paul718e3742002-12-13 20:15:29 +00005589
paul718e3742002-12-13 20:15:29 +00005590 /* Start processing of routes. */
5591 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5592 if (rn->info != NULL)
5593 {
5594 display = 0;
5595
5596 for (ri = rn->info; ri; ri = ri->next)
5597 {
ajs5a646652004-11-05 01:25:55 +00005598 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00005599 || type == bgp_show_type_flap_address
5600 || type == bgp_show_type_flap_prefix
5601 || type == bgp_show_type_flap_cidr_only
5602 || type == bgp_show_type_flap_regexp
5603 || type == bgp_show_type_flap_filter_list
5604 || type == bgp_show_type_flap_prefix_list
5605 || type == bgp_show_type_flap_prefix_longer
5606 || type == bgp_show_type_flap_route_map
5607 || type == bgp_show_type_flap_neighbor
5608 || type == bgp_show_type_dampend_paths
5609 || type == bgp_show_type_damp_neighbor)
5610 {
5611 if (! ri->damp_info)
5612 continue;
5613 }
5614 if (type == bgp_show_type_regexp
5615 || type == bgp_show_type_flap_regexp)
5616 {
ajs5a646652004-11-05 01:25:55 +00005617 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00005618
5619 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5620 continue;
5621 }
5622 if (type == bgp_show_type_prefix_list
5623 || type == bgp_show_type_flap_prefix_list)
5624 {
ajs5a646652004-11-05 01:25:55 +00005625 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00005626
5627 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5628 continue;
5629 }
5630 if (type == bgp_show_type_filter_list
5631 || type == bgp_show_type_flap_filter_list)
5632 {
ajs5a646652004-11-05 01:25:55 +00005633 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00005634
5635 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5636 continue;
5637 }
5638 if (type == bgp_show_type_route_map
5639 || type == bgp_show_type_flap_route_map)
5640 {
ajs5a646652004-11-05 01:25:55 +00005641 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00005642 struct bgp_info binfo;
5643 struct attr dummy_attr;
5644 int ret;
5645
5646 dummy_attr = *ri->attr;
5647 binfo.peer = ri->peer;
5648 binfo.attr = &dummy_attr;
5649
5650 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5651
5652 if (ret == RMAP_DENYMATCH)
5653 continue;
5654 }
5655 if (type == bgp_show_type_neighbor
5656 || type == bgp_show_type_flap_neighbor
5657 || type == bgp_show_type_damp_neighbor)
5658 {
ajs5a646652004-11-05 01:25:55 +00005659 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00005660
5661 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5662 continue;
5663 }
5664 if (type == bgp_show_type_cidr_only
5665 || type == bgp_show_type_flap_cidr_only)
5666 {
5667 u_int32_t destination;
5668
5669 destination = ntohl (rn->p.u.prefix4.s_addr);
5670 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5671 continue;
5672 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5673 continue;
5674 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5675 continue;
5676 }
5677 if (type == bgp_show_type_prefix_longer
5678 || type == bgp_show_type_flap_prefix_longer)
5679 {
ajs5a646652004-11-05 01:25:55 +00005680 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005681
5682 if (! prefix_match (p, &rn->p))
5683 continue;
5684 }
5685 if (type == bgp_show_type_community_all)
5686 {
5687 if (! ri->attr->community)
5688 continue;
5689 }
5690 if (type == bgp_show_type_community)
5691 {
ajs5a646652004-11-05 01:25:55 +00005692 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005693
5694 if (! ri->attr->community ||
5695 ! community_match (ri->attr->community, com))
5696 continue;
5697 }
5698 if (type == bgp_show_type_community_exact)
5699 {
ajs5a646652004-11-05 01:25:55 +00005700 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005701
5702 if (! ri->attr->community ||
5703 ! community_cmp (ri->attr->community, com))
5704 continue;
5705 }
5706 if (type == bgp_show_type_community_list)
5707 {
ajs5a646652004-11-05 01:25:55 +00005708 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005709
5710 if (! community_list_match (ri->attr->community, list))
5711 continue;
5712 }
5713 if (type == bgp_show_type_community_list_exact)
5714 {
ajs5a646652004-11-05 01:25:55 +00005715 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005716
5717 if (! community_list_exact_match (ri->attr->community, list))
5718 continue;
5719 }
5720 if (type == bgp_show_type_flap_address
5721 || type == bgp_show_type_flap_prefix)
5722 {
ajs5a646652004-11-05 01:25:55 +00005723 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005724
5725 if (! prefix_match (&rn->p, p))
5726 continue;
5727
5728 if (type == bgp_show_type_flap_prefix)
5729 if (p->prefixlen != rn->p.prefixlen)
5730 continue;
5731 }
5732 if (type == bgp_show_type_dampend_paths
5733 || type == bgp_show_type_damp_neighbor)
5734 {
5735 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5736 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5737 continue;
5738 }
5739
5740 if (header)
5741 {
hasso93406d82005-02-02 14:40:33 +00005742 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
5743 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
5744 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005745 if (type == bgp_show_type_dampend_paths
5746 || type == bgp_show_type_damp_neighbor)
5747 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5748 else if (type == bgp_show_type_flap_statistics
5749 || type == bgp_show_type_flap_address
5750 || type == bgp_show_type_flap_prefix
5751 || type == bgp_show_type_flap_cidr_only
5752 || type == bgp_show_type_flap_regexp
5753 || type == bgp_show_type_flap_filter_list
5754 || type == bgp_show_type_flap_prefix_list
5755 || type == bgp_show_type_flap_prefix_longer
5756 || type == bgp_show_type_flap_route_map
5757 || type == bgp_show_type_flap_neighbor)
5758 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5759 else
5760 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005761 header = 0;
5762 }
5763
5764 if (type == bgp_show_type_dampend_paths
5765 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00005766 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005767 else if (type == bgp_show_type_flap_statistics
5768 || type == bgp_show_type_flap_address
5769 || type == bgp_show_type_flap_prefix
5770 || type == bgp_show_type_flap_cidr_only
5771 || type == bgp_show_type_flap_regexp
5772 || type == bgp_show_type_flap_filter_list
5773 || type == bgp_show_type_flap_prefix_list
5774 || type == bgp_show_type_flap_prefix_longer
5775 || type == bgp_show_type_flap_route_map
5776 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00005777 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005778 else
ajs5a646652004-11-05 01:25:55 +00005779 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005780 display++;
5781 }
5782 if (display)
ajs5a646652004-11-05 01:25:55 +00005783 output_count++;
paul718e3742002-12-13 20:15:29 +00005784 }
5785
5786 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00005787 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00005788 {
5789 if (type == bgp_show_type_normal)
5790 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5791 }
5792 else
5793 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00005794 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005795
5796 return CMD_SUCCESS;
5797}
5798
ajs5a646652004-11-05 01:25:55 +00005799static int
paulfee0f4c2004-09-13 05:12:46 +00005800bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00005801 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00005802{
5803 struct bgp_table *table;
5804
5805 if (bgp == NULL) {
5806 bgp = bgp_get_default ();
5807 }
5808
5809 if (bgp == NULL)
5810 {
5811 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5812 return CMD_WARNING;
5813 }
5814
5815
5816 table = bgp->rib[afi][safi];
5817
ajs5a646652004-11-05 01:25:55 +00005818 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00005819}
5820
paul718e3742002-12-13 20:15:29 +00005821/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00005822static void
paul718e3742002-12-13 20:15:29 +00005823route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5824 struct bgp_node *rn,
5825 struct prefix_rd *prd, afi_t afi, safi_t safi)
5826{
5827 struct bgp_info *ri;
5828 struct prefix *p;
5829 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00005830 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005831 char buf1[INET6_ADDRSTRLEN];
5832 char buf2[INET6_ADDRSTRLEN];
5833 int count = 0;
5834 int best = 0;
5835 int suppress = 0;
5836 int no_export = 0;
5837 int no_advertise = 0;
5838 int local_as = 0;
5839 int first = 0;
5840
5841 p = &rn->p;
5842 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5843 (safi == SAFI_MPLS_VPN ?
5844 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5845 safi == SAFI_MPLS_VPN ? ":" : "",
5846 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5847 p->prefixlen, VTY_NEWLINE);
5848
5849 for (ri = rn->info; ri; ri = ri->next)
5850 {
5851 count++;
5852 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5853 {
5854 best = count;
5855 if (ri->suppress)
5856 suppress = 1;
5857 if (ri->attr->community != NULL)
5858 {
5859 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5860 no_advertise = 1;
5861 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5862 no_export = 1;
5863 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5864 local_as = 1;
5865 }
5866 }
5867 }
5868
5869 vty_out (vty, "Paths: (%d available", count);
5870 if (best)
5871 {
5872 vty_out (vty, ", best #%d", best);
5873 if (safi == SAFI_UNICAST)
5874 vty_out (vty, ", table Default-IP-Routing-Table");
5875 }
5876 else
5877 vty_out (vty, ", no best path");
5878 if (no_advertise)
5879 vty_out (vty, ", not advertised to any peer");
5880 else if (no_export)
5881 vty_out (vty, ", not advertised to EBGP peer");
5882 else if (local_as)
5883 vty_out (vty, ", not advertised outside local AS");
5884 if (suppress)
5885 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5886 vty_out (vty, ")%s", VTY_NEWLINE);
5887
5888 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00005889 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00005890 {
5891 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5892 {
5893 if (! first)
5894 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5895 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5896 first = 1;
5897 }
5898 }
5899 if (! first)
5900 vty_out (vty, " Not advertised to any peer");
5901 vty_out (vty, "%s", VTY_NEWLINE);
5902}
5903
5904/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00005905static int
paulfee0f4c2004-09-13 05:12:46 +00005906bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00005907 struct bgp_table *rib, const char *ip_str,
5908 afi_t afi, safi_t safi, struct prefix_rd *prd,
5909 int prefix_check)
paul718e3742002-12-13 20:15:29 +00005910{
5911 int ret;
5912 int header;
5913 int display = 0;
5914 struct prefix match;
5915 struct bgp_node *rn;
5916 struct bgp_node *rm;
5917 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00005918 struct bgp_table *table;
5919
paul718e3742002-12-13 20:15:29 +00005920 /* Check IP address argument. */
5921 ret = str2prefix (ip_str, &match);
5922 if (! ret)
5923 {
5924 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5925 return CMD_WARNING;
5926 }
5927
5928 match.family = afi2family (afi);
5929
5930 if (safi == SAFI_MPLS_VPN)
5931 {
paulfee0f4c2004-09-13 05:12:46 +00005932 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00005933 {
5934 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5935 continue;
5936
5937 if ((table = rn->info) != NULL)
5938 {
5939 header = 1;
5940
5941 if ((rm = bgp_node_match (table, &match)) != NULL)
5942 {
5943 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5944 continue;
5945
5946 for (ri = rm->info; ri; ri = ri->next)
5947 {
5948 if (header)
5949 {
5950 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5951 AFI_IP, SAFI_MPLS_VPN);
5952
5953 header = 0;
5954 }
5955 display++;
5956 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5957 }
5958 }
5959 }
5960 }
5961 }
5962 else
5963 {
5964 header = 1;
5965
paulfee0f4c2004-09-13 05:12:46 +00005966 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00005967 {
5968 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5969 {
5970 for (ri = rn->info; ri; ri = ri->next)
5971 {
5972 if (header)
5973 {
5974 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
5975 header = 0;
5976 }
5977 display++;
5978 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
5979 }
5980 }
5981 }
5982 }
5983
5984 if (! display)
5985 {
5986 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5987 return CMD_WARNING;
5988 }
5989
5990 return CMD_SUCCESS;
5991}
5992
paulfee0f4c2004-09-13 05:12:46 +00005993/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00005994static int
paulfd79ac92004-10-13 05:06:08 +00005995bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00005996 afi_t afi, safi_t safi, struct prefix_rd *prd,
5997 int prefix_check)
5998{
5999 struct bgp *bgp;
6000
6001 /* BGP structure lookup. */
6002 if (view_name)
6003 {
6004 bgp = bgp_lookup_by_name (view_name);
6005 if (bgp == NULL)
6006 {
6007 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6008 return CMD_WARNING;
6009 }
6010 }
6011 else
6012 {
6013 bgp = bgp_get_default ();
6014 if (bgp == NULL)
6015 {
6016 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6017 return CMD_WARNING;
6018 }
6019 }
6020
6021 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6022 afi, safi, prd, prefix_check);
6023}
6024
paul718e3742002-12-13 20:15:29 +00006025/* BGP route print out function. */
6026DEFUN (show_ip_bgp,
6027 show_ip_bgp_cmd,
6028 "show ip bgp",
6029 SHOW_STR
6030 IP_STR
6031 BGP_STR)
6032{
ajs5a646652004-11-05 01:25:55 +00006033 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006034}
6035
6036DEFUN (show_ip_bgp_ipv4,
6037 show_ip_bgp_ipv4_cmd,
6038 "show ip bgp ipv4 (unicast|multicast)",
6039 SHOW_STR
6040 IP_STR
6041 BGP_STR
6042 "Address family\n"
6043 "Address Family modifier\n"
6044 "Address Family modifier\n")
6045{
6046 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006047 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6048 NULL);
paul718e3742002-12-13 20:15:29 +00006049
ajs5a646652004-11-05 01:25:55 +00006050 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006051}
6052
6053DEFUN (show_ip_bgp_route,
6054 show_ip_bgp_route_cmd,
6055 "show ip bgp A.B.C.D",
6056 SHOW_STR
6057 IP_STR
6058 BGP_STR
6059 "Network in the BGP routing table to display\n")
6060{
6061 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6062}
6063
6064DEFUN (show_ip_bgp_ipv4_route,
6065 show_ip_bgp_ipv4_route_cmd,
6066 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6067 SHOW_STR
6068 IP_STR
6069 BGP_STR
6070 "Address family\n"
6071 "Address Family modifier\n"
6072 "Address Family modifier\n"
6073 "Network in the BGP routing table to display\n")
6074{
6075 if (strncmp (argv[0], "m", 1) == 0)
6076 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6077
6078 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6079}
6080
6081DEFUN (show_ip_bgp_vpnv4_all_route,
6082 show_ip_bgp_vpnv4_all_route_cmd,
6083 "show ip bgp vpnv4 all A.B.C.D",
6084 SHOW_STR
6085 IP_STR
6086 BGP_STR
6087 "Display VPNv4 NLRI specific information\n"
6088 "Display information about all VPNv4 NLRIs\n"
6089 "Network in the BGP routing table to display\n")
6090{
6091 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6092}
6093
6094DEFUN (show_ip_bgp_vpnv4_rd_route,
6095 show_ip_bgp_vpnv4_rd_route_cmd,
6096 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6097 SHOW_STR
6098 IP_STR
6099 BGP_STR
6100 "Display VPNv4 NLRI specific information\n"
6101 "Display information for a route distinguisher\n"
6102 "VPN Route Distinguisher\n"
6103 "Network in the BGP routing table to display\n")
6104{
6105 int ret;
6106 struct prefix_rd prd;
6107
6108 ret = str2prefix_rd (argv[0], &prd);
6109 if (! ret)
6110 {
6111 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6112 return CMD_WARNING;
6113 }
6114 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6115}
6116
6117DEFUN (show_ip_bgp_prefix,
6118 show_ip_bgp_prefix_cmd,
6119 "show ip bgp A.B.C.D/M",
6120 SHOW_STR
6121 IP_STR
6122 BGP_STR
6123 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6124{
6125 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6126}
6127
6128DEFUN (show_ip_bgp_ipv4_prefix,
6129 show_ip_bgp_ipv4_prefix_cmd,
6130 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6131 SHOW_STR
6132 IP_STR
6133 BGP_STR
6134 "Address family\n"
6135 "Address Family modifier\n"
6136 "Address Family modifier\n"
6137 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6138{
6139 if (strncmp (argv[0], "m", 1) == 0)
6140 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6141
6142 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6143}
6144
6145DEFUN (show_ip_bgp_vpnv4_all_prefix,
6146 show_ip_bgp_vpnv4_all_prefix_cmd,
6147 "show ip bgp vpnv4 all A.B.C.D/M",
6148 SHOW_STR
6149 IP_STR
6150 BGP_STR
6151 "Display VPNv4 NLRI specific information\n"
6152 "Display information about all VPNv4 NLRIs\n"
6153 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6154{
6155 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6156}
6157
6158DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6159 show_ip_bgp_vpnv4_rd_prefix_cmd,
6160 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6161 SHOW_STR
6162 IP_STR
6163 BGP_STR
6164 "Display VPNv4 NLRI specific information\n"
6165 "Display information for a route distinguisher\n"
6166 "VPN Route Distinguisher\n"
6167 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6168{
6169 int ret;
6170 struct prefix_rd prd;
6171
6172 ret = str2prefix_rd (argv[0], &prd);
6173 if (! ret)
6174 {
6175 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6176 return CMD_WARNING;
6177 }
6178 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6179}
6180
6181DEFUN (show_ip_bgp_view,
6182 show_ip_bgp_view_cmd,
6183 "show ip bgp view WORD",
6184 SHOW_STR
6185 IP_STR
6186 BGP_STR
6187 "BGP view\n"
6188 "BGP view name\n")
6189{
paulbb46e942003-10-24 19:02:03 +00006190 struct bgp *bgp;
6191
6192 /* BGP structure lookup. */
6193 bgp = bgp_lookup_by_name (argv[0]);
6194 if (bgp == NULL)
6195 {
6196 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6197 return CMD_WARNING;
6198 }
6199
ajs5a646652004-11-05 01:25:55 +00006200 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006201}
6202
6203DEFUN (show_ip_bgp_view_route,
6204 show_ip_bgp_view_route_cmd,
6205 "show ip bgp view WORD A.B.C.D",
6206 SHOW_STR
6207 IP_STR
6208 BGP_STR
6209 "BGP view\n"
6210 "BGP view name\n"
6211 "Network in the BGP routing table to display\n")
6212{
6213 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6214}
6215
6216DEFUN (show_ip_bgp_view_prefix,
6217 show_ip_bgp_view_prefix_cmd,
6218 "show ip bgp view WORD A.B.C.D/M",
6219 SHOW_STR
6220 IP_STR
6221 BGP_STR
6222 "BGP view\n"
6223 "BGP view name\n"
6224 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6225{
6226 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6227}
6228
6229#ifdef HAVE_IPV6
6230DEFUN (show_bgp,
6231 show_bgp_cmd,
6232 "show bgp",
6233 SHOW_STR
6234 BGP_STR)
6235{
ajs5a646652004-11-05 01:25:55 +00006236 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6237 NULL);
paul718e3742002-12-13 20:15:29 +00006238}
6239
6240ALIAS (show_bgp,
6241 show_bgp_ipv6_cmd,
6242 "show bgp ipv6",
6243 SHOW_STR
6244 BGP_STR
6245 "Address family\n")
6246
6247/* old command */
6248DEFUN (show_ipv6_bgp,
6249 show_ipv6_bgp_cmd,
6250 "show ipv6 bgp",
6251 SHOW_STR
6252 IP_STR
6253 BGP_STR)
6254{
ajs5a646652004-11-05 01:25:55 +00006255 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6256 NULL);
paul718e3742002-12-13 20:15:29 +00006257}
6258
6259DEFUN (show_bgp_route,
6260 show_bgp_route_cmd,
6261 "show bgp X:X::X:X",
6262 SHOW_STR
6263 BGP_STR
6264 "Network in the BGP routing table to display\n")
6265{
6266 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6267}
6268
6269ALIAS (show_bgp_route,
6270 show_bgp_ipv6_route_cmd,
6271 "show bgp ipv6 X:X::X:X",
6272 SHOW_STR
6273 BGP_STR
6274 "Address family\n"
6275 "Network in the BGP routing table to display\n")
6276
6277/* old command */
6278DEFUN (show_ipv6_bgp_route,
6279 show_ipv6_bgp_route_cmd,
6280 "show ipv6 bgp X:X::X:X",
6281 SHOW_STR
6282 IP_STR
6283 BGP_STR
6284 "Network in the BGP routing table to display\n")
6285{
6286 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6287}
6288
6289DEFUN (show_bgp_prefix,
6290 show_bgp_prefix_cmd,
6291 "show bgp X:X::X:X/M",
6292 SHOW_STR
6293 BGP_STR
6294 "IPv6 prefix <network>/<length>\n")
6295{
6296 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6297}
6298
6299ALIAS (show_bgp_prefix,
6300 show_bgp_ipv6_prefix_cmd,
6301 "show bgp ipv6 X:X::X:X/M",
6302 SHOW_STR
6303 BGP_STR
6304 "Address family\n"
6305 "IPv6 prefix <network>/<length>\n")
6306
6307/* old command */
6308DEFUN (show_ipv6_bgp_prefix,
6309 show_ipv6_bgp_prefix_cmd,
6310 "show ipv6 bgp X:X::X:X/M",
6311 SHOW_STR
6312 IP_STR
6313 BGP_STR
6314 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6315{
6316 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6317}
6318
paulbb46e942003-10-24 19:02:03 +00006319DEFUN (show_bgp_view,
6320 show_bgp_view_cmd,
6321 "show bgp view WORD",
6322 SHOW_STR
6323 BGP_STR
6324 "BGP view\n"
6325 "View name\n")
6326{
6327 struct bgp *bgp;
6328
6329 /* BGP structure lookup. */
6330 bgp = bgp_lookup_by_name (argv[0]);
6331 if (bgp == NULL)
6332 {
6333 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6334 return CMD_WARNING;
6335 }
6336
ajs5a646652004-11-05 01:25:55 +00006337 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006338}
6339
6340ALIAS (show_bgp_view,
6341 show_bgp_view_ipv6_cmd,
6342 "show bgp view WORD ipv6",
6343 SHOW_STR
6344 BGP_STR
6345 "BGP view\n"
6346 "View name\n"
6347 "Address family\n")
6348
6349DEFUN (show_bgp_view_route,
6350 show_bgp_view_route_cmd,
6351 "show bgp view WORD X:X::X:X",
6352 SHOW_STR
6353 BGP_STR
6354 "BGP view\n"
6355 "View name\n"
6356 "Network in the BGP routing table to display\n")
6357{
6358 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6359}
6360
6361ALIAS (show_bgp_view_route,
6362 show_bgp_view_ipv6_route_cmd,
6363 "show bgp view WORD ipv6 X:X::X:X",
6364 SHOW_STR
6365 BGP_STR
6366 "BGP view\n"
6367 "View name\n"
6368 "Address family\n"
6369 "Network in the BGP routing table to display\n")
6370
6371DEFUN (show_bgp_view_prefix,
6372 show_bgp_view_prefix_cmd,
6373 "show bgp view WORD X:X::X:X/M",
6374 SHOW_STR
6375 BGP_STR
6376 "BGP view\n"
6377 "View name\n"
6378 "IPv6 prefix <network>/<length>\n")
6379{
6380 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6381}
6382
6383ALIAS (show_bgp_view_prefix,
6384 show_bgp_view_ipv6_prefix_cmd,
6385 "show bgp view WORD ipv6 X:X::X:X/M",
6386 SHOW_STR
6387 BGP_STR
6388 "BGP view\n"
6389 "View name\n"
6390 "Address family\n"
6391 "IPv6 prefix <network>/<length>\n")
6392
paul718e3742002-12-13 20:15:29 +00006393/* old command */
6394DEFUN (show_ipv6_mbgp,
6395 show_ipv6_mbgp_cmd,
6396 "show ipv6 mbgp",
6397 SHOW_STR
6398 IP_STR
6399 MBGP_STR)
6400{
ajs5a646652004-11-05 01:25:55 +00006401 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6402 NULL);
paul718e3742002-12-13 20:15:29 +00006403}
6404
6405/* old command */
6406DEFUN (show_ipv6_mbgp_route,
6407 show_ipv6_mbgp_route_cmd,
6408 "show ipv6 mbgp X:X::X:X",
6409 SHOW_STR
6410 IP_STR
6411 MBGP_STR
6412 "Network in the MBGP routing table to display\n")
6413{
6414 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6415}
6416
6417/* old command */
6418DEFUN (show_ipv6_mbgp_prefix,
6419 show_ipv6_mbgp_prefix_cmd,
6420 "show ipv6 mbgp X:X::X:X/M",
6421 SHOW_STR
6422 IP_STR
6423 MBGP_STR
6424 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6425{
6426 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6427}
6428#endif
6429
paul718e3742002-12-13 20:15:29 +00006430
paul94f2b392005-06-28 12:44:16 +00006431static int
paulfd79ac92004-10-13 05:06:08 +00006432bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006433 safi_t safi, enum bgp_show_type type)
6434{
6435 int i;
6436 struct buffer *b;
6437 char *regstr;
6438 int first;
6439 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006440 int rc;
paul718e3742002-12-13 20:15:29 +00006441
6442 first = 0;
6443 b = buffer_new (1024);
6444 for (i = 0; i < argc; i++)
6445 {
6446 if (first)
6447 buffer_putc (b, ' ');
6448 else
6449 {
6450 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6451 continue;
6452 first = 1;
6453 }
6454
6455 buffer_putstr (b, argv[i]);
6456 }
6457 buffer_putc (b, '\0');
6458
6459 regstr = buffer_getstr (b);
6460 buffer_free (b);
6461
6462 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006463 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006464 if (! regex)
6465 {
6466 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6467 VTY_NEWLINE);
6468 return CMD_WARNING;
6469 }
6470
ajs5a646652004-11-05 01:25:55 +00006471 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6472 bgp_regex_free (regex);
6473 return rc;
paul718e3742002-12-13 20:15:29 +00006474}
6475
6476DEFUN (show_ip_bgp_regexp,
6477 show_ip_bgp_regexp_cmd,
6478 "show ip bgp regexp .LINE",
6479 SHOW_STR
6480 IP_STR
6481 BGP_STR
6482 "Display routes matching the AS path regular expression\n"
6483 "A regular-expression to match the BGP AS paths\n")
6484{
6485 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6486 bgp_show_type_regexp);
6487}
6488
6489DEFUN (show_ip_bgp_flap_regexp,
6490 show_ip_bgp_flap_regexp_cmd,
6491 "show ip bgp flap-statistics regexp .LINE",
6492 SHOW_STR
6493 IP_STR
6494 BGP_STR
6495 "Display flap statistics of routes\n"
6496 "Display routes matching the AS path regular expression\n"
6497 "A regular-expression to match the BGP AS paths\n")
6498{
6499 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6500 bgp_show_type_flap_regexp);
6501}
6502
6503DEFUN (show_ip_bgp_ipv4_regexp,
6504 show_ip_bgp_ipv4_regexp_cmd,
6505 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6506 SHOW_STR
6507 IP_STR
6508 BGP_STR
6509 "Address family\n"
6510 "Address Family modifier\n"
6511 "Address Family modifier\n"
6512 "Display routes matching the AS path regular expression\n"
6513 "A regular-expression to match the BGP AS paths\n")
6514{
6515 if (strncmp (argv[0], "m", 1) == 0)
6516 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6517 bgp_show_type_regexp);
6518
6519 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6520 bgp_show_type_regexp);
6521}
6522
6523#ifdef HAVE_IPV6
6524DEFUN (show_bgp_regexp,
6525 show_bgp_regexp_cmd,
6526 "show bgp regexp .LINE",
6527 SHOW_STR
6528 BGP_STR
6529 "Display routes matching the AS path regular expression\n"
6530 "A regular-expression to match the BGP AS paths\n")
6531{
6532 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6533 bgp_show_type_regexp);
6534}
6535
6536ALIAS (show_bgp_regexp,
6537 show_bgp_ipv6_regexp_cmd,
6538 "show bgp ipv6 regexp .LINE",
6539 SHOW_STR
6540 BGP_STR
6541 "Address family\n"
6542 "Display routes matching the AS path regular expression\n"
6543 "A regular-expression to match the BGP AS paths\n")
6544
6545/* old command */
6546DEFUN (show_ipv6_bgp_regexp,
6547 show_ipv6_bgp_regexp_cmd,
6548 "show ipv6 bgp regexp .LINE",
6549 SHOW_STR
6550 IP_STR
6551 BGP_STR
6552 "Display routes matching the AS path regular expression\n"
6553 "A regular-expression to match the BGP AS paths\n")
6554{
6555 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6556 bgp_show_type_regexp);
6557}
6558
6559/* old command */
6560DEFUN (show_ipv6_mbgp_regexp,
6561 show_ipv6_mbgp_regexp_cmd,
6562 "show ipv6 mbgp regexp .LINE",
6563 SHOW_STR
6564 IP_STR
6565 BGP_STR
6566 "Display routes matching the AS path regular expression\n"
6567 "A regular-expression to match the MBGP AS paths\n")
6568{
6569 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6570 bgp_show_type_regexp);
6571}
6572#endif /* HAVE_IPV6 */
6573
paul94f2b392005-06-28 12:44:16 +00006574static int
paulfd79ac92004-10-13 05:06:08 +00006575bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006576 safi_t safi, enum bgp_show_type type)
6577{
6578 struct prefix_list *plist;
6579
6580 plist = prefix_list_lookup (afi, prefix_list_str);
6581 if (plist == NULL)
6582 {
6583 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6584 prefix_list_str, VTY_NEWLINE);
6585 return CMD_WARNING;
6586 }
6587
ajs5a646652004-11-05 01:25:55 +00006588 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00006589}
6590
6591DEFUN (show_ip_bgp_prefix_list,
6592 show_ip_bgp_prefix_list_cmd,
6593 "show ip bgp prefix-list WORD",
6594 SHOW_STR
6595 IP_STR
6596 BGP_STR
6597 "Display routes conforming to the prefix-list\n"
6598 "IP prefix-list name\n")
6599{
6600 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6601 bgp_show_type_prefix_list);
6602}
6603
6604DEFUN (show_ip_bgp_flap_prefix_list,
6605 show_ip_bgp_flap_prefix_list_cmd,
6606 "show ip bgp flap-statistics prefix-list WORD",
6607 SHOW_STR
6608 IP_STR
6609 BGP_STR
6610 "Display flap statistics of routes\n"
6611 "Display routes conforming to the prefix-list\n"
6612 "IP prefix-list name\n")
6613{
6614 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6615 bgp_show_type_flap_prefix_list);
6616}
6617
6618DEFUN (show_ip_bgp_ipv4_prefix_list,
6619 show_ip_bgp_ipv4_prefix_list_cmd,
6620 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6621 SHOW_STR
6622 IP_STR
6623 BGP_STR
6624 "Address family\n"
6625 "Address Family modifier\n"
6626 "Address Family modifier\n"
6627 "Display routes conforming to the prefix-list\n"
6628 "IP prefix-list name\n")
6629{
6630 if (strncmp (argv[0], "m", 1) == 0)
6631 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6632 bgp_show_type_prefix_list);
6633
6634 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6635 bgp_show_type_prefix_list);
6636}
6637
6638#ifdef HAVE_IPV6
6639DEFUN (show_bgp_prefix_list,
6640 show_bgp_prefix_list_cmd,
6641 "show bgp prefix-list WORD",
6642 SHOW_STR
6643 BGP_STR
6644 "Display routes conforming to the prefix-list\n"
6645 "IPv6 prefix-list name\n")
6646{
6647 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6648 bgp_show_type_prefix_list);
6649}
6650
6651ALIAS (show_bgp_prefix_list,
6652 show_bgp_ipv6_prefix_list_cmd,
6653 "show bgp ipv6 prefix-list WORD",
6654 SHOW_STR
6655 BGP_STR
6656 "Address family\n"
6657 "Display routes conforming to the prefix-list\n"
6658 "IPv6 prefix-list name\n")
6659
6660/* old command */
6661DEFUN (show_ipv6_bgp_prefix_list,
6662 show_ipv6_bgp_prefix_list_cmd,
6663 "show ipv6 bgp prefix-list WORD",
6664 SHOW_STR
6665 IPV6_STR
6666 BGP_STR
6667 "Display routes matching the prefix-list\n"
6668 "IPv6 prefix-list name\n")
6669{
6670 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6671 bgp_show_type_prefix_list);
6672}
6673
6674/* old command */
6675DEFUN (show_ipv6_mbgp_prefix_list,
6676 show_ipv6_mbgp_prefix_list_cmd,
6677 "show ipv6 mbgp prefix-list WORD",
6678 SHOW_STR
6679 IPV6_STR
6680 MBGP_STR
6681 "Display routes matching the prefix-list\n"
6682 "IPv6 prefix-list name\n")
6683{
6684 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6685 bgp_show_type_prefix_list);
6686}
6687#endif /* HAVE_IPV6 */
6688
paul94f2b392005-06-28 12:44:16 +00006689static int
paulfd79ac92004-10-13 05:06:08 +00006690bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006691 safi_t safi, enum bgp_show_type type)
6692{
6693 struct as_list *as_list;
6694
6695 as_list = as_list_lookup (filter);
6696 if (as_list == NULL)
6697 {
6698 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6699 return CMD_WARNING;
6700 }
6701
ajs5a646652004-11-05 01:25:55 +00006702 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00006703}
6704
6705DEFUN (show_ip_bgp_filter_list,
6706 show_ip_bgp_filter_list_cmd,
6707 "show ip bgp filter-list WORD",
6708 SHOW_STR
6709 IP_STR
6710 BGP_STR
6711 "Display routes conforming to the filter-list\n"
6712 "Regular expression access list name\n")
6713{
6714 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6715 bgp_show_type_filter_list);
6716}
6717
6718DEFUN (show_ip_bgp_flap_filter_list,
6719 show_ip_bgp_flap_filter_list_cmd,
6720 "show ip bgp flap-statistics filter-list WORD",
6721 SHOW_STR
6722 IP_STR
6723 BGP_STR
6724 "Display flap statistics of routes\n"
6725 "Display routes conforming to the filter-list\n"
6726 "Regular expression access list name\n")
6727{
6728 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6729 bgp_show_type_flap_filter_list);
6730}
6731
6732DEFUN (show_ip_bgp_ipv4_filter_list,
6733 show_ip_bgp_ipv4_filter_list_cmd,
6734 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6735 SHOW_STR
6736 IP_STR
6737 BGP_STR
6738 "Address family\n"
6739 "Address Family modifier\n"
6740 "Address Family modifier\n"
6741 "Display routes conforming to the filter-list\n"
6742 "Regular expression access list name\n")
6743{
6744 if (strncmp (argv[0], "m", 1) == 0)
6745 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6746 bgp_show_type_filter_list);
6747
6748 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6749 bgp_show_type_filter_list);
6750}
6751
6752#ifdef HAVE_IPV6
6753DEFUN (show_bgp_filter_list,
6754 show_bgp_filter_list_cmd,
6755 "show bgp filter-list WORD",
6756 SHOW_STR
6757 BGP_STR
6758 "Display routes conforming to the filter-list\n"
6759 "Regular expression access list name\n")
6760{
6761 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6762 bgp_show_type_filter_list);
6763}
6764
6765ALIAS (show_bgp_filter_list,
6766 show_bgp_ipv6_filter_list_cmd,
6767 "show bgp ipv6 filter-list WORD",
6768 SHOW_STR
6769 BGP_STR
6770 "Address family\n"
6771 "Display routes conforming to the filter-list\n"
6772 "Regular expression access list name\n")
6773
6774/* old command */
6775DEFUN (show_ipv6_bgp_filter_list,
6776 show_ipv6_bgp_filter_list_cmd,
6777 "show ipv6 bgp filter-list WORD",
6778 SHOW_STR
6779 IPV6_STR
6780 BGP_STR
6781 "Display routes conforming to the filter-list\n"
6782 "Regular expression access list name\n")
6783{
6784 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6785 bgp_show_type_filter_list);
6786}
6787
6788/* old command */
6789DEFUN (show_ipv6_mbgp_filter_list,
6790 show_ipv6_mbgp_filter_list_cmd,
6791 "show ipv6 mbgp filter-list WORD",
6792 SHOW_STR
6793 IPV6_STR
6794 MBGP_STR
6795 "Display routes conforming to the filter-list\n"
6796 "Regular expression access list name\n")
6797{
6798 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6799 bgp_show_type_filter_list);
6800}
6801#endif /* HAVE_IPV6 */
6802
paul94f2b392005-06-28 12:44:16 +00006803static int
paulfd79ac92004-10-13 05:06:08 +00006804bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006805 safi_t safi, enum bgp_show_type type)
6806{
6807 struct route_map *rmap;
6808
6809 rmap = route_map_lookup_by_name (rmap_str);
6810 if (! rmap)
6811 {
6812 vty_out (vty, "%% %s is not a valid route-map name%s",
6813 rmap_str, VTY_NEWLINE);
6814 return CMD_WARNING;
6815 }
6816
ajs5a646652004-11-05 01:25:55 +00006817 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00006818}
6819
6820DEFUN (show_ip_bgp_route_map,
6821 show_ip_bgp_route_map_cmd,
6822 "show ip bgp route-map WORD",
6823 SHOW_STR
6824 IP_STR
6825 BGP_STR
6826 "Display routes matching the route-map\n"
6827 "A route-map to match on\n")
6828{
6829 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6830 bgp_show_type_route_map);
6831}
6832
6833DEFUN (show_ip_bgp_flap_route_map,
6834 show_ip_bgp_flap_route_map_cmd,
6835 "show ip bgp flap-statistics route-map WORD",
6836 SHOW_STR
6837 IP_STR
6838 BGP_STR
6839 "Display flap statistics of routes\n"
6840 "Display routes matching the route-map\n"
6841 "A route-map to match on\n")
6842{
6843 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6844 bgp_show_type_flap_route_map);
6845}
6846
6847DEFUN (show_ip_bgp_ipv4_route_map,
6848 show_ip_bgp_ipv4_route_map_cmd,
6849 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6850 SHOW_STR
6851 IP_STR
6852 BGP_STR
6853 "Address family\n"
6854 "Address Family modifier\n"
6855 "Address Family modifier\n"
6856 "Display routes matching the route-map\n"
6857 "A route-map to match on\n")
6858{
6859 if (strncmp (argv[0], "m", 1) == 0)
6860 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6861 bgp_show_type_route_map);
6862
6863 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6864 bgp_show_type_route_map);
6865}
6866
6867DEFUN (show_bgp_route_map,
6868 show_bgp_route_map_cmd,
6869 "show bgp route-map WORD",
6870 SHOW_STR
6871 BGP_STR
6872 "Display routes matching the route-map\n"
6873 "A route-map to match on\n")
6874{
6875 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6876 bgp_show_type_route_map);
6877}
6878
6879ALIAS (show_bgp_route_map,
6880 show_bgp_ipv6_route_map_cmd,
6881 "show bgp ipv6 route-map WORD",
6882 SHOW_STR
6883 BGP_STR
6884 "Address family\n"
6885 "Display routes matching the route-map\n"
6886 "A route-map to match on\n")
6887
6888DEFUN (show_ip_bgp_cidr_only,
6889 show_ip_bgp_cidr_only_cmd,
6890 "show ip bgp cidr-only",
6891 SHOW_STR
6892 IP_STR
6893 BGP_STR
6894 "Display only routes with non-natural netmasks\n")
6895{
6896 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006897 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006898}
6899
6900DEFUN (show_ip_bgp_flap_cidr_only,
6901 show_ip_bgp_flap_cidr_only_cmd,
6902 "show ip bgp flap-statistics cidr-only",
6903 SHOW_STR
6904 IP_STR
6905 BGP_STR
6906 "Display flap statistics of routes\n"
6907 "Display only routes with non-natural netmasks\n")
6908{
6909 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006910 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006911}
6912
6913DEFUN (show_ip_bgp_ipv4_cidr_only,
6914 show_ip_bgp_ipv4_cidr_only_cmd,
6915 "show ip bgp ipv4 (unicast|multicast) cidr-only",
6916 SHOW_STR
6917 IP_STR
6918 BGP_STR
6919 "Address family\n"
6920 "Address Family modifier\n"
6921 "Address Family modifier\n"
6922 "Display only routes with non-natural netmasks\n")
6923{
6924 if (strncmp (argv[0], "m", 1) == 0)
6925 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006926 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006927
6928 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006929 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006930}
6931
6932DEFUN (show_ip_bgp_community_all,
6933 show_ip_bgp_community_all_cmd,
6934 "show ip bgp community",
6935 SHOW_STR
6936 IP_STR
6937 BGP_STR
6938 "Display routes matching the communities\n")
6939{
6940 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006941 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006942}
6943
6944DEFUN (show_ip_bgp_ipv4_community_all,
6945 show_ip_bgp_ipv4_community_all_cmd,
6946 "show ip bgp ipv4 (unicast|multicast) community",
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 routes matching the communities\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_community_all, 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_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006961}
6962
6963#ifdef HAVE_IPV6
6964DEFUN (show_bgp_community_all,
6965 show_bgp_community_all_cmd,
6966 "show bgp community",
6967 SHOW_STR
6968 BGP_STR
6969 "Display routes matching the communities\n")
6970{
6971 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006972 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006973}
6974
6975ALIAS (show_bgp_community_all,
6976 show_bgp_ipv6_community_all_cmd,
6977 "show bgp ipv6 community",
6978 SHOW_STR
6979 BGP_STR
6980 "Address family\n"
6981 "Display routes matching the communities\n")
6982
6983/* old command */
6984DEFUN (show_ipv6_bgp_community_all,
6985 show_ipv6_bgp_community_all_cmd,
6986 "show ipv6 bgp community",
6987 SHOW_STR
6988 IPV6_STR
6989 BGP_STR
6990 "Display routes matching the communities\n")
6991{
6992 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006993 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006994}
6995
6996/* old command */
6997DEFUN (show_ipv6_mbgp_community_all,
6998 show_ipv6_mbgp_community_all_cmd,
6999 "show ipv6 mbgp community",
7000 SHOW_STR
7001 IPV6_STR
7002 MBGP_STR
7003 "Display routes matching the communities\n")
7004{
7005 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007006 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007007}
7008#endif /* HAVE_IPV6 */
7009
paul94f2b392005-06-28 12:44:16 +00007010static int
paulfd79ac92004-10-13 05:06:08 +00007011bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7012 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007013{
7014 struct community *com;
7015 struct buffer *b;
7016 int i;
7017 char *str;
7018 int first = 0;
7019
7020 b = buffer_new (1024);
7021 for (i = 0; i < argc; i++)
7022 {
7023 if (first)
7024 buffer_putc (b, ' ');
7025 else
7026 {
7027 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7028 continue;
7029 first = 1;
7030 }
7031
7032 buffer_putstr (b, argv[i]);
7033 }
7034 buffer_putc (b, '\0');
7035
7036 str = buffer_getstr (b);
7037 buffer_free (b);
7038
7039 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007040 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007041 if (! com)
7042 {
7043 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7044 return CMD_WARNING;
7045 }
7046
ajs5a646652004-11-05 01:25:55 +00007047 return bgp_show (vty, NULL, afi, safi,
7048 (exact ? bgp_show_type_community_exact :
7049 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007050}
7051
7052DEFUN (show_ip_bgp_community,
7053 show_ip_bgp_community_cmd,
7054 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7055 SHOW_STR
7056 IP_STR
7057 BGP_STR
7058 "Display routes matching the communities\n"
7059 "community number\n"
7060 "Do not send outside local AS (well-known community)\n"
7061 "Do not advertise to any peer (well-known community)\n"
7062 "Do not export to next AS (well-known community)\n")
7063{
7064 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7065}
7066
7067ALIAS (show_ip_bgp_community,
7068 show_ip_bgp_community2_cmd,
7069 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7070 SHOW_STR
7071 IP_STR
7072 BGP_STR
7073 "Display routes matching the communities\n"
7074 "community number\n"
7075 "Do not send outside local AS (well-known community)\n"
7076 "Do not advertise to any peer (well-known community)\n"
7077 "Do not export to next AS (well-known community)\n"
7078 "community number\n"
7079 "Do not send outside local AS (well-known community)\n"
7080 "Do not advertise to any peer (well-known community)\n"
7081 "Do not export to next AS (well-known community)\n")
7082
7083ALIAS (show_ip_bgp_community,
7084 show_ip_bgp_community3_cmd,
7085 "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)",
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 "community number\n"
7095 "Do not send outside local AS (well-known community)\n"
7096 "Do not advertise to any peer (well-known community)\n"
7097 "Do not export to next AS (well-known community)\n"
7098 "community number\n"
7099 "Do not send outside local AS (well-known community)\n"
7100 "Do not advertise to any peer (well-known community)\n"
7101 "Do not export to next AS (well-known community)\n")
7102
7103ALIAS (show_ip_bgp_community,
7104 show_ip_bgp_community4_cmd,
7105 "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)",
7106 SHOW_STR
7107 IP_STR
7108 BGP_STR
7109 "Display routes matching the communities\n"
7110 "community number\n"
7111 "Do not send outside local AS (well-known community)\n"
7112 "Do not advertise to any peer (well-known community)\n"
7113 "Do not export to next AS (well-known community)\n"
7114 "community number\n"
7115 "Do not send outside local AS (well-known community)\n"
7116 "Do not advertise to any peer (well-known community)\n"
7117 "Do not export to next AS (well-known community)\n"
7118 "community number\n"
7119 "Do not send outside local AS (well-known community)\n"
7120 "Do not advertise to any peer (well-known community)\n"
7121 "Do not export to next AS (well-known community)\n"
7122 "community number\n"
7123 "Do not send outside local AS (well-known community)\n"
7124 "Do not advertise to any peer (well-known community)\n"
7125 "Do not export to next AS (well-known community)\n")
7126
7127DEFUN (show_ip_bgp_ipv4_community,
7128 show_ip_bgp_ipv4_community_cmd,
7129 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7130 SHOW_STR
7131 IP_STR
7132 BGP_STR
7133 "Address family\n"
7134 "Address Family modifier\n"
7135 "Address Family modifier\n"
7136 "Display routes matching the communities\n"
7137 "community number\n"
7138 "Do not send outside local AS (well-known community)\n"
7139 "Do not advertise to any peer (well-known community)\n"
7140 "Do not export to next AS (well-known community)\n")
7141{
7142 if (strncmp (argv[0], "m", 1) == 0)
7143 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7144
7145 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7146}
7147
7148ALIAS (show_ip_bgp_ipv4_community,
7149 show_ip_bgp_ipv4_community2_cmd,
7150 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7151 SHOW_STR
7152 IP_STR
7153 BGP_STR
7154 "Address family\n"
7155 "Address Family modifier\n"
7156 "Address Family modifier\n"
7157 "Display routes matching the communities\n"
7158 "community number\n"
7159 "Do not send outside local AS (well-known community)\n"
7160 "Do not advertise to any peer (well-known community)\n"
7161 "Do not export to next AS (well-known community)\n"
7162 "community number\n"
7163 "Do not send outside local AS (well-known community)\n"
7164 "Do not advertise to any peer (well-known community)\n"
7165 "Do not export to next AS (well-known community)\n")
7166
7167ALIAS (show_ip_bgp_ipv4_community,
7168 show_ip_bgp_ipv4_community3_cmd,
7169 "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)",
7170 SHOW_STR
7171 IP_STR
7172 BGP_STR
7173 "Address family\n"
7174 "Address Family modifier\n"
7175 "Address Family modifier\n"
7176 "Display routes matching the communities\n"
7177 "community number\n"
7178 "Do not send outside local AS (well-known community)\n"
7179 "Do not advertise to any peer (well-known community)\n"
7180 "Do not export to next AS (well-known community)\n"
7181 "community number\n"
7182 "Do not send outside local AS (well-known community)\n"
7183 "Do not advertise to any peer (well-known community)\n"
7184 "Do not export to next AS (well-known community)\n"
7185 "community number\n"
7186 "Do not send outside local AS (well-known community)\n"
7187 "Do not advertise to any peer (well-known community)\n"
7188 "Do not export to next AS (well-known community)\n")
7189
7190ALIAS (show_ip_bgp_ipv4_community,
7191 show_ip_bgp_ipv4_community4_cmd,
7192 "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)",
7193 SHOW_STR
7194 IP_STR
7195 BGP_STR
7196 "Address family\n"
7197 "Address Family modifier\n"
7198 "Address Family modifier\n"
7199 "Display routes matching the communities\n"
7200 "community number\n"
7201 "Do not send outside local AS (well-known community)\n"
7202 "Do not advertise to any peer (well-known community)\n"
7203 "Do not export to next AS (well-known community)\n"
7204 "community number\n"
7205 "Do not send outside local AS (well-known community)\n"
7206 "Do not advertise to any peer (well-known community)\n"
7207 "Do not export to next AS (well-known community)\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
7217DEFUN (show_ip_bgp_community_exact,
7218 show_ip_bgp_community_exact_cmd,
7219 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7220 SHOW_STR
7221 IP_STR
7222 BGP_STR
7223 "Display routes matching the communities\n"
7224 "community number\n"
7225 "Do not send outside local AS (well-known community)\n"
7226 "Do not advertise to any peer (well-known community)\n"
7227 "Do not export to next AS (well-known community)\n"
7228 "Exact match of the communities")
7229{
7230 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7231}
7232
7233ALIAS (show_ip_bgp_community_exact,
7234 show_ip_bgp_community2_exact_cmd,
7235 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7236 SHOW_STR
7237 IP_STR
7238 BGP_STR
7239 "Display routes matching the communities\n"
7240 "community number\n"
7241 "Do not send outside local AS (well-known community)\n"
7242 "Do not advertise to any peer (well-known community)\n"
7243 "Do not export to next AS (well-known community)\n"
7244 "community number\n"
7245 "Do not send outside local AS (well-known community)\n"
7246 "Do not advertise to any peer (well-known community)\n"
7247 "Do not export to next AS (well-known community)\n"
7248 "Exact match of the communities")
7249
7250ALIAS (show_ip_bgp_community_exact,
7251 show_ip_bgp_community3_exact_cmd,
7252 "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",
7253 SHOW_STR
7254 IP_STR
7255 BGP_STR
7256 "Display routes matching the communities\n"
7257 "community number\n"
7258 "Do not send outside local AS (well-known community)\n"
7259 "Do not advertise to any peer (well-known community)\n"
7260 "Do not export to next AS (well-known community)\n"
7261 "community number\n"
7262 "Do not send outside local AS (well-known community)\n"
7263 "Do not advertise to any peer (well-known community)\n"
7264 "Do not export to next AS (well-known community)\n"
7265 "community number\n"
7266 "Do not send outside local AS (well-known community)\n"
7267 "Do not advertise to any peer (well-known community)\n"
7268 "Do not export to next AS (well-known community)\n"
7269 "Exact match of the communities")
7270
7271ALIAS (show_ip_bgp_community_exact,
7272 show_ip_bgp_community4_exact_cmd,
7273 "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",
7274 SHOW_STR
7275 IP_STR
7276 BGP_STR
7277 "Display routes matching the communities\n"
7278 "community number\n"
7279 "Do not send outside local AS (well-known community)\n"
7280 "Do not advertise to any peer (well-known community)\n"
7281 "Do not export to next AS (well-known community)\n"
7282 "community number\n"
7283 "Do not send outside local AS (well-known community)\n"
7284 "Do not advertise to any peer (well-known community)\n"
7285 "Do not export to next AS (well-known community)\n"
7286 "community number\n"
7287 "Do not send outside local AS (well-known community)\n"
7288 "Do not advertise to any peer (well-known community)\n"
7289 "Do not export to next AS (well-known community)\n"
7290 "community number\n"
7291 "Do not send outside local AS (well-known community)\n"
7292 "Do not advertise to any peer (well-known community)\n"
7293 "Do not export to next AS (well-known community)\n"
7294 "Exact match of the communities")
7295
7296DEFUN (show_ip_bgp_ipv4_community_exact,
7297 show_ip_bgp_ipv4_community_exact_cmd,
7298 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7299 SHOW_STR
7300 IP_STR
7301 BGP_STR
7302 "Address family\n"
7303 "Address Family modifier\n"
7304 "Address Family modifier\n"
7305 "Display routes matching the communities\n"
7306 "community number\n"
7307 "Do not send outside local AS (well-known community)\n"
7308 "Do not advertise to any peer (well-known community)\n"
7309 "Do not export to next AS (well-known community)\n"
7310 "Exact match of the communities")
7311{
7312 if (strncmp (argv[0], "m", 1) == 0)
7313 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7314
7315 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7316}
7317
7318ALIAS (show_ip_bgp_ipv4_community_exact,
7319 show_ip_bgp_ipv4_community2_exact_cmd,
7320 "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",
7321 SHOW_STR
7322 IP_STR
7323 BGP_STR
7324 "Address family\n"
7325 "Address Family modifier\n"
7326 "Address Family modifier\n"
7327 "Display routes matching the communities\n"
7328 "community number\n"
7329 "Do not send outside local AS (well-known community)\n"
7330 "Do not advertise to any peer (well-known community)\n"
7331 "Do not export to next AS (well-known community)\n"
7332 "community number\n"
7333 "Do not send outside local AS (well-known community)\n"
7334 "Do not advertise to any peer (well-known community)\n"
7335 "Do not export to next AS (well-known community)\n"
7336 "Exact match of the communities")
7337
7338ALIAS (show_ip_bgp_ipv4_community_exact,
7339 show_ip_bgp_ipv4_community3_exact_cmd,
7340 "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",
7341 SHOW_STR
7342 IP_STR
7343 BGP_STR
7344 "Address family\n"
7345 "Address Family modifier\n"
7346 "Address Family modifier\n"
7347 "Display routes matching the communities\n"
7348 "community number\n"
7349 "Do not send outside local AS (well-known community)\n"
7350 "Do not advertise to any peer (well-known community)\n"
7351 "Do not export to next AS (well-known community)\n"
7352 "community number\n"
7353 "Do not send outside local AS (well-known community)\n"
7354 "Do not advertise to any peer (well-known community)\n"
7355 "Do not export to next AS (well-known community)\n"
7356 "community number\n"
7357 "Do not send outside local AS (well-known community)\n"
7358 "Do not advertise to any peer (well-known community)\n"
7359 "Do not export to next AS (well-known community)\n"
7360 "Exact match of the communities")
7361
7362ALIAS (show_ip_bgp_ipv4_community_exact,
7363 show_ip_bgp_ipv4_community4_exact_cmd,
7364 "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",
7365 SHOW_STR
7366 IP_STR
7367 BGP_STR
7368 "Address family\n"
7369 "Address Family modifier\n"
7370 "Address Family modifier\n"
7371 "Display routes matching the communities\n"
7372 "community number\n"
7373 "Do not send outside local AS (well-known community)\n"
7374 "Do not advertise to any peer (well-known community)\n"
7375 "Do not export to next AS (well-known community)\n"
7376 "community number\n"
7377 "Do not send outside local AS (well-known community)\n"
7378 "Do not advertise to any peer (well-known community)\n"
7379 "Do not export to next AS (well-known community)\n"
7380 "community number\n"
7381 "Do not send outside local AS (well-known community)\n"
7382 "Do not advertise to any peer (well-known community)\n"
7383 "Do not export to next AS (well-known community)\n"
7384 "community number\n"
7385 "Do not send outside local AS (well-known community)\n"
7386 "Do not advertise to any peer (well-known community)\n"
7387 "Do not export to next AS (well-known community)\n"
7388 "Exact match of the communities")
7389
7390#ifdef HAVE_IPV6
7391DEFUN (show_bgp_community,
7392 show_bgp_community_cmd,
7393 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7394 SHOW_STR
7395 BGP_STR
7396 "Display routes matching the communities\n"
7397 "community number\n"
7398 "Do not send outside local AS (well-known community)\n"
7399 "Do not advertise to any peer (well-known community)\n"
7400 "Do not export to next AS (well-known community)\n")
7401{
7402 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7403}
7404
7405ALIAS (show_bgp_community,
7406 show_bgp_ipv6_community_cmd,
7407 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7408 SHOW_STR
7409 BGP_STR
7410 "Address family\n"
7411 "Display routes matching the communities\n"
7412 "community number\n"
7413 "Do not send outside local AS (well-known community)\n"
7414 "Do not advertise to any peer (well-known community)\n"
7415 "Do not export to next AS (well-known community)\n")
7416
7417ALIAS (show_bgp_community,
7418 show_bgp_community2_cmd,
7419 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7420 SHOW_STR
7421 BGP_STR
7422 "Display routes matching the communities\n"
7423 "community number\n"
7424 "Do not send outside local AS (well-known community)\n"
7425 "Do not advertise to any peer (well-known community)\n"
7426 "Do not export to next AS (well-known community)\n"
7427 "community number\n"
7428 "Do not send outside local AS (well-known community)\n"
7429 "Do not advertise to any peer (well-known community)\n"
7430 "Do not export to next AS (well-known community)\n")
7431
7432ALIAS (show_bgp_community,
7433 show_bgp_ipv6_community2_cmd,
7434 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7435 SHOW_STR
7436 BGP_STR
7437 "Address family\n"
7438 "Display routes matching the communities\n"
7439 "community number\n"
7440 "Do not send outside local AS (well-known community)\n"
7441 "Do not advertise to any peer (well-known community)\n"
7442 "Do not export to next AS (well-known community)\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_community3_cmd,
7450 "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)",
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 "community number\n"
7463 "Do not send outside local AS (well-known community)\n"
7464 "Do not advertise to any peer (well-known community)\n"
7465 "Do not export to next AS (well-known community)\n")
7466
7467ALIAS (show_bgp_community,
7468 show_bgp_ipv6_community3_cmd,
7469 "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)",
7470 SHOW_STR
7471 BGP_STR
7472 "Address family\n"
7473 "Display routes matching the communities\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 "community number\n"
7479 "Do not send outside local AS (well-known community)\n"
7480 "Do not advertise to any peer (well-known community)\n"
7481 "Do not export to next AS (well-known community)\n"
7482 "community number\n"
7483 "Do not send outside local AS (well-known community)\n"
7484 "Do not advertise to any peer (well-known community)\n"
7485 "Do not export to next AS (well-known community)\n")
7486
7487ALIAS (show_bgp_community,
7488 show_bgp_community4_cmd,
7489 "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)",
7490 SHOW_STR
7491 BGP_STR
7492 "Display routes matching the communities\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 "community number\n"
7498 "Do not send outside local AS (well-known community)\n"
7499 "Do not advertise to any peer (well-known community)\n"
7500 "Do not export to next AS (well-known community)\n"
7501 "community number\n"
7502 "Do not send outside local AS (well-known community)\n"
7503 "Do not advertise to any peer (well-known community)\n"
7504 "Do not export to next AS (well-known community)\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
7510ALIAS (show_bgp_community,
7511 show_bgp_ipv6_community4_cmd,
7512 "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)",
7513 SHOW_STR
7514 BGP_STR
7515 "Address family\n"
7516 "Display routes matching the communities\n"
7517 "community number\n"
7518 "Do not send outside local AS (well-known community)\n"
7519 "Do not advertise to any peer (well-known community)\n"
7520 "Do not export to next AS (well-known community)\n"
7521 "community number\n"
7522 "Do not send outside local AS (well-known community)\n"
7523 "Do not advertise to any peer (well-known community)\n"
7524 "Do not export to next AS (well-known community)\n"
7525 "community number\n"
7526 "Do not send outside local AS (well-known community)\n"
7527 "Do not advertise to any peer (well-known community)\n"
7528 "Do not export to next AS (well-known community)\n"
7529 "community number\n"
7530 "Do not send outside local AS (well-known community)\n"
7531 "Do not advertise to any peer (well-known community)\n"
7532 "Do not export to next AS (well-known community)\n")
7533
7534/* old command */
7535DEFUN (show_ipv6_bgp_community,
7536 show_ipv6_bgp_community_cmd,
7537 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7538 SHOW_STR
7539 IPV6_STR
7540 BGP_STR
7541 "Display routes matching the communities\n"
7542 "community number\n"
7543 "Do not send outside local AS (well-known community)\n"
7544 "Do not advertise to any peer (well-known community)\n"
7545 "Do not export to next AS (well-known community)\n")
7546{
7547 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7548}
7549
7550/* old command */
7551ALIAS (show_ipv6_bgp_community,
7552 show_ipv6_bgp_community2_cmd,
7553 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7554 SHOW_STR
7555 IPV6_STR
7556 BGP_STR
7557 "Display routes matching the communities\n"
7558 "community number\n"
7559 "Do not send outside local AS (well-known community)\n"
7560 "Do not advertise to any peer (well-known community)\n"
7561 "Do not export to next AS (well-known community)\n"
7562 "community number\n"
7563 "Do not send outside local AS (well-known community)\n"
7564 "Do not advertise to any peer (well-known community)\n"
7565 "Do not export to next AS (well-known community)\n")
7566
7567/* old command */
7568ALIAS (show_ipv6_bgp_community,
7569 show_ipv6_bgp_community3_cmd,
7570 "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)",
7571 SHOW_STR
7572 IPV6_STR
7573 BGP_STR
7574 "Display routes matching the communities\n"
7575 "community number\n"
7576 "Do not send outside local AS (well-known community)\n"
7577 "Do not advertise to any peer (well-known community)\n"
7578 "Do not export to next AS (well-known community)\n"
7579 "community number\n"
7580 "Do not send outside local AS (well-known community)\n"
7581 "Do not advertise to any peer (well-known community)\n"
7582 "Do not export to next AS (well-known community)\n"
7583 "community number\n"
7584 "Do not send outside local AS (well-known community)\n"
7585 "Do not advertise to any peer (well-known community)\n"
7586 "Do not export to next AS (well-known community)\n")
7587
7588/* old command */
7589ALIAS (show_ipv6_bgp_community,
7590 show_ipv6_bgp_community4_cmd,
7591 "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)",
7592 SHOW_STR
7593 IPV6_STR
7594 BGP_STR
7595 "Display routes matching the communities\n"
7596 "community number\n"
7597 "Do not send outside local AS (well-known community)\n"
7598 "Do not advertise to any peer (well-known community)\n"
7599 "Do not export to next AS (well-known community)\n"
7600 "community number\n"
7601 "Do not send outside local AS (well-known community)\n"
7602 "Do not advertise to any peer (well-known community)\n"
7603 "Do not export to next AS (well-known community)\n"
7604 "community number\n"
7605 "Do not send outside local AS (well-known community)\n"
7606 "Do not advertise to any peer (well-known community)\n"
7607 "Do not export to next AS (well-known community)\n"
7608 "community number\n"
7609 "Do not send outside local AS (well-known community)\n"
7610 "Do not advertise to any peer (well-known community)\n"
7611 "Do not export to next AS (well-known community)\n")
7612
7613DEFUN (show_bgp_community_exact,
7614 show_bgp_community_exact_cmd,
7615 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7616 SHOW_STR
7617 BGP_STR
7618 "Display routes matching the communities\n"
7619 "community number\n"
7620 "Do not send outside local AS (well-known community)\n"
7621 "Do not advertise to any peer (well-known community)\n"
7622 "Do not export to next AS (well-known community)\n"
7623 "Exact match of the communities")
7624{
7625 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7626}
7627
7628ALIAS (show_bgp_community_exact,
7629 show_bgp_ipv6_community_exact_cmd,
7630 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7631 SHOW_STR
7632 BGP_STR
7633 "Address family\n"
7634 "Display routes matching the communities\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 "Exact match of the communities")
7640
7641ALIAS (show_bgp_community_exact,
7642 show_bgp_community2_exact_cmd,
7643 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7644 SHOW_STR
7645 BGP_STR
7646 "Display routes matching the communities\n"
7647 "community number\n"
7648 "Do not send outside local AS (well-known community)\n"
7649 "Do not advertise to any peer (well-known community)\n"
7650 "Do not export to next AS (well-known community)\n"
7651 "community number\n"
7652 "Do not send outside local AS (well-known community)\n"
7653 "Do not advertise to any peer (well-known community)\n"
7654 "Do not export to next AS (well-known community)\n"
7655 "Exact match of the communities")
7656
7657ALIAS (show_bgp_community_exact,
7658 show_bgp_ipv6_community2_exact_cmd,
7659 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7660 SHOW_STR
7661 BGP_STR
7662 "Address family\n"
7663 "Display routes matching the communities\n"
7664 "community number\n"
7665 "Do not send outside local AS (well-known community)\n"
7666 "Do not advertise to any peer (well-known community)\n"
7667 "Do not export to next AS (well-known community)\n"
7668 "community number\n"
7669 "Do not send outside local AS (well-known community)\n"
7670 "Do not advertise to any peer (well-known community)\n"
7671 "Do not export to next AS (well-known community)\n"
7672 "Exact match of the communities")
7673
7674ALIAS (show_bgp_community_exact,
7675 show_bgp_community3_exact_cmd,
7676 "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",
7677 SHOW_STR
7678 BGP_STR
7679 "Display routes matching the communities\n"
7680 "community number\n"
7681 "Do not send outside local AS (well-known community)\n"
7682 "Do not advertise to any peer (well-known community)\n"
7683 "Do not export to next AS (well-known community)\n"
7684 "community number\n"
7685 "Do not send outside local AS (well-known community)\n"
7686 "Do not advertise to any peer (well-known community)\n"
7687 "Do not export to next AS (well-known community)\n"
7688 "community number\n"
7689 "Do not send outside local AS (well-known community)\n"
7690 "Do not advertise to any peer (well-known community)\n"
7691 "Do not export to next AS (well-known community)\n"
7692 "Exact match of the communities")
7693
7694ALIAS (show_bgp_community_exact,
7695 show_bgp_ipv6_community3_exact_cmd,
7696 "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",
7697 SHOW_STR
7698 BGP_STR
7699 "Address family\n"
7700 "Display routes matching the communities\n"
7701 "community number\n"
7702 "Do not send outside local AS (well-known community)\n"
7703 "Do not advertise to any peer (well-known community)\n"
7704 "Do not export to next AS (well-known community)\n"
7705 "community number\n"
7706 "Do not send outside local AS (well-known community)\n"
7707 "Do not advertise to any peer (well-known community)\n"
7708 "Do not export to next AS (well-known community)\n"
7709 "community number\n"
7710 "Do not send outside local AS (well-known community)\n"
7711 "Do not advertise to any peer (well-known community)\n"
7712 "Do not export to next AS (well-known community)\n"
7713 "Exact match of the communities")
7714
7715ALIAS (show_bgp_community_exact,
7716 show_bgp_community4_exact_cmd,
7717 "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",
7718 SHOW_STR
7719 BGP_STR
7720 "Display routes matching the communities\n"
7721 "community number\n"
7722 "Do not send outside local AS (well-known community)\n"
7723 "Do not advertise to any peer (well-known community)\n"
7724 "Do not export to next AS (well-known community)\n"
7725 "community number\n"
7726 "Do not send outside local AS (well-known community)\n"
7727 "Do not advertise to any peer (well-known community)\n"
7728 "Do not export to next AS (well-known community)\n"
7729 "community number\n"
7730 "Do not send outside local AS (well-known community)\n"
7731 "Do not advertise to any peer (well-known community)\n"
7732 "Do not export to next AS (well-known community)\n"
7733 "community number\n"
7734 "Do not send outside local AS (well-known community)\n"
7735 "Do not advertise to any peer (well-known community)\n"
7736 "Do not export to next AS (well-known community)\n"
7737 "Exact match of the communities")
7738
7739ALIAS (show_bgp_community_exact,
7740 show_bgp_ipv6_community4_exact_cmd,
7741 "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",
7742 SHOW_STR
7743 BGP_STR
7744 "Address family\n"
7745 "Display routes matching the communities\n"
7746 "community number\n"
7747 "Do not send outside local AS (well-known community)\n"
7748 "Do not advertise to any peer (well-known community)\n"
7749 "Do not export to next AS (well-known community)\n"
7750 "community number\n"
7751 "Do not send outside local AS (well-known community)\n"
7752 "Do not advertise to any peer (well-known community)\n"
7753 "Do not export to next AS (well-known community)\n"
7754 "community number\n"
7755 "Do not send outside local AS (well-known community)\n"
7756 "Do not advertise to any peer (well-known community)\n"
7757 "Do not export to next AS (well-known community)\n"
7758 "community number\n"
7759 "Do not send outside local AS (well-known community)\n"
7760 "Do not advertise to any peer (well-known community)\n"
7761 "Do not export to next AS (well-known community)\n"
7762 "Exact match of the communities")
7763
7764/* old command */
7765DEFUN (show_ipv6_bgp_community_exact,
7766 show_ipv6_bgp_community_exact_cmd,
7767 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7768 SHOW_STR
7769 IPV6_STR
7770 BGP_STR
7771 "Display routes matching the communities\n"
7772 "community number\n"
7773 "Do not send outside local AS (well-known community)\n"
7774 "Do not advertise to any peer (well-known community)\n"
7775 "Do not export to next AS (well-known community)\n"
7776 "Exact match of the communities")
7777{
7778 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7779}
7780
7781/* old command */
7782ALIAS (show_ipv6_bgp_community_exact,
7783 show_ipv6_bgp_community2_exact_cmd,
7784 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7785 SHOW_STR
7786 IPV6_STR
7787 BGP_STR
7788 "Display routes matching the communities\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 "community number\n"
7794 "Do not send outside local AS (well-known community)\n"
7795 "Do not advertise to any peer (well-known community)\n"
7796 "Do not export to next AS (well-known community)\n"
7797 "Exact match of the communities")
7798
7799/* old command */
7800ALIAS (show_ipv6_bgp_community_exact,
7801 show_ipv6_bgp_community3_exact_cmd,
7802 "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",
7803 SHOW_STR
7804 IPV6_STR
7805 BGP_STR
7806 "Display routes matching the communities\n"
7807 "community number\n"
7808 "Do not send outside local AS (well-known community)\n"
7809 "Do not advertise to any peer (well-known community)\n"
7810 "Do not export to next AS (well-known community)\n"
7811 "community number\n"
7812 "Do not send outside local AS (well-known community)\n"
7813 "Do not advertise to any peer (well-known community)\n"
7814 "Do not export to next AS (well-known community)\n"
7815 "community number\n"
7816 "Do not send outside local AS (well-known community)\n"
7817 "Do not advertise to any peer (well-known community)\n"
7818 "Do not export to next AS (well-known community)\n"
7819 "Exact match of the communities")
7820
7821/* old command */
7822ALIAS (show_ipv6_bgp_community_exact,
7823 show_ipv6_bgp_community4_exact_cmd,
7824 "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",
7825 SHOW_STR
7826 IPV6_STR
7827 BGP_STR
7828 "Display routes matching the communities\n"
7829 "community number\n"
7830 "Do not send outside local AS (well-known community)\n"
7831 "Do not advertise to any peer (well-known community)\n"
7832 "Do not export to next AS (well-known community)\n"
7833 "community number\n"
7834 "Do not send outside local AS (well-known community)\n"
7835 "Do not advertise to any peer (well-known community)\n"
7836 "Do not export to next AS (well-known community)\n"
7837 "community number\n"
7838 "Do not send outside local AS (well-known community)\n"
7839 "Do not advertise to any peer (well-known community)\n"
7840 "Do not export to next AS (well-known community)\n"
7841 "community number\n"
7842 "Do not send outside local AS (well-known community)\n"
7843 "Do not advertise to any peer (well-known community)\n"
7844 "Do not export to next AS (well-known community)\n"
7845 "Exact match of the communities")
7846
7847/* old command */
7848DEFUN (show_ipv6_mbgp_community,
7849 show_ipv6_mbgp_community_cmd,
7850 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7851 SHOW_STR
7852 IPV6_STR
7853 MBGP_STR
7854 "Display routes matching the communities\n"
7855 "community number\n"
7856 "Do not send outside local AS (well-known community)\n"
7857 "Do not advertise to any peer (well-known community)\n"
7858 "Do not export to next AS (well-known community)\n")
7859{
7860 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7861}
7862
7863/* old command */
7864ALIAS (show_ipv6_mbgp_community,
7865 show_ipv6_mbgp_community2_cmd,
7866 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7867 SHOW_STR
7868 IPV6_STR
7869 MBGP_STR
7870 "Display routes matching the communities\n"
7871 "community number\n"
7872 "Do not send outside local AS (well-known community)\n"
7873 "Do not advertise to any peer (well-known community)\n"
7874 "Do not export to next AS (well-known community)\n"
7875 "community number\n"
7876 "Do not send outside local AS (well-known community)\n"
7877 "Do not advertise to any peer (well-known community)\n"
7878 "Do not export to next AS (well-known community)\n")
7879
7880/* old command */
7881ALIAS (show_ipv6_mbgp_community,
7882 show_ipv6_mbgp_community3_cmd,
7883 "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)",
7884 SHOW_STR
7885 IPV6_STR
7886 MBGP_STR
7887 "Display routes matching the communities\n"
7888 "community number\n"
7889 "Do not send outside local AS (well-known community)\n"
7890 "Do not advertise to any peer (well-known community)\n"
7891 "Do not export to next AS (well-known community)\n"
7892 "community number\n"
7893 "Do not send outside local AS (well-known community)\n"
7894 "Do not advertise to any peer (well-known community)\n"
7895 "Do not export to next AS (well-known community)\n"
7896 "community number\n"
7897 "Do not send outside local AS (well-known community)\n"
7898 "Do not advertise to any peer (well-known community)\n"
7899 "Do not export to next AS (well-known community)\n")
7900
7901/* old command */
7902ALIAS (show_ipv6_mbgp_community,
7903 show_ipv6_mbgp_community4_cmd,
7904 "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)",
7905 SHOW_STR
7906 IPV6_STR
7907 MBGP_STR
7908 "Display routes matching the communities\n"
7909 "community number\n"
7910 "Do not send outside local AS (well-known community)\n"
7911 "Do not advertise to any peer (well-known community)\n"
7912 "Do not export to next AS (well-known community)\n"
7913 "community number\n"
7914 "Do not send outside local AS (well-known community)\n"
7915 "Do not advertise to any peer (well-known community)\n"
7916 "Do not export to next AS (well-known community)\n"
7917 "community number\n"
7918 "Do not send outside local AS (well-known community)\n"
7919 "Do not advertise to any peer (well-known community)\n"
7920 "Do not export to next AS (well-known community)\n"
7921 "community number\n"
7922 "Do not send outside local AS (well-known community)\n"
7923 "Do not advertise to any peer (well-known community)\n"
7924 "Do not export to next AS (well-known community)\n")
7925
7926/* old command */
7927DEFUN (show_ipv6_mbgp_community_exact,
7928 show_ipv6_mbgp_community_exact_cmd,
7929 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7930 SHOW_STR
7931 IPV6_STR
7932 MBGP_STR
7933 "Display routes matching the communities\n"
7934 "community number\n"
7935 "Do not send outside local AS (well-known community)\n"
7936 "Do not advertise to any peer (well-known community)\n"
7937 "Do not export to next AS (well-known community)\n"
7938 "Exact match of the communities")
7939{
7940 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7941}
7942
7943/* old command */
7944ALIAS (show_ipv6_mbgp_community_exact,
7945 show_ipv6_mbgp_community2_exact_cmd,
7946 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7947 SHOW_STR
7948 IPV6_STR
7949 MBGP_STR
7950 "Display routes matching the communities\n"
7951 "community number\n"
7952 "Do not send outside local AS (well-known community)\n"
7953 "Do not advertise to any peer (well-known community)\n"
7954 "Do not export to next AS (well-known community)\n"
7955 "community number\n"
7956 "Do not send outside local AS (well-known community)\n"
7957 "Do not advertise to any peer (well-known community)\n"
7958 "Do not export to next AS (well-known community)\n"
7959 "Exact match of the communities")
7960
7961/* old command */
7962ALIAS (show_ipv6_mbgp_community_exact,
7963 show_ipv6_mbgp_community3_exact_cmd,
7964 "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",
7965 SHOW_STR
7966 IPV6_STR
7967 MBGP_STR
7968 "Display routes matching the communities\n"
7969 "community number\n"
7970 "Do not send outside local AS (well-known community)\n"
7971 "Do not advertise to any peer (well-known community)\n"
7972 "Do not export to next AS (well-known community)\n"
7973 "community number\n"
7974 "Do not send outside local AS (well-known community)\n"
7975 "Do not advertise to any peer (well-known community)\n"
7976 "Do not export to next AS (well-known community)\n"
7977 "community number\n"
7978 "Do not send outside local AS (well-known community)\n"
7979 "Do not advertise to any peer (well-known community)\n"
7980 "Do not export to next AS (well-known community)\n"
7981 "Exact match of the communities")
7982
7983/* old command */
7984ALIAS (show_ipv6_mbgp_community_exact,
7985 show_ipv6_mbgp_community4_exact_cmd,
7986 "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",
7987 SHOW_STR
7988 IPV6_STR
7989 MBGP_STR
7990 "Display routes matching the communities\n"
7991 "community number\n"
7992 "Do not send outside local AS (well-known community)\n"
7993 "Do not advertise to any peer (well-known community)\n"
7994 "Do not export to next AS (well-known community)\n"
7995 "community number\n"
7996 "Do not send outside local AS (well-known community)\n"
7997 "Do not advertise to any peer (well-known community)\n"
7998 "Do not export to next AS (well-known community)\n"
7999 "community number\n"
8000 "Do not send outside local AS (well-known community)\n"
8001 "Do not advertise to any peer (well-known community)\n"
8002 "Do not export to next AS (well-known community)\n"
8003 "community number\n"
8004 "Do not send outside local AS (well-known community)\n"
8005 "Do not advertise to any peer (well-known community)\n"
8006 "Do not export to next AS (well-known community)\n"
8007 "Exact match of the communities")
8008#endif /* HAVE_IPV6 */
8009
paul94f2b392005-06-28 12:44:16 +00008010static int
paulfd79ac92004-10-13 05:06:08 +00008011bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008012 u_int16_t afi, u_char safi)
8013{
8014 struct community_list *list;
8015
hassofee6e4e2005-02-02 16:29:31 +00008016 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008017 if (list == NULL)
8018 {
8019 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8020 VTY_NEWLINE);
8021 return CMD_WARNING;
8022 }
8023
ajs5a646652004-11-05 01:25:55 +00008024 return bgp_show (vty, NULL, afi, safi,
8025 (exact ? bgp_show_type_community_list_exact :
8026 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008027}
8028
8029DEFUN (show_ip_bgp_community_list,
8030 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008031 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008032 SHOW_STR
8033 IP_STR
8034 BGP_STR
8035 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008036 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008037 "community-list name\n")
8038{
8039 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8040}
8041
8042DEFUN (show_ip_bgp_ipv4_community_list,
8043 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008044 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008045 SHOW_STR
8046 IP_STR
8047 BGP_STR
8048 "Address family\n"
8049 "Address Family modifier\n"
8050 "Address Family modifier\n"
8051 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008052 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008053 "community-list name\n")
8054{
8055 if (strncmp (argv[0], "m", 1) == 0)
8056 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8057
8058 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8059}
8060
8061DEFUN (show_ip_bgp_community_list_exact,
8062 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008063 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008064 SHOW_STR
8065 IP_STR
8066 BGP_STR
8067 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008068 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008069 "community-list name\n"
8070 "Exact match of the communities\n")
8071{
8072 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8073}
8074
8075DEFUN (show_ip_bgp_ipv4_community_list_exact,
8076 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008077 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008078 SHOW_STR
8079 IP_STR
8080 BGP_STR
8081 "Address family\n"
8082 "Address Family modifier\n"
8083 "Address Family modifier\n"
8084 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008085 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008086 "community-list name\n"
8087 "Exact match of the communities\n")
8088{
8089 if (strncmp (argv[0], "m", 1) == 0)
8090 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8091
8092 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8093}
8094
8095#ifdef HAVE_IPV6
8096DEFUN (show_bgp_community_list,
8097 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008098 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008099 SHOW_STR
8100 BGP_STR
8101 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008102 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008103 "community-list name\n")
8104{
8105 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8106}
8107
8108ALIAS (show_bgp_community_list,
8109 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008110 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008111 SHOW_STR
8112 BGP_STR
8113 "Address family\n"
8114 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008115 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008116 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008117
8118/* old command */
8119DEFUN (show_ipv6_bgp_community_list,
8120 show_ipv6_bgp_community_list_cmd,
8121 "show ipv6 bgp community-list WORD",
8122 SHOW_STR
8123 IPV6_STR
8124 BGP_STR
8125 "Display routes matching the community-list\n"
8126 "community-list name\n")
8127{
8128 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8129}
8130
8131/* old command */
8132DEFUN (show_ipv6_mbgp_community_list,
8133 show_ipv6_mbgp_community_list_cmd,
8134 "show ipv6 mbgp community-list WORD",
8135 SHOW_STR
8136 IPV6_STR
8137 MBGP_STR
8138 "Display routes matching the community-list\n"
8139 "community-list name\n")
8140{
8141 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8142}
8143
8144DEFUN (show_bgp_community_list_exact,
8145 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008146 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008147 SHOW_STR
8148 BGP_STR
8149 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008150 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008151 "community-list name\n"
8152 "Exact match of the communities\n")
8153{
8154 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8155}
8156
8157ALIAS (show_bgp_community_list_exact,
8158 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008159 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008160 SHOW_STR
8161 BGP_STR
8162 "Address family\n"
8163 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008164 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008165 "community-list name\n"
8166 "Exact match of the communities\n")
8167
8168/* old command */
8169DEFUN (show_ipv6_bgp_community_list_exact,
8170 show_ipv6_bgp_community_list_exact_cmd,
8171 "show ipv6 bgp community-list WORD exact-match",
8172 SHOW_STR
8173 IPV6_STR
8174 BGP_STR
8175 "Display routes matching the community-list\n"
8176 "community-list name\n"
8177 "Exact match of the communities\n")
8178{
8179 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8180}
8181
8182/* old command */
8183DEFUN (show_ipv6_mbgp_community_list_exact,
8184 show_ipv6_mbgp_community_list_exact_cmd,
8185 "show ipv6 mbgp community-list WORD exact-match",
8186 SHOW_STR
8187 IPV6_STR
8188 MBGP_STR
8189 "Display routes matching the community-list\n"
8190 "community-list name\n"
8191 "Exact match of the communities\n")
8192{
8193 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8194}
8195#endif /* HAVE_IPV6 */
8196
paul94f2b392005-06-28 12:44:16 +00008197static int
paulfd79ac92004-10-13 05:06:08 +00008198bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008199 safi_t safi, enum bgp_show_type type)
8200{
8201 int ret;
8202 struct prefix *p;
8203
8204 p = prefix_new();
8205
8206 ret = str2prefix (prefix, p);
8207 if (! ret)
8208 {
8209 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8210 return CMD_WARNING;
8211 }
8212
ajs5a646652004-11-05 01:25:55 +00008213 ret = bgp_show (vty, NULL, afi, safi, type, p);
8214 prefix_free(p);
8215 return ret;
paul718e3742002-12-13 20:15:29 +00008216}
8217
8218DEFUN (show_ip_bgp_prefix_longer,
8219 show_ip_bgp_prefix_longer_cmd,
8220 "show ip bgp A.B.C.D/M longer-prefixes",
8221 SHOW_STR
8222 IP_STR
8223 BGP_STR
8224 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8225 "Display route and more specific routes\n")
8226{
8227 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8228 bgp_show_type_prefix_longer);
8229}
8230
8231DEFUN (show_ip_bgp_flap_prefix_longer,
8232 show_ip_bgp_flap_prefix_longer_cmd,
8233 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8234 SHOW_STR
8235 IP_STR
8236 BGP_STR
8237 "Display flap statistics of routes\n"
8238 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8239 "Display route and more specific routes\n")
8240{
8241 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8242 bgp_show_type_flap_prefix_longer);
8243}
8244
8245DEFUN (show_ip_bgp_ipv4_prefix_longer,
8246 show_ip_bgp_ipv4_prefix_longer_cmd,
8247 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8248 SHOW_STR
8249 IP_STR
8250 BGP_STR
8251 "Address family\n"
8252 "Address Family modifier\n"
8253 "Address Family modifier\n"
8254 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8255 "Display route and more specific routes\n")
8256{
8257 if (strncmp (argv[0], "m", 1) == 0)
8258 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8259 bgp_show_type_prefix_longer);
8260
8261 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8262 bgp_show_type_prefix_longer);
8263}
8264
8265DEFUN (show_ip_bgp_flap_address,
8266 show_ip_bgp_flap_address_cmd,
8267 "show ip bgp flap-statistics A.B.C.D",
8268 SHOW_STR
8269 IP_STR
8270 BGP_STR
8271 "Display flap statistics of routes\n"
8272 "Network in the BGP routing table to display\n")
8273{
8274 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8275 bgp_show_type_flap_address);
8276}
8277
8278DEFUN (show_ip_bgp_flap_prefix,
8279 show_ip_bgp_flap_prefix_cmd,
8280 "show ip bgp flap-statistics A.B.C.D/M",
8281 SHOW_STR
8282 IP_STR
8283 BGP_STR
8284 "Display flap statistics of routes\n"
8285 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8286{
8287 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8288 bgp_show_type_flap_prefix);
8289}
8290#ifdef HAVE_IPV6
8291DEFUN (show_bgp_prefix_longer,
8292 show_bgp_prefix_longer_cmd,
8293 "show bgp X:X::X:X/M longer-prefixes",
8294 SHOW_STR
8295 BGP_STR
8296 "IPv6 prefix <network>/<length>\n"
8297 "Display route and more specific routes\n")
8298{
8299 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8300 bgp_show_type_prefix_longer);
8301}
8302
8303ALIAS (show_bgp_prefix_longer,
8304 show_bgp_ipv6_prefix_longer_cmd,
8305 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8306 SHOW_STR
8307 BGP_STR
8308 "Address family\n"
8309 "IPv6 prefix <network>/<length>\n"
8310 "Display route and more specific routes\n")
8311
8312/* old command */
8313DEFUN (show_ipv6_bgp_prefix_longer,
8314 show_ipv6_bgp_prefix_longer_cmd,
8315 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8316 SHOW_STR
8317 IPV6_STR
8318 BGP_STR
8319 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8320 "Display route and more specific routes\n")
8321{
8322 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8323 bgp_show_type_prefix_longer);
8324}
8325
8326/* old command */
8327DEFUN (show_ipv6_mbgp_prefix_longer,
8328 show_ipv6_mbgp_prefix_longer_cmd,
8329 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8330 SHOW_STR
8331 IPV6_STR
8332 MBGP_STR
8333 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8334 "Display route and more specific routes\n")
8335{
8336 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8337 bgp_show_type_prefix_longer);
8338}
8339#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008340
paul94f2b392005-06-28 12:44:16 +00008341static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008342peer_lookup_in_view (struct vty *vty, const char *view_name,
8343 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008344{
8345 int ret;
8346 struct bgp *bgp;
8347 struct peer *peer;
8348 union sockunion su;
8349
8350 /* BGP structure lookup. */
8351 if (view_name)
8352 {
8353 bgp = bgp_lookup_by_name (view_name);
8354 if (! bgp)
8355 {
8356 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8357 return NULL;
8358 }
8359 }
paul5228ad22004-06-04 17:58:18 +00008360 else
paulbb46e942003-10-24 19:02:03 +00008361 {
8362 bgp = bgp_get_default ();
8363 if (! bgp)
8364 {
8365 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8366 return NULL;
8367 }
8368 }
8369
8370 /* Get peer sockunion. */
8371 ret = str2sockunion (ip_str, &su);
8372 if (ret < 0)
8373 {
8374 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8375 return NULL;
8376 }
8377
8378 /* Peer structure lookup. */
8379 peer = peer_lookup (bgp, &su);
8380 if (! peer)
8381 {
8382 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8383 return NULL;
8384 }
8385
8386 return peer;
8387}
8388
Paul Jakmaff7924f2006-09-04 01:10:36 +00008389enum bgp_pcounts
8390{
8391 PCOUNT_ADJ_IN = 0,
8392 PCOUNT_DAMPED,
8393 PCOUNT_REMOVED,
8394 PCOUNT_HISTORY,
8395 PCOUNT_STALE,
8396 PCOUNT_VALID,
8397 PCOUNT_ALL,
8398 PCOUNT_COUNTED,
8399 PCOUNT_PFCNT, /* the figure we display to users */
8400 PCOUNT_MAX,
8401};
8402
8403static const char *pcount_strs[] =
8404{
8405 [PCOUNT_ADJ_IN] = "Adj-in",
8406 [PCOUNT_DAMPED] = "Damped",
8407 [PCOUNT_REMOVED] = "Removed",
8408 [PCOUNT_HISTORY] = "History",
8409 [PCOUNT_STALE] = "Stale",
8410 [PCOUNT_VALID] = "Valid",
8411 [PCOUNT_ALL] = "All RIB",
8412 [PCOUNT_COUNTED] = "PfxCt counted",
8413 [PCOUNT_PFCNT] = "Useable",
8414 [PCOUNT_MAX] = NULL,
8415};
8416
8417static int
8418bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
8419{
8420 struct bgp_node *rn;
8421 struct bgp_info *ri;
8422 unsigned int pcounts[PCOUNT_MAX], i;
8423
8424 if (!peer || !peer->bgp || !peer->afc[afi][safi]
8425 || !peer->bgp->rib[afi][safi])
8426 {
8427 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8428 return CMD_WARNING;
8429 }
8430
8431 memset (&pcounts, 0, sizeof(pcounts));
8432
8433 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
8434 rn = bgp_route_next (rn))
8435 {
8436 struct bgp_adj_in *ain;
8437
8438 for (ain = rn->adj_in; ain; ain = ain->next)
8439 if (ain->peer == peer)
8440 pcounts[PCOUNT_ADJ_IN]++;
8441
8442#define PFCNT_EXCLUDED (BGP_INFO_DAMPED|BGP_INFO_HISTORY|BGP_INFO_REMOVED|BGP_INFO_STALE)
8443 for (ri = rn->info; ri; ri = ri->next)
8444 {
8445 char buf[SU_ADDRSTRLEN];
8446
8447 if (ri->peer != peer)
8448 continue;
8449
8450 pcounts[PCOUNT_ALL]++;
8451
8452 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
8453 pcounts[PCOUNT_DAMPED]++;
8454 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
8455 pcounts[PCOUNT_HISTORY]++;
8456 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
8457 pcounts[PCOUNT_REMOVED]++;
8458 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
8459 pcounts[PCOUNT_STALE]++;
8460 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
8461 pcounts[PCOUNT_VALID]++;
8462 if (!CHECK_FLAG (ri->flags, PFCNT_EXCLUDED))
8463 pcounts[PCOUNT_PFCNT]++;
8464
8465 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
8466 {
8467 pcounts[PCOUNT_COUNTED]++;
8468 if (CHECK_FLAG (ri->flags, PFCNT_EXCLUDED))
8469 plog_warn (peer->log,
8470 "%s [pcount] %s/%d is counted but flags 0x%x",
8471 peer->host,
8472 inet_ntop(rn->p.family, &rn->p.u.prefix,
8473 buf, SU_ADDRSTRLEN),
8474 rn->p.prefixlen,
8475 ri->flags);
8476 }
8477 else
8478 {
8479 if (!CHECK_FLAG (ri->flags, PFCNT_EXCLUDED))
8480 plog_warn (peer->log,
8481 "%s [pcount] %s/%d not counted but flags 0x%x",
8482 peer->host,
8483 inet_ntop(rn->p.family, &rn->p.u.prefix,
8484 buf, SU_ADDRSTRLEN),
8485 rn->p.prefixlen,
8486 ri->flags);
8487 }
8488 }
8489 }
8490#undef PFCNT_EXCLUDED
8491
8492 vty_out (vty, "Prefix counts for %s, %s%s",
8493 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
8494 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
8495 vty_out (vty, "%sCounts from RIB table walk:%s%s",
8496 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8497
8498 for (i = 0; i < PCOUNT_MAX; i++)
8499 vty_out (vty, "%20s: %-10d%s", pcount_strs[i], pcounts[i], VTY_NEWLINE);
8500
8501 if (pcounts[PCOUNT_PFCNT] != peer->pcount[afi][safi])
8502 {
8503 vty_out (vty, "%s [pcount] PfxCt drift!%s",
8504 peer->host, VTY_NEWLINE);
8505 vty_out (vty, "Please report this bug, with the above command output%s",
8506 VTY_NEWLINE);
8507 }
8508
8509 return CMD_SUCCESS;
8510}
8511
8512DEFUN (show_ip_bgp_neighbor_prefix_counts,
8513 show_ip_bgp_neighbor_prefix_counts_cmd,
8514 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8515 SHOW_STR
8516 IP_STR
8517 BGP_STR
8518 "Detailed information on TCP and BGP neighbor connections\n"
8519 "Neighbor to display information about\n"
8520 "Neighbor to display information about\n"
8521 "Display detailed prefix count information\n")
8522{
8523 struct peer *peer;
8524
8525 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8526 if (! peer)
8527 return CMD_WARNING;
8528
8529 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
8530}
8531
8532DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
8533 show_bgp_ipv6_neighbor_prefix_counts_cmd,
8534 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8535 SHOW_STR
8536 BGP_STR
8537 "Address family\n"
8538 "Detailed information on TCP and BGP neighbor connections\n"
8539 "Neighbor to display information about\n"
8540 "Neighbor to display information about\n"
8541 "Display detailed prefix count information\n")
8542{
8543 struct peer *peer;
8544
8545 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8546 if (! peer)
8547 return CMD_WARNING;
8548
8549 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
8550}
8551
8552DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
8553 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
8554 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8555 SHOW_STR
8556 IP_STR
8557 BGP_STR
8558 "Address family\n"
8559 "Address Family modifier\n"
8560 "Address Family modifier\n"
8561 "Detailed information on TCP and BGP neighbor connections\n"
8562 "Neighbor to display information about\n"
8563 "Neighbor to display information about\n"
8564 "Display detailed prefix count information\n")
8565{
8566 struct peer *peer;
8567
8568 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8569 if (! peer)
8570 return CMD_WARNING;
8571
8572 if (strncmp (argv[0], "m", 1) == 0)
8573 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
8574
8575 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
8576}
8577
8578DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
8579 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
8580 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8581 SHOW_STR
8582 IP_STR
8583 BGP_STR
8584 "Address family\n"
8585 "Address Family modifier\n"
8586 "Address Family modifier\n"
8587 "Detailed information on TCP and BGP neighbor connections\n"
8588 "Neighbor to display information about\n"
8589 "Neighbor to display information about\n"
8590 "Display detailed prefix count information\n")
8591{
8592 struct peer *peer;
8593
8594 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8595 if (! peer)
8596 return CMD_WARNING;
8597
8598 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
8599}
8600
8601
paul94f2b392005-06-28 12:44:16 +00008602static void
paul718e3742002-12-13 20:15:29 +00008603show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
8604 int in)
8605{
8606 struct bgp_table *table;
8607 struct bgp_adj_in *ain;
8608 struct bgp_adj_out *adj;
8609 unsigned long output_count;
8610 struct bgp_node *rn;
8611 int header1 = 1;
8612 struct bgp *bgp;
8613 int header2 = 1;
8614
paulbb46e942003-10-24 19:02:03 +00008615 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00008616
8617 if (! bgp)
8618 return;
8619
8620 table = bgp->rib[afi][safi];
8621
8622 output_count = 0;
8623
8624 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
8625 PEER_STATUS_DEFAULT_ORIGINATE))
8626 {
8627 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 +00008628 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8629 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008630
8631 vty_out (vty, "Originating default network 0.0.0.0%s%s",
8632 VTY_NEWLINE, VTY_NEWLINE);
8633 header1 = 0;
8634 }
8635
8636 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8637 if (in)
8638 {
8639 for (ain = rn->adj_in; ain; ain = ain->next)
8640 if (ain->peer == peer)
8641 {
8642 if (header1)
8643 {
8644 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 +00008645 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8646 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008647 header1 = 0;
8648 }
8649 if (header2)
8650 {
8651 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8652 header2 = 0;
8653 }
8654 if (ain->attr)
8655 {
8656 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
8657 output_count++;
8658 }
8659 }
8660 }
8661 else
8662 {
8663 for (adj = rn->adj_out; adj; adj = adj->next)
8664 if (adj->peer == peer)
8665 {
8666 if (header1)
8667 {
8668 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 +00008669 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8670 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008671 header1 = 0;
8672 }
8673 if (header2)
8674 {
8675 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8676 header2 = 0;
8677 }
8678 if (adj->attr)
8679 {
8680 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
8681 output_count++;
8682 }
8683 }
8684 }
8685
8686 if (output_count != 0)
8687 vty_out (vty, "%sTotal number of prefixes %ld%s",
8688 VTY_NEWLINE, output_count, VTY_NEWLINE);
8689}
8690
paul94f2b392005-06-28 12:44:16 +00008691static int
paulbb46e942003-10-24 19:02:03 +00008692peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
8693{
paul718e3742002-12-13 20:15:29 +00008694 if (! peer || ! peer->afc[afi][safi])
8695 {
8696 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8697 return CMD_WARNING;
8698 }
8699
8700 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8701 {
8702 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
8703 VTY_NEWLINE);
8704 return CMD_WARNING;
8705 }
8706
8707 show_adj_route (vty, peer, afi, safi, in);
8708
8709 return CMD_SUCCESS;
8710}
8711
8712DEFUN (show_ip_bgp_neighbor_advertised_route,
8713 show_ip_bgp_neighbor_advertised_route_cmd,
8714 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8715 SHOW_STR
8716 IP_STR
8717 BGP_STR
8718 "Detailed information on TCP and BGP neighbor connections\n"
8719 "Neighbor to display information about\n"
8720 "Neighbor to display information about\n"
8721 "Display the routes advertised to a BGP neighbor\n")
8722{
paulbb46e942003-10-24 19:02:03 +00008723 struct peer *peer;
8724
8725 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8726 if (! peer)
8727 return CMD_WARNING;
8728
8729 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008730}
8731
8732DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
8733 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
8734 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8735 SHOW_STR
8736 IP_STR
8737 BGP_STR
8738 "Address family\n"
8739 "Address Family modifier\n"
8740 "Address Family modifier\n"
8741 "Detailed information on TCP and BGP neighbor connections\n"
8742 "Neighbor to display information about\n"
8743 "Neighbor to display information about\n"
8744 "Display the routes advertised to a BGP neighbor\n")
8745{
paulbb46e942003-10-24 19:02:03 +00008746 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008747
paulbb46e942003-10-24 19:02:03 +00008748 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8749 if (! peer)
8750 return CMD_WARNING;
8751
8752 if (strncmp (argv[0], "m", 1) == 0)
8753 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
8754
8755 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008756}
8757
8758#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008759DEFUN (show_bgp_view_neighbor_advertised_route,
8760 show_bgp_view_neighbor_advertised_route_cmd,
8761 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8762 SHOW_STR
8763 BGP_STR
8764 "BGP view\n"
8765 "View name\n"
8766 "Detailed information on TCP and BGP neighbor connections\n"
8767 "Neighbor to display information about\n"
8768 "Neighbor to display information about\n"
8769 "Display the routes advertised to a BGP neighbor\n")
8770{
8771 struct peer *peer;
8772
8773 if (argc == 2)
8774 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8775 else
8776 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8777
8778 if (! peer)
8779 return CMD_WARNING;
8780
8781 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
8782}
8783
8784ALIAS (show_bgp_view_neighbor_advertised_route,
8785 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
8786 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8787 SHOW_STR
8788 BGP_STR
8789 "BGP view\n"
8790 "View name\n"
8791 "Address family\n"
8792 "Detailed information on TCP and BGP neighbor connections\n"
8793 "Neighbor to display information about\n"
8794 "Neighbor to display information about\n"
8795 "Display the routes advertised to a BGP neighbor\n")
8796
8797DEFUN (show_bgp_view_neighbor_received_routes,
8798 show_bgp_view_neighbor_received_routes_cmd,
8799 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
8800 SHOW_STR
8801 BGP_STR
8802 "BGP view\n"
8803 "View name\n"
8804 "Detailed information on TCP and BGP neighbor connections\n"
8805 "Neighbor to display information about\n"
8806 "Neighbor to display information about\n"
8807 "Display the received routes from neighbor\n")
8808{
8809 struct peer *peer;
8810
8811 if (argc == 2)
8812 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8813 else
8814 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8815
8816 if (! peer)
8817 return CMD_WARNING;
8818
8819 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
8820}
8821
8822ALIAS (show_bgp_view_neighbor_received_routes,
8823 show_bgp_view_ipv6_neighbor_received_routes_cmd,
8824 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8825 SHOW_STR
8826 BGP_STR
8827 "BGP view\n"
8828 "View name\n"
8829 "Address family\n"
8830 "Detailed information on TCP and BGP neighbor connections\n"
8831 "Neighbor to display information about\n"
8832 "Neighbor to display information about\n"
8833 "Display the received routes from neighbor\n")
8834
8835ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008836 show_bgp_neighbor_advertised_route_cmd,
8837 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8838 SHOW_STR
8839 BGP_STR
8840 "Detailed information on TCP and BGP neighbor connections\n"
8841 "Neighbor to display information about\n"
8842 "Neighbor to display information about\n"
8843 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008844
8845ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008846 show_bgp_ipv6_neighbor_advertised_route_cmd,
8847 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8848 SHOW_STR
8849 BGP_STR
8850 "Address family\n"
8851 "Detailed information on TCP and BGP neighbor connections\n"
8852 "Neighbor to display information about\n"
8853 "Neighbor to display information about\n"
8854 "Display the routes advertised to a BGP neighbor\n")
8855
8856/* old command */
paulbb46e942003-10-24 19:02:03 +00008857ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008858 ipv6_bgp_neighbor_advertised_route_cmd,
8859 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8860 SHOW_STR
8861 IPV6_STR
8862 BGP_STR
8863 "Detailed information on TCP and BGP neighbor connections\n"
8864 "Neighbor to display information about\n"
8865 "Neighbor to display information about\n"
8866 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008867
paul718e3742002-12-13 20:15:29 +00008868/* old command */
8869DEFUN (ipv6_mbgp_neighbor_advertised_route,
8870 ipv6_mbgp_neighbor_advertised_route_cmd,
8871 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8872 SHOW_STR
8873 IPV6_STR
8874 MBGP_STR
8875 "Detailed information on TCP and BGP neighbor connections\n"
8876 "Neighbor to display information about\n"
8877 "Neighbor to display information about\n"
8878 "Display the routes advertised to a BGP neighbor\n")
8879{
paulbb46e942003-10-24 19:02:03 +00008880 struct peer *peer;
8881
8882 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8883 if (! peer)
8884 return CMD_WARNING;
8885
8886 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00008887}
8888#endif /* HAVE_IPV6 */
8889
8890DEFUN (show_ip_bgp_neighbor_received_routes,
8891 show_ip_bgp_neighbor_received_routes_cmd,
8892 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8893 SHOW_STR
8894 IP_STR
8895 BGP_STR
8896 "Detailed information on TCP and BGP neighbor connections\n"
8897 "Neighbor to display information about\n"
8898 "Neighbor to display information about\n"
8899 "Display the received routes from neighbor\n")
8900{
paulbb46e942003-10-24 19:02:03 +00008901 struct peer *peer;
8902
8903 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8904 if (! peer)
8905 return CMD_WARNING;
8906
8907 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008908}
8909
8910DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
8911 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
8912 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
8913 SHOW_STR
8914 IP_STR
8915 BGP_STR
8916 "Address family\n"
8917 "Address Family modifier\n"
8918 "Address Family modifier\n"
8919 "Detailed information on TCP and BGP neighbor connections\n"
8920 "Neighbor to display information about\n"
8921 "Neighbor to display information about\n"
8922 "Display the received routes from neighbor\n")
8923{
paulbb46e942003-10-24 19:02:03 +00008924 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008925
paulbb46e942003-10-24 19:02:03 +00008926 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8927 if (! peer)
8928 return CMD_WARNING;
8929
8930 if (strncmp (argv[0], "m", 1) == 0)
8931 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
8932
8933 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008934}
8935
8936DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
8937 show_ip_bgp_neighbor_received_prefix_filter_cmd,
8938 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8939 SHOW_STR
8940 IP_STR
8941 BGP_STR
8942 "Detailed information on TCP and BGP neighbor connections\n"
8943 "Neighbor to display information about\n"
8944 "Neighbor to display information about\n"
8945 "Display information received from a BGP neighbor\n"
8946 "Display the prefixlist filter\n")
8947{
8948 char name[BUFSIZ];
8949 union sockunion *su;
8950 struct peer *peer;
8951 int count;
8952
8953 su = sockunion_str2su (argv[0]);
8954 if (su == NULL)
8955 return CMD_WARNING;
8956
8957 peer = peer_lookup (NULL, su);
8958 if (! peer)
8959 return CMD_WARNING;
8960
8961 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8962 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8963 if (count)
8964 {
8965 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8966 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8967 }
8968
8969 return CMD_SUCCESS;
8970}
8971
8972DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
8973 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
8974 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8975 SHOW_STR
8976 IP_STR
8977 BGP_STR
8978 "Address family\n"
8979 "Address Family modifier\n"
8980 "Address Family modifier\n"
8981 "Detailed information on TCP and BGP neighbor connections\n"
8982 "Neighbor to display information about\n"
8983 "Neighbor to display information about\n"
8984 "Display information received from a BGP neighbor\n"
8985 "Display the prefixlist filter\n")
8986{
8987 char name[BUFSIZ];
8988 union sockunion *su;
8989 struct peer *peer;
8990 int count;
8991
8992 su = sockunion_str2su (argv[1]);
8993 if (su == NULL)
8994 return CMD_WARNING;
8995
8996 peer = peer_lookup (NULL, su);
8997 if (! peer)
8998 return CMD_WARNING;
8999
9000 if (strncmp (argv[0], "m", 1) == 0)
9001 {
9002 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9003 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9004 if (count)
9005 {
9006 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9007 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9008 }
9009 }
9010 else
9011 {
9012 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9013 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9014 if (count)
9015 {
9016 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9017 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9018 }
9019 }
9020
9021 return CMD_SUCCESS;
9022}
9023
9024
9025#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009026ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009027 show_bgp_neighbor_received_routes_cmd,
9028 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9029 SHOW_STR
9030 BGP_STR
9031 "Detailed information on TCP and BGP neighbor connections\n"
9032 "Neighbor to display information about\n"
9033 "Neighbor to display information about\n"
9034 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009035
paulbb46e942003-10-24 19:02:03 +00009036ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009037 show_bgp_ipv6_neighbor_received_routes_cmd,
9038 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9039 SHOW_STR
9040 BGP_STR
9041 "Address family\n"
9042 "Detailed information on TCP and BGP neighbor connections\n"
9043 "Neighbor to display information about\n"
9044 "Neighbor to display information about\n"
9045 "Display the received routes from neighbor\n")
9046
9047DEFUN (show_bgp_neighbor_received_prefix_filter,
9048 show_bgp_neighbor_received_prefix_filter_cmd,
9049 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9050 SHOW_STR
9051 BGP_STR
9052 "Detailed information on TCP and BGP neighbor connections\n"
9053 "Neighbor to display information about\n"
9054 "Neighbor to display information about\n"
9055 "Display information received from a BGP neighbor\n"
9056 "Display the prefixlist filter\n")
9057{
9058 char name[BUFSIZ];
9059 union sockunion *su;
9060 struct peer *peer;
9061 int count;
9062
9063 su = sockunion_str2su (argv[0]);
9064 if (su == NULL)
9065 return CMD_WARNING;
9066
9067 peer = peer_lookup (NULL, su);
9068 if (! peer)
9069 return CMD_WARNING;
9070
9071 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9072 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9073 if (count)
9074 {
9075 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
9076 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
9077 }
9078
9079 return CMD_SUCCESS;
9080}
9081
9082ALIAS (show_bgp_neighbor_received_prefix_filter,
9083 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
9084 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9085 SHOW_STR
9086 BGP_STR
9087 "Address family\n"
9088 "Detailed information on TCP and BGP neighbor connections\n"
9089 "Neighbor to display information about\n"
9090 "Neighbor to display information about\n"
9091 "Display information received from a BGP neighbor\n"
9092 "Display the prefixlist filter\n")
9093
9094/* old command */
paulbb46e942003-10-24 19:02:03 +00009095ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009096 ipv6_bgp_neighbor_received_routes_cmd,
9097 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9098 SHOW_STR
9099 IPV6_STR
9100 BGP_STR
9101 "Detailed information on TCP and BGP neighbor connections\n"
9102 "Neighbor to display information about\n"
9103 "Neighbor to display information about\n"
9104 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009105
9106/* old command */
9107DEFUN (ipv6_mbgp_neighbor_received_routes,
9108 ipv6_mbgp_neighbor_received_routes_cmd,
9109 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9110 SHOW_STR
9111 IPV6_STR
9112 MBGP_STR
9113 "Detailed information on TCP and BGP neighbor connections\n"
9114 "Neighbor to display information about\n"
9115 "Neighbor to display information about\n"
9116 "Display the received routes from neighbor\n")
9117{
paulbb46e942003-10-24 19:02:03 +00009118 struct peer *peer;
9119
9120 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9121 if (! peer)
9122 return CMD_WARNING;
9123
9124 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00009125}
paulbb46e942003-10-24 19:02:03 +00009126
9127DEFUN (show_bgp_view_neighbor_received_prefix_filter,
9128 show_bgp_view_neighbor_received_prefix_filter_cmd,
9129 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9130 SHOW_STR
9131 BGP_STR
9132 "BGP view\n"
9133 "View name\n"
9134 "Detailed information on TCP and BGP neighbor connections\n"
9135 "Neighbor to display information about\n"
9136 "Neighbor to display information about\n"
9137 "Display information received from a BGP neighbor\n"
9138 "Display the prefixlist filter\n")
9139{
9140 char name[BUFSIZ];
9141 union sockunion *su;
9142 struct peer *peer;
9143 struct bgp *bgp;
9144 int count;
9145
9146 /* BGP structure lookup. */
9147 bgp = bgp_lookup_by_name (argv[0]);
9148 if (bgp == NULL)
9149 {
9150 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9151 return CMD_WARNING;
9152 }
9153
9154 su = sockunion_str2su (argv[1]);
9155 if (su == NULL)
9156 return CMD_WARNING;
9157
9158 peer = peer_lookup (bgp, su);
9159 if (! peer)
9160 return CMD_WARNING;
9161
9162 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9163 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9164 if (count)
9165 {
9166 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
9167 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
9168 }
9169
9170 return CMD_SUCCESS;
9171}
9172
9173ALIAS (show_bgp_view_neighbor_received_prefix_filter,
9174 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
9175 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9176 SHOW_STR
9177 BGP_STR
9178 "BGP view\n"
9179 "View name\n"
9180 "Address family\n"
9181 "Detailed information on TCP and BGP neighbor connections\n"
9182 "Neighbor to display information about\n"
9183 "Neighbor to display information about\n"
9184 "Display information received from a BGP neighbor\n"
9185 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00009186#endif /* HAVE_IPV6 */
9187
paul94f2b392005-06-28 12:44:16 +00009188static int
paulbb46e942003-10-24 19:02:03 +00009189bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009190 safi_t safi, enum bgp_show_type type)
9191{
paul718e3742002-12-13 20:15:29 +00009192 if (! peer || ! peer->afc[afi][safi])
9193 {
9194 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009195 return CMD_WARNING;
9196 }
9197
ajs5a646652004-11-05 01:25:55 +00009198 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +00009199}
9200
9201DEFUN (show_ip_bgp_neighbor_routes,
9202 show_ip_bgp_neighbor_routes_cmd,
9203 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
9204 SHOW_STR
9205 IP_STR
9206 BGP_STR
9207 "Detailed information on TCP and BGP neighbor connections\n"
9208 "Neighbor to display information about\n"
9209 "Neighbor to display information about\n"
9210 "Display routes learned from neighbor\n")
9211{
paulbb46e942003-10-24 19:02:03 +00009212 struct peer *peer;
9213
9214 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9215 if (! peer)
9216 return CMD_WARNING;
9217
9218 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009219 bgp_show_type_neighbor);
9220}
9221
9222DEFUN (show_ip_bgp_neighbor_flap,
9223 show_ip_bgp_neighbor_flap_cmd,
9224 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9225 SHOW_STR
9226 IP_STR
9227 BGP_STR
9228 "Detailed information on TCP and BGP neighbor connections\n"
9229 "Neighbor to display information about\n"
9230 "Neighbor to display information about\n"
9231 "Display flap statistics of the routes learned from neighbor\n")
9232{
paulbb46e942003-10-24 19:02:03 +00009233 struct peer *peer;
9234
9235 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9236 if (! peer)
9237 return CMD_WARNING;
9238
9239 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009240 bgp_show_type_flap_neighbor);
9241}
9242
9243DEFUN (show_ip_bgp_neighbor_damp,
9244 show_ip_bgp_neighbor_damp_cmd,
9245 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9246 SHOW_STR
9247 IP_STR
9248 BGP_STR
9249 "Detailed information on TCP and BGP neighbor connections\n"
9250 "Neighbor to display information about\n"
9251 "Neighbor to display information about\n"
9252 "Display the dampened routes received from neighbor\n")
9253{
paulbb46e942003-10-24 19:02:03 +00009254 struct peer *peer;
9255
9256 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9257 if (! peer)
9258 return CMD_WARNING;
9259
9260 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009261 bgp_show_type_damp_neighbor);
9262}
9263
9264DEFUN (show_ip_bgp_ipv4_neighbor_routes,
9265 show_ip_bgp_ipv4_neighbor_routes_cmd,
9266 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
9267 SHOW_STR
9268 IP_STR
9269 BGP_STR
9270 "Address family\n"
9271 "Address Family modifier\n"
9272 "Address Family modifier\n"
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 routes learned from neighbor\n")
9277{
paulbb46e942003-10-24 19:02:03 +00009278 struct peer *peer;
9279
9280 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9281 if (! peer)
9282 return CMD_WARNING;
9283
paul718e3742002-12-13 20:15:29 +00009284 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00009285 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009286 bgp_show_type_neighbor);
9287
paulbb46e942003-10-24 19:02:03 +00009288 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009289 bgp_show_type_neighbor);
9290}
paulbb46e942003-10-24 19:02:03 +00009291
paulfee0f4c2004-09-13 05:12:46 +00009292DEFUN (show_ip_bgp_view_rsclient,
9293 show_ip_bgp_view_rsclient_cmd,
9294 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9295 SHOW_STR
9296 IP_STR
9297 BGP_STR
9298 "BGP view\n"
9299 "BGP view name\n"
9300 "Information about Route Server Client\n"
9301 NEIGHBOR_ADDR_STR)
9302{
9303 struct bgp_table *table;
9304 struct peer *peer;
9305
9306 if (argc == 2)
9307 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9308 else
9309 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9310
9311 if (! peer)
9312 return CMD_WARNING;
9313
9314 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9315 {
9316 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9317 VTY_NEWLINE);
9318 return CMD_WARNING;
9319 }
9320
9321 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9322 PEER_FLAG_RSERVER_CLIENT))
9323 {
9324 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9325 VTY_NEWLINE);
9326 return CMD_WARNING;
9327 }
9328
9329 table = peer->rib[AFI_IP][SAFI_UNICAST];
9330
ajs5a646652004-11-05 01:25:55 +00009331 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009332}
9333
9334ALIAS (show_ip_bgp_view_rsclient,
9335 show_ip_bgp_rsclient_cmd,
9336 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
9337 SHOW_STR
9338 IP_STR
9339 BGP_STR
9340 "Information about Route Server Client\n"
9341 NEIGHBOR_ADDR_STR)
9342
9343DEFUN (show_ip_bgp_view_rsclient_route,
9344 show_ip_bgp_view_rsclient_route_cmd,
9345 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9346 SHOW_STR
9347 IP_STR
9348 BGP_STR
9349 "BGP view\n"
9350 "BGP view name\n"
9351 "Information about Route Server Client\n"
9352 NEIGHBOR_ADDR_STR
9353 "Network in the BGP routing table to display\n")
9354{
9355 struct bgp *bgp;
9356 struct peer *peer;
9357
9358 /* BGP structure lookup. */
9359 if (argc == 3)
9360 {
9361 bgp = bgp_lookup_by_name (argv[0]);
9362 if (bgp == NULL)
9363 {
9364 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9365 return CMD_WARNING;
9366 }
9367 }
9368 else
9369 {
9370 bgp = bgp_get_default ();
9371 if (bgp == NULL)
9372 {
9373 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9374 return CMD_WARNING;
9375 }
9376 }
9377
9378 if (argc == 3)
9379 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9380 else
9381 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9382
9383 if (! peer)
9384 return CMD_WARNING;
9385
9386 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9387 {
9388 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9389 VTY_NEWLINE);
9390 return CMD_WARNING;
9391}
9392
9393 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9394 PEER_FLAG_RSERVER_CLIENT))
9395 {
9396 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9397 VTY_NEWLINE);
9398 return CMD_WARNING;
9399 }
9400
9401 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9402 (argc == 3) ? argv[2] : argv[1],
9403 AFI_IP, SAFI_UNICAST, NULL, 0);
9404}
9405
9406ALIAS (show_ip_bgp_view_rsclient_route,
9407 show_ip_bgp_rsclient_route_cmd,
9408 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9409 SHOW_STR
9410 IP_STR
9411 BGP_STR
9412 "Information about Route Server Client\n"
9413 NEIGHBOR_ADDR_STR
9414 "Network in the BGP routing table to display\n")
9415
9416DEFUN (show_ip_bgp_view_rsclient_prefix,
9417 show_ip_bgp_view_rsclient_prefix_cmd,
9418 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9419 SHOW_STR
9420 IP_STR
9421 BGP_STR
9422 "BGP view\n"
9423 "BGP view name\n"
9424 "Information about Route Server Client\n"
9425 NEIGHBOR_ADDR_STR
9426 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9427{
9428 struct bgp *bgp;
9429 struct peer *peer;
9430
9431 /* BGP structure lookup. */
9432 if (argc == 3)
9433 {
9434 bgp = bgp_lookup_by_name (argv[0]);
9435 if (bgp == NULL)
9436 {
9437 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9438 return CMD_WARNING;
9439 }
9440 }
9441 else
9442 {
9443 bgp = bgp_get_default ();
9444 if (bgp == NULL)
9445 {
9446 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9447 return CMD_WARNING;
9448 }
9449 }
9450
9451 if (argc == 3)
9452 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9453 else
9454 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9455
9456 if (! peer)
9457 return CMD_WARNING;
9458
9459 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9460 {
9461 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9462 VTY_NEWLINE);
9463 return CMD_WARNING;
9464}
9465
9466 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9467 PEER_FLAG_RSERVER_CLIENT))
9468{
9469 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9470 VTY_NEWLINE);
9471 return CMD_WARNING;
9472 }
9473
9474 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9475 (argc == 3) ? argv[2] : argv[1],
9476 AFI_IP, SAFI_UNICAST, NULL, 1);
9477}
9478
9479ALIAS (show_ip_bgp_view_rsclient_prefix,
9480 show_ip_bgp_rsclient_prefix_cmd,
9481 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9482 SHOW_STR
9483 IP_STR
9484 BGP_STR
9485 "Information about Route Server Client\n"
9486 NEIGHBOR_ADDR_STR
9487 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9488
9489
paul718e3742002-12-13 20:15:29 +00009490#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009491DEFUN (show_bgp_view_neighbor_routes,
9492 show_bgp_view_neighbor_routes_cmd,
9493 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
9494 SHOW_STR
9495 BGP_STR
9496 "BGP view\n"
9497 "BGP view name\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 routes learned from neighbor\n")
9502{
9503 struct peer *peer;
9504
9505 if (argc == 2)
9506 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9507 else
9508 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9509
9510 if (! peer)
9511 return CMD_WARNING;
9512
9513 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9514 bgp_show_type_neighbor);
9515}
9516
9517ALIAS (show_bgp_view_neighbor_routes,
9518 show_bgp_view_ipv6_neighbor_routes_cmd,
9519 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9520 SHOW_STR
9521 BGP_STR
9522 "BGP view\n"
9523 "BGP view name\n"
9524 "Address family\n"
9525 "Detailed information on TCP and BGP neighbor connections\n"
9526 "Neighbor to display information about\n"
9527 "Neighbor to display information about\n"
9528 "Display routes learned from neighbor\n")
9529
9530DEFUN (show_bgp_view_neighbor_damp,
9531 show_bgp_view_neighbor_damp_cmd,
9532 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9533 SHOW_STR
9534 BGP_STR
9535 "BGP view\n"
9536 "BGP view name\n"
9537 "Detailed information on TCP and BGP neighbor connections\n"
9538 "Neighbor to display information about\n"
9539 "Neighbor to display information about\n"
9540 "Display the dampened routes received from neighbor\n")
9541{
9542 struct peer *peer;
9543
9544 if (argc == 2)
9545 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9546 else
9547 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9548
9549 if (! peer)
9550 return CMD_WARNING;
9551
9552 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9553 bgp_show_type_damp_neighbor);
9554}
9555
9556ALIAS (show_bgp_view_neighbor_damp,
9557 show_bgp_view_ipv6_neighbor_damp_cmd,
9558 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9559 SHOW_STR
9560 BGP_STR
9561 "BGP view\n"
9562 "BGP view name\n"
9563 "Address family\n"
9564 "Detailed information on TCP and BGP neighbor connections\n"
9565 "Neighbor to display information about\n"
9566 "Neighbor to display information about\n"
9567 "Display the dampened routes received from neighbor\n")
9568
9569DEFUN (show_bgp_view_neighbor_flap,
9570 show_bgp_view_neighbor_flap_cmd,
9571 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9572 SHOW_STR
9573 BGP_STR
9574 "BGP view\n"
9575 "BGP view name\n"
9576 "Detailed information on TCP and BGP neighbor connections\n"
9577 "Neighbor to display information about\n"
9578 "Neighbor to display information about\n"
9579 "Display flap statistics of the routes learned from neighbor\n")
9580{
9581 struct peer *peer;
9582
9583 if (argc == 2)
9584 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9585 else
9586 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9587
9588 if (! peer)
9589 return CMD_WARNING;
9590
9591 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9592 bgp_show_type_flap_neighbor);
9593}
9594
9595ALIAS (show_bgp_view_neighbor_flap,
9596 show_bgp_view_ipv6_neighbor_flap_cmd,
9597 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9598 SHOW_STR
9599 BGP_STR
9600 "BGP view\n"
9601 "BGP view name\n"
9602 "Address family\n"
9603 "Detailed information on TCP and BGP neighbor connections\n"
9604 "Neighbor to display information about\n"
9605 "Neighbor to display information about\n"
9606 "Display flap statistics of the routes learned from neighbor\n")
9607
9608ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009609 show_bgp_neighbor_routes_cmd,
9610 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
9611 SHOW_STR
9612 BGP_STR
9613 "Detailed information on TCP and BGP neighbor connections\n"
9614 "Neighbor to display information about\n"
9615 "Neighbor to display information about\n"
9616 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009617
paulbb46e942003-10-24 19:02:03 +00009618
9619ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009620 show_bgp_ipv6_neighbor_routes_cmd,
9621 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9622 SHOW_STR
9623 BGP_STR
9624 "Address family\n"
9625 "Detailed information on TCP and BGP neighbor connections\n"
9626 "Neighbor to display information about\n"
9627 "Neighbor to display information about\n"
9628 "Display routes learned from neighbor\n")
9629
9630/* old command */
paulbb46e942003-10-24 19:02:03 +00009631ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009632 ipv6_bgp_neighbor_routes_cmd,
9633 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
9634 SHOW_STR
9635 IPV6_STR
9636 BGP_STR
9637 "Detailed information on TCP and BGP neighbor connections\n"
9638 "Neighbor to display information about\n"
9639 "Neighbor to display information about\n"
9640 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009641
9642/* old command */
9643DEFUN (ipv6_mbgp_neighbor_routes,
9644 ipv6_mbgp_neighbor_routes_cmd,
9645 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
9646 SHOW_STR
9647 IPV6_STR
9648 MBGP_STR
9649 "Detailed information on TCP and BGP neighbor connections\n"
9650 "Neighbor to display information about\n"
9651 "Neighbor to display information about\n"
9652 "Display routes learned from neighbor\n")
9653{
paulbb46e942003-10-24 19:02:03 +00009654 struct peer *peer;
9655
9656 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9657 if (! peer)
9658 return CMD_WARNING;
9659
9660 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009661 bgp_show_type_neighbor);
9662}
paulbb46e942003-10-24 19:02:03 +00009663
9664ALIAS (show_bgp_view_neighbor_flap,
9665 show_bgp_neighbor_flap_cmd,
9666 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9667 SHOW_STR
9668 BGP_STR
9669 "Detailed information on TCP and BGP neighbor connections\n"
9670 "Neighbor to display information about\n"
9671 "Neighbor to display information about\n"
9672 "Display flap statistics of the routes learned from neighbor\n")
9673
9674ALIAS (show_bgp_view_neighbor_flap,
9675 show_bgp_ipv6_neighbor_flap_cmd,
9676 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9677 SHOW_STR
9678 BGP_STR
9679 "Address family\n"
9680 "Detailed information on TCP and BGP neighbor connections\n"
9681 "Neighbor to display information about\n"
9682 "Neighbor to display information about\n"
9683 "Display flap statistics of the routes learned from neighbor\n")
9684
9685ALIAS (show_bgp_view_neighbor_damp,
9686 show_bgp_neighbor_damp_cmd,
9687 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9688 SHOW_STR
9689 BGP_STR
9690 "Detailed information on TCP and BGP neighbor connections\n"
9691 "Neighbor to display information about\n"
9692 "Neighbor to display information about\n"
9693 "Display the dampened routes received from neighbor\n")
9694
9695ALIAS (show_bgp_view_neighbor_damp,
9696 show_bgp_ipv6_neighbor_damp_cmd,
9697 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9698 SHOW_STR
9699 BGP_STR
9700 "Address family\n"
9701 "Detailed information on TCP and BGP neighbor connections\n"
9702 "Neighbor to display information about\n"
9703 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +00009704 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +00009705
9706DEFUN (show_bgp_view_rsclient,
9707 show_bgp_view_rsclient_cmd,
9708 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9709 SHOW_STR
9710 BGP_STR
9711 "BGP view\n"
9712 "BGP view name\n"
9713 "Information about Route Server Client\n"
9714 NEIGHBOR_ADDR_STR)
9715{
9716 struct bgp_table *table;
9717 struct peer *peer;
9718
9719 if (argc == 2)
9720 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9721 else
9722 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9723
9724 if (! peer)
9725 return CMD_WARNING;
9726
9727 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9728 {
9729 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9730 VTY_NEWLINE);
9731 return CMD_WARNING;
9732 }
9733
9734 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9735 PEER_FLAG_RSERVER_CLIENT))
9736 {
9737 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9738 VTY_NEWLINE);
9739 return CMD_WARNING;
9740 }
9741
9742 table = peer->rib[AFI_IP6][SAFI_UNICAST];
9743
ajs5a646652004-11-05 01:25:55 +00009744 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009745}
9746
9747ALIAS (show_bgp_view_rsclient,
9748 show_bgp_rsclient_cmd,
9749 "show bgp rsclient (A.B.C.D|X:X::X:X)",
9750 SHOW_STR
9751 BGP_STR
9752 "Information about Route Server Client\n"
9753 NEIGHBOR_ADDR_STR)
9754
9755DEFUN (show_bgp_view_rsclient_route,
9756 show_bgp_view_rsclient_route_cmd,
9757 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9758 SHOW_STR
9759 BGP_STR
9760 "BGP view\n"
9761 "BGP view name\n"
9762 "Information about Route Server Client\n"
9763 NEIGHBOR_ADDR_STR
9764 "Network in the BGP routing table to display\n")
9765{
9766 struct bgp *bgp;
9767 struct peer *peer;
9768
9769 /* BGP structure lookup. */
9770 if (argc == 3)
9771 {
9772 bgp = bgp_lookup_by_name (argv[0]);
9773 if (bgp == NULL)
9774 {
9775 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9776 return CMD_WARNING;
9777 }
9778 }
9779 else
9780 {
9781 bgp = bgp_get_default ();
9782 if (bgp == NULL)
9783 {
9784 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9785 return CMD_WARNING;
9786 }
9787 }
9788
9789 if (argc == 3)
9790 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9791 else
9792 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9793
9794 if (! peer)
9795 return CMD_WARNING;
9796
9797 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9798 {
9799 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9800 VTY_NEWLINE);
9801 return CMD_WARNING;
9802 }
9803
9804 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9805 PEER_FLAG_RSERVER_CLIENT))
9806 {
9807 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9808 VTY_NEWLINE);
9809 return CMD_WARNING;
9810 }
9811
9812 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9813 (argc == 3) ? argv[2] : argv[1],
9814 AFI_IP6, SAFI_UNICAST, NULL, 0);
9815}
9816
9817ALIAS (show_bgp_view_rsclient_route,
9818 show_bgp_rsclient_route_cmd,
9819 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9820 SHOW_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_bgp_view_rsclient_prefix,
9827 show_bgp_view_rsclient_prefix_cmd,
9828 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9829 SHOW_STR
9830 BGP_STR
9831 "BGP view\n"
9832 "BGP view name\n"
9833 "Information about Route Server Client\n"
9834 NEIGHBOR_ADDR_STR
9835 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9836{
9837 struct bgp *bgp;
9838 struct peer *peer;
9839
9840 /* BGP structure lookup. */
9841 if (argc == 3)
9842 {
9843 bgp = bgp_lookup_by_name (argv[0]);
9844 if (bgp == NULL)
9845 {
9846 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9847 return CMD_WARNING;
9848 }
9849 }
9850 else
9851 {
9852 bgp = bgp_get_default ();
9853 if (bgp == NULL)
9854 {
9855 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9856 return CMD_WARNING;
9857 }
9858 }
9859
9860 if (argc == 3)
9861 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9862 else
9863 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9864
9865 if (! peer)
9866 return CMD_WARNING;
9867
9868 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9869 {
9870 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9871 VTY_NEWLINE);
9872 return CMD_WARNING;
9873 }
9874
9875 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9876 PEER_FLAG_RSERVER_CLIENT))
9877 {
9878 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9879 VTY_NEWLINE);
9880 return CMD_WARNING;
9881 }
9882
9883 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9884 (argc == 3) ? argv[2] : argv[1],
9885 AFI_IP6, SAFI_UNICAST, NULL, 1);
9886}
9887
9888ALIAS (show_bgp_view_rsclient_prefix,
9889 show_bgp_rsclient_prefix_cmd,
9890 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9891 SHOW_STR
9892 BGP_STR
9893 "Information about Route Server Client\n"
9894 NEIGHBOR_ADDR_STR
9895 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9896
paul718e3742002-12-13 20:15:29 +00009897#endif /* HAVE_IPV6 */
9898
9899struct bgp_table *bgp_distance_table;
9900
9901struct bgp_distance
9902{
9903 /* Distance value for the IP source prefix. */
9904 u_char distance;
9905
9906 /* Name of the access-list to be matched. */
9907 char *access_list;
9908};
9909
paul94f2b392005-06-28 12:44:16 +00009910static struct bgp_distance *
paul718e3742002-12-13 20:15:29 +00009911bgp_distance_new ()
9912{
9913 struct bgp_distance *new;
9914 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
9915 memset (new, 0, sizeof (struct bgp_distance));
9916 return new;
9917}
9918
paul94f2b392005-06-28 12:44:16 +00009919static void
paul718e3742002-12-13 20:15:29 +00009920bgp_distance_free (struct bgp_distance *bdistance)
9921{
9922 XFREE (MTYPE_BGP_DISTANCE, bdistance);
9923}
9924
paul94f2b392005-06-28 12:44:16 +00009925static int
paulfd79ac92004-10-13 05:06:08 +00009926bgp_distance_set (struct vty *vty, const char *distance_str,
9927 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009928{
9929 int ret;
9930 struct prefix_ipv4 p;
9931 u_char distance;
9932 struct bgp_node *rn;
9933 struct bgp_distance *bdistance;
9934
9935 ret = str2prefix_ipv4 (ip_str, &p);
9936 if (ret == 0)
9937 {
9938 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9939 return CMD_WARNING;
9940 }
9941
9942 distance = atoi (distance_str);
9943
9944 /* Get BGP distance node. */
9945 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
9946 if (rn->info)
9947 {
9948 bdistance = rn->info;
9949 bgp_unlock_node (rn);
9950 }
9951 else
9952 {
9953 bdistance = bgp_distance_new ();
9954 rn->info = bdistance;
9955 }
9956
9957 /* Set distance value. */
9958 bdistance->distance = distance;
9959
9960 /* Reset access-list configuration. */
9961 if (bdistance->access_list)
9962 {
9963 free (bdistance->access_list);
9964 bdistance->access_list = NULL;
9965 }
9966 if (access_list_str)
9967 bdistance->access_list = strdup (access_list_str);
9968
9969 return CMD_SUCCESS;
9970}
9971
paul94f2b392005-06-28 12:44:16 +00009972static int
paulfd79ac92004-10-13 05:06:08 +00009973bgp_distance_unset (struct vty *vty, const char *distance_str,
9974 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009975{
9976 int ret;
9977 struct prefix_ipv4 p;
9978 u_char distance;
9979 struct bgp_node *rn;
9980 struct bgp_distance *bdistance;
9981
9982 ret = str2prefix_ipv4 (ip_str, &p);
9983 if (ret == 0)
9984 {
9985 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9986 return CMD_WARNING;
9987 }
9988
9989 distance = atoi (distance_str);
9990
9991 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
9992 if (! rn)
9993 {
9994 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
9995 return CMD_WARNING;
9996 }
9997
9998 bdistance = rn->info;
9999
10000 if (bdistance->access_list)
10001 free (bdistance->access_list);
10002 bgp_distance_free (bdistance);
10003
10004 rn->info = NULL;
10005 bgp_unlock_node (rn);
10006 bgp_unlock_node (rn);
10007
10008 return CMD_SUCCESS;
10009}
10010
paul94f2b392005-06-28 12:44:16 +000010011static void
paul718e3742002-12-13 20:15:29 +000010012bgp_distance_reset ()
10013{
10014 struct bgp_node *rn;
10015 struct bgp_distance *bdistance;
10016
10017 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10018 if ((bdistance = rn->info) != NULL)
10019 {
10020 if (bdistance->access_list)
10021 free (bdistance->access_list);
10022 bgp_distance_free (bdistance);
10023 rn->info = NULL;
10024 bgp_unlock_node (rn);
10025 }
10026}
10027
10028/* Apply BGP information to distance method. */
10029u_char
10030bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10031{
10032 struct bgp_node *rn;
10033 struct prefix_ipv4 q;
10034 struct peer *peer;
10035 struct bgp_distance *bdistance;
10036 struct access_list *alist;
10037 struct bgp_static *bgp_static;
10038
10039 if (! bgp)
10040 return 0;
10041
10042 if (p->family != AF_INET)
10043 return 0;
10044
10045 peer = rinfo->peer;
10046
10047 if (peer->su.sa.sa_family != AF_INET)
10048 return 0;
10049
10050 memset (&q, 0, sizeof (struct prefix_ipv4));
10051 q.family = AF_INET;
10052 q.prefix = peer->su.sin.sin_addr;
10053 q.prefixlen = IPV4_MAX_BITLEN;
10054
10055 /* Check source address. */
10056 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
10057 if (rn)
10058 {
10059 bdistance = rn->info;
10060 bgp_unlock_node (rn);
10061
10062 if (bdistance->access_list)
10063 {
10064 alist = access_list_lookup (AFI_IP, bdistance->access_list);
10065 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
10066 return bdistance->distance;
10067 }
10068 else
10069 return bdistance->distance;
10070 }
10071
10072 /* Backdoor check. */
10073 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
10074 if (rn)
10075 {
10076 bgp_static = rn->info;
10077 bgp_unlock_node (rn);
10078
10079 if (bgp_static->backdoor)
10080 {
10081 if (bgp->distance_local)
10082 return bgp->distance_local;
10083 else
10084 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10085 }
10086 }
10087
10088 if (peer_sort (peer) == BGP_PEER_EBGP)
10089 {
10090 if (bgp->distance_ebgp)
10091 return bgp->distance_ebgp;
10092 return ZEBRA_EBGP_DISTANCE_DEFAULT;
10093 }
10094 else
10095 {
10096 if (bgp->distance_ibgp)
10097 return bgp->distance_ibgp;
10098 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10099 }
10100}
10101
10102DEFUN (bgp_distance,
10103 bgp_distance_cmd,
10104 "distance bgp <1-255> <1-255> <1-255>",
10105 "Define an administrative distance\n"
10106 "BGP distance\n"
10107 "Distance for routes external to the AS\n"
10108 "Distance for routes internal to the AS\n"
10109 "Distance for local routes\n")
10110{
10111 struct bgp *bgp;
10112
10113 bgp = vty->index;
10114
10115 bgp->distance_ebgp = atoi (argv[0]);
10116 bgp->distance_ibgp = atoi (argv[1]);
10117 bgp->distance_local = atoi (argv[2]);
10118 return CMD_SUCCESS;
10119}
10120
10121DEFUN (no_bgp_distance,
10122 no_bgp_distance_cmd,
10123 "no distance bgp <1-255> <1-255> <1-255>",
10124 NO_STR
10125 "Define an administrative distance\n"
10126 "BGP distance\n"
10127 "Distance for routes external to the AS\n"
10128 "Distance for routes internal to the AS\n"
10129 "Distance for local routes\n")
10130{
10131 struct bgp *bgp;
10132
10133 bgp = vty->index;
10134
10135 bgp->distance_ebgp= 0;
10136 bgp->distance_ibgp = 0;
10137 bgp->distance_local = 0;
10138 return CMD_SUCCESS;
10139}
10140
10141ALIAS (no_bgp_distance,
10142 no_bgp_distance2_cmd,
10143 "no distance bgp",
10144 NO_STR
10145 "Define an administrative distance\n"
10146 "BGP distance\n")
10147
10148DEFUN (bgp_distance_source,
10149 bgp_distance_source_cmd,
10150 "distance <1-255> A.B.C.D/M",
10151 "Define an administrative distance\n"
10152 "Administrative distance\n"
10153 "IP source prefix\n")
10154{
10155 bgp_distance_set (vty, argv[0], argv[1], NULL);
10156 return CMD_SUCCESS;
10157}
10158
10159DEFUN (no_bgp_distance_source,
10160 no_bgp_distance_source_cmd,
10161 "no distance <1-255> A.B.C.D/M",
10162 NO_STR
10163 "Define an administrative distance\n"
10164 "Administrative distance\n"
10165 "IP source prefix\n")
10166{
10167 bgp_distance_unset (vty, argv[0], argv[1], NULL);
10168 return CMD_SUCCESS;
10169}
10170
10171DEFUN (bgp_distance_source_access_list,
10172 bgp_distance_source_access_list_cmd,
10173 "distance <1-255> A.B.C.D/M WORD",
10174 "Define an administrative distance\n"
10175 "Administrative distance\n"
10176 "IP source prefix\n"
10177 "Access list name\n")
10178{
10179 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
10180 return CMD_SUCCESS;
10181}
10182
10183DEFUN (no_bgp_distance_source_access_list,
10184 no_bgp_distance_source_access_list_cmd,
10185 "no distance <1-255> A.B.C.D/M WORD",
10186 NO_STR
10187 "Define an administrative distance\n"
10188 "Administrative distance\n"
10189 "IP source prefix\n"
10190 "Access list name\n")
10191{
10192 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
10193 return CMD_SUCCESS;
10194}
10195
10196DEFUN (bgp_damp_set,
10197 bgp_damp_set_cmd,
10198 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10199 "BGP Specific commands\n"
10200 "Enable route-flap dampening\n"
10201 "Half-life time for the penalty\n"
10202 "Value to start reusing a route\n"
10203 "Value to start suppressing a route\n"
10204 "Maximum duration to suppress a stable route\n")
10205{
10206 struct bgp *bgp;
10207 int half = DEFAULT_HALF_LIFE * 60;
10208 int reuse = DEFAULT_REUSE;
10209 int suppress = DEFAULT_SUPPRESS;
10210 int max = 4 * half;
10211
10212 if (argc == 4)
10213 {
10214 half = atoi (argv[0]) * 60;
10215 reuse = atoi (argv[1]);
10216 suppress = atoi (argv[2]);
10217 max = atoi (argv[3]) * 60;
10218 }
10219 else if (argc == 1)
10220 {
10221 half = atoi (argv[0]) * 60;
10222 max = 4 * half;
10223 }
10224
10225 bgp = vty->index;
10226 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
10227 half, reuse, suppress, max);
10228}
10229
10230ALIAS (bgp_damp_set,
10231 bgp_damp_set2_cmd,
10232 "bgp dampening <1-45>",
10233 "BGP Specific commands\n"
10234 "Enable route-flap dampening\n"
10235 "Half-life time for the penalty\n")
10236
10237ALIAS (bgp_damp_set,
10238 bgp_damp_set3_cmd,
10239 "bgp dampening",
10240 "BGP Specific commands\n"
10241 "Enable route-flap dampening\n")
10242
10243DEFUN (bgp_damp_unset,
10244 bgp_damp_unset_cmd,
10245 "no bgp dampening",
10246 NO_STR
10247 "BGP Specific commands\n"
10248 "Enable route-flap dampening\n")
10249{
10250 struct bgp *bgp;
10251
10252 bgp = vty->index;
10253 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
10254}
10255
10256ALIAS (bgp_damp_unset,
10257 bgp_damp_unset2_cmd,
10258 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10259 NO_STR
10260 "BGP Specific commands\n"
10261 "Enable route-flap dampening\n"
10262 "Half-life time for the penalty\n"
10263 "Value to start reusing a route\n"
10264 "Value to start suppressing a route\n"
10265 "Maximum duration to suppress a stable route\n")
10266
10267DEFUN (show_ip_bgp_dampened_paths,
10268 show_ip_bgp_dampened_paths_cmd,
10269 "show ip bgp dampened-paths",
10270 SHOW_STR
10271 IP_STR
10272 BGP_STR
10273 "Display paths suppressed due to dampening\n")
10274{
ajs5a646652004-11-05 01:25:55 +000010275 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
10276 NULL);
paul718e3742002-12-13 20:15:29 +000010277}
10278
10279DEFUN (show_ip_bgp_flap_statistics,
10280 show_ip_bgp_flap_statistics_cmd,
10281 "show ip bgp flap-statistics",
10282 SHOW_STR
10283 IP_STR
10284 BGP_STR
10285 "Display flap statistics of routes\n")
10286{
ajs5a646652004-11-05 01:25:55 +000010287 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10288 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000010289}
10290
10291/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000010292static int
paulfd79ac92004-10-13 05:06:08 +000010293bgp_clear_damp_route (struct vty *vty, const char *view_name,
10294 const char *ip_str, afi_t afi, safi_t safi,
10295 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000010296{
10297 int ret;
10298 struct prefix match;
10299 struct bgp_node *rn;
10300 struct bgp_node *rm;
10301 struct bgp_info *ri;
10302 struct bgp_info *ri_temp;
10303 struct bgp *bgp;
10304 struct bgp_table *table;
10305
10306 /* BGP structure lookup. */
10307 if (view_name)
10308 {
10309 bgp = bgp_lookup_by_name (view_name);
10310 if (bgp == NULL)
10311 {
10312 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10313 return CMD_WARNING;
10314 }
10315 }
10316 else
10317 {
10318 bgp = bgp_get_default ();
10319 if (bgp == NULL)
10320 {
10321 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
10322 return CMD_WARNING;
10323 }
10324 }
10325
10326 /* Check IP address argument. */
10327 ret = str2prefix (ip_str, &match);
10328 if (! ret)
10329 {
10330 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
10331 return CMD_WARNING;
10332 }
10333
10334 match.family = afi2family (afi);
10335
10336 if (safi == SAFI_MPLS_VPN)
10337 {
10338 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
10339 {
10340 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
10341 continue;
10342
10343 if ((table = rn->info) != NULL)
10344 if ((rm = bgp_node_match (table, &match)) != NULL)
10345 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
10346 {
10347 ri = rm->info;
10348 while (ri)
10349 {
10350 if (ri->damp_info)
10351 {
10352 ri_temp = ri->next;
10353 bgp_damp_info_free (ri->damp_info, 1);
10354 ri = ri_temp;
10355 }
10356 else
10357 ri = ri->next;
10358 }
10359 }
10360 }
10361 }
10362 else
10363 {
10364 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
10365 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
10366 {
10367 ri = rn->info;
10368 while (ri)
10369 {
10370 if (ri->damp_info)
10371 {
10372 ri_temp = ri->next;
10373 bgp_damp_info_free (ri->damp_info, 1);
10374 ri = ri_temp;
10375 }
10376 else
10377 ri = ri->next;
10378 }
10379 }
10380 }
10381
10382 return CMD_SUCCESS;
10383}
10384
10385DEFUN (clear_ip_bgp_dampening,
10386 clear_ip_bgp_dampening_cmd,
10387 "clear ip bgp dampening",
10388 CLEAR_STR
10389 IP_STR
10390 BGP_STR
10391 "Clear route flap dampening information\n")
10392{
10393 bgp_damp_info_clean ();
10394 return CMD_SUCCESS;
10395}
10396
10397DEFUN (clear_ip_bgp_dampening_prefix,
10398 clear_ip_bgp_dampening_prefix_cmd,
10399 "clear ip bgp dampening A.B.C.D/M",
10400 CLEAR_STR
10401 IP_STR
10402 BGP_STR
10403 "Clear route flap dampening information\n"
10404 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10405{
10406 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10407 SAFI_UNICAST, NULL, 1);
10408}
10409
10410DEFUN (clear_ip_bgp_dampening_address,
10411 clear_ip_bgp_dampening_address_cmd,
10412 "clear ip bgp dampening A.B.C.D",
10413 CLEAR_STR
10414 IP_STR
10415 BGP_STR
10416 "Clear route flap dampening information\n"
10417 "Network to clear damping information\n")
10418{
10419 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10420 SAFI_UNICAST, NULL, 0);
10421}
10422
10423DEFUN (clear_ip_bgp_dampening_address_mask,
10424 clear_ip_bgp_dampening_address_mask_cmd,
10425 "clear ip bgp dampening A.B.C.D A.B.C.D",
10426 CLEAR_STR
10427 IP_STR
10428 BGP_STR
10429 "Clear route flap dampening information\n"
10430 "Network to clear damping information\n"
10431 "Network mask\n")
10432{
10433 int ret;
10434 char prefix_str[BUFSIZ];
10435
10436 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
10437 if (! ret)
10438 {
10439 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
10440 return CMD_WARNING;
10441 }
10442
10443 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
10444 SAFI_UNICAST, NULL, 0);
10445}
10446
paul94f2b392005-06-28 12:44:16 +000010447static int
paul718e3742002-12-13 20:15:29 +000010448bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
10449 afi_t afi, safi_t safi, int *write)
10450{
10451 struct bgp_node *prn;
10452 struct bgp_node *rn;
10453 struct bgp_table *table;
10454 struct prefix *p;
10455 struct prefix_rd *prd;
10456 struct bgp_static *bgp_static;
10457 u_int32_t label;
10458 char buf[SU_ADDRSTRLEN];
10459 char rdbuf[RD_ADDRSTRLEN];
10460
10461 /* Network configuration. */
10462 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
10463 if ((table = prn->info) != NULL)
10464 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10465 if ((bgp_static = rn->info) != NULL)
10466 {
10467 p = &rn->p;
10468 prd = (struct prefix_rd *) &prn->p;
10469
10470 /* "address-family" display. */
10471 bgp_config_write_family_header (vty, afi, safi, write);
10472
10473 /* "network" configuration display. */
10474 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
10475 label = decode_label (bgp_static->tag);
10476
10477 vty_out (vty, " network %s/%d rd %s tag %d",
10478 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10479 p->prefixlen,
10480 rdbuf, label);
10481 vty_out (vty, "%s", VTY_NEWLINE);
10482 }
10483 return 0;
10484}
10485
10486/* Configuration of static route announcement and aggregate
10487 information. */
10488int
10489bgp_config_write_network (struct vty *vty, struct bgp *bgp,
10490 afi_t afi, safi_t safi, int *write)
10491{
10492 struct bgp_node *rn;
10493 struct prefix *p;
10494 struct bgp_static *bgp_static;
10495 struct bgp_aggregate *bgp_aggregate;
10496 char buf[SU_ADDRSTRLEN];
10497
10498 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
10499 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
10500
10501 /* Network configuration. */
10502 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
10503 if ((bgp_static = rn->info) != NULL)
10504 {
10505 p = &rn->p;
10506
10507 /* "address-family" display. */
10508 bgp_config_write_family_header (vty, afi, safi, write);
10509
10510 /* "network" configuration display. */
10511 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10512 {
10513 u_int32_t destination;
10514 struct in_addr netmask;
10515
10516 destination = ntohl (p->u.prefix4.s_addr);
10517 masklen2ip (p->prefixlen, &netmask);
10518 vty_out (vty, " network %s",
10519 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
10520
10521 if ((IN_CLASSC (destination) && p->prefixlen == 24)
10522 || (IN_CLASSB (destination) && p->prefixlen == 16)
10523 || (IN_CLASSA (destination) && p->prefixlen == 8)
10524 || p->u.prefix4.s_addr == 0)
10525 {
10526 /* Natural mask is not display. */
10527 }
10528 else
10529 vty_out (vty, " mask %s", inet_ntoa (netmask));
10530 }
10531 else
10532 {
10533 vty_out (vty, " network %s/%d",
10534 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10535 p->prefixlen);
10536 }
10537
10538 if (bgp_static->rmap.name)
10539 vty_out (vty, " route-map %s", bgp_static->rmap.name);
10540 else if (bgp_static->backdoor)
10541 vty_out (vty, " backdoor");
10542
10543 vty_out (vty, "%s", VTY_NEWLINE);
10544 }
10545
10546 /* Aggregate-address configuration. */
10547 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
10548 if ((bgp_aggregate = rn->info) != NULL)
10549 {
10550 p = &rn->p;
10551
10552 /* "address-family" display. */
10553 bgp_config_write_family_header (vty, afi, safi, write);
10554
10555 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10556 {
10557 struct in_addr netmask;
10558
10559 masklen2ip (p->prefixlen, &netmask);
10560 vty_out (vty, " aggregate-address %s %s",
10561 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10562 inet_ntoa (netmask));
10563 }
10564 else
10565 {
10566 vty_out (vty, " aggregate-address %s/%d",
10567 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10568 p->prefixlen);
10569 }
10570
10571 if (bgp_aggregate->as_set)
10572 vty_out (vty, " as-set");
10573
10574 if (bgp_aggregate->summary_only)
10575 vty_out (vty, " summary-only");
10576
10577 vty_out (vty, "%s", VTY_NEWLINE);
10578 }
10579
10580 return 0;
10581}
10582
10583int
10584bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
10585{
10586 struct bgp_node *rn;
10587 struct bgp_distance *bdistance;
10588
10589 /* Distance configuration. */
10590 if (bgp->distance_ebgp
10591 && bgp->distance_ibgp
10592 && bgp->distance_local
10593 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
10594 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
10595 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
10596 vty_out (vty, " distance bgp %d %d %d%s",
10597 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
10598 VTY_NEWLINE);
10599
10600 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10601 if ((bdistance = rn->info) != NULL)
10602 {
10603 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
10604 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
10605 bdistance->access_list ? bdistance->access_list : "",
10606 VTY_NEWLINE);
10607 }
10608
10609 return 0;
10610}
10611
10612/* Allocate routing table structure and install commands. */
10613void
10614bgp_route_init ()
10615{
10616 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000010617 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010618
10619 /* IPv4 BGP commands. */
10620 install_element (BGP_NODE, &bgp_network_cmd);
10621 install_element (BGP_NODE, &bgp_network_mask_cmd);
10622 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
10623 install_element (BGP_NODE, &bgp_network_route_map_cmd);
10624 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
10625 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
10626 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
10627 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
10628 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
10629 install_element (BGP_NODE, &no_bgp_network_cmd);
10630 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
10631 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
10632 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
10633 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
10634 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10635 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
10636 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
10637 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
10638
10639 install_element (BGP_NODE, &aggregate_address_cmd);
10640 install_element (BGP_NODE, &aggregate_address_mask_cmd);
10641 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
10642 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
10643 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
10644 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
10645 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
10646 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
10647 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
10648 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
10649 install_element (BGP_NODE, &no_aggregate_address_cmd);
10650 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
10651 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
10652 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
10653 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
10654 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
10655 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
10656 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
10657 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10658 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10659
10660 /* IPv4 unicast configuration. */
10661 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
10662 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
10663 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
10664 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
10665 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
10666 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
10667 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
10668 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
10669 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
10670 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
10671 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
10672 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10673 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
10674 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
10675 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
10676 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
10677 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
10678 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
10679 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
10680 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
10681 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
10682 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
10683 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
10684 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
10685 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
10686 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
10687 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
10688 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
10689 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
10690 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
10691 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10692 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10693
10694 /* IPv4 multicast configuration. */
10695 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
10696 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
10697 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
10698 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
10699 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
10700 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
10701 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
10702 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
10703 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
10704 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
10705 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
10706 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10707 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
10708 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
10709 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
10710 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
10711 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
10712 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
10713 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
10714 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
10715 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
10716 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
10717 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
10718 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
10719 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
10720 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
10721 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
10722 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
10723 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
10724 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
10725 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10726 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10727
10728 install_element (VIEW_NODE, &show_ip_bgp_cmd);
10729 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
10730 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
10731 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
10732 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10733 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10734 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
10735 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10736 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10737 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10738 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
10739 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
10740 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
10741 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
10742 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10743 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
10744 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10745 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
10746 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10747 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
10748 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10749 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
10750 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10751 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
10752 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10753 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
10754 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
10755 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
10756 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
10757 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
10758 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
10759 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
10760 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
10761 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
10762 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
10763 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
10764 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
10765 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10766 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10767 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10768 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10769 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
10770 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10771 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
10772 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10773 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
10774 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10775 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10776 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10777 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10778 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10779 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
10780 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10781 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10782 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10783 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
10784 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
10785 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
10786 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
10787 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10788 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
10789 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
10790 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10791 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10792 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
10793 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
10794 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010795 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
10796 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
10797 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10798 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
10799 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10800 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010801
10802 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
10803 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
10804 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
10805 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
10806 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10807 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10808 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
10809 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10810 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10811 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10812 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
10813 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
10814 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
10815 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
10816 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10817 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
10818 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10819 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
10820 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10821 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
10822 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10823 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
10824 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10825 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
10826 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10827 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
10828 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
10829 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
10830 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
10831 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
10832 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
10833 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
10834 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
10835 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
10836 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
10837 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
10838 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
10839 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10840 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10841 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10842 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10843 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
10844 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10845 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
10846 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10847 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
10848 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10849 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10850 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10851 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10852 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10853 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
10854 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10855 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10856 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10857 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
10858 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
10859 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
10860 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
10861 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10862 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
10863 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
10864 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10865 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10866 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
10867 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
10868 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010869 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
10870 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
10871 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10872 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
10873 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10874 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010875
10876 /* BGP dampening clear commands */
10877 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
10878 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
10879 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
10880 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
10881
Paul Jakmaff7924f2006-09-04 01:10:36 +000010882 /* prefix count */
10883 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
10884 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
10885 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000010886#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000010887 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
10888
paul718e3742002-12-13 20:15:29 +000010889 /* New config IPv6 BGP commands. */
10890 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
10891 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
10892 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
10893 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
10894
10895 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
10896 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
10897 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
10898 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
10899
10900 /* Old config IPv6 BGP commands. */
10901 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
10902 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
10903
10904 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
10905 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
10906 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
10907 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
10908
10909 install_element (VIEW_NODE, &show_bgp_cmd);
10910 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
10911 install_element (VIEW_NODE, &show_bgp_route_cmd);
10912 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
10913 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
10914 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
10915 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
10916 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
10917 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
10918 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
10919 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
10920 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
10921 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
10922 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
10923 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
10924 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
10925 install_element (VIEW_NODE, &show_bgp_community_cmd);
10926 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
10927 install_element (VIEW_NODE, &show_bgp_community2_cmd);
10928 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
10929 install_element (VIEW_NODE, &show_bgp_community3_cmd);
10930 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
10931 install_element (VIEW_NODE, &show_bgp_community4_cmd);
10932 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
10933 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
10934 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
10935 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
10936 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
10937 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
10938 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
10939 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
10940 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
10941 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
10942 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
10943 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
10944 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10945 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
10946 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10947 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
10948 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10949 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
10950 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10951 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
10952 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10953 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10954 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010955 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
10956 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10957 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
10958 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010959 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
10960 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
10961 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010962 install_element (VIEW_NODE, &show_bgp_view_cmd);
10963 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
10964 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
10965 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
10966 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
10967 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
10968 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10969 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10970 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10971 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10972 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
10973 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10974 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10975 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10976 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
10977 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10978 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
10979 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010980 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
10981 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
10982 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010983
10984 install_element (ENABLE_NODE, &show_bgp_cmd);
10985 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
10986 install_element (ENABLE_NODE, &show_bgp_route_cmd);
10987 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
10988 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
10989 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
10990 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
10991 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
10992 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
10993 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
10994 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
10995 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
10996 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
10997 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
10998 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
10999 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
11000 install_element (ENABLE_NODE, &show_bgp_community_cmd);
11001 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
11002 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
11003 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
11004 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
11005 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
11006 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
11007 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
11008 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
11009 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
11010 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
11011 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
11012 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
11013 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
11014 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
11015 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
11016 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
11017 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
11018 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
11019 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11020 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
11021 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11022 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
11023 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11024 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
11025 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11026 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
11027 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11028 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11029 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011030 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
11031 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11032 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
11033 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011034 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
11035 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
11036 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011037 install_element (ENABLE_NODE, &show_bgp_view_cmd);
11038 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
11039 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
11040 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
11041 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
11042 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
11043 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11044 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11045 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11046 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11047 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
11048 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11049 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11050 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11051 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
11052 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11053 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
11054 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011055 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
11056 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
11057 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011058
11059 /* old command */
11060 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
11061 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
11062 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
11063 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
11064 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
11065 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
11066 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
11067 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
11068 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
11069 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
11070 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
11071 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
11072 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
11073 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
11074 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
11075 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
11076 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
11077 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
11078 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
11079 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
11080 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
11081 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
11082 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
11083 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
11084 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
11085 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
11086 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
11087 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
11088 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
11089 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
11090 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
11091 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
11092 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
11093 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
11094 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
11095 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000011096
paul718e3742002-12-13 20:15:29 +000011097 /* old command */
11098 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
11099 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
11100 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
11101 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
11102 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
11103 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
11104 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
11105 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
11106 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
11107 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
11108 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
11109 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
11110 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
11111 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
11112 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
11113 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
11114 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
11115 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
11116 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
11117 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
11118 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
11119 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
11120 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
11121 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
11122 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
11123 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
11124 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
11125 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
11126 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
11127 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
11128 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
11129 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
11130 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
11131 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
11132 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
11133 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
11134
11135 /* old command */
11136 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
11137 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
11138 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
11139 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
11140
11141 /* old command */
11142 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
11143 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
11144 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
11145 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
11146
11147 /* old command */
11148 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
11149 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
11150 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
11151 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
11152#endif /* HAVE_IPV6 */
11153
11154 install_element (BGP_NODE, &bgp_distance_cmd);
11155 install_element (BGP_NODE, &no_bgp_distance_cmd);
11156 install_element (BGP_NODE, &no_bgp_distance2_cmd);
11157 install_element (BGP_NODE, &bgp_distance_source_cmd);
11158 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
11159 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
11160 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
11161
11162 install_element (BGP_NODE, &bgp_damp_set_cmd);
11163 install_element (BGP_NODE, &bgp_damp_set2_cmd);
11164 install_element (BGP_NODE, &bgp_damp_set3_cmd);
11165 install_element (BGP_NODE, &bgp_damp_unset_cmd);
11166 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
11167 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
11168 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
11169 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
11170 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
11171 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
11172}