blob: f5d69e887a60a86ca5a5153edd75253720c3fbfb [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
2940 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2941
2942 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2943 if (bgp_static)
2944 {
2945 attr.nexthop = bgp_static->igpnexthop;
2946 attr.med = bgp_static->igpmetric;
2947 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
2948 }
2949
2950 new_attr = attr;
2951
2952 /* Apply network route-map for export to this rsclient. */
2953 if (bgp_static->rmap.name)
2954 {
2955 info.peer = rsclient;
2956 info.attr = &new_attr;
2957
2958 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
2959 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
2960
2961 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
2962
2963 rsclient->rmap_type = 0;
2964
2965 if (ret == RMAP_DENYMATCH)
2966 {
2967 /* Free uninterned attribute. */
2968 bgp_attr_flush (&new_attr);
2969
2970 /* Unintern original. */
2971 aspath_unintern (attr.aspath);
2972 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2973
2974 return;
2975 }
2976 attr_new = bgp_attr_intern (&new_attr);
2977 }
2978 else
2979 attr_new = bgp_attr_intern (&attr);
2980
2981 new_attr = *attr_new;
2982
2983 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
2984
2985 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) == RMAP_DENY)
2986{
2987 /* This BGP update is filtered. Log the reason then update BGP entry. */
2988 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002989 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002990 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
2991 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2992 p->prefixlen, rsclient->host);
2993
2994 bgp->peer_self->rmap_type = 0;
2995
2996 bgp_attr_unintern (attr_new);
2997 aspath_unintern (attr.aspath);
2998
2999 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3000
3001 return;
3002 }
3003
3004 bgp->peer_self->rmap_type = 0;
3005
3006 bgp_attr_unintern (attr_new);
3007 attr_new = bgp_attr_intern (&new_attr);
3008
3009 for (ri = rn->info; ri; ri = ri->next)
3010 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3011 && ri->sub_type == BGP_ROUTE_STATIC)
3012 break;
3013
3014 if (ri)
3015 {
3016 if (attrhash_cmp (ri->attr, attr_new))
3017 {
3018 bgp_unlock_node (rn);
3019 bgp_attr_unintern (attr_new);
3020 aspath_unintern (attr.aspath);
3021 return;
3022 }
3023 else
3024 {
3025 /* The attribute is changed. */
3026 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3027
3028 /* Rewrite BGP route information. */
3029 bgp_attr_unintern (ri->attr);
3030 ri->attr = attr_new;
3031 ri->uptime = time (NULL);
3032
3033 /* Process change. */
3034 bgp_process (bgp, rn, afi, safi);
3035 bgp_unlock_node (rn);
3036 aspath_unintern (attr.aspath);
3037 return;
3038 }
3039}
3040
3041 /* Make new BGP info. */
3042 new = bgp_info_new ();
3043 new->type = ZEBRA_ROUTE_BGP;
3044 new->sub_type = BGP_ROUTE_STATIC;
3045 new->peer = bgp->peer_self;
3046 SET_FLAG (new->flags, BGP_INFO_VALID);
3047 new->attr = attr_new;
3048 new->uptime = time (NULL);
3049
3050 /* Register new BGP information. */
3051 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003052
3053 /* route_node_get lock */
3054 bgp_unlock_node (rn);
3055
paulfee0f4c2004-09-13 05:12:46 +00003056 /* Process change. */
3057 bgp_process (bgp, rn, afi, safi);
3058
3059 /* Unintern original. */
3060 aspath_unintern (attr.aspath);
3061}
3062
paul94f2b392005-06-28 12:44:16 +00003063static void
paulfee0f4c2004-09-13 05:12:46 +00003064bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003065 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3066{
3067 struct bgp_node *rn;
3068 struct bgp_info *ri;
3069 struct bgp_info *new;
3070 struct bgp_info info;
3071 struct attr attr;
paul286e1e72003-08-08 00:24:31 +00003072 struct attr attr_tmp;
paul718e3742002-12-13 20:15:29 +00003073 struct attr *attr_new;
3074 int ret;
3075
paulfee0f4c2004-09-13 05:12:46 +00003076 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003077
3078 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3079 if (bgp_static)
3080 {
3081 attr.nexthop = bgp_static->igpnexthop;
3082 attr.med = bgp_static->igpmetric;
3083 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3084 }
3085
3086 /* Apply route-map. */
3087 if (bgp_static->rmap.name)
3088 {
paul286e1e72003-08-08 00:24:31 +00003089 attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003090 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003091 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003092
paulfee0f4c2004-09-13 05:12:46 +00003093 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3094
paul718e3742002-12-13 20:15:29 +00003095 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003096
paulfee0f4c2004-09-13 05:12:46 +00003097 bgp->peer_self->rmap_type = 0;
3098
paul718e3742002-12-13 20:15:29 +00003099 if (ret == RMAP_DENYMATCH)
3100 {
3101 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003102 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003103
3104 /* Unintern original. */
3105 aspath_unintern (attr.aspath);
3106 bgp_static_withdraw (bgp, p, afi, safi);
3107 return;
3108 }
paul286e1e72003-08-08 00:24:31 +00003109 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003110 }
paul286e1e72003-08-08 00:24:31 +00003111 else
3112 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003113
3114 for (ri = rn->info; ri; ri = ri->next)
3115 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3116 && ri->sub_type == BGP_ROUTE_STATIC)
3117 break;
3118
3119 if (ri)
3120 {
3121 if (attrhash_cmp (ri->attr, attr_new))
3122 {
3123 bgp_unlock_node (rn);
3124 bgp_attr_unintern (attr_new);
3125 aspath_unintern (attr.aspath);
3126 return;
3127 }
3128 else
3129 {
3130 /* The attribute is changed. */
3131 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3132
3133 /* Rewrite BGP route information. */
3134 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3135 bgp_attr_unintern (ri->attr);
3136 ri->attr = attr_new;
3137 ri->uptime = time (NULL);
3138
3139 /* Process change. */
3140 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3141 bgp_process (bgp, rn, afi, safi);
3142 bgp_unlock_node (rn);
3143 aspath_unintern (attr.aspath);
3144 return;
3145 }
3146 }
3147
3148 /* Make new BGP info. */
3149 new = bgp_info_new ();
3150 new->type = ZEBRA_ROUTE_BGP;
3151 new->sub_type = BGP_ROUTE_STATIC;
3152 new->peer = bgp->peer_self;
3153 SET_FLAG (new->flags, BGP_INFO_VALID);
3154 new->attr = attr_new;
3155 new->uptime = time (NULL);
3156
3157 /* Aggregate address increment. */
3158 bgp_aggregate_increment (bgp, p, new, afi, safi);
3159
3160 /* Register new BGP information. */
3161 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003162
3163 /* route_node_get lock */
3164 bgp_unlock_node (rn);
3165
paul718e3742002-12-13 20:15:29 +00003166 /* Process change. */
3167 bgp_process (bgp, rn, afi, safi);
3168
3169 /* Unintern original. */
3170 aspath_unintern (attr.aspath);
3171}
3172
3173void
paulfee0f4c2004-09-13 05:12:46 +00003174bgp_static_update (struct bgp *bgp, struct prefix *p,
3175 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3176{
3177 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003178 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003179
3180 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3181
paul1eb8ef22005-04-07 07:30:20 +00003182 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003183 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003184 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3185 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003186 }
3187}
3188
paul94f2b392005-06-28 12:44:16 +00003189static void
paul718e3742002-12-13 20:15:29 +00003190bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3191 u_char safi, struct prefix_rd *prd, u_char *tag)
3192{
3193 struct bgp_node *rn;
3194 struct bgp_info *new;
3195
paulfee0f4c2004-09-13 05:12:46 +00003196 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003197
3198 /* Make new BGP info. */
3199 new = bgp_info_new ();
3200 new->type = ZEBRA_ROUTE_BGP;
3201 new->sub_type = BGP_ROUTE_STATIC;
3202 new->peer = bgp->peer_self;
3203 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3204 SET_FLAG (new->flags, BGP_INFO_VALID);
3205 new->uptime = time (NULL);
3206 memcpy (new->tag, tag, 3);
3207
3208 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003209 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003210
3211 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003212 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003213
paul200df112005-06-01 11:17:05 +00003214 /* route_node_get lock */
3215 bgp_unlock_node (rn);
3216
paul718e3742002-12-13 20:15:29 +00003217 /* Process change. */
3218 bgp_process (bgp, rn, afi, safi);
3219}
3220
3221void
3222bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3223 safi_t safi)
3224{
3225 struct bgp_node *rn;
3226 struct bgp_info *ri;
3227
paulfee0f4c2004-09-13 05:12:46 +00003228 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003229
3230 /* Check selected route and self inserted route. */
3231 for (ri = rn->info; ri; ri = ri->next)
3232 if (ri->peer == bgp->peer_self
3233 && ri->type == ZEBRA_ROUTE_BGP
3234 && ri->sub_type == BGP_ROUTE_STATIC)
3235 break;
3236
3237 /* Withdraw static BGP route from routing table. */
3238 if (ri)
3239 {
3240 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3241 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3242 bgp_process (bgp, rn, afi, safi);
3243 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003244 }
3245
3246 /* Unlock bgp_node_lookup. */
3247 bgp_unlock_node (rn);
3248}
3249
3250void
paulfee0f4c2004-09-13 05:12:46 +00003251bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3252{
3253 struct bgp_static *bgp_static;
3254 struct bgp *bgp;
3255 struct bgp_node *rn;
3256 struct prefix *p;
3257
3258 bgp = rsclient->bgp;
3259
3260 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3261 if ((bgp_static = rn->info) != NULL)
3262 {
3263 p = &rn->p;
3264
3265 bgp_static_update_rsclient (rsclient, p, bgp_static,
3266 afi, safi);
3267 }
3268}
3269
paul94f2b392005-06-28 12:44:16 +00003270static void
paul718e3742002-12-13 20:15:29 +00003271bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3272 u_char safi, struct prefix_rd *prd, u_char *tag)
3273{
3274 struct bgp_node *rn;
3275 struct bgp_info *ri;
3276
paulfee0f4c2004-09-13 05:12:46 +00003277 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003278
3279 /* Check selected route and self inserted route. */
3280 for (ri = rn->info; ri; ri = ri->next)
3281 if (ri->peer == bgp->peer_self
3282 && ri->type == ZEBRA_ROUTE_BGP
3283 && ri->sub_type == BGP_ROUTE_STATIC)
3284 break;
3285
3286 /* Withdraw static BGP route from routing table. */
3287 if (ri)
3288 {
3289 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3290 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3291 bgp_process (bgp, rn, afi, safi);
3292 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003293 }
3294
3295 /* Unlock bgp_node_lookup. */
3296 bgp_unlock_node (rn);
3297}
3298
3299/* Configure static BGP network. When user don't run zebra, static
3300 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003301static int
paulfd79ac92004-10-13 05:06:08 +00003302bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3303 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003304{
3305 int ret;
3306 struct prefix p;
3307 struct bgp_static *bgp_static;
3308 struct bgp_node *rn;
3309 int need_update = 0;
3310
3311 /* Convert IP prefix string to struct prefix. */
3312 ret = str2prefix (ip_str, &p);
3313 if (! ret)
3314 {
3315 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3316 return CMD_WARNING;
3317 }
3318#ifdef HAVE_IPV6
3319 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3320 {
3321 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3322 VTY_NEWLINE);
3323 return CMD_WARNING;
3324 }
3325#endif /* HAVE_IPV6 */
3326
3327 apply_mask (&p);
3328
3329 /* Set BGP static route configuration. */
3330 rn = bgp_node_get (bgp->route[afi][safi], &p);
3331
3332 if (rn->info)
3333 {
3334 /* Configuration change. */
3335 bgp_static = rn->info;
3336
3337 /* Check previous routes are installed into BGP. */
3338 if (! bgp_static->backdoor && bgp_static->valid)
3339 need_update = 1;
3340
3341 bgp_static->backdoor = backdoor;
3342 if (rmap)
3343 {
3344 if (bgp_static->rmap.name)
3345 free (bgp_static->rmap.name);
3346 bgp_static->rmap.name = strdup (rmap);
3347 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3348 }
3349 else
3350 {
3351 if (bgp_static->rmap.name)
3352 free (bgp_static->rmap.name);
3353 bgp_static->rmap.name = NULL;
3354 bgp_static->rmap.map = NULL;
3355 bgp_static->valid = 0;
3356 }
3357 bgp_unlock_node (rn);
3358 }
3359 else
3360 {
3361 /* New configuration. */
3362 bgp_static = bgp_static_new ();
3363 bgp_static->backdoor = backdoor;
3364 bgp_static->valid = 0;
3365 bgp_static->igpmetric = 0;
3366 bgp_static->igpnexthop.s_addr = 0;
3367 if (rmap)
3368 {
3369 if (bgp_static->rmap.name)
3370 free (bgp_static->rmap.name);
3371 bgp_static->rmap.name = strdup (rmap);
3372 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3373 }
3374 rn->info = bgp_static;
3375 }
3376
3377 /* If BGP scan is not enabled, we should install this route here. */
3378 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3379 {
3380 bgp_static->valid = 1;
3381
3382 if (need_update)
3383 bgp_static_withdraw (bgp, &p, afi, safi);
3384
3385 if (! bgp_static->backdoor)
3386 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3387 }
3388
3389 return CMD_SUCCESS;
3390}
3391
3392/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003393static int
paulfd79ac92004-10-13 05:06:08 +00003394bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003395 u_int16_t afi, u_char safi)
3396{
3397 int ret;
3398 struct prefix p;
3399 struct bgp_static *bgp_static;
3400 struct bgp_node *rn;
3401
3402 /* Convert IP prefix string to struct prefix. */
3403 ret = str2prefix (ip_str, &p);
3404 if (! ret)
3405 {
3406 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3407 return CMD_WARNING;
3408 }
3409#ifdef HAVE_IPV6
3410 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3411 {
3412 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3413 VTY_NEWLINE);
3414 return CMD_WARNING;
3415 }
3416#endif /* HAVE_IPV6 */
3417
3418 apply_mask (&p);
3419
3420 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3421 if (! rn)
3422 {
3423 vty_out (vty, "%% Can't find specified static route configuration.%s",
3424 VTY_NEWLINE);
3425 return CMD_WARNING;
3426 }
3427
3428 bgp_static = rn->info;
3429
3430 /* Update BGP RIB. */
3431 if (! bgp_static->backdoor)
3432 bgp_static_withdraw (bgp, &p, afi, safi);
3433
3434 /* Clear configuration. */
3435 bgp_static_free (bgp_static);
3436 rn->info = NULL;
3437 bgp_unlock_node (rn);
3438 bgp_unlock_node (rn);
3439
3440 return CMD_SUCCESS;
3441}
3442
3443/* Called from bgp_delete(). Delete all static routes from the BGP
3444 instance. */
3445void
3446bgp_static_delete (struct bgp *bgp)
3447{
3448 afi_t afi;
3449 safi_t safi;
3450 struct bgp_node *rn;
3451 struct bgp_node *rm;
3452 struct bgp_table *table;
3453 struct bgp_static *bgp_static;
3454
3455 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3456 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3457 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3458 if (rn->info != NULL)
3459 {
3460 if (safi == SAFI_MPLS_VPN)
3461 {
3462 table = rn->info;
3463
3464 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3465 {
3466 bgp_static = rn->info;
3467 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3468 AFI_IP, SAFI_MPLS_VPN,
3469 (struct prefix_rd *)&rn->p,
3470 bgp_static->tag);
3471 bgp_static_free (bgp_static);
3472 rn->info = NULL;
3473 bgp_unlock_node (rn);
3474 }
3475 }
3476 else
3477 {
3478 bgp_static = rn->info;
3479 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3480 bgp_static_free (bgp_static);
3481 rn->info = NULL;
3482 bgp_unlock_node (rn);
3483 }
3484 }
3485}
3486
3487int
paulfd79ac92004-10-13 05:06:08 +00003488bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3489 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003490{
3491 int ret;
3492 struct prefix p;
3493 struct prefix_rd prd;
3494 struct bgp *bgp;
3495 struct bgp_node *prn;
3496 struct bgp_node *rn;
3497 struct bgp_table *table;
3498 struct bgp_static *bgp_static;
3499 u_char tag[3];
3500
3501 bgp = vty->index;
3502
3503 ret = str2prefix (ip_str, &p);
3504 if (! ret)
3505 {
3506 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3507 return CMD_WARNING;
3508 }
3509 apply_mask (&p);
3510
3511 ret = str2prefix_rd (rd_str, &prd);
3512 if (! ret)
3513 {
3514 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3515 return CMD_WARNING;
3516 }
3517
3518 ret = str2tag (tag_str, tag);
3519 if (! ret)
3520 {
3521 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3522 return CMD_WARNING;
3523 }
3524
3525 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3526 (struct prefix *)&prd);
3527 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003528 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003529 else
3530 bgp_unlock_node (prn);
3531 table = prn->info;
3532
3533 rn = bgp_node_get (table, &p);
3534
3535 if (rn->info)
3536 {
3537 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3538 bgp_unlock_node (rn);
3539 }
3540 else
3541 {
3542 /* New configuration. */
3543 bgp_static = bgp_static_new ();
3544 bgp_static->valid = 1;
3545 memcpy (bgp_static->tag, tag, 3);
3546 rn->info = bgp_static;
3547
3548 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3549 }
3550
3551 return CMD_SUCCESS;
3552}
3553
3554/* Configure static BGP network. */
3555int
paulfd79ac92004-10-13 05:06:08 +00003556bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3557 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003558{
3559 int ret;
3560 struct bgp *bgp;
3561 struct prefix p;
3562 struct prefix_rd prd;
3563 struct bgp_node *prn;
3564 struct bgp_node *rn;
3565 struct bgp_table *table;
3566 struct bgp_static *bgp_static;
3567 u_char tag[3];
3568
3569 bgp = vty->index;
3570
3571 /* Convert IP prefix string to struct prefix. */
3572 ret = str2prefix (ip_str, &p);
3573 if (! ret)
3574 {
3575 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3576 return CMD_WARNING;
3577 }
3578 apply_mask (&p);
3579
3580 ret = str2prefix_rd (rd_str, &prd);
3581 if (! ret)
3582 {
3583 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3584 return CMD_WARNING;
3585 }
3586
3587 ret = str2tag (tag_str, tag);
3588 if (! ret)
3589 {
3590 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3591 return CMD_WARNING;
3592 }
3593
3594 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3595 (struct prefix *)&prd);
3596 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003597 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003598 else
3599 bgp_unlock_node (prn);
3600 table = prn->info;
3601
3602 rn = bgp_node_lookup (table, &p);
3603
3604 if (rn)
3605 {
3606 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3607
3608 bgp_static = rn->info;
3609 bgp_static_free (bgp_static);
3610 rn->info = NULL;
3611 bgp_unlock_node (rn);
3612 bgp_unlock_node (rn);
3613 }
3614 else
3615 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3616
3617 return CMD_SUCCESS;
3618}
3619
3620DEFUN (bgp_network,
3621 bgp_network_cmd,
3622 "network A.B.C.D/M",
3623 "Specify a network to announce via BGP\n"
3624 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3625{
3626 return bgp_static_set (vty, vty->index, argv[0],
3627 AFI_IP, bgp_node_safi (vty), NULL, 0);
3628}
3629
3630DEFUN (bgp_network_route_map,
3631 bgp_network_route_map_cmd,
3632 "network A.B.C.D/M route-map WORD",
3633 "Specify a network to announce via BGP\n"
3634 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3635 "Route-map to modify the attributes\n"
3636 "Name of the route map\n")
3637{
3638 return bgp_static_set (vty, vty->index, argv[0],
3639 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3640}
3641
3642DEFUN (bgp_network_backdoor,
3643 bgp_network_backdoor_cmd,
3644 "network A.B.C.D/M backdoor",
3645 "Specify a network to announce via BGP\n"
3646 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3647 "Specify a BGP backdoor route\n")
3648{
3649 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
3650}
3651
3652DEFUN (bgp_network_mask,
3653 bgp_network_mask_cmd,
3654 "network A.B.C.D mask A.B.C.D",
3655 "Specify a network to announce via BGP\n"
3656 "Network number\n"
3657 "Network mask\n"
3658 "Network mask\n")
3659{
3660 int ret;
3661 char prefix_str[BUFSIZ];
3662
3663 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3664 if (! ret)
3665 {
3666 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3667 return CMD_WARNING;
3668 }
3669
3670 return bgp_static_set (vty, vty->index, prefix_str,
3671 AFI_IP, bgp_node_safi (vty), NULL, 0);
3672}
3673
3674DEFUN (bgp_network_mask_route_map,
3675 bgp_network_mask_route_map_cmd,
3676 "network A.B.C.D mask A.B.C.D route-map WORD",
3677 "Specify a network to announce via BGP\n"
3678 "Network number\n"
3679 "Network mask\n"
3680 "Network mask\n"
3681 "Route-map to modify the attributes\n"
3682 "Name of the route map\n")
3683{
3684 int ret;
3685 char prefix_str[BUFSIZ];
3686
3687 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3688 if (! ret)
3689 {
3690 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3691 return CMD_WARNING;
3692 }
3693
3694 return bgp_static_set (vty, vty->index, prefix_str,
3695 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3696}
3697
3698DEFUN (bgp_network_mask_backdoor,
3699 bgp_network_mask_backdoor_cmd,
3700 "network A.B.C.D mask A.B.C.D backdoor",
3701 "Specify a network to announce via BGP\n"
3702 "Network number\n"
3703 "Network mask\n"
3704 "Network mask\n"
3705 "Specify a BGP backdoor route\n")
3706{
3707 int ret;
3708 char prefix_str[BUFSIZ];
3709
3710 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3711 if (! ret)
3712 {
3713 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3714 return CMD_WARNING;
3715 }
3716
3717 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3718}
3719
3720DEFUN (bgp_network_mask_natural,
3721 bgp_network_mask_natural_cmd,
3722 "network A.B.C.D",
3723 "Specify a network to announce via BGP\n"
3724 "Network number\n")
3725{
3726 int ret;
3727 char prefix_str[BUFSIZ];
3728
3729 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3730 if (! ret)
3731 {
3732 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3733 return CMD_WARNING;
3734 }
3735
3736 return bgp_static_set (vty, vty->index, prefix_str,
3737 AFI_IP, bgp_node_safi (vty), NULL, 0);
3738}
3739
3740DEFUN (bgp_network_mask_natural_route_map,
3741 bgp_network_mask_natural_route_map_cmd,
3742 "network A.B.C.D route-map WORD",
3743 "Specify a network to announce via BGP\n"
3744 "Network number\n"
3745 "Route-map to modify the attributes\n"
3746 "Name of the route map\n")
3747{
3748 int ret;
3749 char prefix_str[BUFSIZ];
3750
3751 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3752 if (! ret)
3753 {
3754 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3755 return CMD_WARNING;
3756 }
3757
3758 return bgp_static_set (vty, vty->index, prefix_str,
3759 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3760}
3761
3762DEFUN (bgp_network_mask_natural_backdoor,
3763 bgp_network_mask_natural_backdoor_cmd,
3764 "network A.B.C.D backdoor",
3765 "Specify a network to announce via BGP\n"
3766 "Network number\n"
3767 "Specify a BGP backdoor route\n")
3768{
3769 int ret;
3770 char prefix_str[BUFSIZ];
3771
3772 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3773 if (! ret)
3774 {
3775 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3776 return CMD_WARNING;
3777 }
3778
3779 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3780}
3781
3782DEFUN (no_bgp_network,
3783 no_bgp_network_cmd,
3784 "no network A.B.C.D/M",
3785 NO_STR
3786 "Specify a network to announce via BGP\n"
3787 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3788{
3789 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
3790 bgp_node_safi (vty));
3791}
3792
3793ALIAS (no_bgp_network,
3794 no_bgp_network_route_map_cmd,
3795 "no network A.B.C.D/M route-map WORD",
3796 NO_STR
3797 "Specify a network to announce via BGP\n"
3798 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3799 "Route-map to modify the attributes\n"
3800 "Name of the route map\n")
3801
3802ALIAS (no_bgp_network,
3803 no_bgp_network_backdoor_cmd,
3804 "no network A.B.C.D/M backdoor",
3805 NO_STR
3806 "Specify a network to announce via BGP\n"
3807 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3808 "Specify a BGP backdoor route\n")
3809
3810DEFUN (no_bgp_network_mask,
3811 no_bgp_network_mask_cmd,
3812 "no network A.B.C.D mask A.B.C.D",
3813 NO_STR
3814 "Specify a network to announce via BGP\n"
3815 "Network number\n"
3816 "Network mask\n"
3817 "Network mask\n")
3818{
3819 int ret;
3820 char prefix_str[BUFSIZ];
3821
3822 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3823 if (! ret)
3824 {
3825 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3826 return CMD_WARNING;
3827 }
3828
3829 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3830 bgp_node_safi (vty));
3831}
3832
3833ALIAS (no_bgp_network_mask,
3834 no_bgp_network_mask_route_map_cmd,
3835 "no network A.B.C.D mask A.B.C.D route-map WORD",
3836 NO_STR
3837 "Specify a network to announce via BGP\n"
3838 "Network number\n"
3839 "Network mask\n"
3840 "Network mask\n"
3841 "Route-map to modify the attributes\n"
3842 "Name of the route map\n")
3843
3844ALIAS (no_bgp_network_mask,
3845 no_bgp_network_mask_backdoor_cmd,
3846 "no network A.B.C.D mask A.B.C.D backdoor",
3847 NO_STR
3848 "Specify a network to announce via BGP\n"
3849 "Network number\n"
3850 "Network mask\n"
3851 "Network mask\n"
3852 "Specify a BGP backdoor route\n")
3853
3854DEFUN (no_bgp_network_mask_natural,
3855 no_bgp_network_mask_natural_cmd,
3856 "no network A.B.C.D",
3857 NO_STR
3858 "Specify a network to announce via BGP\n"
3859 "Network number\n")
3860{
3861 int ret;
3862 char prefix_str[BUFSIZ];
3863
3864 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3865 if (! ret)
3866 {
3867 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3868 return CMD_WARNING;
3869 }
3870
3871 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3872 bgp_node_safi (vty));
3873}
3874
3875ALIAS (no_bgp_network_mask_natural,
3876 no_bgp_network_mask_natural_route_map_cmd,
3877 "no network A.B.C.D route-map WORD",
3878 NO_STR
3879 "Specify a network to announce via BGP\n"
3880 "Network number\n"
3881 "Route-map to modify the attributes\n"
3882 "Name of the route map\n")
3883
3884ALIAS (no_bgp_network_mask_natural,
3885 no_bgp_network_mask_natural_backdoor_cmd,
3886 "no network A.B.C.D backdoor",
3887 NO_STR
3888 "Specify a network to announce via BGP\n"
3889 "Network number\n"
3890 "Specify a BGP backdoor route\n")
3891
3892#ifdef HAVE_IPV6
3893DEFUN (ipv6_bgp_network,
3894 ipv6_bgp_network_cmd,
3895 "network X:X::X:X/M",
3896 "Specify a network to announce via BGP\n"
3897 "IPv6 prefix <network>/<length>\n")
3898{
3899 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
3900}
3901
3902DEFUN (ipv6_bgp_network_route_map,
3903 ipv6_bgp_network_route_map_cmd,
3904 "network X:X::X:X/M route-map WORD",
3905 "Specify a network to announce via BGP\n"
3906 "IPv6 prefix <network>/<length>\n"
3907 "Route-map to modify the attributes\n"
3908 "Name of the route map\n")
3909{
3910 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
3911 bgp_node_safi (vty), argv[1], 0);
3912}
3913
3914DEFUN (no_ipv6_bgp_network,
3915 no_ipv6_bgp_network_cmd,
3916 "no network X:X::X:X/M",
3917 NO_STR
3918 "Specify a network to announce via BGP\n"
3919 "IPv6 prefix <network>/<length>\n")
3920{
3921 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
3922}
3923
3924ALIAS (no_ipv6_bgp_network,
3925 no_ipv6_bgp_network_route_map_cmd,
3926 "no network X:X::X:X/M route-map WORD",
3927 NO_STR
3928 "Specify a network to announce via BGP\n"
3929 "IPv6 prefix <network>/<length>\n"
3930 "Route-map to modify the attributes\n"
3931 "Name of the route map\n")
3932
3933ALIAS (ipv6_bgp_network,
3934 old_ipv6_bgp_network_cmd,
3935 "ipv6 bgp network X:X::X:X/M",
3936 IPV6_STR
3937 BGP_STR
3938 "Specify a network to announce via BGP\n"
3939 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3940
3941ALIAS (no_ipv6_bgp_network,
3942 old_no_ipv6_bgp_network_cmd,
3943 "no ipv6 bgp network X:X::X:X/M",
3944 NO_STR
3945 IPV6_STR
3946 BGP_STR
3947 "Specify a network to announce via BGP\n"
3948 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3949#endif /* HAVE_IPV6 */
3950
3951/* Aggreagete address:
3952
3953 advertise-map Set condition to advertise attribute
3954 as-set Generate AS set path information
3955 attribute-map Set attributes of aggregate
3956 route-map Set parameters of aggregate
3957 summary-only Filter more specific routes from updates
3958 suppress-map Conditionally filter more specific routes from updates
3959 <cr>
3960 */
3961struct bgp_aggregate
3962{
3963 /* Summary-only flag. */
3964 u_char summary_only;
3965
3966 /* AS set generation. */
3967 u_char as_set;
3968
3969 /* Route-map for aggregated route. */
3970 struct route_map *map;
3971
3972 /* Suppress-count. */
3973 unsigned long count;
3974
3975 /* SAFI configuration. */
3976 safi_t safi;
3977};
3978
paul94f2b392005-06-28 12:44:16 +00003979static struct bgp_aggregate *
paul718e3742002-12-13 20:15:29 +00003980bgp_aggregate_new ()
3981{
3982 struct bgp_aggregate *new;
3983 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
3984 memset (new, 0, sizeof (struct bgp_aggregate));
3985 return new;
3986}
3987
paul94f2b392005-06-28 12:44:16 +00003988static void
paul718e3742002-12-13 20:15:29 +00003989bgp_aggregate_free (struct bgp_aggregate *aggregate)
3990{
3991 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
3992}
3993
paul94f2b392005-06-28 12:44:16 +00003994static void
paul718e3742002-12-13 20:15:29 +00003995bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
3996 afi_t afi, safi_t safi, struct bgp_info *del,
3997 struct bgp_aggregate *aggregate)
3998{
3999 struct bgp_table *table;
4000 struct bgp_node *top;
4001 struct bgp_node *rn;
4002 u_char origin;
4003 struct aspath *aspath = NULL;
4004 struct aspath *asmerge = NULL;
4005 struct community *community = NULL;
4006 struct community *commerge = NULL;
4007 struct in_addr nexthop;
4008 u_int32_t med = 0;
4009 struct bgp_info *ri;
4010 struct bgp_info *new;
4011 int first = 1;
4012 unsigned long match = 0;
4013
4014 /* Record adding route's nexthop and med. */
4015 if (rinew)
4016 {
4017 nexthop = rinew->attr->nexthop;
4018 med = rinew->attr->med;
4019 }
4020
4021 /* ORIGIN attribute: If at least one route among routes that are
4022 aggregated has ORIGIN with the value INCOMPLETE, then the
4023 aggregated route must have the ORIGIN attribute with the value
4024 INCOMPLETE. Otherwise, if at least one route among routes that
4025 are aggregated has ORIGIN with the value EGP, then the aggregated
4026 route must have the origin attribute with the value EGP. In all
4027 other case the value of the ORIGIN attribute of the aggregated
4028 route is INTERNAL. */
4029 origin = BGP_ORIGIN_IGP;
4030
4031 table = bgp->rib[afi][safi];
4032
4033 top = bgp_node_get (table, p);
4034 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4035 if (rn->p.prefixlen > p->prefixlen)
4036 {
4037 match = 0;
4038
4039 for (ri = rn->info; ri; ri = ri->next)
4040 {
4041 if (BGP_INFO_HOLDDOWN (ri))
4042 continue;
4043
4044 if (del && ri == del)
4045 continue;
4046
4047 if (! rinew && first)
4048 {
4049 nexthop = ri->attr->nexthop;
4050 med = ri->attr->med;
4051 first = 0;
4052 }
4053
4054#ifdef AGGREGATE_NEXTHOP_CHECK
4055 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4056 || ri->attr->med != med)
4057 {
4058 if (aspath)
4059 aspath_free (aspath);
4060 if (community)
4061 community_free (community);
4062 bgp_unlock_node (rn);
4063 bgp_unlock_node (top);
4064 return;
4065 }
4066#endif /* AGGREGATE_NEXTHOP_CHECK */
4067
4068 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4069 {
4070 if (aggregate->summary_only)
4071 {
4072 ri->suppress++;
4073 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4074 match++;
4075 }
4076
4077 aggregate->count++;
4078
4079 if (aggregate->as_set)
4080 {
4081 if (origin < ri->attr->origin)
4082 origin = ri->attr->origin;
4083
4084 if (aspath)
4085 {
4086 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4087 aspath_free (aspath);
4088 aspath = asmerge;
4089 }
4090 else
4091 aspath = aspath_dup (ri->attr->aspath);
4092
4093 if (ri->attr->community)
4094 {
4095 if (community)
4096 {
4097 commerge = community_merge (community,
4098 ri->attr->community);
4099 community = community_uniq_sort (commerge);
4100 community_free (commerge);
4101 }
4102 else
4103 community = community_dup (ri->attr->community);
4104 }
4105 }
4106 }
4107 }
4108 if (match)
4109 bgp_process (bgp, rn, afi, safi);
4110 }
4111 bgp_unlock_node (top);
4112
4113 if (rinew)
4114 {
4115 aggregate->count++;
4116
4117 if (aggregate->summary_only)
4118 rinew->suppress++;
4119
4120 if (aggregate->as_set)
4121 {
4122 if (origin < rinew->attr->origin)
4123 origin = rinew->attr->origin;
4124
4125 if (aspath)
4126 {
4127 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4128 aspath_free (aspath);
4129 aspath = asmerge;
4130 }
4131 else
4132 aspath = aspath_dup (rinew->attr->aspath);
4133
4134 if (rinew->attr->community)
4135 {
4136 if (community)
4137 {
4138 commerge = community_merge (community,
4139 rinew->attr->community);
4140 community = community_uniq_sort (commerge);
4141 community_free (commerge);
4142 }
4143 else
4144 community = community_dup (rinew->attr->community);
4145 }
4146 }
4147 }
4148
4149 if (aggregate->count > 0)
4150 {
4151 rn = bgp_node_get (table, p);
4152 new = bgp_info_new ();
4153 new->type = ZEBRA_ROUTE_BGP;
4154 new->sub_type = BGP_ROUTE_AGGREGATE;
4155 new->peer = bgp->peer_self;
4156 SET_FLAG (new->flags, BGP_INFO_VALID);
4157 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4158 new->uptime = time (NULL);
4159
4160 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004161 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004162 bgp_process (bgp, rn, afi, safi);
4163 }
4164 else
4165 {
4166 if (aspath)
4167 aspath_free (aspath);
4168 if (community)
4169 community_free (community);
4170 }
4171}
4172
4173void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4174 struct bgp_aggregate *);
4175
4176void
4177bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4178 struct bgp_info *ri, afi_t afi, safi_t safi)
4179{
4180 struct bgp_node *child;
4181 struct bgp_node *rn;
4182 struct bgp_aggregate *aggregate;
4183
4184 /* MPLS-VPN aggregation is not yet supported. */
4185 if (safi == SAFI_MPLS_VPN)
4186 return;
4187
4188 if (p->prefixlen == 0)
4189 return;
4190
4191 if (BGP_INFO_HOLDDOWN (ri))
4192 return;
4193
4194 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4195
4196 /* Aggregate address configuration check. */
4197 for (rn = child; rn; rn = rn->parent)
4198 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4199 {
4200 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004201 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004202 }
4203 bgp_unlock_node (child);
4204}
4205
4206void
4207bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4208 struct bgp_info *del, afi_t afi, safi_t safi)
4209{
4210 struct bgp_node *child;
4211 struct bgp_node *rn;
4212 struct bgp_aggregate *aggregate;
4213
4214 /* MPLS-VPN aggregation is not yet supported. */
4215 if (safi == SAFI_MPLS_VPN)
4216 return;
4217
4218 if (p->prefixlen == 0)
4219 return;
4220
4221 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4222
4223 /* Aggregate address configuration check. */
4224 for (rn = child; rn; rn = rn->parent)
4225 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4226 {
4227 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004228 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004229 }
4230 bgp_unlock_node (child);
4231}
4232
paul94f2b392005-06-28 12:44:16 +00004233static void
paul718e3742002-12-13 20:15:29 +00004234bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4235 struct bgp_aggregate *aggregate)
4236{
4237 struct bgp_table *table;
4238 struct bgp_node *top;
4239 struct bgp_node *rn;
4240 struct bgp_info *new;
4241 struct bgp_info *ri;
4242 unsigned long match;
4243 u_char origin = BGP_ORIGIN_IGP;
4244 struct aspath *aspath = NULL;
4245 struct aspath *asmerge = NULL;
4246 struct community *community = NULL;
4247 struct community *commerge = NULL;
4248
4249 table = bgp->rib[afi][safi];
4250
4251 /* Sanity check. */
4252 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4253 return;
4254 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4255 return;
4256
4257 /* If routes exists below this node, generate aggregate routes. */
4258 top = bgp_node_get (table, p);
4259 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4260 if (rn->p.prefixlen > p->prefixlen)
4261 {
4262 match = 0;
4263
4264 for (ri = rn->info; ri; ri = ri->next)
4265 {
4266 if (BGP_INFO_HOLDDOWN (ri))
4267 continue;
4268
4269 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4270 {
4271 /* summary-only aggregate route suppress aggregated
4272 route announcement. */
4273 if (aggregate->summary_only)
4274 {
4275 ri->suppress++;
4276 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4277 match++;
4278 }
4279 /* as-set aggregate route generate origin, as path,
4280 community aggregation. */
4281 if (aggregate->as_set)
4282 {
4283 if (origin < ri->attr->origin)
4284 origin = ri->attr->origin;
4285
4286 if (aspath)
4287 {
4288 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4289 aspath_free (aspath);
4290 aspath = asmerge;
4291 }
4292 else
4293 aspath = aspath_dup (ri->attr->aspath);
4294
4295 if (ri->attr->community)
4296 {
4297 if (community)
4298 {
4299 commerge = community_merge (community,
4300 ri->attr->community);
4301 community = community_uniq_sort (commerge);
4302 community_free (commerge);
4303 }
4304 else
4305 community = community_dup (ri->attr->community);
4306 }
4307 }
4308 aggregate->count++;
4309 }
4310 }
4311
4312 /* If this node is suppressed, process the change. */
4313 if (match)
4314 bgp_process (bgp, rn, afi, safi);
4315 }
4316 bgp_unlock_node (top);
4317
4318 /* Add aggregate route to BGP table. */
4319 if (aggregate->count)
4320 {
4321 rn = bgp_node_get (table, p);
4322
4323 new = bgp_info_new ();
4324 new->type = ZEBRA_ROUTE_BGP;
4325 new->sub_type = BGP_ROUTE_AGGREGATE;
4326 new->peer = bgp->peer_self;
4327 SET_FLAG (new->flags, BGP_INFO_VALID);
4328 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4329 new->uptime = time (NULL);
4330
4331 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004332 bgp_unlock_node (rn);
4333
paul718e3742002-12-13 20:15:29 +00004334 /* Process change. */
4335 bgp_process (bgp, rn, afi, safi);
4336 }
4337}
4338
4339void
4340bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4341 safi_t safi, struct bgp_aggregate *aggregate)
4342{
4343 struct bgp_table *table;
4344 struct bgp_node *top;
4345 struct bgp_node *rn;
4346 struct bgp_info *ri;
4347 unsigned long match;
4348
4349 table = bgp->rib[afi][safi];
4350
4351 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4352 return;
4353 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4354 return;
4355
4356 /* If routes exists below this node, generate aggregate routes. */
4357 top = bgp_node_get (table, p);
4358 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4359 if (rn->p.prefixlen > p->prefixlen)
4360 {
4361 match = 0;
4362
4363 for (ri = rn->info; ri; ri = ri->next)
4364 {
4365 if (BGP_INFO_HOLDDOWN (ri))
4366 continue;
4367
4368 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4369 {
4370 if (aggregate->summary_only)
4371 {
4372 ri->suppress--;
4373
4374 if (ri->suppress == 0)
4375 {
4376 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4377 match++;
4378 }
4379 }
4380 aggregate->count--;
4381 }
4382 }
4383
4384 /* If this node is suppressed, process the change. */
4385 if (match)
4386 bgp_process (bgp, rn, afi, safi);
4387 }
4388 bgp_unlock_node (top);
4389
4390 /* Delete aggregate route from BGP table. */
4391 rn = bgp_node_get (table, p);
4392
4393 for (ri = rn->info; ri; ri = ri->next)
4394 if (ri->peer == bgp->peer_self
4395 && ri->type == ZEBRA_ROUTE_BGP
4396 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4397 break;
4398
4399 /* Withdraw static BGP route from routing table. */
4400 if (ri)
4401 {
4402 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4403 bgp_process (bgp, rn, afi, safi);
4404 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004405 }
4406
4407 /* Unlock bgp_node_lookup. */
4408 bgp_unlock_node (rn);
4409}
4410
4411/* Aggregate route attribute. */
4412#define AGGREGATE_SUMMARY_ONLY 1
4413#define AGGREGATE_AS_SET 1
4414
paul94f2b392005-06-28 12:44:16 +00004415static int
paulfd79ac92004-10-13 05:06:08 +00004416bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4417 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004418 u_char summary_only, u_char as_set)
4419{
4420 int ret;
4421 struct prefix p;
4422 struct bgp_node *rn;
4423 struct bgp *bgp;
4424 struct bgp_aggregate *aggregate;
4425
4426 /* Convert string to prefix structure. */
4427 ret = str2prefix (prefix_str, &p);
4428 if (!ret)
4429 {
4430 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4431 return CMD_WARNING;
4432 }
4433 apply_mask (&p);
4434
4435 /* Get BGP structure. */
4436 bgp = vty->index;
4437
4438 /* Old configuration check. */
4439 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4440
4441 if (rn->info)
4442 {
4443 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4444 bgp_unlock_node (rn);
4445 return CMD_WARNING;
4446 }
4447
4448 /* Make aggregate address structure. */
4449 aggregate = bgp_aggregate_new ();
4450 aggregate->summary_only = summary_only;
4451 aggregate->as_set = as_set;
4452 aggregate->safi = safi;
4453 rn->info = aggregate;
4454
4455 /* Aggregate address insert into BGP routing table. */
4456 if (safi & SAFI_UNICAST)
4457 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4458 if (safi & SAFI_MULTICAST)
4459 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4460
4461 return CMD_SUCCESS;
4462}
4463
paul94f2b392005-06-28 12:44:16 +00004464static int
paulfd79ac92004-10-13 05:06:08 +00004465bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4466 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004467{
4468 int ret;
4469 struct prefix p;
4470 struct bgp_node *rn;
4471 struct bgp *bgp;
4472 struct bgp_aggregate *aggregate;
4473
4474 /* Convert string to prefix structure. */
4475 ret = str2prefix (prefix_str, &p);
4476 if (!ret)
4477 {
4478 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4479 return CMD_WARNING;
4480 }
4481 apply_mask (&p);
4482
4483 /* Get BGP structure. */
4484 bgp = vty->index;
4485
4486 /* Old configuration check. */
4487 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4488 if (! rn)
4489 {
4490 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4491 VTY_NEWLINE);
4492 return CMD_WARNING;
4493 }
4494
4495 aggregate = rn->info;
4496 if (aggregate->safi & SAFI_UNICAST)
4497 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4498 if (aggregate->safi & SAFI_MULTICAST)
4499 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4500
4501 /* Unlock aggregate address configuration. */
4502 rn->info = NULL;
4503 bgp_aggregate_free (aggregate);
4504 bgp_unlock_node (rn);
4505 bgp_unlock_node (rn);
4506
4507 return CMD_SUCCESS;
4508}
4509
4510DEFUN (aggregate_address,
4511 aggregate_address_cmd,
4512 "aggregate-address A.B.C.D/M",
4513 "Configure BGP aggregate entries\n"
4514 "Aggregate prefix\n")
4515{
4516 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4517}
4518
4519DEFUN (aggregate_address_mask,
4520 aggregate_address_mask_cmd,
4521 "aggregate-address A.B.C.D A.B.C.D",
4522 "Configure BGP aggregate entries\n"
4523 "Aggregate address\n"
4524 "Aggregate mask\n")
4525{
4526 int ret;
4527 char prefix_str[BUFSIZ];
4528
4529 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4530
4531 if (! ret)
4532 {
4533 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4534 return CMD_WARNING;
4535 }
4536
4537 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4538 0, 0);
4539}
4540
4541DEFUN (aggregate_address_summary_only,
4542 aggregate_address_summary_only_cmd,
4543 "aggregate-address A.B.C.D/M summary-only",
4544 "Configure BGP aggregate entries\n"
4545 "Aggregate prefix\n"
4546 "Filter more specific routes from updates\n")
4547{
4548 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4549 AGGREGATE_SUMMARY_ONLY, 0);
4550}
4551
4552DEFUN (aggregate_address_mask_summary_only,
4553 aggregate_address_mask_summary_only_cmd,
4554 "aggregate-address A.B.C.D A.B.C.D summary-only",
4555 "Configure BGP aggregate entries\n"
4556 "Aggregate address\n"
4557 "Aggregate mask\n"
4558 "Filter more specific routes from updates\n")
4559{
4560 int ret;
4561 char prefix_str[BUFSIZ];
4562
4563 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4564
4565 if (! ret)
4566 {
4567 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4568 return CMD_WARNING;
4569 }
4570
4571 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4572 AGGREGATE_SUMMARY_ONLY, 0);
4573}
4574
4575DEFUN (aggregate_address_as_set,
4576 aggregate_address_as_set_cmd,
4577 "aggregate-address A.B.C.D/M as-set",
4578 "Configure BGP aggregate entries\n"
4579 "Aggregate prefix\n"
4580 "Generate AS set path information\n")
4581{
4582 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4583 0, AGGREGATE_AS_SET);
4584}
4585
4586DEFUN (aggregate_address_mask_as_set,
4587 aggregate_address_mask_as_set_cmd,
4588 "aggregate-address A.B.C.D A.B.C.D as-set",
4589 "Configure BGP aggregate entries\n"
4590 "Aggregate address\n"
4591 "Aggregate mask\n"
4592 "Generate AS set path information\n")
4593{
4594 int ret;
4595 char prefix_str[BUFSIZ];
4596
4597 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4598
4599 if (! ret)
4600 {
4601 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4602 return CMD_WARNING;
4603 }
4604
4605 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4606 0, AGGREGATE_AS_SET);
4607}
4608
4609
4610DEFUN (aggregate_address_as_set_summary,
4611 aggregate_address_as_set_summary_cmd,
4612 "aggregate-address A.B.C.D/M as-set summary-only",
4613 "Configure BGP aggregate entries\n"
4614 "Aggregate prefix\n"
4615 "Generate AS set path information\n"
4616 "Filter more specific routes from updates\n")
4617{
4618 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4619 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4620}
4621
4622ALIAS (aggregate_address_as_set_summary,
4623 aggregate_address_summary_as_set_cmd,
4624 "aggregate-address A.B.C.D/M summary-only as-set",
4625 "Configure BGP aggregate entries\n"
4626 "Aggregate prefix\n"
4627 "Filter more specific routes from updates\n"
4628 "Generate AS set path information\n")
4629
4630DEFUN (aggregate_address_mask_as_set_summary,
4631 aggregate_address_mask_as_set_summary_cmd,
4632 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4633 "Configure BGP aggregate entries\n"
4634 "Aggregate address\n"
4635 "Aggregate mask\n"
4636 "Generate AS set path information\n"
4637 "Filter more specific routes from updates\n")
4638{
4639 int ret;
4640 char prefix_str[BUFSIZ];
4641
4642 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4643
4644 if (! ret)
4645 {
4646 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4647 return CMD_WARNING;
4648 }
4649
4650 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4651 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4652}
4653
4654ALIAS (aggregate_address_mask_as_set_summary,
4655 aggregate_address_mask_summary_as_set_cmd,
4656 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4657 "Configure BGP aggregate entries\n"
4658 "Aggregate address\n"
4659 "Aggregate mask\n"
4660 "Filter more specific routes from updates\n"
4661 "Generate AS set path information\n")
4662
4663DEFUN (no_aggregate_address,
4664 no_aggregate_address_cmd,
4665 "no aggregate-address A.B.C.D/M",
4666 NO_STR
4667 "Configure BGP aggregate entries\n"
4668 "Aggregate prefix\n")
4669{
4670 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4671}
4672
4673ALIAS (no_aggregate_address,
4674 no_aggregate_address_summary_only_cmd,
4675 "no aggregate-address A.B.C.D/M summary-only",
4676 NO_STR
4677 "Configure BGP aggregate entries\n"
4678 "Aggregate prefix\n"
4679 "Filter more specific routes from updates\n")
4680
4681ALIAS (no_aggregate_address,
4682 no_aggregate_address_as_set_cmd,
4683 "no aggregate-address A.B.C.D/M as-set",
4684 NO_STR
4685 "Configure BGP aggregate entries\n"
4686 "Aggregate prefix\n"
4687 "Generate AS set path information\n")
4688
4689ALIAS (no_aggregate_address,
4690 no_aggregate_address_as_set_summary_cmd,
4691 "no aggregate-address A.B.C.D/M as-set summary-only",
4692 NO_STR
4693 "Configure BGP aggregate entries\n"
4694 "Aggregate prefix\n"
4695 "Generate AS set path information\n"
4696 "Filter more specific routes from updates\n")
4697
4698ALIAS (no_aggregate_address,
4699 no_aggregate_address_summary_as_set_cmd,
4700 "no aggregate-address A.B.C.D/M summary-only as-set",
4701 NO_STR
4702 "Configure BGP aggregate entries\n"
4703 "Aggregate prefix\n"
4704 "Filter more specific routes from updates\n"
4705 "Generate AS set path information\n")
4706
4707DEFUN (no_aggregate_address_mask,
4708 no_aggregate_address_mask_cmd,
4709 "no aggregate-address A.B.C.D A.B.C.D",
4710 NO_STR
4711 "Configure BGP aggregate entries\n"
4712 "Aggregate address\n"
4713 "Aggregate mask\n")
4714{
4715 int ret;
4716 char prefix_str[BUFSIZ];
4717
4718 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4719
4720 if (! ret)
4721 {
4722 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4723 return CMD_WARNING;
4724 }
4725
4726 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4727}
4728
4729ALIAS (no_aggregate_address_mask,
4730 no_aggregate_address_mask_summary_only_cmd,
4731 "no aggregate-address A.B.C.D A.B.C.D summary-only",
4732 NO_STR
4733 "Configure BGP aggregate entries\n"
4734 "Aggregate address\n"
4735 "Aggregate mask\n"
4736 "Filter more specific routes from updates\n")
4737
4738ALIAS (no_aggregate_address_mask,
4739 no_aggregate_address_mask_as_set_cmd,
4740 "no aggregate-address A.B.C.D A.B.C.D as-set",
4741 NO_STR
4742 "Configure BGP aggregate entries\n"
4743 "Aggregate address\n"
4744 "Aggregate mask\n"
4745 "Generate AS set path information\n")
4746
4747ALIAS (no_aggregate_address_mask,
4748 no_aggregate_address_mask_as_set_summary_cmd,
4749 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4750 NO_STR
4751 "Configure BGP aggregate entries\n"
4752 "Aggregate address\n"
4753 "Aggregate mask\n"
4754 "Generate AS set path information\n"
4755 "Filter more specific routes from updates\n")
4756
4757ALIAS (no_aggregate_address_mask,
4758 no_aggregate_address_mask_summary_as_set_cmd,
4759 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4760 NO_STR
4761 "Configure BGP aggregate entries\n"
4762 "Aggregate address\n"
4763 "Aggregate mask\n"
4764 "Filter more specific routes from updates\n"
4765 "Generate AS set path information\n")
4766
4767#ifdef HAVE_IPV6
4768DEFUN (ipv6_aggregate_address,
4769 ipv6_aggregate_address_cmd,
4770 "aggregate-address X:X::X:X/M",
4771 "Configure BGP aggregate entries\n"
4772 "Aggregate prefix\n")
4773{
4774 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4775}
4776
4777DEFUN (ipv6_aggregate_address_summary_only,
4778 ipv6_aggregate_address_summary_only_cmd,
4779 "aggregate-address X:X::X:X/M summary-only",
4780 "Configure BGP aggregate entries\n"
4781 "Aggregate prefix\n"
4782 "Filter more specific routes from updates\n")
4783{
4784 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4785 AGGREGATE_SUMMARY_ONLY, 0);
4786}
4787
4788DEFUN (no_ipv6_aggregate_address,
4789 no_ipv6_aggregate_address_cmd,
4790 "no aggregate-address X:X::X:X/M",
4791 NO_STR
4792 "Configure BGP aggregate entries\n"
4793 "Aggregate prefix\n")
4794{
4795 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4796}
4797
4798DEFUN (no_ipv6_aggregate_address_summary_only,
4799 no_ipv6_aggregate_address_summary_only_cmd,
4800 "no aggregate-address X:X::X:X/M summary-only",
4801 NO_STR
4802 "Configure BGP aggregate entries\n"
4803 "Aggregate prefix\n"
4804 "Filter more specific routes from updates\n")
4805{
4806 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4807}
4808
4809ALIAS (ipv6_aggregate_address,
4810 old_ipv6_aggregate_address_cmd,
4811 "ipv6 bgp aggregate-address X:X::X:X/M",
4812 IPV6_STR
4813 BGP_STR
4814 "Configure BGP aggregate entries\n"
4815 "Aggregate prefix\n")
4816
4817ALIAS (ipv6_aggregate_address_summary_only,
4818 old_ipv6_aggregate_address_summary_only_cmd,
4819 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4820 IPV6_STR
4821 BGP_STR
4822 "Configure BGP aggregate entries\n"
4823 "Aggregate prefix\n"
4824 "Filter more specific routes from updates\n")
4825
4826ALIAS (no_ipv6_aggregate_address,
4827 old_no_ipv6_aggregate_address_cmd,
4828 "no ipv6 bgp aggregate-address X:X::X:X/M",
4829 NO_STR
4830 IPV6_STR
4831 BGP_STR
4832 "Configure BGP aggregate entries\n"
4833 "Aggregate prefix\n")
4834
4835ALIAS (no_ipv6_aggregate_address_summary_only,
4836 old_no_ipv6_aggregate_address_summary_only_cmd,
4837 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4838 NO_STR
4839 IPV6_STR
4840 BGP_STR
4841 "Configure BGP aggregate entries\n"
4842 "Aggregate prefix\n"
4843 "Filter more specific routes from updates\n")
4844#endif /* HAVE_IPV6 */
4845
4846/* Redistribute route treatment. */
4847void
4848bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4849 u_int32_t metric, u_char type)
4850{
4851 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004852 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004853 struct bgp_info *new;
4854 struct bgp_info *bi;
4855 struct bgp_info info;
4856 struct bgp_node *bn;
4857 struct attr attr;
4858 struct attr attr_new;
4859 struct attr *new_attr;
4860 afi_t afi;
4861 int ret;
4862
4863 /* Make default attribute. */
4864 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4865 if (nexthop)
4866 attr.nexthop = *nexthop;
4867
4868 attr.med = metric;
4869 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4870
paul1eb8ef22005-04-07 07:30:20 +00004871 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004872 {
4873 afi = family2afi (p->family);
4874
4875 if (bgp->redist[afi][type])
4876 {
4877 /* Copy attribute for modification. */
4878 attr_new = attr;
4879
4880 if (bgp->redist_metric_flag[afi][type])
4881 attr_new.med = bgp->redist_metric[afi][type];
4882
4883 /* Apply route-map. */
4884 if (bgp->rmap[afi][type].map)
4885 {
4886 info.peer = bgp->peer_self;
4887 info.attr = &attr_new;
4888
paulfee0f4c2004-09-13 05:12:46 +00004889 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
4890
paul718e3742002-12-13 20:15:29 +00004891 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
4892 &info);
paulfee0f4c2004-09-13 05:12:46 +00004893
4894 bgp->peer_self->rmap_type = 0;
4895
paul718e3742002-12-13 20:15:29 +00004896 if (ret == RMAP_DENYMATCH)
4897 {
4898 /* Free uninterned attribute. */
4899 bgp_attr_flush (&attr_new);
4900
4901 /* Unintern original. */
4902 aspath_unintern (attr.aspath);
4903 bgp_redistribute_delete (p, type);
4904 return;
4905 }
4906 }
4907
paulfee0f4c2004-09-13 05:12:46 +00004908 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004909 new_attr = bgp_attr_intern (&attr_new);
4910
4911 for (bi = bn->info; bi; bi = bi->next)
4912 if (bi->peer == bgp->peer_self
4913 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
4914 break;
4915
4916 if (bi)
4917 {
4918 if (attrhash_cmp (bi->attr, new_attr))
4919 {
4920 bgp_attr_unintern (new_attr);
4921 aspath_unintern (attr.aspath);
4922 bgp_unlock_node (bn);
4923 return;
4924 }
4925 else
4926 {
4927 /* The attribute is changed. */
4928 SET_FLAG (bi->flags, BGP_INFO_ATTR_CHANGED);
4929
4930 /* Rewrite BGP route information. */
4931 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
4932 bgp_attr_unintern (bi->attr);
4933 bi->attr = new_attr;
4934 bi->uptime = time (NULL);
4935
4936 /* Process change. */
4937 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
4938 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4939 bgp_unlock_node (bn);
4940 aspath_unintern (attr.aspath);
4941 return;
4942 }
4943 }
4944
4945 new = bgp_info_new ();
4946 new->type = type;
4947 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
4948 new->peer = bgp->peer_self;
4949 SET_FLAG (new->flags, BGP_INFO_VALID);
4950 new->attr = new_attr;
4951 new->uptime = time (NULL);
4952
4953 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
4954 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00004955 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00004956 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4957 }
4958 }
4959
4960 /* Unintern original. */
4961 aspath_unintern (attr.aspath);
4962}
4963
4964void
4965bgp_redistribute_delete (struct prefix *p, u_char type)
4966{
4967 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004968 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004969 afi_t afi;
4970 struct bgp_node *rn;
4971 struct bgp_info *ri;
4972
paul1eb8ef22005-04-07 07:30:20 +00004973 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004974 {
4975 afi = family2afi (p->family);
4976
4977 if (bgp->redist[afi][type])
4978 {
paulfee0f4c2004-09-13 05:12:46 +00004979 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004980
4981 for (ri = rn->info; ri; ri = ri->next)
4982 if (ri->peer == bgp->peer_self
4983 && ri->type == type)
4984 break;
4985
4986 if (ri)
4987 {
4988 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
4989 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4990 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4991 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004992 }
4993 bgp_unlock_node (rn);
4994 }
4995 }
4996}
4997
4998/* Withdraw specified route type's route. */
4999void
5000bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5001{
5002 struct bgp_node *rn;
5003 struct bgp_info *ri;
5004 struct bgp_table *table;
5005
5006 table = bgp->rib[afi][SAFI_UNICAST];
5007
5008 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5009 {
5010 for (ri = rn->info; ri; ri = ri->next)
5011 if (ri->peer == bgp->peer_self
5012 && ri->type == type)
5013 break;
5014
5015 if (ri)
5016 {
5017 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
5018 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
5019 bgp_process (bgp, rn, afi, SAFI_UNICAST);
5020 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00005021 }
5022 }
5023}
5024
5025/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005026static void
paul718e3742002-12-13 20:15:29 +00005027route_vty_out_route (struct prefix *p, struct vty *vty)
5028{
5029 int len;
5030 u_int32_t destination;
5031 char buf[BUFSIZ];
5032
5033 if (p->family == AF_INET)
5034 {
5035 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5036 destination = ntohl (p->u.prefix4.s_addr);
5037
5038 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5039 || (IN_CLASSB (destination) && p->prefixlen == 16)
5040 || (IN_CLASSA (destination) && p->prefixlen == 8)
5041 || p->u.prefix4.s_addr == 0)
5042 {
5043 /* When mask is natural, mask is not displayed. */
5044 }
5045 else
5046 len += vty_out (vty, "/%d", p->prefixlen);
5047 }
5048 else
5049 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5050 p->prefixlen);
5051
5052 len = 17 - len;
5053 if (len < 1)
5054 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5055 else
5056 vty_out (vty, "%*s", len, " ");
5057}
5058
paul718e3742002-12-13 20:15:29 +00005059enum bgp_display_type
5060{
5061 normal_list,
5062};
5063
paulb40d9392005-08-22 22:34:41 +00005064/* Print the short form route status for a bgp_info */
5065static void
5066route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005067{
paulb40d9392005-08-22 22:34:41 +00005068 /* Route status display. */
5069 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5070 vty_out (vty, "R");
5071 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005072 vty_out (vty, "S");
5073 else if (binfo->suppress)
paul718e3742002-12-13 20:15:29 +00005074 vty_out (vty, "s");
5075 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5076 vty_out (vty, "*");
5077 else
5078 vty_out (vty, " ");
5079
5080 /* Selected */
5081 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5082 vty_out (vty, "h");
5083 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5084 vty_out (vty, "d");
5085 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5086 vty_out (vty, ">");
5087 else
5088 vty_out (vty, " ");
5089
5090 /* Internal route. */
5091 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5092 vty_out (vty, "i");
5093 else
paulb40d9392005-08-22 22:34:41 +00005094 vty_out (vty, " ");
5095}
5096
5097/* called from terminal list command */
5098void
5099route_vty_out (struct vty *vty, struct prefix *p,
5100 struct bgp_info *binfo, int display, safi_t safi)
5101{
5102 struct attr *attr;
5103
5104 /* short status lead text */
5105 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005106
5107 /* print prefix and mask */
5108 if (! display)
5109 route_vty_out_route (p, vty);
5110 else
5111 vty_out (vty, "%*s", 17, " ");
5112
5113 /* Print attribute */
5114 attr = binfo->attr;
5115 if (attr)
5116 {
5117 if (p->family == AF_INET)
5118 {
5119 if (safi == SAFI_MPLS_VPN)
5120 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5121 else
5122 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5123 }
5124#ifdef HAVE_IPV6
5125 else if (p->family == AF_INET6)
5126 {
5127 int len;
5128 char buf[BUFSIZ];
5129
5130 len = vty_out (vty, "%s",
5131 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5132 len = 16 - len;
5133 if (len < 1)
5134 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5135 else
5136 vty_out (vty, "%*s", len, " ");
5137 }
5138#endif /* HAVE_IPV6 */
5139
5140 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5141 vty_out (vty, "%10d", attr->med);
5142 else
5143 vty_out (vty, " ");
5144
5145 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5146 vty_out (vty, "%7d", attr->local_pref);
5147 else
5148 vty_out (vty, " ");
5149
5150 vty_out (vty, "%7u ",attr->weight);
5151
5152 /* Print aspath */
5153 if (attr->aspath)
5154 aspath_print_vty (vty, attr->aspath);
5155
5156 /* Print origin */
5157 if (strlen (attr->aspath->str) == 0)
5158 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5159 else
5160 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5161 }
5162 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005163}
5164
5165/* called from terminal list command */
5166void
5167route_vty_out_tmp (struct vty *vty, struct prefix *p,
5168 struct attr *attr, safi_t safi)
5169{
5170 /* Route status display. */
5171 vty_out (vty, "*");
5172 vty_out (vty, ">");
5173 vty_out (vty, " ");
5174
5175 /* print prefix and mask */
5176 route_vty_out_route (p, vty);
5177
5178 /* Print attribute */
5179 if (attr)
5180 {
5181 if (p->family == AF_INET)
5182 {
5183 if (safi == SAFI_MPLS_VPN)
5184 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5185 else
5186 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5187 }
5188#ifdef HAVE_IPV6
5189 else if (p->family == AF_INET6)
5190 {
5191 int len;
5192 char buf[BUFSIZ];
5193
5194 len = vty_out (vty, "%s",
5195 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5196 len = 16 - len;
5197 if (len < 1)
5198 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5199 else
5200 vty_out (vty, "%*s", len, " ");
5201 }
5202#endif /* HAVE_IPV6 */
5203
5204 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5205 vty_out (vty, "%10d", attr->med);
5206 else
5207 vty_out (vty, " ");
5208
5209 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5210 vty_out (vty, "%7d", attr->local_pref);
5211 else
5212 vty_out (vty, " ");
5213
5214 vty_out (vty, "%7d ",attr->weight);
5215
5216 /* Print aspath */
5217 if (attr->aspath)
5218 aspath_print_vty (vty, attr->aspath);
5219
5220 /* Print origin */
5221 if (strlen (attr->aspath->str) == 0)
5222 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5223 else
5224 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5225 }
5226
5227 vty_out (vty, "%s", VTY_NEWLINE);
5228}
5229
ajs5a646652004-11-05 01:25:55 +00005230void
paul718e3742002-12-13 20:15:29 +00005231route_vty_out_tag (struct vty *vty, struct prefix *p,
5232 struct bgp_info *binfo, int display, safi_t safi)
5233{
5234 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005235 u_int32_t label = 0;
5236
paulb40d9392005-08-22 22:34:41 +00005237 /* short status lead text */
5238 route_vty_short_status_out (vty, binfo);
5239
paul718e3742002-12-13 20:15:29 +00005240 /* print prefix and mask */
5241 if (! display)
5242 route_vty_out_route (p, vty);
5243 else
5244 vty_out (vty, "%*s", 17, " ");
5245
5246 /* Print attribute */
5247 attr = binfo->attr;
5248 if (attr)
5249 {
5250 if (p->family == AF_INET)
5251 {
5252 if (safi == SAFI_MPLS_VPN)
5253 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5254 else
5255 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5256 }
5257#ifdef HAVE_IPV6
5258 else if (p->family == AF_INET6)
5259 {
5260 char buf[BUFSIZ];
5261 char buf1[BUFSIZ];
5262 if (attr->mp_nexthop_len == 16)
5263 vty_out (vty, "%s",
5264 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5265 else if (attr->mp_nexthop_len == 32)
5266 vty_out (vty, "%s(%s)",
5267 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
5268 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
5269
5270 }
5271#endif /* HAVE_IPV6 */
5272 }
5273
5274 label = decode_label (binfo->tag);
5275
5276 vty_out (vty, "notag/%d", label);
5277
5278 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005279}
5280
5281/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005282static void
paul718e3742002-12-13 20:15:29 +00005283damp_route_vty_out (struct vty *vty, struct prefix *p,
5284 struct bgp_info *binfo, int display, safi_t safi)
5285{
5286 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005287 int len;
5288
paulb40d9392005-08-22 22:34:41 +00005289 /* short status lead text */
5290 route_vty_short_status_out (vty, binfo);
5291
paul718e3742002-12-13 20:15:29 +00005292 /* print prefix and mask */
5293 if (! display)
5294 route_vty_out_route (p, vty);
5295 else
5296 vty_out (vty, "%*s", 17, " ");
5297
5298 len = vty_out (vty, "%s", binfo->peer->host);
5299 len = 17 - len;
5300 if (len < 1)
5301 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5302 else
5303 vty_out (vty, "%*s", len, " ");
5304
5305 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5306
5307 /* Print attribute */
5308 attr = binfo->attr;
5309 if (attr)
5310 {
5311 /* Print aspath */
5312 if (attr->aspath)
5313 aspath_print_vty (vty, attr->aspath);
5314
5315 /* Print origin */
5316 if (strlen (attr->aspath->str) == 0)
5317 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5318 else
5319 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5320 }
5321 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005322}
5323
5324#define BGP_UPTIME_LEN 25
5325
5326/* flap route */
ajs5a646652004-11-05 01:25:55 +00005327static void
paul718e3742002-12-13 20:15:29 +00005328flap_route_vty_out (struct vty *vty, struct prefix *p,
5329 struct bgp_info *binfo, int display, safi_t safi)
5330{
5331 struct attr *attr;
5332 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005333 char timebuf[BGP_UPTIME_LEN];
5334 int len;
5335
paul718e3742002-12-13 20:15:29 +00005336 bdi = binfo->damp_info;
5337
paulb40d9392005-08-22 22:34:41 +00005338 /* short status lead text */
5339 route_vty_short_status_out (vty, binfo);
5340
paul718e3742002-12-13 20:15:29 +00005341 /* print prefix and mask */
5342 if (! display)
5343 route_vty_out_route (p, vty);
5344 else
5345 vty_out (vty, "%*s", 17, " ");
5346
5347 len = vty_out (vty, "%s", binfo->peer->host);
5348 len = 16 - len;
5349 if (len < 1)
5350 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5351 else
5352 vty_out (vty, "%*s", len, " ");
5353
5354 len = vty_out (vty, "%d", bdi->flap);
5355 len = 5 - len;
5356 if (len < 1)
5357 vty_out (vty, " ");
5358 else
5359 vty_out (vty, "%*s ", len, " ");
5360
5361 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5362 timebuf, BGP_UPTIME_LEN));
5363
5364 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5365 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5366 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5367 else
5368 vty_out (vty, "%*s ", 8, " ");
5369
5370 /* Print attribute */
5371 attr = binfo->attr;
5372 if (attr)
5373 {
5374 /* Print aspath */
5375 if (attr->aspath)
5376 aspath_print_vty (vty, attr->aspath);
5377
5378 /* Print origin */
5379 if (strlen (attr->aspath->str) == 0)
5380 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5381 else
5382 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5383 }
5384 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005385}
5386
paul94f2b392005-06-28 12:44:16 +00005387static void
paul718e3742002-12-13 20:15:29 +00005388route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5389 struct bgp_info *binfo, afi_t afi, safi_t safi)
5390{
5391 char buf[INET6_ADDRSTRLEN];
5392 char buf1[BUFSIZ];
5393 struct attr *attr;
5394 int sockunion_vty_out (struct vty *, union sockunion *);
5395
5396 attr = binfo->attr;
5397
5398 if (attr)
5399 {
5400 /* Line1 display AS-path, Aggregator */
5401 if (attr->aspath)
5402 {
5403 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005404 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005405 vty_out (vty, "Local");
5406 else
5407 aspath_print_vty (vty, attr->aspath);
5408 }
5409
paulb40d9392005-08-22 22:34:41 +00005410 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5411 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005412 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5413 vty_out (vty, ", (stale)");
5414 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5415 vty_out (vty, ", (aggregated by %d %s)", attr->aggregator_as,
5416 inet_ntoa (attr->aggregator_addr));
5417 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5418 vty_out (vty, ", (Received from a RR-client)");
5419 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5420 vty_out (vty, ", (Received from a RS-client)");
5421 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5422 vty_out (vty, ", (history entry)");
5423 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5424 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005425 vty_out (vty, "%s", VTY_NEWLINE);
5426
5427 /* Line2 display Next-hop, Neighbor, Router-id */
5428 if (p->family == AF_INET)
5429 {
5430 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5431 inet_ntoa (attr->mp_nexthop_global_in) :
5432 inet_ntoa (attr->nexthop));
5433 }
5434#ifdef HAVE_IPV6
5435 else
5436 {
5437 vty_out (vty, " %s",
5438 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5439 buf, INET6_ADDRSTRLEN));
5440 }
5441#endif /* HAVE_IPV6 */
5442
5443 if (binfo->peer == bgp->peer_self)
5444 {
5445 vty_out (vty, " from %s ",
5446 p->family == AF_INET ? "0.0.0.0" : "::");
5447 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5448 }
5449 else
5450 {
5451 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5452 vty_out (vty, " (inaccessible)");
5453 else if (binfo->igpmetric)
5454 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005455 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005456 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5457 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5458 else
5459 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5460 }
5461 vty_out (vty, "%s", VTY_NEWLINE);
5462
5463#ifdef HAVE_IPV6
5464 /* display nexthop local */
5465 if (attr->mp_nexthop_len == 32)
5466 {
5467 vty_out (vty, " (%s)%s",
5468 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5469 buf, INET6_ADDRSTRLEN),
5470 VTY_NEWLINE);
5471 }
5472#endif /* HAVE_IPV6 */
5473
5474 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5475 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5476
5477 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5478 vty_out (vty, ", metric %d", attr->med);
5479
5480 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5481 vty_out (vty, ", localpref %d", attr->local_pref);
5482 else
5483 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5484
5485 if (attr->weight != 0)
5486 vty_out (vty, ", weight %d", attr->weight);
5487
5488 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5489 vty_out (vty, ", valid");
5490
5491 if (binfo->peer != bgp->peer_self)
5492 {
5493 if (binfo->peer->as == binfo->peer->local_as)
5494 vty_out (vty, ", internal");
5495 else
5496 vty_out (vty, ", %s",
5497 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5498 }
5499 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5500 vty_out (vty, ", aggregated, local");
5501 else if (binfo->type != ZEBRA_ROUTE_BGP)
5502 vty_out (vty, ", sourced");
5503 else
5504 vty_out (vty, ", sourced, local");
5505
5506 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5507 vty_out (vty, ", atomic-aggregate");
5508
5509 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5510 vty_out (vty, ", best");
5511
5512 vty_out (vty, "%s", VTY_NEWLINE);
5513
5514 /* Line 4 display Community */
5515 if (attr->community)
5516 vty_out (vty, " Community: %s%s", attr->community->str,
5517 VTY_NEWLINE);
5518
5519 /* Line 5 display Extended-community */
5520 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5521 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5522 VTY_NEWLINE);
5523
5524 /* Line 6 display Originator, Cluster-id */
5525 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5526 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5527 {
5528 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5529 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5530
5531 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5532 {
5533 int i;
5534 vty_out (vty, ", Cluster list: ");
5535 for (i = 0; i < attr->cluster->length / 4; i++)
5536 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5537 }
5538 vty_out (vty, "%s", VTY_NEWLINE);
5539 }
5540
5541 if (binfo->damp_info)
5542 bgp_damp_info_vty (vty, binfo);
5543
5544 /* Line 7 display Uptime */
5545 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5546 }
5547 vty_out (vty, "%s", VTY_NEWLINE);
5548}
5549
paulb40d9392005-08-22 22:34:41 +00005550#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 +00005551#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005552#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5553#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5554#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5555
5556enum bgp_show_type
5557{
5558 bgp_show_type_normal,
5559 bgp_show_type_regexp,
5560 bgp_show_type_prefix_list,
5561 bgp_show_type_filter_list,
5562 bgp_show_type_route_map,
5563 bgp_show_type_neighbor,
5564 bgp_show_type_cidr_only,
5565 bgp_show_type_prefix_longer,
5566 bgp_show_type_community_all,
5567 bgp_show_type_community,
5568 bgp_show_type_community_exact,
5569 bgp_show_type_community_list,
5570 bgp_show_type_community_list_exact,
5571 bgp_show_type_flap_statistics,
5572 bgp_show_type_flap_address,
5573 bgp_show_type_flap_prefix,
5574 bgp_show_type_flap_cidr_only,
5575 bgp_show_type_flap_regexp,
5576 bgp_show_type_flap_filter_list,
5577 bgp_show_type_flap_prefix_list,
5578 bgp_show_type_flap_prefix_longer,
5579 bgp_show_type_flap_route_map,
5580 bgp_show_type_flap_neighbor,
5581 bgp_show_type_dampend_paths,
5582 bgp_show_type_damp_neighbor
5583};
5584
ajs5a646652004-11-05 01:25:55 +00005585static int
paulfee0f4c2004-09-13 05:12:46 +00005586bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00005587 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00005588{
paul718e3742002-12-13 20:15:29 +00005589 struct bgp_info *ri;
5590 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005591 int header = 1;
paul718e3742002-12-13 20:15:29 +00005592 int display;
ajs5a646652004-11-05 01:25:55 +00005593 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00005594
5595 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00005596 output_count = 0;
paul718e3742002-12-13 20:15:29 +00005597
paul718e3742002-12-13 20:15:29 +00005598 /* Start processing of routes. */
5599 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5600 if (rn->info != NULL)
5601 {
5602 display = 0;
5603
5604 for (ri = rn->info; ri; ri = ri->next)
5605 {
ajs5a646652004-11-05 01:25:55 +00005606 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00005607 || type == bgp_show_type_flap_address
5608 || type == bgp_show_type_flap_prefix
5609 || type == bgp_show_type_flap_cidr_only
5610 || type == bgp_show_type_flap_regexp
5611 || type == bgp_show_type_flap_filter_list
5612 || type == bgp_show_type_flap_prefix_list
5613 || type == bgp_show_type_flap_prefix_longer
5614 || type == bgp_show_type_flap_route_map
5615 || type == bgp_show_type_flap_neighbor
5616 || type == bgp_show_type_dampend_paths
5617 || type == bgp_show_type_damp_neighbor)
5618 {
5619 if (! ri->damp_info)
5620 continue;
5621 }
5622 if (type == bgp_show_type_regexp
5623 || type == bgp_show_type_flap_regexp)
5624 {
ajs5a646652004-11-05 01:25:55 +00005625 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00005626
5627 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5628 continue;
5629 }
5630 if (type == bgp_show_type_prefix_list
5631 || type == bgp_show_type_flap_prefix_list)
5632 {
ajs5a646652004-11-05 01:25:55 +00005633 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00005634
5635 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5636 continue;
5637 }
5638 if (type == bgp_show_type_filter_list
5639 || type == bgp_show_type_flap_filter_list)
5640 {
ajs5a646652004-11-05 01:25:55 +00005641 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00005642
5643 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5644 continue;
5645 }
5646 if (type == bgp_show_type_route_map
5647 || type == bgp_show_type_flap_route_map)
5648 {
ajs5a646652004-11-05 01:25:55 +00005649 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00005650 struct bgp_info binfo;
5651 struct attr dummy_attr;
5652 int ret;
5653
5654 dummy_attr = *ri->attr;
5655 binfo.peer = ri->peer;
5656 binfo.attr = &dummy_attr;
5657
5658 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5659
5660 if (ret == RMAP_DENYMATCH)
5661 continue;
5662 }
5663 if (type == bgp_show_type_neighbor
5664 || type == bgp_show_type_flap_neighbor
5665 || type == bgp_show_type_damp_neighbor)
5666 {
ajs5a646652004-11-05 01:25:55 +00005667 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00005668
5669 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5670 continue;
5671 }
5672 if (type == bgp_show_type_cidr_only
5673 || type == bgp_show_type_flap_cidr_only)
5674 {
5675 u_int32_t destination;
5676
5677 destination = ntohl (rn->p.u.prefix4.s_addr);
5678 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5679 continue;
5680 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5681 continue;
5682 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5683 continue;
5684 }
5685 if (type == bgp_show_type_prefix_longer
5686 || type == bgp_show_type_flap_prefix_longer)
5687 {
ajs5a646652004-11-05 01:25:55 +00005688 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005689
5690 if (! prefix_match (p, &rn->p))
5691 continue;
5692 }
5693 if (type == bgp_show_type_community_all)
5694 {
5695 if (! ri->attr->community)
5696 continue;
5697 }
5698 if (type == bgp_show_type_community)
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_match (ri->attr->community, com))
5704 continue;
5705 }
5706 if (type == bgp_show_type_community_exact)
5707 {
ajs5a646652004-11-05 01:25:55 +00005708 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005709
5710 if (! ri->attr->community ||
5711 ! community_cmp (ri->attr->community, com))
5712 continue;
5713 }
5714 if (type == bgp_show_type_community_list)
5715 {
ajs5a646652004-11-05 01:25:55 +00005716 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005717
5718 if (! community_list_match (ri->attr->community, list))
5719 continue;
5720 }
5721 if (type == bgp_show_type_community_list_exact)
5722 {
ajs5a646652004-11-05 01:25:55 +00005723 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005724
5725 if (! community_list_exact_match (ri->attr->community, list))
5726 continue;
5727 }
5728 if (type == bgp_show_type_flap_address
5729 || type == bgp_show_type_flap_prefix)
5730 {
ajs5a646652004-11-05 01:25:55 +00005731 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005732
5733 if (! prefix_match (&rn->p, p))
5734 continue;
5735
5736 if (type == bgp_show_type_flap_prefix)
5737 if (p->prefixlen != rn->p.prefixlen)
5738 continue;
5739 }
5740 if (type == bgp_show_type_dampend_paths
5741 || type == bgp_show_type_damp_neighbor)
5742 {
5743 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5744 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5745 continue;
5746 }
5747
5748 if (header)
5749 {
hasso93406d82005-02-02 14:40:33 +00005750 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
5751 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
5752 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005753 if (type == bgp_show_type_dampend_paths
5754 || type == bgp_show_type_damp_neighbor)
5755 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5756 else if (type == bgp_show_type_flap_statistics
5757 || type == bgp_show_type_flap_address
5758 || type == bgp_show_type_flap_prefix
5759 || type == bgp_show_type_flap_cidr_only
5760 || type == bgp_show_type_flap_regexp
5761 || type == bgp_show_type_flap_filter_list
5762 || type == bgp_show_type_flap_prefix_list
5763 || type == bgp_show_type_flap_prefix_longer
5764 || type == bgp_show_type_flap_route_map
5765 || type == bgp_show_type_flap_neighbor)
5766 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5767 else
5768 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005769 header = 0;
5770 }
5771
5772 if (type == bgp_show_type_dampend_paths
5773 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00005774 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005775 else if (type == bgp_show_type_flap_statistics
5776 || type == bgp_show_type_flap_address
5777 || type == bgp_show_type_flap_prefix
5778 || type == bgp_show_type_flap_cidr_only
5779 || type == bgp_show_type_flap_regexp
5780 || type == bgp_show_type_flap_filter_list
5781 || type == bgp_show_type_flap_prefix_list
5782 || type == bgp_show_type_flap_prefix_longer
5783 || type == bgp_show_type_flap_route_map
5784 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00005785 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005786 else
ajs5a646652004-11-05 01:25:55 +00005787 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005788 display++;
5789 }
5790 if (display)
ajs5a646652004-11-05 01:25:55 +00005791 output_count++;
paul718e3742002-12-13 20:15:29 +00005792 }
5793
5794 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00005795 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00005796 {
5797 if (type == bgp_show_type_normal)
5798 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5799 }
5800 else
5801 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00005802 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005803
5804 return CMD_SUCCESS;
5805}
5806
ajs5a646652004-11-05 01:25:55 +00005807static int
paulfee0f4c2004-09-13 05:12:46 +00005808bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00005809 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00005810{
5811 struct bgp_table *table;
5812
5813 if (bgp == NULL) {
5814 bgp = bgp_get_default ();
5815 }
5816
5817 if (bgp == NULL)
5818 {
5819 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5820 return CMD_WARNING;
5821 }
5822
5823
5824 table = bgp->rib[afi][safi];
5825
ajs5a646652004-11-05 01:25:55 +00005826 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00005827}
5828
paul718e3742002-12-13 20:15:29 +00005829/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00005830static void
paul718e3742002-12-13 20:15:29 +00005831route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5832 struct bgp_node *rn,
5833 struct prefix_rd *prd, afi_t afi, safi_t safi)
5834{
5835 struct bgp_info *ri;
5836 struct prefix *p;
5837 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00005838 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005839 char buf1[INET6_ADDRSTRLEN];
5840 char buf2[INET6_ADDRSTRLEN];
5841 int count = 0;
5842 int best = 0;
5843 int suppress = 0;
5844 int no_export = 0;
5845 int no_advertise = 0;
5846 int local_as = 0;
5847 int first = 0;
5848
5849 p = &rn->p;
5850 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5851 (safi == SAFI_MPLS_VPN ?
5852 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5853 safi == SAFI_MPLS_VPN ? ":" : "",
5854 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5855 p->prefixlen, VTY_NEWLINE);
5856
5857 for (ri = rn->info; ri; ri = ri->next)
5858 {
5859 count++;
5860 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5861 {
5862 best = count;
5863 if (ri->suppress)
5864 suppress = 1;
5865 if (ri->attr->community != NULL)
5866 {
5867 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5868 no_advertise = 1;
5869 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5870 no_export = 1;
5871 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5872 local_as = 1;
5873 }
5874 }
5875 }
5876
5877 vty_out (vty, "Paths: (%d available", count);
5878 if (best)
5879 {
5880 vty_out (vty, ", best #%d", best);
5881 if (safi == SAFI_UNICAST)
5882 vty_out (vty, ", table Default-IP-Routing-Table");
5883 }
5884 else
5885 vty_out (vty, ", no best path");
5886 if (no_advertise)
5887 vty_out (vty, ", not advertised to any peer");
5888 else if (no_export)
5889 vty_out (vty, ", not advertised to EBGP peer");
5890 else if (local_as)
5891 vty_out (vty, ", not advertised outside local AS");
5892 if (suppress)
5893 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5894 vty_out (vty, ")%s", VTY_NEWLINE);
5895
5896 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00005897 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00005898 {
5899 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5900 {
5901 if (! first)
5902 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5903 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5904 first = 1;
5905 }
5906 }
5907 if (! first)
5908 vty_out (vty, " Not advertised to any peer");
5909 vty_out (vty, "%s", VTY_NEWLINE);
5910}
5911
5912/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00005913static int
paulfee0f4c2004-09-13 05:12:46 +00005914bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00005915 struct bgp_table *rib, const char *ip_str,
5916 afi_t afi, safi_t safi, struct prefix_rd *prd,
5917 int prefix_check)
paul718e3742002-12-13 20:15:29 +00005918{
5919 int ret;
5920 int header;
5921 int display = 0;
5922 struct prefix match;
5923 struct bgp_node *rn;
5924 struct bgp_node *rm;
5925 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00005926 struct bgp_table *table;
5927
paul718e3742002-12-13 20:15:29 +00005928 /* Check IP address argument. */
5929 ret = str2prefix (ip_str, &match);
5930 if (! ret)
5931 {
5932 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5933 return CMD_WARNING;
5934 }
5935
5936 match.family = afi2family (afi);
5937
5938 if (safi == SAFI_MPLS_VPN)
5939 {
paulfee0f4c2004-09-13 05:12:46 +00005940 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00005941 {
5942 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5943 continue;
5944
5945 if ((table = rn->info) != NULL)
5946 {
5947 header = 1;
5948
5949 if ((rm = bgp_node_match (table, &match)) != NULL)
5950 {
5951 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5952 continue;
5953
5954 for (ri = rm->info; ri; ri = ri->next)
5955 {
5956 if (header)
5957 {
5958 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5959 AFI_IP, SAFI_MPLS_VPN);
5960
5961 header = 0;
5962 }
5963 display++;
5964 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5965 }
5966 }
5967 }
5968 }
5969 }
5970 else
5971 {
5972 header = 1;
5973
paulfee0f4c2004-09-13 05:12:46 +00005974 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00005975 {
5976 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5977 {
5978 for (ri = rn->info; ri; ri = ri->next)
5979 {
5980 if (header)
5981 {
5982 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
5983 header = 0;
5984 }
5985 display++;
5986 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
5987 }
5988 }
5989 }
5990 }
5991
5992 if (! display)
5993 {
5994 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5995 return CMD_WARNING;
5996 }
5997
5998 return CMD_SUCCESS;
5999}
6000
paulfee0f4c2004-09-13 05:12:46 +00006001/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006002static int
paulfd79ac92004-10-13 05:06:08 +00006003bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006004 afi_t afi, safi_t safi, struct prefix_rd *prd,
6005 int prefix_check)
6006{
6007 struct bgp *bgp;
6008
6009 /* BGP structure lookup. */
6010 if (view_name)
6011 {
6012 bgp = bgp_lookup_by_name (view_name);
6013 if (bgp == NULL)
6014 {
6015 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6016 return CMD_WARNING;
6017 }
6018 }
6019 else
6020 {
6021 bgp = bgp_get_default ();
6022 if (bgp == NULL)
6023 {
6024 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6025 return CMD_WARNING;
6026 }
6027 }
6028
6029 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6030 afi, safi, prd, prefix_check);
6031}
6032
paul718e3742002-12-13 20:15:29 +00006033/* BGP route print out function. */
6034DEFUN (show_ip_bgp,
6035 show_ip_bgp_cmd,
6036 "show ip bgp",
6037 SHOW_STR
6038 IP_STR
6039 BGP_STR)
6040{
ajs5a646652004-11-05 01:25:55 +00006041 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006042}
6043
6044DEFUN (show_ip_bgp_ipv4,
6045 show_ip_bgp_ipv4_cmd,
6046 "show ip bgp ipv4 (unicast|multicast)",
6047 SHOW_STR
6048 IP_STR
6049 BGP_STR
6050 "Address family\n"
6051 "Address Family modifier\n"
6052 "Address Family modifier\n")
6053{
6054 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006055 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6056 NULL);
paul718e3742002-12-13 20:15:29 +00006057
ajs5a646652004-11-05 01:25:55 +00006058 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006059}
6060
6061DEFUN (show_ip_bgp_route,
6062 show_ip_bgp_route_cmd,
6063 "show ip bgp A.B.C.D",
6064 SHOW_STR
6065 IP_STR
6066 BGP_STR
6067 "Network in the BGP routing table to display\n")
6068{
6069 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6070}
6071
6072DEFUN (show_ip_bgp_ipv4_route,
6073 show_ip_bgp_ipv4_route_cmd,
6074 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6075 SHOW_STR
6076 IP_STR
6077 BGP_STR
6078 "Address family\n"
6079 "Address Family modifier\n"
6080 "Address Family modifier\n"
6081 "Network in the BGP routing table to display\n")
6082{
6083 if (strncmp (argv[0], "m", 1) == 0)
6084 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6085
6086 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6087}
6088
6089DEFUN (show_ip_bgp_vpnv4_all_route,
6090 show_ip_bgp_vpnv4_all_route_cmd,
6091 "show ip bgp vpnv4 all A.B.C.D",
6092 SHOW_STR
6093 IP_STR
6094 BGP_STR
6095 "Display VPNv4 NLRI specific information\n"
6096 "Display information about all VPNv4 NLRIs\n"
6097 "Network in the BGP routing table to display\n")
6098{
6099 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6100}
6101
6102DEFUN (show_ip_bgp_vpnv4_rd_route,
6103 show_ip_bgp_vpnv4_rd_route_cmd,
6104 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6105 SHOW_STR
6106 IP_STR
6107 BGP_STR
6108 "Display VPNv4 NLRI specific information\n"
6109 "Display information for a route distinguisher\n"
6110 "VPN Route Distinguisher\n"
6111 "Network in the BGP routing table to display\n")
6112{
6113 int ret;
6114 struct prefix_rd prd;
6115
6116 ret = str2prefix_rd (argv[0], &prd);
6117 if (! ret)
6118 {
6119 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6120 return CMD_WARNING;
6121 }
6122 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6123}
6124
6125DEFUN (show_ip_bgp_prefix,
6126 show_ip_bgp_prefix_cmd,
6127 "show ip bgp A.B.C.D/M",
6128 SHOW_STR
6129 IP_STR
6130 BGP_STR
6131 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6132{
6133 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6134}
6135
6136DEFUN (show_ip_bgp_ipv4_prefix,
6137 show_ip_bgp_ipv4_prefix_cmd,
6138 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6139 SHOW_STR
6140 IP_STR
6141 BGP_STR
6142 "Address family\n"
6143 "Address Family modifier\n"
6144 "Address Family modifier\n"
6145 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6146{
6147 if (strncmp (argv[0], "m", 1) == 0)
6148 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6149
6150 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6151}
6152
6153DEFUN (show_ip_bgp_vpnv4_all_prefix,
6154 show_ip_bgp_vpnv4_all_prefix_cmd,
6155 "show ip bgp vpnv4 all A.B.C.D/M",
6156 SHOW_STR
6157 IP_STR
6158 BGP_STR
6159 "Display VPNv4 NLRI specific information\n"
6160 "Display information about all VPNv4 NLRIs\n"
6161 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6162{
6163 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6164}
6165
6166DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6167 show_ip_bgp_vpnv4_rd_prefix_cmd,
6168 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6169 SHOW_STR
6170 IP_STR
6171 BGP_STR
6172 "Display VPNv4 NLRI specific information\n"
6173 "Display information for a route distinguisher\n"
6174 "VPN Route Distinguisher\n"
6175 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6176{
6177 int ret;
6178 struct prefix_rd prd;
6179
6180 ret = str2prefix_rd (argv[0], &prd);
6181 if (! ret)
6182 {
6183 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6184 return CMD_WARNING;
6185 }
6186 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6187}
6188
6189DEFUN (show_ip_bgp_view,
6190 show_ip_bgp_view_cmd,
6191 "show ip bgp view WORD",
6192 SHOW_STR
6193 IP_STR
6194 BGP_STR
6195 "BGP view\n"
6196 "BGP view name\n")
6197{
paulbb46e942003-10-24 19:02:03 +00006198 struct bgp *bgp;
6199
6200 /* BGP structure lookup. */
6201 bgp = bgp_lookup_by_name (argv[0]);
6202 if (bgp == NULL)
6203 {
6204 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6205 return CMD_WARNING;
6206 }
6207
ajs5a646652004-11-05 01:25:55 +00006208 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006209}
6210
6211DEFUN (show_ip_bgp_view_route,
6212 show_ip_bgp_view_route_cmd,
6213 "show ip bgp view WORD A.B.C.D",
6214 SHOW_STR
6215 IP_STR
6216 BGP_STR
6217 "BGP view\n"
6218 "BGP view name\n"
6219 "Network in the BGP routing table to display\n")
6220{
6221 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6222}
6223
6224DEFUN (show_ip_bgp_view_prefix,
6225 show_ip_bgp_view_prefix_cmd,
6226 "show ip bgp view WORD A.B.C.D/M",
6227 SHOW_STR
6228 IP_STR
6229 BGP_STR
6230 "BGP view\n"
6231 "BGP view name\n"
6232 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6233{
6234 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6235}
6236
6237#ifdef HAVE_IPV6
6238DEFUN (show_bgp,
6239 show_bgp_cmd,
6240 "show bgp",
6241 SHOW_STR
6242 BGP_STR)
6243{
ajs5a646652004-11-05 01:25:55 +00006244 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6245 NULL);
paul718e3742002-12-13 20:15:29 +00006246}
6247
6248ALIAS (show_bgp,
6249 show_bgp_ipv6_cmd,
6250 "show bgp ipv6",
6251 SHOW_STR
6252 BGP_STR
6253 "Address family\n")
6254
6255/* old command */
6256DEFUN (show_ipv6_bgp,
6257 show_ipv6_bgp_cmd,
6258 "show ipv6 bgp",
6259 SHOW_STR
6260 IP_STR
6261 BGP_STR)
6262{
ajs5a646652004-11-05 01:25:55 +00006263 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6264 NULL);
paul718e3742002-12-13 20:15:29 +00006265}
6266
6267DEFUN (show_bgp_route,
6268 show_bgp_route_cmd,
6269 "show bgp X:X::X:X",
6270 SHOW_STR
6271 BGP_STR
6272 "Network in the BGP routing table to display\n")
6273{
6274 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6275}
6276
6277ALIAS (show_bgp_route,
6278 show_bgp_ipv6_route_cmd,
6279 "show bgp ipv6 X:X::X:X",
6280 SHOW_STR
6281 BGP_STR
6282 "Address family\n"
6283 "Network in the BGP routing table to display\n")
6284
6285/* old command */
6286DEFUN (show_ipv6_bgp_route,
6287 show_ipv6_bgp_route_cmd,
6288 "show ipv6 bgp X:X::X:X",
6289 SHOW_STR
6290 IP_STR
6291 BGP_STR
6292 "Network in the BGP routing table to display\n")
6293{
6294 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6295}
6296
6297DEFUN (show_bgp_prefix,
6298 show_bgp_prefix_cmd,
6299 "show bgp X:X::X:X/M",
6300 SHOW_STR
6301 BGP_STR
6302 "IPv6 prefix <network>/<length>\n")
6303{
6304 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6305}
6306
6307ALIAS (show_bgp_prefix,
6308 show_bgp_ipv6_prefix_cmd,
6309 "show bgp ipv6 X:X::X:X/M",
6310 SHOW_STR
6311 BGP_STR
6312 "Address family\n"
6313 "IPv6 prefix <network>/<length>\n")
6314
6315/* old command */
6316DEFUN (show_ipv6_bgp_prefix,
6317 show_ipv6_bgp_prefix_cmd,
6318 "show ipv6 bgp X:X::X:X/M",
6319 SHOW_STR
6320 IP_STR
6321 BGP_STR
6322 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6323{
6324 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6325}
6326
paulbb46e942003-10-24 19:02:03 +00006327DEFUN (show_bgp_view,
6328 show_bgp_view_cmd,
6329 "show bgp view WORD",
6330 SHOW_STR
6331 BGP_STR
6332 "BGP view\n"
6333 "View name\n")
6334{
6335 struct bgp *bgp;
6336
6337 /* BGP structure lookup. */
6338 bgp = bgp_lookup_by_name (argv[0]);
6339 if (bgp == NULL)
6340 {
6341 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6342 return CMD_WARNING;
6343 }
6344
ajs5a646652004-11-05 01:25:55 +00006345 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006346}
6347
6348ALIAS (show_bgp_view,
6349 show_bgp_view_ipv6_cmd,
6350 "show bgp view WORD ipv6",
6351 SHOW_STR
6352 BGP_STR
6353 "BGP view\n"
6354 "View name\n"
6355 "Address family\n")
6356
6357DEFUN (show_bgp_view_route,
6358 show_bgp_view_route_cmd,
6359 "show bgp view WORD X:X::X:X",
6360 SHOW_STR
6361 BGP_STR
6362 "BGP view\n"
6363 "View name\n"
6364 "Network in the BGP routing table to display\n")
6365{
6366 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6367}
6368
6369ALIAS (show_bgp_view_route,
6370 show_bgp_view_ipv6_route_cmd,
6371 "show bgp view WORD ipv6 X:X::X:X",
6372 SHOW_STR
6373 BGP_STR
6374 "BGP view\n"
6375 "View name\n"
6376 "Address family\n"
6377 "Network in the BGP routing table to display\n")
6378
6379DEFUN (show_bgp_view_prefix,
6380 show_bgp_view_prefix_cmd,
6381 "show bgp view WORD X:X::X:X/M",
6382 SHOW_STR
6383 BGP_STR
6384 "BGP view\n"
6385 "View name\n"
6386 "IPv6 prefix <network>/<length>\n")
6387{
6388 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6389}
6390
6391ALIAS (show_bgp_view_prefix,
6392 show_bgp_view_ipv6_prefix_cmd,
6393 "show bgp view WORD ipv6 X:X::X:X/M",
6394 SHOW_STR
6395 BGP_STR
6396 "BGP view\n"
6397 "View name\n"
6398 "Address family\n"
6399 "IPv6 prefix <network>/<length>\n")
6400
paul718e3742002-12-13 20:15:29 +00006401/* old command */
6402DEFUN (show_ipv6_mbgp,
6403 show_ipv6_mbgp_cmd,
6404 "show ipv6 mbgp",
6405 SHOW_STR
6406 IP_STR
6407 MBGP_STR)
6408{
ajs5a646652004-11-05 01:25:55 +00006409 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6410 NULL);
paul718e3742002-12-13 20:15:29 +00006411}
6412
6413/* old command */
6414DEFUN (show_ipv6_mbgp_route,
6415 show_ipv6_mbgp_route_cmd,
6416 "show ipv6 mbgp X:X::X:X",
6417 SHOW_STR
6418 IP_STR
6419 MBGP_STR
6420 "Network in the MBGP routing table to display\n")
6421{
6422 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6423}
6424
6425/* old command */
6426DEFUN (show_ipv6_mbgp_prefix,
6427 show_ipv6_mbgp_prefix_cmd,
6428 "show ipv6 mbgp X:X::X:X/M",
6429 SHOW_STR
6430 IP_STR
6431 MBGP_STR
6432 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6433{
6434 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6435}
6436#endif
6437
paul718e3742002-12-13 20:15:29 +00006438
paul94f2b392005-06-28 12:44:16 +00006439static int
paulfd79ac92004-10-13 05:06:08 +00006440bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006441 safi_t safi, enum bgp_show_type type)
6442{
6443 int i;
6444 struct buffer *b;
6445 char *regstr;
6446 int first;
6447 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006448 int rc;
paul718e3742002-12-13 20:15:29 +00006449
6450 first = 0;
6451 b = buffer_new (1024);
6452 for (i = 0; i < argc; i++)
6453 {
6454 if (first)
6455 buffer_putc (b, ' ');
6456 else
6457 {
6458 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6459 continue;
6460 first = 1;
6461 }
6462
6463 buffer_putstr (b, argv[i]);
6464 }
6465 buffer_putc (b, '\0');
6466
6467 regstr = buffer_getstr (b);
6468 buffer_free (b);
6469
6470 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006471 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006472 if (! regex)
6473 {
6474 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6475 VTY_NEWLINE);
6476 return CMD_WARNING;
6477 }
6478
ajs5a646652004-11-05 01:25:55 +00006479 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6480 bgp_regex_free (regex);
6481 return rc;
paul718e3742002-12-13 20:15:29 +00006482}
6483
6484DEFUN (show_ip_bgp_regexp,
6485 show_ip_bgp_regexp_cmd,
6486 "show ip bgp regexp .LINE",
6487 SHOW_STR
6488 IP_STR
6489 BGP_STR
6490 "Display routes matching the AS path regular expression\n"
6491 "A regular-expression to match the BGP AS paths\n")
6492{
6493 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6494 bgp_show_type_regexp);
6495}
6496
6497DEFUN (show_ip_bgp_flap_regexp,
6498 show_ip_bgp_flap_regexp_cmd,
6499 "show ip bgp flap-statistics regexp .LINE",
6500 SHOW_STR
6501 IP_STR
6502 BGP_STR
6503 "Display flap statistics of routes\n"
6504 "Display routes matching the AS path regular expression\n"
6505 "A regular-expression to match the BGP AS paths\n")
6506{
6507 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6508 bgp_show_type_flap_regexp);
6509}
6510
6511DEFUN (show_ip_bgp_ipv4_regexp,
6512 show_ip_bgp_ipv4_regexp_cmd,
6513 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6514 SHOW_STR
6515 IP_STR
6516 BGP_STR
6517 "Address family\n"
6518 "Address Family modifier\n"
6519 "Address Family modifier\n"
6520 "Display routes matching the AS path regular expression\n"
6521 "A regular-expression to match the BGP AS paths\n")
6522{
6523 if (strncmp (argv[0], "m", 1) == 0)
6524 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6525 bgp_show_type_regexp);
6526
6527 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6528 bgp_show_type_regexp);
6529}
6530
6531#ifdef HAVE_IPV6
6532DEFUN (show_bgp_regexp,
6533 show_bgp_regexp_cmd,
6534 "show bgp regexp .LINE",
6535 SHOW_STR
6536 BGP_STR
6537 "Display routes matching the AS path regular expression\n"
6538 "A regular-expression to match the BGP AS paths\n")
6539{
6540 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6541 bgp_show_type_regexp);
6542}
6543
6544ALIAS (show_bgp_regexp,
6545 show_bgp_ipv6_regexp_cmd,
6546 "show bgp ipv6 regexp .LINE",
6547 SHOW_STR
6548 BGP_STR
6549 "Address family\n"
6550 "Display routes matching the AS path regular expression\n"
6551 "A regular-expression to match the BGP AS paths\n")
6552
6553/* old command */
6554DEFUN (show_ipv6_bgp_regexp,
6555 show_ipv6_bgp_regexp_cmd,
6556 "show ipv6 bgp regexp .LINE",
6557 SHOW_STR
6558 IP_STR
6559 BGP_STR
6560 "Display routes matching the AS path regular expression\n"
6561 "A regular-expression to match the BGP AS paths\n")
6562{
6563 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6564 bgp_show_type_regexp);
6565}
6566
6567/* old command */
6568DEFUN (show_ipv6_mbgp_regexp,
6569 show_ipv6_mbgp_regexp_cmd,
6570 "show ipv6 mbgp regexp .LINE",
6571 SHOW_STR
6572 IP_STR
6573 BGP_STR
6574 "Display routes matching the AS path regular expression\n"
6575 "A regular-expression to match the MBGP AS paths\n")
6576{
6577 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6578 bgp_show_type_regexp);
6579}
6580#endif /* HAVE_IPV6 */
6581
paul94f2b392005-06-28 12:44:16 +00006582static int
paulfd79ac92004-10-13 05:06:08 +00006583bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006584 safi_t safi, enum bgp_show_type type)
6585{
6586 struct prefix_list *plist;
6587
6588 plist = prefix_list_lookup (afi, prefix_list_str);
6589 if (plist == NULL)
6590 {
6591 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6592 prefix_list_str, VTY_NEWLINE);
6593 return CMD_WARNING;
6594 }
6595
ajs5a646652004-11-05 01:25:55 +00006596 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00006597}
6598
6599DEFUN (show_ip_bgp_prefix_list,
6600 show_ip_bgp_prefix_list_cmd,
6601 "show ip bgp prefix-list WORD",
6602 SHOW_STR
6603 IP_STR
6604 BGP_STR
6605 "Display routes conforming to the prefix-list\n"
6606 "IP prefix-list name\n")
6607{
6608 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6609 bgp_show_type_prefix_list);
6610}
6611
6612DEFUN (show_ip_bgp_flap_prefix_list,
6613 show_ip_bgp_flap_prefix_list_cmd,
6614 "show ip bgp flap-statistics prefix-list WORD",
6615 SHOW_STR
6616 IP_STR
6617 BGP_STR
6618 "Display flap statistics of routes\n"
6619 "Display routes conforming to the prefix-list\n"
6620 "IP prefix-list name\n")
6621{
6622 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6623 bgp_show_type_flap_prefix_list);
6624}
6625
6626DEFUN (show_ip_bgp_ipv4_prefix_list,
6627 show_ip_bgp_ipv4_prefix_list_cmd,
6628 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6629 SHOW_STR
6630 IP_STR
6631 BGP_STR
6632 "Address family\n"
6633 "Address Family modifier\n"
6634 "Address Family modifier\n"
6635 "Display routes conforming to the prefix-list\n"
6636 "IP prefix-list name\n")
6637{
6638 if (strncmp (argv[0], "m", 1) == 0)
6639 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6640 bgp_show_type_prefix_list);
6641
6642 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6643 bgp_show_type_prefix_list);
6644}
6645
6646#ifdef HAVE_IPV6
6647DEFUN (show_bgp_prefix_list,
6648 show_bgp_prefix_list_cmd,
6649 "show bgp prefix-list WORD",
6650 SHOW_STR
6651 BGP_STR
6652 "Display routes conforming to the prefix-list\n"
6653 "IPv6 prefix-list name\n")
6654{
6655 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6656 bgp_show_type_prefix_list);
6657}
6658
6659ALIAS (show_bgp_prefix_list,
6660 show_bgp_ipv6_prefix_list_cmd,
6661 "show bgp ipv6 prefix-list WORD",
6662 SHOW_STR
6663 BGP_STR
6664 "Address family\n"
6665 "Display routes conforming to the prefix-list\n"
6666 "IPv6 prefix-list name\n")
6667
6668/* old command */
6669DEFUN (show_ipv6_bgp_prefix_list,
6670 show_ipv6_bgp_prefix_list_cmd,
6671 "show ipv6 bgp prefix-list WORD",
6672 SHOW_STR
6673 IPV6_STR
6674 BGP_STR
6675 "Display routes matching the prefix-list\n"
6676 "IPv6 prefix-list name\n")
6677{
6678 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6679 bgp_show_type_prefix_list);
6680}
6681
6682/* old command */
6683DEFUN (show_ipv6_mbgp_prefix_list,
6684 show_ipv6_mbgp_prefix_list_cmd,
6685 "show ipv6 mbgp prefix-list WORD",
6686 SHOW_STR
6687 IPV6_STR
6688 MBGP_STR
6689 "Display routes matching the prefix-list\n"
6690 "IPv6 prefix-list name\n")
6691{
6692 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6693 bgp_show_type_prefix_list);
6694}
6695#endif /* HAVE_IPV6 */
6696
paul94f2b392005-06-28 12:44:16 +00006697static int
paulfd79ac92004-10-13 05:06:08 +00006698bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006699 safi_t safi, enum bgp_show_type type)
6700{
6701 struct as_list *as_list;
6702
6703 as_list = as_list_lookup (filter);
6704 if (as_list == NULL)
6705 {
6706 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6707 return CMD_WARNING;
6708 }
6709
ajs5a646652004-11-05 01:25:55 +00006710 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00006711}
6712
6713DEFUN (show_ip_bgp_filter_list,
6714 show_ip_bgp_filter_list_cmd,
6715 "show ip bgp filter-list WORD",
6716 SHOW_STR
6717 IP_STR
6718 BGP_STR
6719 "Display routes conforming to the filter-list\n"
6720 "Regular expression access list name\n")
6721{
6722 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6723 bgp_show_type_filter_list);
6724}
6725
6726DEFUN (show_ip_bgp_flap_filter_list,
6727 show_ip_bgp_flap_filter_list_cmd,
6728 "show ip bgp flap-statistics filter-list WORD",
6729 SHOW_STR
6730 IP_STR
6731 BGP_STR
6732 "Display flap statistics of routes\n"
6733 "Display routes conforming to the filter-list\n"
6734 "Regular expression access list name\n")
6735{
6736 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6737 bgp_show_type_flap_filter_list);
6738}
6739
6740DEFUN (show_ip_bgp_ipv4_filter_list,
6741 show_ip_bgp_ipv4_filter_list_cmd,
6742 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6743 SHOW_STR
6744 IP_STR
6745 BGP_STR
6746 "Address family\n"
6747 "Address Family modifier\n"
6748 "Address Family modifier\n"
6749 "Display routes conforming to the filter-list\n"
6750 "Regular expression access list name\n")
6751{
6752 if (strncmp (argv[0], "m", 1) == 0)
6753 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6754 bgp_show_type_filter_list);
6755
6756 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6757 bgp_show_type_filter_list);
6758}
6759
6760#ifdef HAVE_IPV6
6761DEFUN (show_bgp_filter_list,
6762 show_bgp_filter_list_cmd,
6763 "show bgp filter-list WORD",
6764 SHOW_STR
6765 BGP_STR
6766 "Display routes conforming to the filter-list\n"
6767 "Regular expression access list name\n")
6768{
6769 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6770 bgp_show_type_filter_list);
6771}
6772
6773ALIAS (show_bgp_filter_list,
6774 show_bgp_ipv6_filter_list_cmd,
6775 "show bgp ipv6 filter-list WORD",
6776 SHOW_STR
6777 BGP_STR
6778 "Address family\n"
6779 "Display routes conforming to the filter-list\n"
6780 "Regular expression access list name\n")
6781
6782/* old command */
6783DEFUN (show_ipv6_bgp_filter_list,
6784 show_ipv6_bgp_filter_list_cmd,
6785 "show ipv6 bgp filter-list WORD",
6786 SHOW_STR
6787 IPV6_STR
6788 BGP_STR
6789 "Display routes conforming to the filter-list\n"
6790 "Regular expression access list name\n")
6791{
6792 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6793 bgp_show_type_filter_list);
6794}
6795
6796/* old command */
6797DEFUN (show_ipv6_mbgp_filter_list,
6798 show_ipv6_mbgp_filter_list_cmd,
6799 "show ipv6 mbgp filter-list WORD",
6800 SHOW_STR
6801 IPV6_STR
6802 MBGP_STR
6803 "Display routes conforming to the filter-list\n"
6804 "Regular expression access list name\n")
6805{
6806 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6807 bgp_show_type_filter_list);
6808}
6809#endif /* HAVE_IPV6 */
6810
paul94f2b392005-06-28 12:44:16 +00006811static int
paulfd79ac92004-10-13 05:06:08 +00006812bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006813 safi_t safi, enum bgp_show_type type)
6814{
6815 struct route_map *rmap;
6816
6817 rmap = route_map_lookup_by_name (rmap_str);
6818 if (! rmap)
6819 {
6820 vty_out (vty, "%% %s is not a valid route-map name%s",
6821 rmap_str, VTY_NEWLINE);
6822 return CMD_WARNING;
6823 }
6824
ajs5a646652004-11-05 01:25:55 +00006825 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00006826}
6827
6828DEFUN (show_ip_bgp_route_map,
6829 show_ip_bgp_route_map_cmd,
6830 "show ip bgp route-map WORD",
6831 SHOW_STR
6832 IP_STR
6833 BGP_STR
6834 "Display routes matching the route-map\n"
6835 "A route-map to match on\n")
6836{
6837 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6838 bgp_show_type_route_map);
6839}
6840
6841DEFUN (show_ip_bgp_flap_route_map,
6842 show_ip_bgp_flap_route_map_cmd,
6843 "show ip bgp flap-statistics route-map WORD",
6844 SHOW_STR
6845 IP_STR
6846 BGP_STR
6847 "Display flap statistics of routes\n"
6848 "Display routes matching the route-map\n"
6849 "A route-map to match on\n")
6850{
6851 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6852 bgp_show_type_flap_route_map);
6853}
6854
6855DEFUN (show_ip_bgp_ipv4_route_map,
6856 show_ip_bgp_ipv4_route_map_cmd,
6857 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6858 SHOW_STR
6859 IP_STR
6860 BGP_STR
6861 "Address family\n"
6862 "Address Family modifier\n"
6863 "Address Family modifier\n"
6864 "Display routes matching the route-map\n"
6865 "A route-map to match on\n")
6866{
6867 if (strncmp (argv[0], "m", 1) == 0)
6868 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6869 bgp_show_type_route_map);
6870
6871 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6872 bgp_show_type_route_map);
6873}
6874
6875DEFUN (show_bgp_route_map,
6876 show_bgp_route_map_cmd,
6877 "show bgp route-map WORD",
6878 SHOW_STR
6879 BGP_STR
6880 "Display routes matching the route-map\n"
6881 "A route-map to match on\n")
6882{
6883 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6884 bgp_show_type_route_map);
6885}
6886
6887ALIAS (show_bgp_route_map,
6888 show_bgp_ipv6_route_map_cmd,
6889 "show bgp ipv6 route-map WORD",
6890 SHOW_STR
6891 BGP_STR
6892 "Address family\n"
6893 "Display routes matching the route-map\n"
6894 "A route-map to match on\n")
6895
6896DEFUN (show_ip_bgp_cidr_only,
6897 show_ip_bgp_cidr_only_cmd,
6898 "show ip bgp cidr-only",
6899 SHOW_STR
6900 IP_STR
6901 BGP_STR
6902 "Display only routes with non-natural netmasks\n")
6903{
6904 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006905 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006906}
6907
6908DEFUN (show_ip_bgp_flap_cidr_only,
6909 show_ip_bgp_flap_cidr_only_cmd,
6910 "show ip bgp flap-statistics cidr-only",
6911 SHOW_STR
6912 IP_STR
6913 BGP_STR
6914 "Display flap statistics of routes\n"
6915 "Display only routes with non-natural netmasks\n")
6916{
6917 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006918 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006919}
6920
6921DEFUN (show_ip_bgp_ipv4_cidr_only,
6922 show_ip_bgp_ipv4_cidr_only_cmd,
6923 "show ip bgp ipv4 (unicast|multicast) cidr-only",
6924 SHOW_STR
6925 IP_STR
6926 BGP_STR
6927 "Address family\n"
6928 "Address Family modifier\n"
6929 "Address Family modifier\n"
6930 "Display only routes with non-natural netmasks\n")
6931{
6932 if (strncmp (argv[0], "m", 1) == 0)
6933 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006934 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006935
6936 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006937 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006938}
6939
6940DEFUN (show_ip_bgp_community_all,
6941 show_ip_bgp_community_all_cmd,
6942 "show ip bgp community",
6943 SHOW_STR
6944 IP_STR
6945 BGP_STR
6946 "Display routes matching the communities\n")
6947{
6948 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006949 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006950}
6951
6952DEFUN (show_ip_bgp_ipv4_community_all,
6953 show_ip_bgp_ipv4_community_all_cmd,
6954 "show ip bgp ipv4 (unicast|multicast) community",
6955 SHOW_STR
6956 IP_STR
6957 BGP_STR
6958 "Address family\n"
6959 "Address Family modifier\n"
6960 "Address Family modifier\n"
6961 "Display routes matching the communities\n")
6962{
6963 if (strncmp (argv[0], "m", 1) == 0)
6964 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006965 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006966
6967 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006968 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006969}
6970
6971#ifdef HAVE_IPV6
6972DEFUN (show_bgp_community_all,
6973 show_bgp_community_all_cmd,
6974 "show bgp community",
6975 SHOW_STR
6976 BGP_STR
6977 "Display routes matching the communities\n")
6978{
6979 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006980 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006981}
6982
6983ALIAS (show_bgp_community_all,
6984 show_bgp_ipv6_community_all_cmd,
6985 "show bgp ipv6 community",
6986 SHOW_STR
6987 BGP_STR
6988 "Address family\n"
6989 "Display routes matching the communities\n")
6990
6991/* old command */
6992DEFUN (show_ipv6_bgp_community_all,
6993 show_ipv6_bgp_community_all_cmd,
6994 "show ipv6 bgp community",
6995 SHOW_STR
6996 IPV6_STR
6997 BGP_STR
6998 "Display routes matching the communities\n")
6999{
7000 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007001 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007002}
7003
7004/* old command */
7005DEFUN (show_ipv6_mbgp_community_all,
7006 show_ipv6_mbgp_community_all_cmd,
7007 "show ipv6 mbgp community",
7008 SHOW_STR
7009 IPV6_STR
7010 MBGP_STR
7011 "Display routes matching the communities\n")
7012{
7013 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007014 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007015}
7016#endif /* HAVE_IPV6 */
7017
paul94f2b392005-06-28 12:44:16 +00007018static int
paulfd79ac92004-10-13 05:06:08 +00007019bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7020 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007021{
7022 struct community *com;
7023 struct buffer *b;
7024 int i;
7025 char *str;
7026 int first = 0;
7027
7028 b = buffer_new (1024);
7029 for (i = 0; i < argc; i++)
7030 {
7031 if (first)
7032 buffer_putc (b, ' ');
7033 else
7034 {
7035 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7036 continue;
7037 first = 1;
7038 }
7039
7040 buffer_putstr (b, argv[i]);
7041 }
7042 buffer_putc (b, '\0');
7043
7044 str = buffer_getstr (b);
7045 buffer_free (b);
7046
7047 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007048 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007049 if (! com)
7050 {
7051 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7052 return CMD_WARNING;
7053 }
7054
ajs5a646652004-11-05 01:25:55 +00007055 return bgp_show (vty, NULL, afi, safi,
7056 (exact ? bgp_show_type_community_exact :
7057 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007058}
7059
7060DEFUN (show_ip_bgp_community,
7061 show_ip_bgp_community_cmd,
7062 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7063 SHOW_STR
7064 IP_STR
7065 BGP_STR
7066 "Display routes matching the communities\n"
7067 "community number\n"
7068 "Do not send outside local AS (well-known community)\n"
7069 "Do not advertise to any peer (well-known community)\n"
7070 "Do not export to next AS (well-known community)\n")
7071{
7072 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7073}
7074
7075ALIAS (show_ip_bgp_community,
7076 show_ip_bgp_community2_cmd,
7077 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7078 SHOW_STR
7079 IP_STR
7080 BGP_STR
7081 "Display routes matching the communities\n"
7082 "community number\n"
7083 "Do not send outside local AS (well-known community)\n"
7084 "Do not advertise to any peer (well-known community)\n"
7085 "Do not export to next AS (well-known community)\n"
7086 "community number\n"
7087 "Do not send outside local AS (well-known community)\n"
7088 "Do not advertise to any peer (well-known community)\n"
7089 "Do not export to next AS (well-known community)\n")
7090
7091ALIAS (show_ip_bgp_community,
7092 show_ip_bgp_community3_cmd,
7093 "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)",
7094 SHOW_STR
7095 IP_STR
7096 BGP_STR
7097 "Display routes matching the communities\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 "community number\n"
7103 "Do not send outside local AS (well-known community)\n"
7104 "Do not advertise to any peer (well-known community)\n"
7105 "Do not export to next AS (well-known community)\n"
7106 "community number\n"
7107 "Do not send outside local AS (well-known community)\n"
7108 "Do not advertise to any peer (well-known community)\n"
7109 "Do not export to next AS (well-known community)\n")
7110
7111ALIAS (show_ip_bgp_community,
7112 show_ip_bgp_community4_cmd,
7113 "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)",
7114 SHOW_STR
7115 IP_STR
7116 BGP_STR
7117 "Display routes matching the communities\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 "community number\n"
7127 "Do not send outside local AS (well-known community)\n"
7128 "Do not advertise to any peer (well-known community)\n"
7129 "Do not export to next AS (well-known community)\n"
7130 "community number\n"
7131 "Do not send outside local AS (well-known community)\n"
7132 "Do not advertise to any peer (well-known community)\n"
7133 "Do not export to next AS (well-known community)\n")
7134
7135DEFUN (show_ip_bgp_ipv4_community,
7136 show_ip_bgp_ipv4_community_cmd,
7137 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7138 SHOW_STR
7139 IP_STR
7140 BGP_STR
7141 "Address family\n"
7142 "Address Family modifier\n"
7143 "Address Family modifier\n"
7144 "Display routes matching the communities\n"
7145 "community number\n"
7146 "Do not send outside local AS (well-known community)\n"
7147 "Do not advertise to any peer (well-known community)\n"
7148 "Do not export to next AS (well-known community)\n")
7149{
7150 if (strncmp (argv[0], "m", 1) == 0)
7151 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7152
7153 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7154}
7155
7156ALIAS (show_ip_bgp_ipv4_community,
7157 show_ip_bgp_ipv4_community2_cmd,
7158 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7159 SHOW_STR
7160 IP_STR
7161 BGP_STR
7162 "Address family\n"
7163 "Address Family modifier\n"
7164 "Address Family modifier\n"
7165 "Display routes matching the communities\n"
7166 "community number\n"
7167 "Do not send outside local AS (well-known community)\n"
7168 "Do not advertise to any peer (well-known community)\n"
7169 "Do not export to next AS (well-known community)\n"
7170 "community number\n"
7171 "Do not send outside local AS (well-known community)\n"
7172 "Do not advertise to any peer (well-known community)\n"
7173 "Do not export to next AS (well-known community)\n")
7174
7175ALIAS (show_ip_bgp_ipv4_community,
7176 show_ip_bgp_ipv4_community3_cmd,
7177 "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)",
7178 SHOW_STR
7179 IP_STR
7180 BGP_STR
7181 "Address family\n"
7182 "Address Family modifier\n"
7183 "Address Family modifier\n"
7184 "Display routes matching the communities\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 "community number\n"
7190 "Do not send outside local AS (well-known community)\n"
7191 "Do not advertise to any peer (well-known community)\n"
7192 "Do not export to next AS (well-known community)\n"
7193 "community number\n"
7194 "Do not send outside local AS (well-known community)\n"
7195 "Do not advertise to any peer (well-known community)\n"
7196 "Do not export to next AS (well-known community)\n")
7197
7198ALIAS (show_ip_bgp_ipv4_community,
7199 show_ip_bgp_ipv4_community4_cmd,
7200 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7201 SHOW_STR
7202 IP_STR
7203 BGP_STR
7204 "Address family\n"
7205 "Address Family modifier\n"
7206 "Address Family modifier\n"
7207 "Display routes matching the communities\n"
7208 "community number\n"
7209 "Do not send outside local AS (well-known community)\n"
7210 "Do not advertise to any peer (well-known community)\n"
7211 "Do not export to next AS (well-known community)\n"
7212 "community number\n"
7213 "Do not send outside local AS (well-known community)\n"
7214 "Do not advertise to any peer (well-known community)\n"
7215 "Do not export to next AS (well-known community)\n"
7216 "community number\n"
7217 "Do not send outside local AS (well-known community)\n"
7218 "Do not advertise to any peer (well-known community)\n"
7219 "Do not export to next AS (well-known community)\n"
7220 "community number\n"
7221 "Do not send outside local AS (well-known community)\n"
7222 "Do not advertise to any peer (well-known community)\n"
7223 "Do not export to next AS (well-known community)\n")
7224
7225DEFUN (show_ip_bgp_community_exact,
7226 show_ip_bgp_community_exact_cmd,
7227 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7228 SHOW_STR
7229 IP_STR
7230 BGP_STR
7231 "Display routes matching the communities\n"
7232 "community number\n"
7233 "Do not send outside local AS (well-known community)\n"
7234 "Do not advertise to any peer (well-known community)\n"
7235 "Do not export to next AS (well-known community)\n"
7236 "Exact match of the communities")
7237{
7238 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7239}
7240
7241ALIAS (show_ip_bgp_community_exact,
7242 show_ip_bgp_community2_exact_cmd,
7243 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7244 SHOW_STR
7245 IP_STR
7246 BGP_STR
7247 "Display routes matching the communities\n"
7248 "community number\n"
7249 "Do not send outside local AS (well-known community)\n"
7250 "Do not advertise to any peer (well-known community)\n"
7251 "Do not export to next AS (well-known community)\n"
7252 "community number\n"
7253 "Do not send outside local AS (well-known community)\n"
7254 "Do not advertise to any peer (well-known community)\n"
7255 "Do not export to next AS (well-known community)\n"
7256 "Exact match of the communities")
7257
7258ALIAS (show_ip_bgp_community_exact,
7259 show_ip_bgp_community3_exact_cmd,
7260 "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",
7261 SHOW_STR
7262 IP_STR
7263 BGP_STR
7264 "Display routes matching the communities\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 "community number\n"
7270 "Do not send outside local AS (well-known community)\n"
7271 "Do not advertise to any peer (well-known community)\n"
7272 "Do not export to next AS (well-known community)\n"
7273 "community number\n"
7274 "Do not send outside local AS (well-known community)\n"
7275 "Do not advertise to any peer (well-known community)\n"
7276 "Do not export to next AS (well-known community)\n"
7277 "Exact match of the communities")
7278
7279ALIAS (show_ip_bgp_community_exact,
7280 show_ip_bgp_community4_exact_cmd,
7281 "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",
7282 SHOW_STR
7283 IP_STR
7284 BGP_STR
7285 "Display routes matching the communities\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 "community number\n"
7295 "Do not send outside local AS (well-known community)\n"
7296 "Do not advertise to any peer (well-known community)\n"
7297 "Do not export to next AS (well-known community)\n"
7298 "community number\n"
7299 "Do not send outside local AS (well-known community)\n"
7300 "Do not advertise to any peer (well-known community)\n"
7301 "Do not export to next AS (well-known community)\n"
7302 "Exact match of the communities")
7303
7304DEFUN (show_ip_bgp_ipv4_community_exact,
7305 show_ip_bgp_ipv4_community_exact_cmd,
7306 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7307 SHOW_STR
7308 IP_STR
7309 BGP_STR
7310 "Address family\n"
7311 "Address Family modifier\n"
7312 "Address Family modifier\n"
7313 "Display routes matching the communities\n"
7314 "community number\n"
7315 "Do not send outside local AS (well-known community)\n"
7316 "Do not advertise to any peer (well-known community)\n"
7317 "Do not export to next AS (well-known community)\n"
7318 "Exact match of the communities")
7319{
7320 if (strncmp (argv[0], "m", 1) == 0)
7321 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7322
7323 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7324}
7325
7326ALIAS (show_ip_bgp_ipv4_community_exact,
7327 show_ip_bgp_ipv4_community2_exact_cmd,
7328 "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",
7329 SHOW_STR
7330 IP_STR
7331 BGP_STR
7332 "Address family\n"
7333 "Address Family modifier\n"
7334 "Address Family modifier\n"
7335 "Display routes matching the communities\n"
7336 "community number\n"
7337 "Do not send outside local AS (well-known community)\n"
7338 "Do not advertise to any peer (well-known community)\n"
7339 "Do not export to next AS (well-known community)\n"
7340 "community number\n"
7341 "Do not send outside local AS (well-known community)\n"
7342 "Do not advertise to any peer (well-known community)\n"
7343 "Do not export to next AS (well-known community)\n"
7344 "Exact match of the communities")
7345
7346ALIAS (show_ip_bgp_ipv4_community_exact,
7347 show_ip_bgp_ipv4_community3_exact_cmd,
7348 "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",
7349 SHOW_STR
7350 IP_STR
7351 BGP_STR
7352 "Address family\n"
7353 "Address Family modifier\n"
7354 "Address Family modifier\n"
7355 "Display routes matching the communities\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 "community number\n"
7361 "Do not send outside local AS (well-known community)\n"
7362 "Do not advertise to any peer (well-known community)\n"
7363 "Do not export to next AS (well-known community)\n"
7364 "community number\n"
7365 "Do not send outside local AS (well-known community)\n"
7366 "Do not advertise to any peer (well-known community)\n"
7367 "Do not export to next AS (well-known community)\n"
7368 "Exact match of the communities")
7369
7370ALIAS (show_ip_bgp_ipv4_community_exact,
7371 show_ip_bgp_ipv4_community4_exact_cmd,
7372 "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",
7373 SHOW_STR
7374 IP_STR
7375 BGP_STR
7376 "Address family\n"
7377 "Address Family modifier\n"
7378 "Address Family modifier\n"
7379 "Display routes matching the communities\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 "community number\n"
7389 "Do not send outside local AS (well-known community)\n"
7390 "Do not advertise to any peer (well-known community)\n"
7391 "Do not export to next AS (well-known community)\n"
7392 "community number\n"
7393 "Do not send outside local AS (well-known community)\n"
7394 "Do not advertise to any peer (well-known community)\n"
7395 "Do not export to next AS (well-known community)\n"
7396 "Exact match of the communities")
7397
7398#ifdef HAVE_IPV6
7399DEFUN (show_bgp_community,
7400 show_bgp_community_cmd,
7401 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7402 SHOW_STR
7403 BGP_STR
7404 "Display routes matching the communities\n"
7405 "community number\n"
7406 "Do not send outside local AS (well-known community)\n"
7407 "Do not advertise to any peer (well-known community)\n"
7408 "Do not export to next AS (well-known community)\n")
7409{
7410 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7411}
7412
7413ALIAS (show_bgp_community,
7414 show_bgp_ipv6_community_cmd,
7415 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7416 SHOW_STR
7417 BGP_STR
7418 "Address family\n"
7419 "Display routes matching the communities\n"
7420 "community number\n"
7421 "Do not send outside local AS (well-known community)\n"
7422 "Do not advertise to any peer (well-known community)\n"
7423 "Do not export to next AS (well-known community)\n")
7424
7425ALIAS (show_bgp_community,
7426 show_bgp_community2_cmd,
7427 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7428 SHOW_STR
7429 BGP_STR
7430 "Display routes matching the communities\n"
7431 "community number\n"
7432 "Do not send outside local AS (well-known community)\n"
7433 "Do not advertise to any peer (well-known community)\n"
7434 "Do not export to next AS (well-known community)\n"
7435 "community number\n"
7436 "Do not send outside local AS (well-known community)\n"
7437 "Do not advertise to any peer (well-known community)\n"
7438 "Do not export to next AS (well-known community)\n")
7439
7440ALIAS (show_bgp_community,
7441 show_bgp_ipv6_community2_cmd,
7442 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7443 SHOW_STR
7444 BGP_STR
7445 "Address family\n"
7446 "Display routes matching the communities\n"
7447 "community number\n"
7448 "Do not send outside local AS (well-known community)\n"
7449 "Do not advertise to any peer (well-known community)\n"
7450 "Do not export to next AS (well-known community)\n"
7451 "community number\n"
7452 "Do not send outside local AS (well-known community)\n"
7453 "Do not advertise to any peer (well-known community)\n"
7454 "Do not export to next AS (well-known community)\n")
7455
7456ALIAS (show_bgp_community,
7457 show_bgp_community3_cmd,
7458 "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)",
7459 SHOW_STR
7460 BGP_STR
7461 "Display routes matching the communities\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 "community number\n"
7467 "Do not send outside local AS (well-known community)\n"
7468 "Do not advertise to any peer (well-known community)\n"
7469 "Do not export to next AS (well-known community)\n"
7470 "community number\n"
7471 "Do not send outside local AS (well-known community)\n"
7472 "Do not advertise to any peer (well-known community)\n"
7473 "Do not export to next AS (well-known community)\n")
7474
7475ALIAS (show_bgp_community,
7476 show_bgp_ipv6_community3_cmd,
7477 "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)",
7478 SHOW_STR
7479 BGP_STR
7480 "Address family\n"
7481 "Display routes matching the communities\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 "community number\n"
7487 "Do not send outside local AS (well-known community)\n"
7488 "Do not advertise to any peer (well-known community)\n"
7489 "Do not export to next AS (well-known community)\n"
7490 "community number\n"
7491 "Do not send outside local AS (well-known community)\n"
7492 "Do not advertise to any peer (well-known community)\n"
7493 "Do not export to next AS (well-known community)\n")
7494
7495ALIAS (show_bgp_community,
7496 show_bgp_community4_cmd,
7497 "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)",
7498 SHOW_STR
7499 BGP_STR
7500 "Display routes matching the communities\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 "community number\n"
7510 "Do not send outside local AS (well-known community)\n"
7511 "Do not advertise to any peer (well-known community)\n"
7512 "Do not export to next AS (well-known community)\n"
7513 "community number\n"
7514 "Do not send outside local AS (well-known community)\n"
7515 "Do not advertise to any peer (well-known community)\n"
7516 "Do not export to next AS (well-known community)\n")
7517
7518ALIAS (show_bgp_community,
7519 show_bgp_ipv6_community4_cmd,
7520 "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)",
7521 SHOW_STR
7522 BGP_STR
7523 "Address family\n"
7524 "Display routes matching the communities\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 "community number\n"
7534 "Do not send outside local AS (well-known community)\n"
7535 "Do not advertise to any peer (well-known community)\n"
7536 "Do not export to next AS (well-known community)\n"
7537 "community number\n"
7538 "Do not send outside local AS (well-known community)\n"
7539 "Do not advertise to any peer (well-known community)\n"
7540 "Do not export to next AS (well-known community)\n")
7541
7542/* old command */
7543DEFUN (show_ipv6_bgp_community,
7544 show_ipv6_bgp_community_cmd,
7545 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7546 SHOW_STR
7547 IPV6_STR
7548 BGP_STR
7549 "Display routes matching the communities\n"
7550 "community number\n"
7551 "Do not send outside local AS (well-known community)\n"
7552 "Do not advertise to any peer (well-known community)\n"
7553 "Do not export to next AS (well-known community)\n")
7554{
7555 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7556}
7557
7558/* old command */
7559ALIAS (show_ipv6_bgp_community,
7560 show_ipv6_bgp_community2_cmd,
7561 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7562 SHOW_STR
7563 IPV6_STR
7564 BGP_STR
7565 "Display routes matching the communities\n"
7566 "community number\n"
7567 "Do not send outside local AS (well-known community)\n"
7568 "Do not advertise to any peer (well-known community)\n"
7569 "Do not export to next AS (well-known community)\n"
7570 "community number\n"
7571 "Do not send outside local AS (well-known community)\n"
7572 "Do not advertise to any peer (well-known community)\n"
7573 "Do not export to next AS (well-known community)\n")
7574
7575/* old command */
7576ALIAS (show_ipv6_bgp_community,
7577 show_ipv6_bgp_community3_cmd,
7578 "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)",
7579 SHOW_STR
7580 IPV6_STR
7581 BGP_STR
7582 "Display routes matching the communities\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 "community number\n"
7588 "Do not send outside local AS (well-known community)\n"
7589 "Do not advertise to any peer (well-known community)\n"
7590 "Do not export to next AS (well-known community)\n"
7591 "community number\n"
7592 "Do not send outside local AS (well-known community)\n"
7593 "Do not advertise to any peer (well-known community)\n"
7594 "Do not export to next AS (well-known community)\n")
7595
7596/* old command */
7597ALIAS (show_ipv6_bgp_community,
7598 show_ipv6_bgp_community4_cmd,
7599 "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)",
7600 SHOW_STR
7601 IPV6_STR
7602 BGP_STR
7603 "Display routes matching the communities\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 "community number\n"
7613 "Do not send outside local AS (well-known community)\n"
7614 "Do not advertise to any peer (well-known community)\n"
7615 "Do not export to next AS (well-known community)\n"
7616 "community number\n"
7617 "Do not send outside local AS (well-known community)\n"
7618 "Do not advertise to any peer (well-known community)\n"
7619 "Do not export to next AS (well-known community)\n")
7620
7621DEFUN (show_bgp_community_exact,
7622 show_bgp_community_exact_cmd,
7623 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7624 SHOW_STR
7625 BGP_STR
7626 "Display routes matching the communities\n"
7627 "community number\n"
7628 "Do not send outside local AS (well-known community)\n"
7629 "Do not advertise to any peer (well-known community)\n"
7630 "Do not export to next AS (well-known community)\n"
7631 "Exact match of the communities")
7632{
7633 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7634}
7635
7636ALIAS (show_bgp_community_exact,
7637 show_bgp_ipv6_community_exact_cmd,
7638 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7639 SHOW_STR
7640 BGP_STR
7641 "Address family\n"
7642 "Display routes matching the communities\n"
7643 "community number\n"
7644 "Do not send outside local AS (well-known community)\n"
7645 "Do not advertise to any peer (well-known community)\n"
7646 "Do not export to next AS (well-known community)\n"
7647 "Exact match of the communities")
7648
7649ALIAS (show_bgp_community_exact,
7650 show_bgp_community2_exact_cmd,
7651 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7652 SHOW_STR
7653 BGP_STR
7654 "Display routes matching the communities\n"
7655 "community number\n"
7656 "Do not send outside local AS (well-known community)\n"
7657 "Do not advertise to any peer (well-known community)\n"
7658 "Do not export to next AS (well-known community)\n"
7659 "community number\n"
7660 "Do not send outside local AS (well-known community)\n"
7661 "Do not advertise to any peer (well-known community)\n"
7662 "Do not export to next AS (well-known community)\n"
7663 "Exact match of the communities")
7664
7665ALIAS (show_bgp_community_exact,
7666 show_bgp_ipv6_community2_exact_cmd,
7667 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7668 SHOW_STR
7669 BGP_STR
7670 "Address family\n"
7671 "Display routes matching the communities\n"
7672 "community number\n"
7673 "Do not send outside local AS (well-known community)\n"
7674 "Do not advertise to any peer (well-known community)\n"
7675 "Do not export to next AS (well-known community)\n"
7676 "community number\n"
7677 "Do not send outside local AS (well-known community)\n"
7678 "Do not advertise to any peer (well-known community)\n"
7679 "Do not export to next AS (well-known community)\n"
7680 "Exact match of the communities")
7681
7682ALIAS (show_bgp_community_exact,
7683 show_bgp_community3_exact_cmd,
7684 "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",
7685 SHOW_STR
7686 BGP_STR
7687 "Display routes matching the communities\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 "community number\n"
7693 "Do not send outside local AS (well-known community)\n"
7694 "Do not advertise to any peer (well-known community)\n"
7695 "Do not export to next AS (well-known community)\n"
7696 "community number\n"
7697 "Do not send outside local AS (well-known community)\n"
7698 "Do not advertise to any peer (well-known community)\n"
7699 "Do not export to next AS (well-known community)\n"
7700 "Exact match of the communities")
7701
7702ALIAS (show_bgp_community_exact,
7703 show_bgp_ipv6_community3_exact_cmd,
7704 "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",
7705 SHOW_STR
7706 BGP_STR
7707 "Address family\n"
7708 "Display routes matching the communities\n"
7709 "community number\n"
7710 "Do not send outside local AS (well-known community)\n"
7711 "Do not advertise to any peer (well-known community)\n"
7712 "Do not export to next AS (well-known community)\n"
7713 "community number\n"
7714 "Do not send outside local AS (well-known community)\n"
7715 "Do not advertise to any peer (well-known community)\n"
7716 "Do not export to next AS (well-known community)\n"
7717 "community number\n"
7718 "Do not send outside local AS (well-known community)\n"
7719 "Do not advertise to any peer (well-known community)\n"
7720 "Do not export to next AS (well-known community)\n"
7721 "Exact match of the communities")
7722
7723ALIAS (show_bgp_community_exact,
7724 show_bgp_community4_exact_cmd,
7725 "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",
7726 SHOW_STR
7727 BGP_STR
7728 "Display routes matching the communities\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 "community number\n"
7738 "Do not send outside local AS (well-known community)\n"
7739 "Do not advertise to any peer (well-known community)\n"
7740 "Do not export to next AS (well-known community)\n"
7741 "community number\n"
7742 "Do not send outside local AS (well-known community)\n"
7743 "Do not advertise to any peer (well-known community)\n"
7744 "Do not export to next AS (well-known community)\n"
7745 "Exact match of the communities")
7746
7747ALIAS (show_bgp_community_exact,
7748 show_bgp_ipv6_community4_exact_cmd,
7749 "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",
7750 SHOW_STR
7751 BGP_STR
7752 "Address family\n"
7753 "Display routes matching the communities\n"
7754 "community number\n"
7755 "Do not send outside local AS (well-known community)\n"
7756 "Do not advertise to any peer (well-known community)\n"
7757 "Do not export to next AS (well-known community)\n"
7758 "community number\n"
7759 "Do not send outside local AS (well-known community)\n"
7760 "Do not advertise to any peer (well-known community)\n"
7761 "Do not export to next AS (well-known community)\n"
7762 "community number\n"
7763 "Do not send outside local AS (well-known community)\n"
7764 "Do not advertise to any peer (well-known community)\n"
7765 "Do not export to next AS (well-known community)\n"
7766 "community number\n"
7767 "Do not send outside local AS (well-known community)\n"
7768 "Do not advertise to any peer (well-known community)\n"
7769 "Do not export to next AS (well-known community)\n"
7770 "Exact match of the communities")
7771
7772/* old command */
7773DEFUN (show_ipv6_bgp_community_exact,
7774 show_ipv6_bgp_community_exact_cmd,
7775 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7776 SHOW_STR
7777 IPV6_STR
7778 BGP_STR
7779 "Display routes matching the communities\n"
7780 "community number\n"
7781 "Do not send outside local AS (well-known community)\n"
7782 "Do not advertise to any peer (well-known community)\n"
7783 "Do not export to next AS (well-known community)\n"
7784 "Exact match of the communities")
7785{
7786 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7787}
7788
7789/* old command */
7790ALIAS (show_ipv6_bgp_community_exact,
7791 show_ipv6_bgp_community2_exact_cmd,
7792 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7793 SHOW_STR
7794 IPV6_STR
7795 BGP_STR
7796 "Display routes matching the communities\n"
7797 "community number\n"
7798 "Do not send outside local AS (well-known community)\n"
7799 "Do not advertise to any peer (well-known community)\n"
7800 "Do not export to next AS (well-known community)\n"
7801 "community number\n"
7802 "Do not send outside local AS (well-known community)\n"
7803 "Do not advertise to any peer (well-known community)\n"
7804 "Do not export to next AS (well-known community)\n"
7805 "Exact match of the communities")
7806
7807/* old command */
7808ALIAS (show_ipv6_bgp_community_exact,
7809 show_ipv6_bgp_community3_exact_cmd,
7810 "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",
7811 SHOW_STR
7812 IPV6_STR
7813 BGP_STR
7814 "Display routes matching the communities\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 "community number\n"
7820 "Do not send outside local AS (well-known community)\n"
7821 "Do not advertise to any peer (well-known community)\n"
7822 "Do not export to next AS (well-known community)\n"
7823 "community number\n"
7824 "Do not send outside local AS (well-known community)\n"
7825 "Do not advertise to any peer (well-known community)\n"
7826 "Do not export to next AS (well-known community)\n"
7827 "Exact match of the communities")
7828
7829/* old command */
7830ALIAS (show_ipv6_bgp_community_exact,
7831 show_ipv6_bgp_community4_exact_cmd,
7832 "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",
7833 SHOW_STR
7834 IPV6_STR
7835 BGP_STR
7836 "Display routes matching the communities\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 "community number\n"
7846 "Do not send outside local AS (well-known community)\n"
7847 "Do not advertise to any peer (well-known community)\n"
7848 "Do not export to next AS (well-known community)\n"
7849 "community number\n"
7850 "Do not send outside local AS (well-known community)\n"
7851 "Do not advertise to any peer (well-known community)\n"
7852 "Do not export to next AS (well-known community)\n"
7853 "Exact match of the communities")
7854
7855/* old command */
7856DEFUN (show_ipv6_mbgp_community,
7857 show_ipv6_mbgp_community_cmd,
7858 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7859 SHOW_STR
7860 IPV6_STR
7861 MBGP_STR
7862 "Display routes matching the communities\n"
7863 "community number\n"
7864 "Do not send outside local AS (well-known community)\n"
7865 "Do not advertise to any peer (well-known community)\n"
7866 "Do not export to next AS (well-known community)\n")
7867{
7868 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7869}
7870
7871/* old command */
7872ALIAS (show_ipv6_mbgp_community,
7873 show_ipv6_mbgp_community2_cmd,
7874 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7875 SHOW_STR
7876 IPV6_STR
7877 MBGP_STR
7878 "Display routes matching the communities\n"
7879 "community number\n"
7880 "Do not send outside local AS (well-known community)\n"
7881 "Do not advertise to any peer (well-known community)\n"
7882 "Do not export to next AS (well-known community)\n"
7883 "community number\n"
7884 "Do not send outside local AS (well-known community)\n"
7885 "Do not advertise to any peer (well-known community)\n"
7886 "Do not export to next AS (well-known community)\n")
7887
7888/* old command */
7889ALIAS (show_ipv6_mbgp_community,
7890 show_ipv6_mbgp_community3_cmd,
7891 "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)",
7892 SHOW_STR
7893 IPV6_STR
7894 MBGP_STR
7895 "Display routes matching the communities\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 "community number\n"
7901 "Do not send outside local AS (well-known community)\n"
7902 "Do not advertise to any peer (well-known community)\n"
7903 "Do not export to next AS (well-known community)\n"
7904 "community number\n"
7905 "Do not send outside local AS (well-known community)\n"
7906 "Do not advertise to any peer (well-known community)\n"
7907 "Do not export to next AS (well-known community)\n")
7908
7909/* old command */
7910ALIAS (show_ipv6_mbgp_community,
7911 show_ipv6_mbgp_community4_cmd,
7912 "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)",
7913 SHOW_STR
7914 IPV6_STR
7915 MBGP_STR
7916 "Display routes matching the communities\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 "community number\n"
7926 "Do not send outside local AS (well-known community)\n"
7927 "Do not advertise to any peer (well-known community)\n"
7928 "Do not export to next AS (well-known community)\n"
7929 "community number\n"
7930 "Do not send outside local AS (well-known community)\n"
7931 "Do not advertise to any peer (well-known community)\n"
7932 "Do not export to next AS (well-known community)\n")
7933
7934/* old command */
7935DEFUN (show_ipv6_mbgp_community_exact,
7936 show_ipv6_mbgp_community_exact_cmd,
7937 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7938 SHOW_STR
7939 IPV6_STR
7940 MBGP_STR
7941 "Display routes matching the communities\n"
7942 "community number\n"
7943 "Do not send outside local AS (well-known community)\n"
7944 "Do not advertise to any peer (well-known community)\n"
7945 "Do not export to next AS (well-known community)\n"
7946 "Exact match of the communities")
7947{
7948 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7949}
7950
7951/* old command */
7952ALIAS (show_ipv6_mbgp_community_exact,
7953 show_ipv6_mbgp_community2_exact_cmd,
7954 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7955 SHOW_STR
7956 IPV6_STR
7957 MBGP_STR
7958 "Display routes matching the communities\n"
7959 "community number\n"
7960 "Do not send outside local AS (well-known community)\n"
7961 "Do not advertise to any peer (well-known community)\n"
7962 "Do not export to next AS (well-known community)\n"
7963 "community number\n"
7964 "Do not send outside local AS (well-known community)\n"
7965 "Do not advertise to any peer (well-known community)\n"
7966 "Do not export to next AS (well-known community)\n"
7967 "Exact match of the communities")
7968
7969/* old command */
7970ALIAS (show_ipv6_mbgp_community_exact,
7971 show_ipv6_mbgp_community3_exact_cmd,
7972 "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",
7973 SHOW_STR
7974 IPV6_STR
7975 MBGP_STR
7976 "Display routes matching the communities\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 "community number\n"
7982 "Do not send outside local AS (well-known community)\n"
7983 "Do not advertise to any peer (well-known community)\n"
7984 "Do not export to next AS (well-known community)\n"
7985 "community number\n"
7986 "Do not send outside local AS (well-known community)\n"
7987 "Do not advertise to any peer (well-known community)\n"
7988 "Do not export to next AS (well-known community)\n"
7989 "Exact match of the communities")
7990
7991/* old command */
7992ALIAS (show_ipv6_mbgp_community_exact,
7993 show_ipv6_mbgp_community4_exact_cmd,
7994 "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",
7995 SHOW_STR
7996 IPV6_STR
7997 MBGP_STR
7998 "Display routes matching the communities\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 "community number\n"
8008 "Do not send outside local AS (well-known community)\n"
8009 "Do not advertise to any peer (well-known community)\n"
8010 "Do not export to next AS (well-known community)\n"
8011 "community number\n"
8012 "Do not send outside local AS (well-known community)\n"
8013 "Do not advertise to any peer (well-known community)\n"
8014 "Do not export to next AS (well-known community)\n"
8015 "Exact match of the communities")
8016#endif /* HAVE_IPV6 */
8017
paul94f2b392005-06-28 12:44:16 +00008018static int
paulfd79ac92004-10-13 05:06:08 +00008019bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008020 u_int16_t afi, u_char safi)
8021{
8022 struct community_list *list;
8023
hassofee6e4e2005-02-02 16:29:31 +00008024 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008025 if (list == NULL)
8026 {
8027 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8028 VTY_NEWLINE);
8029 return CMD_WARNING;
8030 }
8031
ajs5a646652004-11-05 01:25:55 +00008032 return bgp_show (vty, NULL, afi, safi,
8033 (exact ? bgp_show_type_community_list_exact :
8034 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008035}
8036
8037DEFUN (show_ip_bgp_community_list,
8038 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008039 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008040 SHOW_STR
8041 IP_STR
8042 BGP_STR
8043 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008044 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008045 "community-list name\n")
8046{
8047 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8048}
8049
8050DEFUN (show_ip_bgp_ipv4_community_list,
8051 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008052 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008053 SHOW_STR
8054 IP_STR
8055 BGP_STR
8056 "Address family\n"
8057 "Address Family modifier\n"
8058 "Address Family modifier\n"
8059 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008060 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008061 "community-list name\n")
8062{
8063 if (strncmp (argv[0], "m", 1) == 0)
8064 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8065
8066 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8067}
8068
8069DEFUN (show_ip_bgp_community_list_exact,
8070 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008071 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008072 SHOW_STR
8073 IP_STR
8074 BGP_STR
8075 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008076 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008077 "community-list name\n"
8078 "Exact match of the communities\n")
8079{
8080 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8081}
8082
8083DEFUN (show_ip_bgp_ipv4_community_list_exact,
8084 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008085 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008086 SHOW_STR
8087 IP_STR
8088 BGP_STR
8089 "Address family\n"
8090 "Address Family modifier\n"
8091 "Address Family modifier\n"
8092 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008093 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008094 "community-list name\n"
8095 "Exact match of the communities\n")
8096{
8097 if (strncmp (argv[0], "m", 1) == 0)
8098 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8099
8100 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8101}
8102
8103#ifdef HAVE_IPV6
8104DEFUN (show_bgp_community_list,
8105 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008106 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008107 SHOW_STR
8108 BGP_STR
8109 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008110 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008111 "community-list name\n")
8112{
8113 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8114}
8115
8116ALIAS (show_bgp_community_list,
8117 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008118 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008119 SHOW_STR
8120 BGP_STR
8121 "Address family\n"
8122 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008123 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008124 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008125
8126/* old command */
8127DEFUN (show_ipv6_bgp_community_list,
8128 show_ipv6_bgp_community_list_cmd,
8129 "show ipv6 bgp community-list WORD",
8130 SHOW_STR
8131 IPV6_STR
8132 BGP_STR
8133 "Display routes matching the community-list\n"
8134 "community-list name\n")
8135{
8136 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8137}
8138
8139/* old command */
8140DEFUN (show_ipv6_mbgp_community_list,
8141 show_ipv6_mbgp_community_list_cmd,
8142 "show ipv6 mbgp community-list WORD",
8143 SHOW_STR
8144 IPV6_STR
8145 MBGP_STR
8146 "Display routes matching the community-list\n"
8147 "community-list name\n")
8148{
8149 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8150}
8151
8152DEFUN (show_bgp_community_list_exact,
8153 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008154 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008155 SHOW_STR
8156 BGP_STR
8157 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008158 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008159 "community-list name\n"
8160 "Exact match of the communities\n")
8161{
8162 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8163}
8164
8165ALIAS (show_bgp_community_list_exact,
8166 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008167 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008168 SHOW_STR
8169 BGP_STR
8170 "Address family\n"
8171 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008172 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008173 "community-list name\n"
8174 "Exact match of the communities\n")
8175
8176/* old command */
8177DEFUN (show_ipv6_bgp_community_list_exact,
8178 show_ipv6_bgp_community_list_exact_cmd,
8179 "show ipv6 bgp community-list WORD exact-match",
8180 SHOW_STR
8181 IPV6_STR
8182 BGP_STR
8183 "Display routes matching the community-list\n"
8184 "community-list name\n"
8185 "Exact match of the communities\n")
8186{
8187 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8188}
8189
8190/* old command */
8191DEFUN (show_ipv6_mbgp_community_list_exact,
8192 show_ipv6_mbgp_community_list_exact_cmd,
8193 "show ipv6 mbgp community-list WORD exact-match",
8194 SHOW_STR
8195 IPV6_STR
8196 MBGP_STR
8197 "Display routes matching the community-list\n"
8198 "community-list name\n"
8199 "Exact match of the communities\n")
8200{
8201 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8202}
8203#endif /* HAVE_IPV6 */
8204
paul94f2b392005-06-28 12:44:16 +00008205static int
paulfd79ac92004-10-13 05:06:08 +00008206bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008207 safi_t safi, enum bgp_show_type type)
8208{
8209 int ret;
8210 struct prefix *p;
8211
8212 p = prefix_new();
8213
8214 ret = str2prefix (prefix, p);
8215 if (! ret)
8216 {
8217 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8218 return CMD_WARNING;
8219 }
8220
ajs5a646652004-11-05 01:25:55 +00008221 ret = bgp_show (vty, NULL, afi, safi, type, p);
8222 prefix_free(p);
8223 return ret;
paul718e3742002-12-13 20:15:29 +00008224}
8225
8226DEFUN (show_ip_bgp_prefix_longer,
8227 show_ip_bgp_prefix_longer_cmd,
8228 "show ip bgp A.B.C.D/M longer-prefixes",
8229 SHOW_STR
8230 IP_STR
8231 BGP_STR
8232 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8233 "Display route and more specific routes\n")
8234{
8235 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8236 bgp_show_type_prefix_longer);
8237}
8238
8239DEFUN (show_ip_bgp_flap_prefix_longer,
8240 show_ip_bgp_flap_prefix_longer_cmd,
8241 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8242 SHOW_STR
8243 IP_STR
8244 BGP_STR
8245 "Display flap statistics of routes\n"
8246 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8247 "Display route and more specific routes\n")
8248{
8249 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8250 bgp_show_type_flap_prefix_longer);
8251}
8252
8253DEFUN (show_ip_bgp_ipv4_prefix_longer,
8254 show_ip_bgp_ipv4_prefix_longer_cmd,
8255 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8256 SHOW_STR
8257 IP_STR
8258 BGP_STR
8259 "Address family\n"
8260 "Address Family modifier\n"
8261 "Address Family modifier\n"
8262 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8263 "Display route and more specific routes\n")
8264{
8265 if (strncmp (argv[0], "m", 1) == 0)
8266 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8267 bgp_show_type_prefix_longer);
8268
8269 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8270 bgp_show_type_prefix_longer);
8271}
8272
8273DEFUN (show_ip_bgp_flap_address,
8274 show_ip_bgp_flap_address_cmd,
8275 "show ip bgp flap-statistics A.B.C.D",
8276 SHOW_STR
8277 IP_STR
8278 BGP_STR
8279 "Display flap statistics of routes\n"
8280 "Network in the BGP routing table to display\n")
8281{
8282 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8283 bgp_show_type_flap_address);
8284}
8285
8286DEFUN (show_ip_bgp_flap_prefix,
8287 show_ip_bgp_flap_prefix_cmd,
8288 "show ip bgp flap-statistics A.B.C.D/M",
8289 SHOW_STR
8290 IP_STR
8291 BGP_STR
8292 "Display flap statistics of routes\n"
8293 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8294{
8295 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8296 bgp_show_type_flap_prefix);
8297}
8298#ifdef HAVE_IPV6
8299DEFUN (show_bgp_prefix_longer,
8300 show_bgp_prefix_longer_cmd,
8301 "show bgp X:X::X:X/M longer-prefixes",
8302 SHOW_STR
8303 BGP_STR
8304 "IPv6 prefix <network>/<length>\n"
8305 "Display route and more specific routes\n")
8306{
8307 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8308 bgp_show_type_prefix_longer);
8309}
8310
8311ALIAS (show_bgp_prefix_longer,
8312 show_bgp_ipv6_prefix_longer_cmd,
8313 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8314 SHOW_STR
8315 BGP_STR
8316 "Address family\n"
8317 "IPv6 prefix <network>/<length>\n"
8318 "Display route and more specific routes\n")
8319
8320/* old command */
8321DEFUN (show_ipv6_bgp_prefix_longer,
8322 show_ipv6_bgp_prefix_longer_cmd,
8323 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8324 SHOW_STR
8325 IPV6_STR
8326 BGP_STR
8327 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8328 "Display route and more specific routes\n")
8329{
8330 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8331 bgp_show_type_prefix_longer);
8332}
8333
8334/* old command */
8335DEFUN (show_ipv6_mbgp_prefix_longer,
8336 show_ipv6_mbgp_prefix_longer_cmd,
8337 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8338 SHOW_STR
8339 IPV6_STR
8340 MBGP_STR
8341 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8342 "Display route and more specific routes\n")
8343{
8344 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8345 bgp_show_type_prefix_longer);
8346}
8347#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008348
paul94f2b392005-06-28 12:44:16 +00008349static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008350peer_lookup_in_view (struct vty *vty, const char *view_name,
8351 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008352{
8353 int ret;
8354 struct bgp *bgp;
8355 struct peer *peer;
8356 union sockunion su;
8357
8358 /* BGP structure lookup. */
8359 if (view_name)
8360 {
8361 bgp = bgp_lookup_by_name (view_name);
8362 if (! bgp)
8363 {
8364 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8365 return NULL;
8366 }
8367 }
paul5228ad22004-06-04 17:58:18 +00008368 else
paulbb46e942003-10-24 19:02:03 +00008369 {
8370 bgp = bgp_get_default ();
8371 if (! bgp)
8372 {
8373 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8374 return NULL;
8375 }
8376 }
8377
8378 /* Get peer sockunion. */
8379 ret = str2sockunion (ip_str, &su);
8380 if (ret < 0)
8381 {
8382 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8383 return NULL;
8384 }
8385
8386 /* Peer structure lookup. */
8387 peer = peer_lookup (bgp, &su);
8388 if (! peer)
8389 {
8390 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8391 return NULL;
8392 }
8393
8394 return peer;
8395}
8396
paul94f2b392005-06-28 12:44:16 +00008397static void
paul718e3742002-12-13 20:15:29 +00008398show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
8399 int in)
8400{
8401 struct bgp_table *table;
8402 struct bgp_adj_in *ain;
8403 struct bgp_adj_out *adj;
8404 unsigned long output_count;
8405 struct bgp_node *rn;
8406 int header1 = 1;
8407 struct bgp *bgp;
8408 int header2 = 1;
8409
paulbb46e942003-10-24 19:02:03 +00008410 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00008411
8412 if (! bgp)
8413 return;
8414
8415 table = bgp->rib[afi][safi];
8416
8417 output_count = 0;
8418
8419 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
8420 PEER_STATUS_DEFAULT_ORIGINATE))
8421 {
8422 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 +00008423 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8424 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008425
8426 vty_out (vty, "Originating default network 0.0.0.0%s%s",
8427 VTY_NEWLINE, VTY_NEWLINE);
8428 header1 = 0;
8429 }
8430
8431 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8432 if (in)
8433 {
8434 for (ain = rn->adj_in; ain; ain = ain->next)
8435 if (ain->peer == peer)
8436 {
8437 if (header1)
8438 {
8439 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 +00008440 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8441 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008442 header1 = 0;
8443 }
8444 if (header2)
8445 {
8446 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8447 header2 = 0;
8448 }
8449 if (ain->attr)
8450 {
8451 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
8452 output_count++;
8453 }
8454 }
8455 }
8456 else
8457 {
8458 for (adj = rn->adj_out; adj; adj = adj->next)
8459 if (adj->peer == peer)
8460 {
8461 if (header1)
8462 {
8463 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 +00008464 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8465 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008466 header1 = 0;
8467 }
8468 if (header2)
8469 {
8470 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8471 header2 = 0;
8472 }
8473 if (adj->attr)
8474 {
8475 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
8476 output_count++;
8477 }
8478 }
8479 }
8480
8481 if (output_count != 0)
8482 vty_out (vty, "%sTotal number of prefixes %ld%s",
8483 VTY_NEWLINE, output_count, VTY_NEWLINE);
8484}
8485
paul94f2b392005-06-28 12:44:16 +00008486static int
paulbb46e942003-10-24 19:02:03 +00008487peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
8488{
paul718e3742002-12-13 20:15:29 +00008489 if (! peer || ! peer->afc[afi][safi])
8490 {
8491 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8492 return CMD_WARNING;
8493 }
8494
8495 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8496 {
8497 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
8498 VTY_NEWLINE);
8499 return CMD_WARNING;
8500 }
8501
8502 show_adj_route (vty, peer, afi, safi, in);
8503
8504 return CMD_SUCCESS;
8505}
8506
8507DEFUN (show_ip_bgp_neighbor_advertised_route,
8508 show_ip_bgp_neighbor_advertised_route_cmd,
8509 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8510 SHOW_STR
8511 IP_STR
8512 BGP_STR
8513 "Detailed information on TCP and BGP neighbor connections\n"
8514 "Neighbor to display information about\n"
8515 "Neighbor to display information about\n"
8516 "Display the routes advertised to a BGP neighbor\n")
8517{
paulbb46e942003-10-24 19:02:03 +00008518 struct peer *peer;
8519
8520 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8521 if (! peer)
8522 return CMD_WARNING;
8523
8524 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008525}
8526
8527DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
8528 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
8529 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8530 SHOW_STR
8531 IP_STR
8532 BGP_STR
8533 "Address family\n"
8534 "Address Family modifier\n"
8535 "Address Family modifier\n"
8536 "Detailed information on TCP and BGP neighbor connections\n"
8537 "Neighbor to display information about\n"
8538 "Neighbor to display information about\n"
8539 "Display the routes advertised to a BGP neighbor\n")
8540{
paulbb46e942003-10-24 19:02:03 +00008541 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008542
paulbb46e942003-10-24 19:02:03 +00008543 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8544 if (! peer)
8545 return CMD_WARNING;
8546
8547 if (strncmp (argv[0], "m", 1) == 0)
8548 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
8549
8550 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008551}
8552
8553#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008554DEFUN (show_bgp_view_neighbor_advertised_route,
8555 show_bgp_view_neighbor_advertised_route_cmd,
8556 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8557 SHOW_STR
8558 BGP_STR
8559 "BGP view\n"
8560 "View name\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 the routes advertised to a BGP neighbor\n")
8565{
8566 struct peer *peer;
8567
8568 if (argc == 2)
8569 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8570 else
8571 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8572
8573 if (! peer)
8574 return CMD_WARNING;
8575
8576 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
8577}
8578
8579ALIAS (show_bgp_view_neighbor_advertised_route,
8580 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
8581 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8582 SHOW_STR
8583 BGP_STR
8584 "BGP view\n"
8585 "View name\n"
8586 "Address family\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 the routes advertised to a BGP neighbor\n")
8591
8592DEFUN (show_bgp_view_neighbor_received_routes,
8593 show_bgp_view_neighbor_received_routes_cmd,
8594 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
8595 SHOW_STR
8596 BGP_STR
8597 "BGP view\n"
8598 "View name\n"
8599 "Detailed information on TCP and BGP neighbor connections\n"
8600 "Neighbor to display information about\n"
8601 "Neighbor to display information about\n"
8602 "Display the received routes from neighbor\n")
8603{
8604 struct peer *peer;
8605
8606 if (argc == 2)
8607 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8608 else
8609 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8610
8611 if (! peer)
8612 return CMD_WARNING;
8613
8614 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
8615}
8616
8617ALIAS (show_bgp_view_neighbor_received_routes,
8618 show_bgp_view_ipv6_neighbor_received_routes_cmd,
8619 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8620 SHOW_STR
8621 BGP_STR
8622 "BGP view\n"
8623 "View name\n"
8624 "Address family\n"
8625 "Detailed information on TCP and BGP neighbor connections\n"
8626 "Neighbor to display information about\n"
8627 "Neighbor to display information about\n"
8628 "Display the received routes from neighbor\n")
8629
8630ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008631 show_bgp_neighbor_advertised_route_cmd,
8632 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8633 SHOW_STR
8634 BGP_STR
8635 "Detailed information on TCP and BGP neighbor connections\n"
8636 "Neighbor to display information about\n"
8637 "Neighbor to display information about\n"
8638 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008639
8640ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008641 show_bgp_ipv6_neighbor_advertised_route_cmd,
8642 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8643 SHOW_STR
8644 BGP_STR
8645 "Address family\n"
8646 "Detailed information on TCP and BGP neighbor connections\n"
8647 "Neighbor to display information about\n"
8648 "Neighbor to display information about\n"
8649 "Display the routes advertised to a BGP neighbor\n")
8650
8651/* old command */
paulbb46e942003-10-24 19:02:03 +00008652ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008653 ipv6_bgp_neighbor_advertised_route_cmd,
8654 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8655 SHOW_STR
8656 IPV6_STR
8657 BGP_STR
8658 "Detailed information on TCP and BGP neighbor connections\n"
8659 "Neighbor to display information about\n"
8660 "Neighbor to display information about\n"
8661 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008662
paul718e3742002-12-13 20:15:29 +00008663/* old command */
8664DEFUN (ipv6_mbgp_neighbor_advertised_route,
8665 ipv6_mbgp_neighbor_advertised_route_cmd,
8666 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8667 SHOW_STR
8668 IPV6_STR
8669 MBGP_STR
8670 "Detailed information on TCP and BGP neighbor connections\n"
8671 "Neighbor to display information about\n"
8672 "Neighbor to display information about\n"
8673 "Display the routes advertised to a BGP neighbor\n")
8674{
paulbb46e942003-10-24 19:02:03 +00008675 struct peer *peer;
8676
8677 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8678 if (! peer)
8679 return CMD_WARNING;
8680
8681 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00008682}
8683#endif /* HAVE_IPV6 */
8684
8685DEFUN (show_ip_bgp_neighbor_received_routes,
8686 show_ip_bgp_neighbor_received_routes_cmd,
8687 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8688 SHOW_STR
8689 IP_STR
8690 BGP_STR
8691 "Detailed information on TCP and BGP neighbor connections\n"
8692 "Neighbor to display information about\n"
8693 "Neighbor to display information about\n"
8694 "Display the received routes from neighbor\n")
8695{
paulbb46e942003-10-24 19:02:03 +00008696 struct peer *peer;
8697
8698 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8699 if (! peer)
8700 return CMD_WARNING;
8701
8702 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008703}
8704
8705DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
8706 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
8707 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
8708 SHOW_STR
8709 IP_STR
8710 BGP_STR
8711 "Address family\n"
8712 "Address Family modifier\n"
8713 "Address Family modifier\n"
8714 "Detailed information on TCP and BGP neighbor connections\n"
8715 "Neighbor to display information about\n"
8716 "Neighbor to display information about\n"
8717 "Display the received routes from neighbor\n")
8718{
paulbb46e942003-10-24 19:02:03 +00008719 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008720
paulbb46e942003-10-24 19:02:03 +00008721 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8722 if (! peer)
8723 return CMD_WARNING;
8724
8725 if (strncmp (argv[0], "m", 1) == 0)
8726 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
8727
8728 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008729}
8730
8731DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
8732 show_ip_bgp_neighbor_received_prefix_filter_cmd,
8733 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8734 SHOW_STR
8735 IP_STR
8736 BGP_STR
8737 "Detailed information on TCP and BGP neighbor connections\n"
8738 "Neighbor to display information about\n"
8739 "Neighbor to display information about\n"
8740 "Display information received from a BGP neighbor\n"
8741 "Display the prefixlist filter\n")
8742{
8743 char name[BUFSIZ];
8744 union sockunion *su;
8745 struct peer *peer;
8746 int count;
8747
8748 su = sockunion_str2su (argv[0]);
8749 if (su == NULL)
8750 return CMD_WARNING;
8751
8752 peer = peer_lookup (NULL, su);
8753 if (! peer)
8754 return CMD_WARNING;
8755
8756 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8757 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8758 if (count)
8759 {
8760 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8761 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8762 }
8763
8764 return CMD_SUCCESS;
8765}
8766
8767DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
8768 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
8769 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8770 SHOW_STR
8771 IP_STR
8772 BGP_STR
8773 "Address family\n"
8774 "Address Family modifier\n"
8775 "Address Family modifier\n"
8776 "Detailed information on TCP and BGP neighbor connections\n"
8777 "Neighbor to display information about\n"
8778 "Neighbor to display information about\n"
8779 "Display information received from a BGP neighbor\n"
8780 "Display the prefixlist filter\n")
8781{
8782 char name[BUFSIZ];
8783 union sockunion *su;
8784 struct peer *peer;
8785 int count;
8786
8787 su = sockunion_str2su (argv[1]);
8788 if (su == NULL)
8789 return CMD_WARNING;
8790
8791 peer = peer_lookup (NULL, su);
8792 if (! peer)
8793 return CMD_WARNING;
8794
8795 if (strncmp (argv[0], "m", 1) == 0)
8796 {
8797 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
8798 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8799 if (count)
8800 {
8801 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
8802 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8803 }
8804 }
8805 else
8806 {
8807 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8808 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8809 if (count)
8810 {
8811 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8812 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8813 }
8814 }
8815
8816 return CMD_SUCCESS;
8817}
8818
8819
8820#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008821ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008822 show_bgp_neighbor_received_routes_cmd,
8823 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8824 SHOW_STR
8825 BGP_STR
8826 "Detailed information on TCP and BGP neighbor connections\n"
8827 "Neighbor to display information about\n"
8828 "Neighbor to display information about\n"
8829 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008830
paulbb46e942003-10-24 19:02:03 +00008831ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008832 show_bgp_ipv6_neighbor_received_routes_cmd,
8833 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8834 SHOW_STR
8835 BGP_STR
8836 "Address family\n"
8837 "Detailed information on TCP and BGP neighbor connections\n"
8838 "Neighbor to display information about\n"
8839 "Neighbor to display information about\n"
8840 "Display the received routes from neighbor\n")
8841
8842DEFUN (show_bgp_neighbor_received_prefix_filter,
8843 show_bgp_neighbor_received_prefix_filter_cmd,
8844 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8845 SHOW_STR
8846 BGP_STR
8847 "Detailed information on TCP and BGP neighbor connections\n"
8848 "Neighbor to display information about\n"
8849 "Neighbor to display information about\n"
8850 "Display information received from a BGP neighbor\n"
8851 "Display the prefixlist filter\n")
8852{
8853 char name[BUFSIZ];
8854 union sockunion *su;
8855 struct peer *peer;
8856 int count;
8857
8858 su = sockunion_str2su (argv[0]);
8859 if (su == NULL)
8860 return CMD_WARNING;
8861
8862 peer = peer_lookup (NULL, su);
8863 if (! peer)
8864 return CMD_WARNING;
8865
8866 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8867 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8868 if (count)
8869 {
8870 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8871 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8872 }
8873
8874 return CMD_SUCCESS;
8875}
8876
8877ALIAS (show_bgp_neighbor_received_prefix_filter,
8878 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
8879 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8880 SHOW_STR
8881 BGP_STR
8882 "Address family\n"
8883 "Detailed information on TCP and BGP neighbor connections\n"
8884 "Neighbor to display information about\n"
8885 "Neighbor to display information about\n"
8886 "Display information received from a BGP neighbor\n"
8887 "Display the prefixlist filter\n")
8888
8889/* old command */
paulbb46e942003-10-24 19:02:03 +00008890ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008891 ipv6_bgp_neighbor_received_routes_cmd,
8892 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8893 SHOW_STR
8894 IPV6_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")
paul718e3742002-12-13 20:15:29 +00008900
8901/* old command */
8902DEFUN (ipv6_mbgp_neighbor_received_routes,
8903 ipv6_mbgp_neighbor_received_routes_cmd,
8904 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8905 SHOW_STR
8906 IPV6_STR
8907 MBGP_STR
8908 "Detailed information on TCP and BGP neighbor connections\n"
8909 "Neighbor to display information about\n"
8910 "Neighbor to display information about\n"
8911 "Display the received routes from neighbor\n")
8912{
paulbb46e942003-10-24 19:02:03 +00008913 struct peer *peer;
8914
8915 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8916 if (! peer)
8917 return CMD_WARNING;
8918
8919 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00008920}
paulbb46e942003-10-24 19:02:03 +00008921
8922DEFUN (show_bgp_view_neighbor_received_prefix_filter,
8923 show_bgp_view_neighbor_received_prefix_filter_cmd,
8924 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8925 SHOW_STR
8926 BGP_STR
8927 "BGP view\n"
8928 "View name\n"
8929 "Detailed information on TCP and BGP neighbor connections\n"
8930 "Neighbor to display information about\n"
8931 "Neighbor to display information about\n"
8932 "Display information received from a BGP neighbor\n"
8933 "Display the prefixlist filter\n")
8934{
8935 char name[BUFSIZ];
8936 union sockunion *su;
8937 struct peer *peer;
8938 struct bgp *bgp;
8939 int count;
8940
8941 /* BGP structure lookup. */
8942 bgp = bgp_lookup_by_name (argv[0]);
8943 if (bgp == NULL)
8944 {
8945 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8946 return CMD_WARNING;
8947 }
8948
8949 su = sockunion_str2su (argv[1]);
8950 if (su == NULL)
8951 return CMD_WARNING;
8952
8953 peer = peer_lookup (bgp, su);
8954 if (! peer)
8955 return CMD_WARNING;
8956
8957 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8958 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8959 if (count)
8960 {
8961 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8962 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8963 }
8964
8965 return CMD_SUCCESS;
8966}
8967
8968ALIAS (show_bgp_view_neighbor_received_prefix_filter,
8969 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
8970 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8971 SHOW_STR
8972 BGP_STR
8973 "BGP view\n"
8974 "View name\n"
8975 "Address family\n"
8976 "Detailed information on TCP and BGP neighbor connections\n"
8977 "Neighbor to display information about\n"
8978 "Neighbor to display information about\n"
8979 "Display information received from a BGP neighbor\n"
8980 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00008981#endif /* HAVE_IPV6 */
8982
paul94f2b392005-06-28 12:44:16 +00008983static int
paulbb46e942003-10-24 19:02:03 +00008984bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008985 safi_t safi, enum bgp_show_type type)
8986{
paul718e3742002-12-13 20:15:29 +00008987 if (! peer || ! peer->afc[afi][safi])
8988 {
8989 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008990 return CMD_WARNING;
8991 }
8992
ajs5a646652004-11-05 01:25:55 +00008993 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +00008994}
8995
8996DEFUN (show_ip_bgp_neighbor_routes,
8997 show_ip_bgp_neighbor_routes_cmd,
8998 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
8999 SHOW_STR
9000 IP_STR
9001 BGP_STR
9002 "Detailed information on TCP and BGP neighbor connections\n"
9003 "Neighbor to display information about\n"
9004 "Neighbor to display information about\n"
9005 "Display routes learned from neighbor\n")
9006{
paulbb46e942003-10-24 19:02:03 +00009007 struct peer *peer;
9008
9009 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9010 if (! peer)
9011 return CMD_WARNING;
9012
9013 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009014 bgp_show_type_neighbor);
9015}
9016
9017DEFUN (show_ip_bgp_neighbor_flap,
9018 show_ip_bgp_neighbor_flap_cmd,
9019 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9020 SHOW_STR
9021 IP_STR
9022 BGP_STR
9023 "Detailed information on TCP and BGP neighbor connections\n"
9024 "Neighbor to display information about\n"
9025 "Neighbor to display information about\n"
9026 "Display flap statistics of the routes learned from neighbor\n")
9027{
paulbb46e942003-10-24 19:02:03 +00009028 struct peer *peer;
9029
9030 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9031 if (! peer)
9032 return CMD_WARNING;
9033
9034 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009035 bgp_show_type_flap_neighbor);
9036}
9037
9038DEFUN (show_ip_bgp_neighbor_damp,
9039 show_ip_bgp_neighbor_damp_cmd,
9040 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9041 SHOW_STR
9042 IP_STR
9043 BGP_STR
9044 "Detailed information on TCP and BGP neighbor connections\n"
9045 "Neighbor to display information about\n"
9046 "Neighbor to display information about\n"
9047 "Display the dampened routes received from neighbor\n")
9048{
paulbb46e942003-10-24 19:02:03 +00009049 struct peer *peer;
9050
9051 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9052 if (! peer)
9053 return CMD_WARNING;
9054
9055 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009056 bgp_show_type_damp_neighbor);
9057}
9058
9059DEFUN (show_ip_bgp_ipv4_neighbor_routes,
9060 show_ip_bgp_ipv4_neighbor_routes_cmd,
9061 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
9062 SHOW_STR
9063 IP_STR
9064 BGP_STR
9065 "Address family\n"
9066 "Address Family modifier\n"
9067 "Address Family modifier\n"
9068 "Detailed information on TCP and BGP neighbor connections\n"
9069 "Neighbor to display information about\n"
9070 "Neighbor to display information about\n"
9071 "Display routes learned from neighbor\n")
9072{
paulbb46e942003-10-24 19:02:03 +00009073 struct peer *peer;
9074
9075 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9076 if (! peer)
9077 return CMD_WARNING;
9078
paul718e3742002-12-13 20:15:29 +00009079 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00009080 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009081 bgp_show_type_neighbor);
9082
paulbb46e942003-10-24 19:02:03 +00009083 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009084 bgp_show_type_neighbor);
9085}
paulbb46e942003-10-24 19:02:03 +00009086
paulfee0f4c2004-09-13 05:12:46 +00009087DEFUN (show_ip_bgp_view_rsclient,
9088 show_ip_bgp_view_rsclient_cmd,
9089 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9090 SHOW_STR
9091 IP_STR
9092 BGP_STR
9093 "BGP view\n"
9094 "BGP view name\n"
9095 "Information about Route Server Client\n"
9096 NEIGHBOR_ADDR_STR)
9097{
9098 struct bgp_table *table;
9099 struct peer *peer;
9100
9101 if (argc == 2)
9102 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9103 else
9104 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9105
9106 if (! peer)
9107 return CMD_WARNING;
9108
9109 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9110 {
9111 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9112 VTY_NEWLINE);
9113 return CMD_WARNING;
9114 }
9115
9116 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9117 PEER_FLAG_RSERVER_CLIENT))
9118 {
9119 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9120 VTY_NEWLINE);
9121 return CMD_WARNING;
9122 }
9123
9124 table = peer->rib[AFI_IP][SAFI_UNICAST];
9125
ajs5a646652004-11-05 01:25:55 +00009126 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009127}
9128
9129ALIAS (show_ip_bgp_view_rsclient,
9130 show_ip_bgp_rsclient_cmd,
9131 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
9132 SHOW_STR
9133 IP_STR
9134 BGP_STR
9135 "Information about Route Server Client\n"
9136 NEIGHBOR_ADDR_STR)
9137
9138DEFUN (show_ip_bgp_view_rsclient_route,
9139 show_ip_bgp_view_rsclient_route_cmd,
9140 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9141 SHOW_STR
9142 IP_STR
9143 BGP_STR
9144 "BGP view\n"
9145 "BGP view name\n"
9146 "Information about Route Server Client\n"
9147 NEIGHBOR_ADDR_STR
9148 "Network in the BGP routing table to display\n")
9149{
9150 struct bgp *bgp;
9151 struct peer *peer;
9152
9153 /* BGP structure lookup. */
9154 if (argc == 3)
9155 {
9156 bgp = bgp_lookup_by_name (argv[0]);
9157 if (bgp == NULL)
9158 {
9159 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9160 return CMD_WARNING;
9161 }
9162 }
9163 else
9164 {
9165 bgp = bgp_get_default ();
9166 if (bgp == NULL)
9167 {
9168 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9169 return CMD_WARNING;
9170 }
9171 }
9172
9173 if (argc == 3)
9174 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9175 else
9176 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9177
9178 if (! peer)
9179 return CMD_WARNING;
9180
9181 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9182 {
9183 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9184 VTY_NEWLINE);
9185 return CMD_WARNING;
9186}
9187
9188 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9189 PEER_FLAG_RSERVER_CLIENT))
9190 {
9191 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9192 VTY_NEWLINE);
9193 return CMD_WARNING;
9194 }
9195
9196 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9197 (argc == 3) ? argv[2] : argv[1],
9198 AFI_IP, SAFI_UNICAST, NULL, 0);
9199}
9200
9201ALIAS (show_ip_bgp_view_rsclient_route,
9202 show_ip_bgp_rsclient_route_cmd,
9203 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9204 SHOW_STR
9205 IP_STR
9206 BGP_STR
9207 "Information about Route Server Client\n"
9208 NEIGHBOR_ADDR_STR
9209 "Network in the BGP routing table to display\n")
9210
9211DEFUN (show_ip_bgp_view_rsclient_prefix,
9212 show_ip_bgp_view_rsclient_prefix_cmd,
9213 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9214 SHOW_STR
9215 IP_STR
9216 BGP_STR
9217 "BGP view\n"
9218 "BGP view name\n"
9219 "Information about Route Server Client\n"
9220 NEIGHBOR_ADDR_STR
9221 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9222{
9223 struct bgp *bgp;
9224 struct peer *peer;
9225
9226 /* BGP structure lookup. */
9227 if (argc == 3)
9228 {
9229 bgp = bgp_lookup_by_name (argv[0]);
9230 if (bgp == NULL)
9231 {
9232 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9233 return CMD_WARNING;
9234 }
9235 }
9236 else
9237 {
9238 bgp = bgp_get_default ();
9239 if (bgp == NULL)
9240 {
9241 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9242 return CMD_WARNING;
9243 }
9244 }
9245
9246 if (argc == 3)
9247 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9248 else
9249 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9250
9251 if (! peer)
9252 return CMD_WARNING;
9253
9254 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9255 {
9256 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9257 VTY_NEWLINE);
9258 return CMD_WARNING;
9259}
9260
9261 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9262 PEER_FLAG_RSERVER_CLIENT))
9263{
9264 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9265 VTY_NEWLINE);
9266 return CMD_WARNING;
9267 }
9268
9269 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9270 (argc == 3) ? argv[2] : argv[1],
9271 AFI_IP, SAFI_UNICAST, NULL, 1);
9272}
9273
9274ALIAS (show_ip_bgp_view_rsclient_prefix,
9275 show_ip_bgp_rsclient_prefix_cmd,
9276 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9277 SHOW_STR
9278 IP_STR
9279 BGP_STR
9280 "Information about Route Server Client\n"
9281 NEIGHBOR_ADDR_STR
9282 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9283
9284
paul718e3742002-12-13 20:15:29 +00009285#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009286DEFUN (show_bgp_view_neighbor_routes,
9287 show_bgp_view_neighbor_routes_cmd,
9288 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
9289 SHOW_STR
9290 BGP_STR
9291 "BGP view\n"
9292 "BGP view name\n"
9293 "Detailed information on TCP and BGP neighbor connections\n"
9294 "Neighbor to display information about\n"
9295 "Neighbor to display information about\n"
9296 "Display routes learned from neighbor\n")
9297{
9298 struct peer *peer;
9299
9300 if (argc == 2)
9301 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9302 else
9303 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9304
9305 if (! peer)
9306 return CMD_WARNING;
9307
9308 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9309 bgp_show_type_neighbor);
9310}
9311
9312ALIAS (show_bgp_view_neighbor_routes,
9313 show_bgp_view_ipv6_neighbor_routes_cmd,
9314 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9315 SHOW_STR
9316 BGP_STR
9317 "BGP view\n"
9318 "BGP view name\n"
9319 "Address family\n"
9320 "Detailed information on TCP and BGP neighbor connections\n"
9321 "Neighbor to display information about\n"
9322 "Neighbor to display information about\n"
9323 "Display routes learned from neighbor\n")
9324
9325DEFUN (show_bgp_view_neighbor_damp,
9326 show_bgp_view_neighbor_damp_cmd,
9327 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9328 SHOW_STR
9329 BGP_STR
9330 "BGP view\n"
9331 "BGP view name\n"
9332 "Detailed information on TCP and BGP neighbor connections\n"
9333 "Neighbor to display information about\n"
9334 "Neighbor to display information about\n"
9335 "Display the dampened routes received from neighbor\n")
9336{
9337 struct peer *peer;
9338
9339 if (argc == 2)
9340 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9341 else
9342 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9343
9344 if (! peer)
9345 return CMD_WARNING;
9346
9347 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9348 bgp_show_type_damp_neighbor);
9349}
9350
9351ALIAS (show_bgp_view_neighbor_damp,
9352 show_bgp_view_ipv6_neighbor_damp_cmd,
9353 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9354 SHOW_STR
9355 BGP_STR
9356 "BGP view\n"
9357 "BGP view name\n"
9358 "Address family\n"
9359 "Detailed information on TCP and BGP neighbor connections\n"
9360 "Neighbor to display information about\n"
9361 "Neighbor to display information about\n"
9362 "Display the dampened routes received from neighbor\n")
9363
9364DEFUN (show_bgp_view_neighbor_flap,
9365 show_bgp_view_neighbor_flap_cmd,
9366 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9367 SHOW_STR
9368 BGP_STR
9369 "BGP view\n"
9370 "BGP view name\n"
9371 "Detailed information on TCP and BGP neighbor connections\n"
9372 "Neighbor to display information about\n"
9373 "Neighbor to display information about\n"
9374 "Display flap statistics of the routes learned from neighbor\n")
9375{
9376 struct peer *peer;
9377
9378 if (argc == 2)
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 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9387 bgp_show_type_flap_neighbor);
9388}
9389
9390ALIAS (show_bgp_view_neighbor_flap,
9391 show_bgp_view_ipv6_neighbor_flap_cmd,
9392 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9393 SHOW_STR
9394 BGP_STR
9395 "BGP view\n"
9396 "BGP view name\n"
9397 "Address family\n"
9398 "Detailed information on TCP and BGP neighbor connections\n"
9399 "Neighbor to display information about\n"
9400 "Neighbor to display information about\n"
9401 "Display flap statistics of the routes learned from neighbor\n")
9402
9403ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009404 show_bgp_neighbor_routes_cmd,
9405 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
9406 SHOW_STR
9407 BGP_STR
9408 "Detailed information on TCP and BGP neighbor connections\n"
9409 "Neighbor to display information about\n"
9410 "Neighbor to display information about\n"
9411 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009412
paulbb46e942003-10-24 19:02:03 +00009413
9414ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009415 show_bgp_ipv6_neighbor_routes_cmd,
9416 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9417 SHOW_STR
9418 BGP_STR
9419 "Address family\n"
9420 "Detailed information on TCP and BGP neighbor connections\n"
9421 "Neighbor to display information about\n"
9422 "Neighbor to display information about\n"
9423 "Display routes learned from neighbor\n")
9424
9425/* old command */
paulbb46e942003-10-24 19:02:03 +00009426ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009427 ipv6_bgp_neighbor_routes_cmd,
9428 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
9429 SHOW_STR
9430 IPV6_STR
9431 BGP_STR
9432 "Detailed information on TCP and BGP neighbor connections\n"
9433 "Neighbor to display information about\n"
9434 "Neighbor to display information about\n"
9435 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009436
9437/* old command */
9438DEFUN (ipv6_mbgp_neighbor_routes,
9439 ipv6_mbgp_neighbor_routes_cmd,
9440 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
9441 SHOW_STR
9442 IPV6_STR
9443 MBGP_STR
9444 "Detailed information on TCP and BGP neighbor connections\n"
9445 "Neighbor to display information about\n"
9446 "Neighbor to display information about\n"
9447 "Display routes learned from neighbor\n")
9448{
paulbb46e942003-10-24 19:02:03 +00009449 struct peer *peer;
9450
9451 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9452 if (! peer)
9453 return CMD_WARNING;
9454
9455 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009456 bgp_show_type_neighbor);
9457}
paulbb46e942003-10-24 19:02:03 +00009458
9459ALIAS (show_bgp_view_neighbor_flap,
9460 show_bgp_neighbor_flap_cmd,
9461 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9462 SHOW_STR
9463 BGP_STR
9464 "Detailed information on TCP and BGP neighbor connections\n"
9465 "Neighbor to display information about\n"
9466 "Neighbor to display information about\n"
9467 "Display flap statistics of the routes learned from neighbor\n")
9468
9469ALIAS (show_bgp_view_neighbor_flap,
9470 show_bgp_ipv6_neighbor_flap_cmd,
9471 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9472 SHOW_STR
9473 BGP_STR
9474 "Address family\n"
9475 "Detailed information on TCP and BGP neighbor connections\n"
9476 "Neighbor to display information about\n"
9477 "Neighbor to display information about\n"
9478 "Display flap statistics of the routes learned from neighbor\n")
9479
9480ALIAS (show_bgp_view_neighbor_damp,
9481 show_bgp_neighbor_damp_cmd,
9482 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9483 SHOW_STR
9484 BGP_STR
9485 "Detailed information on TCP and BGP neighbor connections\n"
9486 "Neighbor to display information about\n"
9487 "Neighbor to display information about\n"
9488 "Display the dampened routes received from neighbor\n")
9489
9490ALIAS (show_bgp_view_neighbor_damp,
9491 show_bgp_ipv6_neighbor_damp_cmd,
9492 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9493 SHOW_STR
9494 BGP_STR
9495 "Address family\n"
9496 "Detailed information on TCP and BGP neighbor connections\n"
9497 "Neighbor to display information about\n"
9498 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +00009499 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +00009500
9501DEFUN (show_bgp_view_rsclient,
9502 show_bgp_view_rsclient_cmd,
9503 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9504 SHOW_STR
9505 BGP_STR
9506 "BGP view\n"
9507 "BGP view name\n"
9508 "Information about Route Server Client\n"
9509 NEIGHBOR_ADDR_STR)
9510{
9511 struct bgp_table *table;
9512 struct peer *peer;
9513
9514 if (argc == 2)
9515 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9516 else
9517 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9518
9519 if (! peer)
9520 return CMD_WARNING;
9521
9522 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9523 {
9524 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9525 VTY_NEWLINE);
9526 return CMD_WARNING;
9527 }
9528
9529 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9530 PEER_FLAG_RSERVER_CLIENT))
9531 {
9532 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9533 VTY_NEWLINE);
9534 return CMD_WARNING;
9535 }
9536
9537 table = peer->rib[AFI_IP6][SAFI_UNICAST];
9538
ajs5a646652004-11-05 01:25:55 +00009539 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009540}
9541
9542ALIAS (show_bgp_view_rsclient,
9543 show_bgp_rsclient_cmd,
9544 "show bgp rsclient (A.B.C.D|X:X::X:X)",
9545 SHOW_STR
9546 BGP_STR
9547 "Information about Route Server Client\n"
9548 NEIGHBOR_ADDR_STR)
9549
9550DEFUN (show_bgp_view_rsclient_route,
9551 show_bgp_view_rsclient_route_cmd,
9552 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9553 SHOW_STR
9554 BGP_STR
9555 "BGP view\n"
9556 "BGP view name\n"
9557 "Information about Route Server Client\n"
9558 NEIGHBOR_ADDR_STR
9559 "Network in the BGP routing table to display\n")
9560{
9561 struct bgp *bgp;
9562 struct peer *peer;
9563
9564 /* BGP structure lookup. */
9565 if (argc == 3)
9566 {
9567 bgp = bgp_lookup_by_name (argv[0]);
9568 if (bgp == NULL)
9569 {
9570 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9571 return CMD_WARNING;
9572 }
9573 }
9574 else
9575 {
9576 bgp = bgp_get_default ();
9577 if (bgp == NULL)
9578 {
9579 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9580 return CMD_WARNING;
9581 }
9582 }
9583
9584 if (argc == 3)
9585 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9586 else
9587 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9588
9589 if (! peer)
9590 return CMD_WARNING;
9591
9592 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9593 {
9594 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9595 VTY_NEWLINE);
9596 return CMD_WARNING;
9597 }
9598
9599 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9600 PEER_FLAG_RSERVER_CLIENT))
9601 {
9602 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9603 VTY_NEWLINE);
9604 return CMD_WARNING;
9605 }
9606
9607 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9608 (argc == 3) ? argv[2] : argv[1],
9609 AFI_IP6, SAFI_UNICAST, NULL, 0);
9610}
9611
9612ALIAS (show_bgp_view_rsclient_route,
9613 show_bgp_rsclient_route_cmd,
9614 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9615 SHOW_STR
9616 BGP_STR
9617 "Information about Route Server Client\n"
9618 NEIGHBOR_ADDR_STR
9619 "Network in the BGP routing table to display\n")
9620
9621DEFUN (show_bgp_view_rsclient_prefix,
9622 show_bgp_view_rsclient_prefix_cmd,
9623 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9624 SHOW_STR
9625 BGP_STR
9626 "BGP view\n"
9627 "BGP view name\n"
9628 "Information about Route Server Client\n"
9629 NEIGHBOR_ADDR_STR
9630 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9631{
9632 struct bgp *bgp;
9633 struct peer *peer;
9634
9635 /* BGP structure lookup. */
9636 if (argc == 3)
9637 {
9638 bgp = bgp_lookup_by_name (argv[0]);
9639 if (bgp == NULL)
9640 {
9641 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9642 return CMD_WARNING;
9643 }
9644 }
9645 else
9646 {
9647 bgp = bgp_get_default ();
9648 if (bgp == NULL)
9649 {
9650 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9651 return CMD_WARNING;
9652 }
9653 }
9654
9655 if (argc == 3)
9656 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9657 else
9658 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9659
9660 if (! peer)
9661 return CMD_WARNING;
9662
9663 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9664 {
9665 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9666 VTY_NEWLINE);
9667 return CMD_WARNING;
9668 }
9669
9670 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9671 PEER_FLAG_RSERVER_CLIENT))
9672 {
9673 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9674 VTY_NEWLINE);
9675 return CMD_WARNING;
9676 }
9677
9678 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9679 (argc == 3) ? argv[2] : argv[1],
9680 AFI_IP6, SAFI_UNICAST, NULL, 1);
9681}
9682
9683ALIAS (show_bgp_view_rsclient_prefix,
9684 show_bgp_rsclient_prefix_cmd,
9685 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9686 SHOW_STR
9687 BGP_STR
9688 "Information about Route Server Client\n"
9689 NEIGHBOR_ADDR_STR
9690 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9691
paul718e3742002-12-13 20:15:29 +00009692#endif /* HAVE_IPV6 */
9693
9694struct bgp_table *bgp_distance_table;
9695
9696struct bgp_distance
9697{
9698 /* Distance value for the IP source prefix. */
9699 u_char distance;
9700
9701 /* Name of the access-list to be matched. */
9702 char *access_list;
9703};
9704
paul94f2b392005-06-28 12:44:16 +00009705static struct bgp_distance *
paul718e3742002-12-13 20:15:29 +00009706bgp_distance_new ()
9707{
9708 struct bgp_distance *new;
9709 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
9710 memset (new, 0, sizeof (struct bgp_distance));
9711 return new;
9712}
9713
paul94f2b392005-06-28 12:44:16 +00009714static void
paul718e3742002-12-13 20:15:29 +00009715bgp_distance_free (struct bgp_distance *bdistance)
9716{
9717 XFREE (MTYPE_BGP_DISTANCE, bdistance);
9718}
9719
paul94f2b392005-06-28 12:44:16 +00009720static int
paulfd79ac92004-10-13 05:06:08 +00009721bgp_distance_set (struct vty *vty, const char *distance_str,
9722 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009723{
9724 int ret;
9725 struct prefix_ipv4 p;
9726 u_char distance;
9727 struct bgp_node *rn;
9728 struct bgp_distance *bdistance;
9729
9730 ret = str2prefix_ipv4 (ip_str, &p);
9731 if (ret == 0)
9732 {
9733 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9734 return CMD_WARNING;
9735 }
9736
9737 distance = atoi (distance_str);
9738
9739 /* Get BGP distance node. */
9740 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
9741 if (rn->info)
9742 {
9743 bdistance = rn->info;
9744 bgp_unlock_node (rn);
9745 }
9746 else
9747 {
9748 bdistance = bgp_distance_new ();
9749 rn->info = bdistance;
9750 }
9751
9752 /* Set distance value. */
9753 bdistance->distance = distance;
9754
9755 /* Reset access-list configuration. */
9756 if (bdistance->access_list)
9757 {
9758 free (bdistance->access_list);
9759 bdistance->access_list = NULL;
9760 }
9761 if (access_list_str)
9762 bdistance->access_list = strdup (access_list_str);
9763
9764 return CMD_SUCCESS;
9765}
9766
paul94f2b392005-06-28 12:44:16 +00009767static int
paulfd79ac92004-10-13 05:06:08 +00009768bgp_distance_unset (struct vty *vty, const char *distance_str,
9769 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009770{
9771 int ret;
9772 struct prefix_ipv4 p;
9773 u_char distance;
9774 struct bgp_node *rn;
9775 struct bgp_distance *bdistance;
9776
9777 ret = str2prefix_ipv4 (ip_str, &p);
9778 if (ret == 0)
9779 {
9780 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9781 return CMD_WARNING;
9782 }
9783
9784 distance = atoi (distance_str);
9785
9786 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
9787 if (! rn)
9788 {
9789 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
9790 return CMD_WARNING;
9791 }
9792
9793 bdistance = rn->info;
9794
9795 if (bdistance->access_list)
9796 free (bdistance->access_list);
9797 bgp_distance_free (bdistance);
9798
9799 rn->info = NULL;
9800 bgp_unlock_node (rn);
9801 bgp_unlock_node (rn);
9802
9803 return CMD_SUCCESS;
9804}
9805
paul94f2b392005-06-28 12:44:16 +00009806static void
paul718e3742002-12-13 20:15:29 +00009807bgp_distance_reset ()
9808{
9809 struct bgp_node *rn;
9810 struct bgp_distance *bdistance;
9811
9812 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
9813 if ((bdistance = rn->info) != NULL)
9814 {
9815 if (bdistance->access_list)
9816 free (bdistance->access_list);
9817 bgp_distance_free (bdistance);
9818 rn->info = NULL;
9819 bgp_unlock_node (rn);
9820 }
9821}
9822
9823/* Apply BGP information to distance method. */
9824u_char
9825bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
9826{
9827 struct bgp_node *rn;
9828 struct prefix_ipv4 q;
9829 struct peer *peer;
9830 struct bgp_distance *bdistance;
9831 struct access_list *alist;
9832 struct bgp_static *bgp_static;
9833
9834 if (! bgp)
9835 return 0;
9836
9837 if (p->family != AF_INET)
9838 return 0;
9839
9840 peer = rinfo->peer;
9841
9842 if (peer->su.sa.sa_family != AF_INET)
9843 return 0;
9844
9845 memset (&q, 0, sizeof (struct prefix_ipv4));
9846 q.family = AF_INET;
9847 q.prefix = peer->su.sin.sin_addr;
9848 q.prefixlen = IPV4_MAX_BITLEN;
9849
9850 /* Check source address. */
9851 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
9852 if (rn)
9853 {
9854 bdistance = rn->info;
9855 bgp_unlock_node (rn);
9856
9857 if (bdistance->access_list)
9858 {
9859 alist = access_list_lookup (AFI_IP, bdistance->access_list);
9860 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
9861 return bdistance->distance;
9862 }
9863 else
9864 return bdistance->distance;
9865 }
9866
9867 /* Backdoor check. */
9868 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
9869 if (rn)
9870 {
9871 bgp_static = rn->info;
9872 bgp_unlock_node (rn);
9873
9874 if (bgp_static->backdoor)
9875 {
9876 if (bgp->distance_local)
9877 return bgp->distance_local;
9878 else
9879 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9880 }
9881 }
9882
9883 if (peer_sort (peer) == BGP_PEER_EBGP)
9884 {
9885 if (bgp->distance_ebgp)
9886 return bgp->distance_ebgp;
9887 return ZEBRA_EBGP_DISTANCE_DEFAULT;
9888 }
9889 else
9890 {
9891 if (bgp->distance_ibgp)
9892 return bgp->distance_ibgp;
9893 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9894 }
9895}
9896
9897DEFUN (bgp_distance,
9898 bgp_distance_cmd,
9899 "distance bgp <1-255> <1-255> <1-255>",
9900 "Define an administrative distance\n"
9901 "BGP distance\n"
9902 "Distance for routes external to the AS\n"
9903 "Distance for routes internal to the AS\n"
9904 "Distance for local routes\n")
9905{
9906 struct bgp *bgp;
9907
9908 bgp = vty->index;
9909
9910 bgp->distance_ebgp = atoi (argv[0]);
9911 bgp->distance_ibgp = atoi (argv[1]);
9912 bgp->distance_local = atoi (argv[2]);
9913 return CMD_SUCCESS;
9914}
9915
9916DEFUN (no_bgp_distance,
9917 no_bgp_distance_cmd,
9918 "no distance bgp <1-255> <1-255> <1-255>",
9919 NO_STR
9920 "Define an administrative distance\n"
9921 "BGP distance\n"
9922 "Distance for routes external to the AS\n"
9923 "Distance for routes internal to the AS\n"
9924 "Distance for local routes\n")
9925{
9926 struct bgp *bgp;
9927
9928 bgp = vty->index;
9929
9930 bgp->distance_ebgp= 0;
9931 bgp->distance_ibgp = 0;
9932 bgp->distance_local = 0;
9933 return CMD_SUCCESS;
9934}
9935
9936ALIAS (no_bgp_distance,
9937 no_bgp_distance2_cmd,
9938 "no distance bgp",
9939 NO_STR
9940 "Define an administrative distance\n"
9941 "BGP distance\n")
9942
9943DEFUN (bgp_distance_source,
9944 bgp_distance_source_cmd,
9945 "distance <1-255> A.B.C.D/M",
9946 "Define an administrative distance\n"
9947 "Administrative distance\n"
9948 "IP source prefix\n")
9949{
9950 bgp_distance_set (vty, argv[0], argv[1], NULL);
9951 return CMD_SUCCESS;
9952}
9953
9954DEFUN (no_bgp_distance_source,
9955 no_bgp_distance_source_cmd,
9956 "no distance <1-255> A.B.C.D/M",
9957 NO_STR
9958 "Define an administrative distance\n"
9959 "Administrative distance\n"
9960 "IP source prefix\n")
9961{
9962 bgp_distance_unset (vty, argv[0], argv[1], NULL);
9963 return CMD_SUCCESS;
9964}
9965
9966DEFUN (bgp_distance_source_access_list,
9967 bgp_distance_source_access_list_cmd,
9968 "distance <1-255> A.B.C.D/M WORD",
9969 "Define an administrative distance\n"
9970 "Administrative distance\n"
9971 "IP source prefix\n"
9972 "Access list name\n")
9973{
9974 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
9975 return CMD_SUCCESS;
9976}
9977
9978DEFUN (no_bgp_distance_source_access_list,
9979 no_bgp_distance_source_access_list_cmd,
9980 "no distance <1-255> A.B.C.D/M WORD",
9981 NO_STR
9982 "Define an administrative distance\n"
9983 "Administrative distance\n"
9984 "IP source prefix\n"
9985 "Access list name\n")
9986{
9987 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
9988 return CMD_SUCCESS;
9989}
9990
9991DEFUN (bgp_damp_set,
9992 bgp_damp_set_cmd,
9993 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
9994 "BGP Specific commands\n"
9995 "Enable route-flap dampening\n"
9996 "Half-life time for the penalty\n"
9997 "Value to start reusing a route\n"
9998 "Value to start suppressing a route\n"
9999 "Maximum duration to suppress a stable route\n")
10000{
10001 struct bgp *bgp;
10002 int half = DEFAULT_HALF_LIFE * 60;
10003 int reuse = DEFAULT_REUSE;
10004 int suppress = DEFAULT_SUPPRESS;
10005 int max = 4 * half;
10006
10007 if (argc == 4)
10008 {
10009 half = atoi (argv[0]) * 60;
10010 reuse = atoi (argv[1]);
10011 suppress = atoi (argv[2]);
10012 max = atoi (argv[3]) * 60;
10013 }
10014 else if (argc == 1)
10015 {
10016 half = atoi (argv[0]) * 60;
10017 max = 4 * half;
10018 }
10019
10020 bgp = vty->index;
10021 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
10022 half, reuse, suppress, max);
10023}
10024
10025ALIAS (bgp_damp_set,
10026 bgp_damp_set2_cmd,
10027 "bgp dampening <1-45>",
10028 "BGP Specific commands\n"
10029 "Enable route-flap dampening\n"
10030 "Half-life time for the penalty\n")
10031
10032ALIAS (bgp_damp_set,
10033 bgp_damp_set3_cmd,
10034 "bgp dampening",
10035 "BGP Specific commands\n"
10036 "Enable route-flap dampening\n")
10037
10038DEFUN (bgp_damp_unset,
10039 bgp_damp_unset_cmd,
10040 "no bgp dampening",
10041 NO_STR
10042 "BGP Specific commands\n"
10043 "Enable route-flap dampening\n")
10044{
10045 struct bgp *bgp;
10046
10047 bgp = vty->index;
10048 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
10049}
10050
10051ALIAS (bgp_damp_unset,
10052 bgp_damp_unset2_cmd,
10053 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10054 NO_STR
10055 "BGP Specific commands\n"
10056 "Enable route-flap dampening\n"
10057 "Half-life time for the penalty\n"
10058 "Value to start reusing a route\n"
10059 "Value to start suppressing a route\n"
10060 "Maximum duration to suppress a stable route\n")
10061
10062DEFUN (show_ip_bgp_dampened_paths,
10063 show_ip_bgp_dampened_paths_cmd,
10064 "show ip bgp dampened-paths",
10065 SHOW_STR
10066 IP_STR
10067 BGP_STR
10068 "Display paths suppressed due to dampening\n")
10069{
ajs5a646652004-11-05 01:25:55 +000010070 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
10071 NULL);
paul718e3742002-12-13 20:15:29 +000010072}
10073
10074DEFUN (show_ip_bgp_flap_statistics,
10075 show_ip_bgp_flap_statistics_cmd,
10076 "show ip bgp flap-statistics",
10077 SHOW_STR
10078 IP_STR
10079 BGP_STR
10080 "Display flap statistics of routes\n")
10081{
ajs5a646652004-11-05 01:25:55 +000010082 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10083 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000010084}
10085
10086/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000010087static int
paulfd79ac92004-10-13 05:06:08 +000010088bgp_clear_damp_route (struct vty *vty, const char *view_name,
10089 const char *ip_str, afi_t afi, safi_t safi,
10090 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000010091{
10092 int ret;
10093 struct prefix match;
10094 struct bgp_node *rn;
10095 struct bgp_node *rm;
10096 struct bgp_info *ri;
10097 struct bgp_info *ri_temp;
10098 struct bgp *bgp;
10099 struct bgp_table *table;
10100
10101 /* BGP structure lookup. */
10102 if (view_name)
10103 {
10104 bgp = bgp_lookup_by_name (view_name);
10105 if (bgp == NULL)
10106 {
10107 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10108 return CMD_WARNING;
10109 }
10110 }
10111 else
10112 {
10113 bgp = bgp_get_default ();
10114 if (bgp == NULL)
10115 {
10116 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
10117 return CMD_WARNING;
10118 }
10119 }
10120
10121 /* Check IP address argument. */
10122 ret = str2prefix (ip_str, &match);
10123 if (! ret)
10124 {
10125 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
10126 return CMD_WARNING;
10127 }
10128
10129 match.family = afi2family (afi);
10130
10131 if (safi == SAFI_MPLS_VPN)
10132 {
10133 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
10134 {
10135 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
10136 continue;
10137
10138 if ((table = rn->info) != NULL)
10139 if ((rm = bgp_node_match (table, &match)) != NULL)
10140 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
10141 {
10142 ri = rm->info;
10143 while (ri)
10144 {
10145 if (ri->damp_info)
10146 {
10147 ri_temp = ri->next;
10148 bgp_damp_info_free (ri->damp_info, 1);
10149 ri = ri_temp;
10150 }
10151 else
10152 ri = ri->next;
10153 }
10154 }
10155 }
10156 }
10157 else
10158 {
10159 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
10160 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
10161 {
10162 ri = rn->info;
10163 while (ri)
10164 {
10165 if (ri->damp_info)
10166 {
10167 ri_temp = ri->next;
10168 bgp_damp_info_free (ri->damp_info, 1);
10169 ri = ri_temp;
10170 }
10171 else
10172 ri = ri->next;
10173 }
10174 }
10175 }
10176
10177 return CMD_SUCCESS;
10178}
10179
10180DEFUN (clear_ip_bgp_dampening,
10181 clear_ip_bgp_dampening_cmd,
10182 "clear ip bgp dampening",
10183 CLEAR_STR
10184 IP_STR
10185 BGP_STR
10186 "Clear route flap dampening information\n")
10187{
10188 bgp_damp_info_clean ();
10189 return CMD_SUCCESS;
10190}
10191
10192DEFUN (clear_ip_bgp_dampening_prefix,
10193 clear_ip_bgp_dampening_prefix_cmd,
10194 "clear ip bgp dampening A.B.C.D/M",
10195 CLEAR_STR
10196 IP_STR
10197 BGP_STR
10198 "Clear route flap dampening information\n"
10199 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10200{
10201 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10202 SAFI_UNICAST, NULL, 1);
10203}
10204
10205DEFUN (clear_ip_bgp_dampening_address,
10206 clear_ip_bgp_dampening_address_cmd,
10207 "clear ip bgp dampening A.B.C.D",
10208 CLEAR_STR
10209 IP_STR
10210 BGP_STR
10211 "Clear route flap dampening information\n"
10212 "Network to clear damping information\n")
10213{
10214 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10215 SAFI_UNICAST, NULL, 0);
10216}
10217
10218DEFUN (clear_ip_bgp_dampening_address_mask,
10219 clear_ip_bgp_dampening_address_mask_cmd,
10220 "clear ip bgp dampening A.B.C.D A.B.C.D",
10221 CLEAR_STR
10222 IP_STR
10223 BGP_STR
10224 "Clear route flap dampening information\n"
10225 "Network to clear damping information\n"
10226 "Network mask\n")
10227{
10228 int ret;
10229 char prefix_str[BUFSIZ];
10230
10231 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
10232 if (! ret)
10233 {
10234 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
10235 return CMD_WARNING;
10236 }
10237
10238 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
10239 SAFI_UNICAST, NULL, 0);
10240}
10241
paul94f2b392005-06-28 12:44:16 +000010242static int
paul718e3742002-12-13 20:15:29 +000010243bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
10244 afi_t afi, safi_t safi, int *write)
10245{
10246 struct bgp_node *prn;
10247 struct bgp_node *rn;
10248 struct bgp_table *table;
10249 struct prefix *p;
10250 struct prefix_rd *prd;
10251 struct bgp_static *bgp_static;
10252 u_int32_t label;
10253 char buf[SU_ADDRSTRLEN];
10254 char rdbuf[RD_ADDRSTRLEN];
10255
10256 /* Network configuration. */
10257 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
10258 if ((table = prn->info) != NULL)
10259 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10260 if ((bgp_static = rn->info) != NULL)
10261 {
10262 p = &rn->p;
10263 prd = (struct prefix_rd *) &prn->p;
10264
10265 /* "address-family" display. */
10266 bgp_config_write_family_header (vty, afi, safi, write);
10267
10268 /* "network" configuration display. */
10269 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
10270 label = decode_label (bgp_static->tag);
10271
10272 vty_out (vty, " network %s/%d rd %s tag %d",
10273 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10274 p->prefixlen,
10275 rdbuf, label);
10276 vty_out (vty, "%s", VTY_NEWLINE);
10277 }
10278 return 0;
10279}
10280
10281/* Configuration of static route announcement and aggregate
10282 information. */
10283int
10284bgp_config_write_network (struct vty *vty, struct bgp *bgp,
10285 afi_t afi, safi_t safi, int *write)
10286{
10287 struct bgp_node *rn;
10288 struct prefix *p;
10289 struct bgp_static *bgp_static;
10290 struct bgp_aggregate *bgp_aggregate;
10291 char buf[SU_ADDRSTRLEN];
10292
10293 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
10294 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
10295
10296 /* Network configuration. */
10297 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
10298 if ((bgp_static = rn->info) != NULL)
10299 {
10300 p = &rn->p;
10301
10302 /* "address-family" display. */
10303 bgp_config_write_family_header (vty, afi, safi, write);
10304
10305 /* "network" configuration display. */
10306 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10307 {
10308 u_int32_t destination;
10309 struct in_addr netmask;
10310
10311 destination = ntohl (p->u.prefix4.s_addr);
10312 masklen2ip (p->prefixlen, &netmask);
10313 vty_out (vty, " network %s",
10314 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
10315
10316 if ((IN_CLASSC (destination) && p->prefixlen == 24)
10317 || (IN_CLASSB (destination) && p->prefixlen == 16)
10318 || (IN_CLASSA (destination) && p->prefixlen == 8)
10319 || p->u.prefix4.s_addr == 0)
10320 {
10321 /* Natural mask is not display. */
10322 }
10323 else
10324 vty_out (vty, " mask %s", inet_ntoa (netmask));
10325 }
10326 else
10327 {
10328 vty_out (vty, " network %s/%d",
10329 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10330 p->prefixlen);
10331 }
10332
10333 if (bgp_static->rmap.name)
10334 vty_out (vty, " route-map %s", bgp_static->rmap.name);
10335 else if (bgp_static->backdoor)
10336 vty_out (vty, " backdoor");
10337
10338 vty_out (vty, "%s", VTY_NEWLINE);
10339 }
10340
10341 /* Aggregate-address configuration. */
10342 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
10343 if ((bgp_aggregate = rn->info) != NULL)
10344 {
10345 p = &rn->p;
10346
10347 /* "address-family" display. */
10348 bgp_config_write_family_header (vty, afi, safi, write);
10349
10350 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10351 {
10352 struct in_addr netmask;
10353
10354 masklen2ip (p->prefixlen, &netmask);
10355 vty_out (vty, " aggregate-address %s %s",
10356 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10357 inet_ntoa (netmask));
10358 }
10359 else
10360 {
10361 vty_out (vty, " aggregate-address %s/%d",
10362 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10363 p->prefixlen);
10364 }
10365
10366 if (bgp_aggregate->as_set)
10367 vty_out (vty, " as-set");
10368
10369 if (bgp_aggregate->summary_only)
10370 vty_out (vty, " summary-only");
10371
10372 vty_out (vty, "%s", VTY_NEWLINE);
10373 }
10374
10375 return 0;
10376}
10377
10378int
10379bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
10380{
10381 struct bgp_node *rn;
10382 struct bgp_distance *bdistance;
10383
10384 /* Distance configuration. */
10385 if (bgp->distance_ebgp
10386 && bgp->distance_ibgp
10387 && bgp->distance_local
10388 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
10389 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
10390 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
10391 vty_out (vty, " distance bgp %d %d %d%s",
10392 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
10393 VTY_NEWLINE);
10394
10395 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10396 if ((bdistance = rn->info) != NULL)
10397 {
10398 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
10399 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
10400 bdistance->access_list ? bdistance->access_list : "",
10401 VTY_NEWLINE);
10402 }
10403
10404 return 0;
10405}
10406
10407/* Allocate routing table structure and install commands. */
10408void
10409bgp_route_init ()
10410{
10411 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000010412 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010413
10414 /* IPv4 BGP commands. */
10415 install_element (BGP_NODE, &bgp_network_cmd);
10416 install_element (BGP_NODE, &bgp_network_mask_cmd);
10417 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
10418 install_element (BGP_NODE, &bgp_network_route_map_cmd);
10419 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
10420 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
10421 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
10422 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
10423 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
10424 install_element (BGP_NODE, &no_bgp_network_cmd);
10425 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
10426 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
10427 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
10428 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
10429 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10430 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
10431 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
10432 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
10433
10434 install_element (BGP_NODE, &aggregate_address_cmd);
10435 install_element (BGP_NODE, &aggregate_address_mask_cmd);
10436 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
10437 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
10438 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
10439 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
10440 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
10441 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
10442 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
10443 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
10444 install_element (BGP_NODE, &no_aggregate_address_cmd);
10445 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
10446 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
10447 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
10448 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
10449 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
10450 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
10451 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
10452 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10453 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10454
10455 /* IPv4 unicast configuration. */
10456 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
10457 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
10458 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
10459 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
10460 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
10461 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
10462 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
10463 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
10464 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
10465 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
10466 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
10467 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10468 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
10469 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
10470 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
10471 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
10472 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
10473 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
10474 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
10475 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
10476 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
10477 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
10478 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
10479 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
10480 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
10481 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
10482 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
10483 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
10484 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
10485 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
10486 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10487 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10488
10489 /* IPv4 multicast configuration. */
10490 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
10491 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
10492 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
10493 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
10494 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
10495 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
10496 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
10497 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
10498 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
10499 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
10500 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
10501 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10502 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
10503 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
10504 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
10505 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
10506 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
10507 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
10508 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
10509 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
10510 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
10511 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
10512 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
10513 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
10514 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
10515 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
10516 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
10517 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
10518 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
10519 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
10520 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10521 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10522
10523 install_element (VIEW_NODE, &show_ip_bgp_cmd);
10524 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
10525 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
10526 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
10527 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10528 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10529 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
10530 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10531 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10532 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10533 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
10534 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
10535 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
10536 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
10537 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10538 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
10539 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10540 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
10541 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10542 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
10543 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10544 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
10545 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10546 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
10547 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10548 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
10549 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
10550 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
10551 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
10552 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
10553 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
10554 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
10555 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
10556 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
10557 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
10558 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
10559 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
10560 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10561 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10562 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10563 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10564 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
10565 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10566 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
10567 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10568 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
10569 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10570 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10571 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10572 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10573 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10574 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
10575 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10576 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10577 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10578 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
10579 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
10580 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
10581 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
10582 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10583 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
10584 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
10585 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10586 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10587 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
10588 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
10589 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010590 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
10591 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
10592 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10593 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
10594 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10595 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010596
10597 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
10598 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
10599 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
10600 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
10601 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10602 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10603 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
10604 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10605 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10606 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10607 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
10608 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
10609 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
10610 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
10611 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10612 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
10613 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10614 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
10615 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10616 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
10617 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10618 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
10619 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10620 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
10621 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10622 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
10623 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
10624 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
10625 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
10626 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
10627 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
10628 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
10629 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
10630 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
10631 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
10632 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
10633 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
10634 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10635 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10637 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10638 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
10639 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10640 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
10641 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10642 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
10643 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10644 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10645 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10646 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10647 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10648 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
10649 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10650 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10651 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10652 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
10653 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
10654 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
10655 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
10656 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10657 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
10658 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
10659 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10660 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10661 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
10662 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
10663 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010664 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
10665 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
10666 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10667 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
10668 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10669 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010670
10671 /* BGP dampening clear commands */
10672 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
10673 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
10674 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
10675 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
10676
10677#ifdef HAVE_IPV6
10678 /* New config IPv6 BGP commands. */
10679 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
10680 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
10681 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
10682 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
10683
10684 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
10685 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
10686 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
10687 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
10688
10689 /* Old config IPv6 BGP commands. */
10690 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
10691 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
10692
10693 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
10694 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
10695 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
10696 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
10697
10698 install_element (VIEW_NODE, &show_bgp_cmd);
10699 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
10700 install_element (VIEW_NODE, &show_bgp_route_cmd);
10701 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
10702 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
10703 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
10704 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
10705 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
10706 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
10707 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
10708 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
10709 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
10710 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
10711 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
10712 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
10713 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
10714 install_element (VIEW_NODE, &show_bgp_community_cmd);
10715 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
10716 install_element (VIEW_NODE, &show_bgp_community2_cmd);
10717 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
10718 install_element (VIEW_NODE, &show_bgp_community3_cmd);
10719 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
10720 install_element (VIEW_NODE, &show_bgp_community4_cmd);
10721 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
10722 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
10723 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
10724 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
10725 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
10726 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
10727 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
10728 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
10729 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
10730 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
10731 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
10732 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
10733 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10734 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
10735 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10736 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
10737 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10738 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
10739 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10740 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
10741 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10742 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10743 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010744 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
10745 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10746 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
10747 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010748 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
10749 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
10750 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010751 install_element (VIEW_NODE, &show_bgp_view_cmd);
10752 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
10753 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
10754 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
10755 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
10756 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
10757 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10758 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10759 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10760 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10761 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
10762 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10763 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10764 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10765 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
10766 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10767 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
10768 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010769 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
10770 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
10771 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010772
10773 install_element (ENABLE_NODE, &show_bgp_cmd);
10774 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
10775 install_element (ENABLE_NODE, &show_bgp_route_cmd);
10776 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
10777 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
10778 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
10779 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
10780 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
10781 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
10782 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
10783 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
10784 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
10785 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
10786 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
10787 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
10788 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
10789 install_element (ENABLE_NODE, &show_bgp_community_cmd);
10790 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
10791 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
10792 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
10793 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
10794 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
10795 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
10796 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
10797 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
10798 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
10799 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
10800 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
10801 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
10802 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
10803 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
10804 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
10805 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
10806 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
10807 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
10808 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10809 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
10810 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10811 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
10812 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10813 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
10814 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10815 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
10816 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10817 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10818 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010819 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
10820 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10821 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
10822 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010823 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
10824 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
10825 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010826 install_element (ENABLE_NODE, &show_bgp_view_cmd);
10827 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
10828 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
10829 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
10830 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
10831 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
10832 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10833 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10834 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10835 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10836 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
10837 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10838 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10839 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10840 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
10841 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10842 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
10843 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010844 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
10845 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
10846 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010847
10848 /* old command */
10849 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
10850 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
10851 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
10852 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
10853 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
10854 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
10855 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
10856 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
10857 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
10858 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
10859 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
10860 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
10861 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
10862 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
10863 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
10864 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
10865 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10866 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10867 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
10868 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
10869 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
10870 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
10871 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10872 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
10873 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
10874 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
10875 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
10876 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
10877 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
10878 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
10879 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10880 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10881 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10882 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
10883 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10884 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000010885
paul718e3742002-12-13 20:15:29 +000010886 /* old command */
10887 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
10888 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
10889 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
10890 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
10891 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
10892 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
10893 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
10894 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
10895 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
10896 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
10897 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
10898 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
10899 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
10900 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
10901 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
10902 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
10903 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10904 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10905 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
10906 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
10907 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
10908 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
10909 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10910 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
10911 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
10912 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
10913 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
10914 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
10915 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
10916 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
10917 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10918 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10919 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10920 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
10921 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10922 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
10923
10924 /* old command */
10925 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10926 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10927 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10928 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10929
10930 /* old command */
10931 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10932 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10933 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10934 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10935
10936 /* old command */
10937 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
10938 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
10939 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10940 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10941#endif /* HAVE_IPV6 */
10942
10943 install_element (BGP_NODE, &bgp_distance_cmd);
10944 install_element (BGP_NODE, &no_bgp_distance_cmd);
10945 install_element (BGP_NODE, &no_bgp_distance2_cmd);
10946 install_element (BGP_NODE, &bgp_distance_source_cmd);
10947 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
10948 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
10949 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
10950
10951 install_element (BGP_NODE, &bgp_damp_set_cmd);
10952 install_element (BGP_NODE, &bgp_damp_set2_cmd);
10953 install_element (BGP_NODE, &bgp_damp_set3_cmd);
10954 install_element (BGP_NODE, &bgp_damp_unset_cmd);
10955 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
10956 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
10957 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
10958 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
10959 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
10960 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
10961}