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