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