blob: 93074abbcad4ae96a82825acd1dc832f151607d3 [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;
paul718e3742002-12-13 20:15:29 +000068
69 if (safi == SAFI_MPLS_VPN)
70 {
paulfee0f4c2004-09-13 05:12:46 +000071 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000072
73 if (prn->info == NULL)
74 prn->info = bgp_table_init ();
75 else
76 bgp_unlock_node (prn);
77 table = prn->info;
78 }
paul718e3742002-12-13 20:15:29 +000079
80 rn = bgp_node_get (table, p);
81
82 if (safi == SAFI_MPLS_VPN)
83 rn->prn = prn;
84
85 return rn;
86}
87
88/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +000089static struct bgp_info *
paul718e3742002-12-13 20:15:29 +000090bgp_info_new ()
91{
92 struct bgp_info *new;
93
94 new = XMALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
95 memset (new, 0, sizeof (struct bgp_info));
96
97 return new;
98}
99
100/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000101static void
paul718e3742002-12-13 20:15:29 +0000102bgp_info_free (struct bgp_info *binfo)
103{
104 if (binfo->attr)
105 bgp_attr_unintern (binfo->attr);
106
107 if (binfo->damp_info)
108 bgp_damp_info_free (binfo->damp_info, 0);
109
paul200df112005-06-01 11:17:05 +0000110 peer_unlock (binfo->peer); /* bgp_info peer reference */
111
paul718e3742002-12-13 20:15:29 +0000112 XFREE (MTYPE_BGP_ROUTE, binfo);
113}
114
paul200df112005-06-01 11:17:05 +0000115struct bgp_info *
116bgp_info_lock (struct bgp_info *binfo)
117{
118 binfo->lock++;
119 return binfo;
120}
121
122struct bgp_info *
123bgp_info_unlock (struct bgp_info *binfo)
124{
125 assert (binfo && binfo->lock > 0);
126 binfo->lock--;
127
128 if (binfo->lock == 0)
129 {
130#if 0
131 zlog_debug ("%s: unlocked and freeing", __func__);
132 zlog_backtrace (LOG_DEBUG);
133#endif
134 bgp_info_free (binfo);
135 return NULL;
136 }
137
138#if 0
139 if (binfo->lock == 1)
140 {
141 zlog_debug ("%s: unlocked to 1", __func__);
142 zlog_backtrace (LOG_DEBUG);
143 }
144#endif
145
146 return binfo;
147}
148
paul718e3742002-12-13 20:15:29 +0000149void
150bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
151{
152 struct bgp_info *top;
153
154 top = rn->info;
paul200df112005-06-01 11:17:05 +0000155
paul718e3742002-12-13 20:15:29 +0000156 ri->next = rn->info;
157 ri->prev = NULL;
158 if (top)
159 top->prev = ri;
160 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000161
162 bgp_info_lock (ri);
163 bgp_lock_node (rn);
164 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000165}
166
167void
168bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
169{
170 if (ri->next)
171 ri->next->prev = ri->prev;
172 if (ri->prev)
173 ri->prev->next = ri->next;
174 else
175 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000176
177 bgp_info_unlock (ri);
178 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000179}
180
181/* Get MED value. If MED value is missing and "bgp bestpath
182 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000183static u_int32_t
paul718e3742002-12-13 20:15:29 +0000184bgp_med_value (struct attr *attr, struct bgp *bgp)
185{
186 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
187 return attr->med;
188 else
189 {
190 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000191 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000192 else
193 return 0;
194 }
195}
196
197/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000198static int
paul718e3742002-12-13 20:15:29 +0000199bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
200{
201 u_int32_t new_pref;
202 u_int32_t exist_pref;
203 u_int32_t new_med;
204 u_int32_t exist_med;
205 struct in_addr new_id;
206 struct in_addr exist_id;
207 int new_cluster;
208 int exist_cluster;
209 int internal_as_route = 0;
210 int confed_as_route = 0;
211 int ret;
212
213 /* 0. Null check. */
214 if (new == NULL)
215 return 0;
216 if (exist == NULL)
217 return 1;
218
219 /* 1. Weight check. */
220 if (new->attr->weight > exist->attr->weight)
221 return 1;
222 if (new->attr->weight < exist->attr->weight)
223 return 0;
224
225 /* 2. Local preference check. */
226 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
227 new_pref = new->attr->local_pref;
228 else
229 new_pref = bgp->default_local_pref;
230
231 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
232 exist_pref = exist->attr->local_pref;
233 else
234 exist_pref = bgp->default_local_pref;
235
236 if (new_pref > exist_pref)
237 return 1;
238 if (new_pref < exist_pref)
239 return 0;
240
241 /* 3. Local route check. */
242 if (new->sub_type == BGP_ROUTE_STATIC)
243 return 1;
244 if (exist->sub_type == BGP_ROUTE_STATIC)
245 return 0;
246
247 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
248 return 1;
249 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
250 return 0;
251
252 if (new->sub_type == BGP_ROUTE_AGGREGATE)
253 return 1;
254 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
255 return 0;
256
257 /* 4. AS path length check. */
258 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
259 {
hasso68118452005-04-08 15:40:36 +0000260 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
261 {
262 if ((new->attr->aspath->count +
263 new->attr->aspath->confed_count)
264 < (exist->attr->aspath->count +
265 exist->attr->aspath->confed_count))
266 return 1;
267 if ((new->attr->aspath->count +
268 new->attr->aspath->confed_count)
269 > (exist->attr->aspath->count +
270 exist->attr->aspath->confed_count))
271 return 0;
272 }
273 else
274 {
275 if (new->attr->aspath->count < exist->attr->aspath->count)
276 return 1;
277 if (new->attr->aspath->count > exist->attr->aspath->count)
278 return 0;
279 }
paul718e3742002-12-13 20:15:29 +0000280 }
281
282 /* 5. Origin check. */
283 if (new->attr->origin < exist->attr->origin)
284 return 1;
285 if (new->attr->origin > exist->attr->origin)
286 return 0;
287
288 /* 6. MED check. */
289 internal_as_route = (new->attr->aspath->length == 0
290 && exist->attr->aspath->length == 0);
291 confed_as_route = (new->attr->aspath->length > 0
292 && exist->attr->aspath->length > 0
293 && new->attr->aspath->count == 0
294 && exist->attr->aspath->count == 0);
295
296 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
297 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
298 && confed_as_route)
299 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
300 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
301 || internal_as_route)
302 {
303 new_med = bgp_med_value (new->attr, bgp);
304 exist_med = bgp_med_value (exist->attr, bgp);
305
306 if (new_med < exist_med)
307 return 1;
308 if (new_med > exist_med)
309 return 0;
310 }
311
312 /* 7. Peer type check. */
313 if (peer_sort (new->peer) == BGP_PEER_EBGP
314 && peer_sort (exist->peer) == BGP_PEER_IBGP)
315 return 1;
316 if (peer_sort (new->peer) == BGP_PEER_EBGP
317 && peer_sort (exist->peer) == BGP_PEER_CONFED)
318 return 1;
319 if (peer_sort (new->peer) == BGP_PEER_IBGP
320 && peer_sort (exist->peer) == BGP_PEER_EBGP)
321 return 0;
322 if (peer_sort (new->peer) == BGP_PEER_CONFED
323 && peer_sort (exist->peer) == BGP_PEER_EBGP)
324 return 0;
325
326 /* 8. IGP metric check. */
327 if (new->igpmetric < exist->igpmetric)
328 return 1;
329 if (new->igpmetric > exist->igpmetric)
330 return 0;
331
332 /* 9. Maximum path check. */
333
334 /* 10. If both paths are external, prefer the path that was received
335 first (the oldest one). This step minimizes route-flap, since a
336 newer path won't displace an older one, even if it was the
337 preferred route based on the additional decision criteria below. */
338 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
339 && peer_sort (new->peer) == BGP_PEER_EBGP
340 && peer_sort (exist->peer) == BGP_PEER_EBGP)
341 {
342 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
343 return 1;
344 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
345 return 0;
346 }
347
348 /* 11. Rourter-ID comparision. */
349 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
350 new_id.s_addr = new->attr->originator_id.s_addr;
351 else
352 new_id.s_addr = new->peer->remote_id.s_addr;
353 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
354 exist_id.s_addr = exist->attr->originator_id.s_addr;
355 else
356 exist_id.s_addr = exist->peer->remote_id.s_addr;
357
358 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
359 return 1;
360 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
361 return 0;
362
363 /* 12. Cluster length comparision. */
364 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
365 new_cluster = new->attr->cluster->length;
366 else
367 new_cluster = 0;
368 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
369 exist_cluster = exist->attr->cluster->length;
370 else
371 exist_cluster = 0;
372
373 if (new_cluster < exist_cluster)
374 return 1;
375 if (new_cluster > exist_cluster)
376 return 0;
377
378 /* 13. Neighbor address comparision. */
379 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
380
381 if (ret == 1)
382 return 0;
383 if (ret == -1)
384 return 1;
385
386 return 1;
387}
388
paul94f2b392005-06-28 12:44:16 +0000389static enum filter_type
paul718e3742002-12-13 20:15:29 +0000390bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
391 afi_t afi, safi_t safi)
392{
393 struct bgp_filter *filter;
394
395 filter = &peer->filter[afi][safi];
396
397 if (DISTRIBUTE_IN_NAME (filter))
398 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
399 return FILTER_DENY;
400
401 if (PREFIX_LIST_IN_NAME (filter))
402 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
403 return FILTER_DENY;
404
405 if (FILTER_LIST_IN_NAME (filter))
406 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
407 return FILTER_DENY;
408
409 return FILTER_PERMIT;
410}
411
paul94f2b392005-06-28 12:44:16 +0000412static enum filter_type
paul718e3742002-12-13 20:15:29 +0000413bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
414 afi_t afi, safi_t safi)
415{
416 struct bgp_filter *filter;
417
418 filter = &peer->filter[afi][safi];
419
420 if (DISTRIBUTE_OUT_NAME (filter))
421 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
422 return FILTER_DENY;
423
424 if (PREFIX_LIST_OUT_NAME (filter))
425 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
426 return FILTER_DENY;
427
428 if (FILTER_LIST_OUT_NAME (filter))
429 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
430 return FILTER_DENY;
431
432 return FILTER_PERMIT;
433}
434
435/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000436static int
paul718e3742002-12-13 20:15:29 +0000437bgp_community_filter (struct peer *peer, struct attr *attr)
438{
439 if (attr->community)
440 {
441 /* NO_ADVERTISE check. */
442 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
443 return 1;
444
445 /* NO_EXPORT check. */
446 if (peer_sort (peer) == BGP_PEER_EBGP &&
447 community_include (attr->community, COMMUNITY_NO_EXPORT))
448 return 1;
449
450 /* NO_EXPORT_SUBCONFED check. */
451 if (peer_sort (peer) == BGP_PEER_EBGP
452 || peer_sort (peer) == BGP_PEER_CONFED)
453 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
454 return 1;
455 }
456 return 0;
457}
458
459/* Route reflection loop check. */
460static int
461bgp_cluster_filter (struct peer *peer, struct attr *attr)
462{
463 struct in_addr cluster_id;
464
465 if (attr->cluster)
466 {
467 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
468 cluster_id = peer->bgp->cluster_id;
469 else
470 cluster_id = peer->bgp->router_id;
471
472 if (cluster_loop_check (attr->cluster, cluster_id))
473 return 1;
474 }
475 return 0;
476}
477
paul94f2b392005-06-28 12:44:16 +0000478static int
paul718e3742002-12-13 20:15:29 +0000479bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
480 afi_t afi, safi_t safi)
481{
482 struct bgp_filter *filter;
483 struct bgp_info info;
484 route_map_result_t ret;
485
486 filter = &peer->filter[afi][safi];
487
488 /* Apply default weight value. */
489 attr->weight = peer->weight;
490
491 /* Route map apply. */
492 if (ROUTE_MAP_IN_NAME (filter))
493 {
494 /* Duplicate current value to new strucutre for modification. */
495 info.peer = peer;
496 info.attr = attr;
497
paulac41b2a2003-08-12 05:32:27 +0000498 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
499
paul718e3742002-12-13 20:15:29 +0000500 /* Apply BGP route map to the attribute. */
501 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000502
503 peer->rmap_type = 0;
504
paul718e3742002-12-13 20:15:29 +0000505 if (ret == RMAP_DENYMATCH)
506 {
507 /* Free newly generated AS path and community by route-map. */
508 bgp_attr_flush (attr);
509 return RMAP_DENY;
510 }
511 }
512 return RMAP_PERMIT;
513}
514
paul94f2b392005-06-28 12:44:16 +0000515static int
paulfee0f4c2004-09-13 05:12:46 +0000516bgp_export_modifier (struct peer *rsclient, struct peer *peer,
517 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
518{
519 struct bgp_filter *filter;
520 struct bgp_info info;
521 route_map_result_t ret;
522
523 filter = &peer->filter[afi][safi];
524
525 /* Route map apply. */
526 if (ROUTE_MAP_EXPORT_NAME (filter))
527 {
528 /* Duplicate current value to new strucutre for modification. */
529 info.peer = rsclient;
530 info.attr = attr;
531
532 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
533
534 /* Apply BGP route map to the attribute. */
535 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
536
537 rsclient->rmap_type = 0;
538
539 if (ret == RMAP_DENYMATCH)
540 {
541 /* Free newly generated AS path and community by route-map. */
542 bgp_attr_flush (attr);
543 return RMAP_DENY;
544 }
545 }
546 return RMAP_PERMIT;
547}
548
paul94f2b392005-06-28 12:44:16 +0000549static int
paulfee0f4c2004-09-13 05:12:46 +0000550bgp_import_modifier (struct peer *rsclient, struct peer *peer,
551 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
552{
553 struct bgp_filter *filter;
554 struct bgp_info info;
555 route_map_result_t ret;
556
557 filter = &rsclient->filter[afi][safi];
558
559 /* Apply default weight value. */
560 attr->weight = peer->weight;
561
562 /* Route map apply. */
563 if (ROUTE_MAP_IMPORT_NAME (filter))
564 {
565 /* Duplicate current value to new strucutre for modification. */
566 info.peer = peer;
567 info.attr = attr;
568
569 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
570
571 /* Apply BGP route map to the attribute. */
572 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
573
574 peer->rmap_type = 0;
575
576 if (ret == RMAP_DENYMATCH)
577 {
578 /* Free newly generated AS path and community by route-map. */
579 bgp_attr_flush (attr);
580 return RMAP_DENY;
581 }
582 }
583 return RMAP_PERMIT;
584}
585
paul94f2b392005-06-28 12:44:16 +0000586static int
paul718e3742002-12-13 20:15:29 +0000587bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
588 struct attr *attr, afi_t afi, safi_t safi)
589{
590 int ret;
591 char buf[SU_ADDRSTRLEN];
592 struct bgp_filter *filter;
593 struct bgp_info info;
594 struct peer *from;
595 struct bgp *bgp;
596 struct attr dummy_attr;
597 int transparent;
598 int reflect;
599
600 from = ri->peer;
601 filter = &peer->filter[afi][safi];
602 bgp = peer->bgp;
603
604#ifdef DISABLE_BGP_ANNOUNCE
605 return 0;
606#endif
607
paulfee0f4c2004-09-13 05:12:46 +0000608 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
609 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
610 return 0;
611
paul718e3742002-12-13 20:15:29 +0000612 /* Do not send back route to sender. */
613 if (from == peer)
614 return 0;
615
paul35be31b2004-05-01 18:17:04 +0000616 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
617 if (p->family == AF_INET
618 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
619 return 0;
620#ifdef HAVE_IPV6
621 if (p->family == AF_INET6
622 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
623 return 0;
624#endif
625
paul718e3742002-12-13 20:15:29 +0000626 /* Aggregate-address suppress check. */
627 if (ri->suppress)
628 if (! UNSUPPRESS_MAP_NAME (filter))
629 return 0;
630
631 /* Default route check. */
632 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
633 {
634 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
635 return 0;
636#ifdef HAVE_IPV6
637 else if (p->family == AF_INET6 && p->prefixlen == 0)
638 return 0;
639#endif /* HAVE_IPV6 */
640 }
641
paul286e1e72003-08-08 00:24:31 +0000642 /* Transparency check. */
643 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
644 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
645 transparent = 1;
646 else
647 transparent = 0;
648
paul718e3742002-12-13 20:15:29 +0000649 /* If community is not disabled check the no-export and local. */
paul286e1e72003-08-08 00:24:31 +0000650 if (! transparent && bgp_community_filter (peer, ri->attr))
paul718e3742002-12-13 20:15:29 +0000651 return 0;
652
653 /* If the attribute has originator-id and it is same as remote
654 peer's id. */
655 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
656 {
657 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->originator_id))
658 {
659 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000660 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000661 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
662 peer->host,
663 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
664 p->prefixlen);
665 return 0;
666 }
667 }
668
669 /* ORF prefix-list filter check */
670 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
671 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
672 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
673 if (peer->orf_plist[afi][safi])
674 {
675 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
676 return 0;
677 }
678
679 /* Output filter check. */
680 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
681 {
682 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000683 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000684 "%s [Update:SEND] %s/%d is filtered",
685 peer->host,
686 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
687 p->prefixlen);
688 return 0;
689 }
690
691#ifdef BGP_SEND_ASPATH_CHECK
692 /* AS path loop check. */
693 if (aspath_loop_check (ri->attr->aspath, peer->as))
694 {
695 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000696 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000697 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
698 peer->host, peer->as);
699 return 0;
700 }
701#endif /* BGP_SEND_ASPATH_CHECK */
702
703 /* If we're a CONFED we need to loop check the CONFED ID too */
704 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
705 {
706 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
707 {
708 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000709 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000710 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
711 peer->host,
712 bgp->confed_id);
713 return 0;
714 }
715 }
716
717 /* Route-Reflect check. */
718 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
719 reflect = 1;
720 else
721 reflect = 0;
722
723 /* IBGP reflection check. */
724 if (reflect)
725 {
726 /* A route from a Client peer. */
727 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
728 {
729 /* Reflect to all the Non-Client peers and also to the
730 Client peers other than the originator. Originator check
731 is already done. So there is noting to do. */
732 /* no bgp client-to-client reflection check. */
733 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
734 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
735 return 0;
736 }
737 else
738 {
739 /* A route from a Non-client peer. Reflect to all other
740 clients. */
741 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
742 return 0;
743 }
744 }
745
746 /* For modify attribute, copy it to temporary structure. */
747 *attr = *ri->attr;
748
749 /* If local-preference is not set. */
750 if ((peer_sort (peer) == BGP_PEER_IBGP
751 || peer_sort (peer) == BGP_PEER_CONFED)
752 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
753 {
754 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
755 attr->local_pref = bgp->default_local_pref;
756 }
757
paul718e3742002-12-13 20:15:29 +0000758 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
759 if (peer_sort (peer) == BGP_PEER_EBGP
760 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
761 {
762 if (ri->peer != bgp->peer_self && ! transparent
763 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
764 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
765 }
766
767 /* next-hop-set */
768 if (transparent || reflect
769 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
770 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000771#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000772 || (p->family == AF_INET6 &&
773 ! IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000774#endif /* HAVE_IPV6 */
775 )))
paul718e3742002-12-13 20:15:29 +0000776 {
777 /* NEXT-HOP Unchanged. */
778 }
779 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
780 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
781#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000782 || (p->family == AF_INET6 &&
783 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000784#endif /* HAVE_IPV6 */
785 || (peer_sort (peer) == BGP_PEER_EBGP
786 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
787 {
788 /* Set IPv4 nexthop. */
789 if (p->family == AF_INET)
790 {
791 if (safi == SAFI_MPLS_VPN)
792 memcpy (&attr->mp_nexthop_global_in, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
793 else
794 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
795 }
796#ifdef HAVE_IPV6
797 /* Set IPv6 nexthop. */
798 if (p->family == AF_INET6)
799 {
800 /* IPv6 global nexthop must be included. */
801 memcpy (&attr->mp_nexthop_global, &peer->nexthop.v6_global,
802 IPV6_MAX_BYTELEN);
803 attr->mp_nexthop_len = 16;
804 }
805#endif /* HAVE_IPV6 */
806 }
807
808#ifdef HAVE_IPV6
809 if (p->family == AF_INET6)
810 {
paulfee0f4c2004-09-13 05:12:46 +0000811 /* Left nexthop_local unchanged if so configured. */
812 if ( CHECK_FLAG (peer->af_flags[afi][safi],
813 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
814 {
815 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
816 attr->mp_nexthop_len=32;
817 else
818 attr->mp_nexthop_len=16;
819 }
820
821 /* Default nexthop_local treatment for non-RS-Clients */
822 else
823 {
paul718e3742002-12-13 20:15:29 +0000824 /* Link-local address should not be transit to different peer. */
825 attr->mp_nexthop_len = 16;
826
827 /* Set link-local address for shared network peer. */
828 if (peer->shared_network
829 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
830 {
831 memcpy (&attr->mp_nexthop_local, &peer->nexthop.v6_local,
832 IPV6_MAX_BYTELEN);
833 attr->mp_nexthop_len = 32;
834 }
835
836 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
837 address.*/
838 if (reflect)
839 attr->mp_nexthop_len = 16;
840
841 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
842 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
843 attr->mp_nexthop_len = 16;
844 }
paulfee0f4c2004-09-13 05:12:46 +0000845
846 }
paul718e3742002-12-13 20:15:29 +0000847#endif /* HAVE_IPV6 */
848
849 /* If this is EBGP peer and remove-private-AS is set. */
850 if (peer_sort (peer) == BGP_PEER_EBGP
851 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
852 && aspath_private_as_check (attr->aspath))
853 attr->aspath = aspath_empty_get ();
854
855 /* Route map & unsuppress-map apply. */
856 if (ROUTE_MAP_OUT_NAME (filter)
857 || ri->suppress)
858 {
859 info.peer = peer;
860 info.attr = attr;
861
862 /* The route reflector is not allowed to modify the attributes
863 of the reflected IBGP routes. */
864 if (peer_sort (from) == BGP_PEER_IBGP
865 && peer_sort (peer) == BGP_PEER_IBGP)
866 {
867 dummy_attr = *attr;
868 info.attr = &dummy_attr;
869 }
paulac41b2a2003-08-12 05:32:27 +0000870
871 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
872
paul718e3742002-12-13 20:15:29 +0000873 if (ri->suppress)
874 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
875 else
876 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
877
paulac41b2a2003-08-12 05:32:27 +0000878 peer->rmap_type = 0;
879
paul718e3742002-12-13 20:15:29 +0000880 if (ret == RMAP_DENYMATCH)
881 {
882 bgp_attr_flush (attr);
883 return 0;
884 }
885 }
886 return 1;
887}
888
paul94f2b392005-06-28 12:44:16 +0000889static int
paulfee0f4c2004-09-13 05:12:46 +0000890bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
891 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000892{
paulfee0f4c2004-09-13 05:12:46 +0000893 int ret;
894 char buf[SU_ADDRSTRLEN];
895 struct bgp_filter *filter;
896 struct bgp_info info;
897 struct peer *from;
898 struct bgp *bgp;
899
900 from = ri->peer;
901 filter = &rsclient->filter[afi][safi];
902 bgp = rsclient->bgp;
903
904#ifdef DISABLE_BGP_ANNOUNCE
905 return 0;
906#endif
907
908 /* Do not send back route to sender. */
909 if (from == rsclient)
910 return 0;
911
912 /* Aggregate-address suppress check. */
913 if (ri->suppress)
914 if (! UNSUPPRESS_MAP_NAME (filter))
915 return 0;
916
917 /* Default route check. */
918 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
919 PEER_STATUS_DEFAULT_ORIGINATE))
920 {
921 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
922 return 0;
923#ifdef HAVE_IPV6
924 else if (p->family == AF_INET6 && p->prefixlen == 0)
925 return 0;
926#endif /* HAVE_IPV6 */
927 }
928
929 /* If the attribute has originator-id and it is same as remote
930 peer's id. */
931 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
932 {
933 if (IPV4_ADDR_SAME (&rsclient->remote_id, &ri->attr->originator_id))
934 {
935 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000936 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000937 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
938 rsclient->host,
939 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
940 p->prefixlen);
941 return 0;
942 }
943 }
944
945 /* ORF prefix-list filter check */
946 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
947 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
948 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
949 if (rsclient->orf_plist[afi][safi])
950 {
951 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
952 return 0;
953 }
954
955 /* Output filter check. */
956 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
957 {
958 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000959 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000960 "%s [Update:SEND] %s/%d is filtered",
961 rsclient->host,
962 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
963 p->prefixlen);
964 return 0;
965 }
966
967#ifdef BGP_SEND_ASPATH_CHECK
968 /* AS path loop check. */
969 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
970 {
971 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000972 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000973 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
974 rsclient->host, rsclient->as);
975 return 0;
976 }
977#endif /* BGP_SEND_ASPATH_CHECK */
978
979 /* For modify attribute, copy it to temporary structure. */
980 *attr = *ri->attr;
981
982 /* next-hop-set */
983 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
984#ifdef HAVE_IPV6
985 || (p->family == AF_INET6 &&
986 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
987#endif /* HAVE_IPV6 */
988 )
989 {
990 /* Set IPv4 nexthop. */
991 if (p->family == AF_INET)
992 {
993 if (safi == SAFI_MPLS_VPN)
994 memcpy (&attr->mp_nexthop_global_in, &rsclient->nexthop.v4,
995 IPV4_MAX_BYTELEN);
996 else
997 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
998 }
999#ifdef HAVE_IPV6
1000 /* Set IPv6 nexthop. */
1001 if (p->family == AF_INET6)
1002 {
1003 /* IPv6 global nexthop must be included. */
1004 memcpy (&attr->mp_nexthop_global, &rsclient->nexthop.v6_global,
1005
1006 IPV6_MAX_BYTELEN);
1007 attr->mp_nexthop_len = 16;
1008 }
1009#endif /* HAVE_IPV6 */
1010 }
1011
1012#ifdef HAVE_IPV6
1013 if (p->family == AF_INET6)
1014 {
1015 /* Left nexthop_local unchanged if so configured. */
1016 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1017 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1018 {
1019 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1020 attr->mp_nexthop_len=32;
1021 else
1022 attr->mp_nexthop_len=16;
1023 }
1024
1025 /* Default nexthop_local treatment for RS-Clients */
1026 else
1027 {
1028 /* Announcer and RS-Client are both in the same network */
1029 if (rsclient->shared_network && from->shared_network &&
1030 (rsclient->ifindex == from->ifindex))
1031 {
1032 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1033 attr->mp_nexthop_len=32;
1034 else
1035 attr->mp_nexthop_len=16;
1036 }
1037
1038 /* Set link-local address for shared network peer. */
1039 else if (rsclient->shared_network
1040 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1041 {
1042 memcpy (&attr->mp_nexthop_local, &rsclient->nexthop.v6_local,
1043 IPV6_MAX_BYTELEN);
1044 attr->mp_nexthop_len = 32;
1045 }
1046
1047 else
1048 attr->mp_nexthop_len = 16;
1049 }
1050
1051 }
1052#endif /* HAVE_IPV6 */
1053
1054
1055 /* If this is EBGP peer and remove-private-AS is set. */
1056 if (peer_sort (rsclient) == BGP_PEER_EBGP
1057 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1058 && aspath_private_as_check (attr->aspath))
1059 attr->aspath = aspath_empty_get ();
1060
1061 /* Route map & unsuppress-map apply. */
1062 if (ROUTE_MAP_OUT_NAME (filter) || ri->suppress)
1063 {
1064 info.peer = rsclient;
1065 info.attr = attr;
1066
1067 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1068
1069 if (ri->suppress)
1070 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1071 else
1072 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1073
1074 rsclient->rmap_type = 0;
1075
1076 if (ret == RMAP_DENYMATCH)
1077 {
1078 bgp_attr_flush (attr);
1079 return 0;
1080 }
1081 }
1082
1083 return 1;
1084}
1085
1086struct bgp_info_pair
1087{
1088 struct bgp_info *old;
1089 struct bgp_info *new;
1090};
1091
paul94f2b392005-06-28 12:44:16 +00001092static void
paulfee0f4c2004-09-13 05:12:46 +00001093bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1094{
paul718e3742002-12-13 20:15:29 +00001095 struct bgp_info *new_select;
1096 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001097 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001098 struct bgp_info *ri1;
1099 struct bgp_info *ri2;
1100
paul718e3742002-12-13 20:15:29 +00001101 /* bgp deterministic-med */
1102 new_select = NULL;
1103 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1104 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1105 {
1106 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1107 continue;
1108 if (BGP_INFO_HOLDDOWN (ri1))
1109 continue;
1110
1111 new_select = ri1;
1112 if (ri1->next)
1113 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1114 {
1115 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1116 continue;
1117 if (BGP_INFO_HOLDDOWN (ri2))
1118 continue;
1119
1120 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1121 || aspath_cmp_left_confed (ri1->attr->aspath,
1122 ri2->attr->aspath))
1123 {
1124 if (bgp_info_cmp (bgp, ri2, new_select))
1125 {
1126 UNSET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
1127 new_select = ri2;
1128 }
1129
1130 SET_FLAG (ri2->flags, BGP_INFO_DMED_CHECK);
1131 }
1132 }
1133 SET_FLAG (new_select->flags, BGP_INFO_DMED_CHECK);
1134 SET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
1135 }
1136
1137 /* Check old selected route and new selected route. */
1138 old_select = NULL;
1139 new_select = NULL;
1140 for (ri = rn->info; ri; ri = ri->next)
1141 {
1142 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1143 old_select = ri;
1144
1145 if (BGP_INFO_HOLDDOWN (ri))
1146 continue;
1147
1148 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1149 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1150 {
1151 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
1152 continue;
1153 }
1154 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
1155 UNSET_FLAG (ri->flags, BGP_INFO_DMED_SELECTED);
1156
1157 if (bgp_info_cmp (bgp, ri, new_select))
1158 new_select = ri;
1159 }
1160
paulfee0f4c2004-09-13 05:12:46 +00001161 result->old = old_select;
1162 result->new = new_select;
1163
1164 return;
1165}
1166
paul94f2b392005-06-28 12:44:16 +00001167static int
paulfee0f4c2004-09-13 05:12:46 +00001168bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1169 struct bgp_node *rn, struct attr *attr, afi_t afi, safi_t safi)
1170 {
1171 struct prefix *p;
1172
1173 p = &rn->p;
1174
1175 /* Announce route to Established peer. */
1176 if (peer->status != Established)
1177 return 0;
1178
1179 /* Address family configuration check. */
1180 if (! peer->afc_nego[afi][safi])
1181 return 0;
1182
1183 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1184 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1185 PEER_STATUS_ORF_WAIT_REFRESH))
1186 return 0;
1187
1188 switch (rn->table->type)
1189 {
1190 case BGP_TABLE_MAIN:
1191 /* Announcement to peer->conf. If the route is filtered,
1192 withdraw it. */
1193 if (selected && bgp_announce_check (selected, peer, p, attr, afi, safi))
1194 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1195 else
1196 bgp_adj_out_unset (rn, peer, p, afi, safi);
1197 break;
1198 case BGP_TABLE_RSCLIENT:
1199 /* Announcement to peer->conf. If the route is filtered,
1200 withdraw it. */
1201 if (selected && bgp_announce_check_rsclient
1202 (selected, peer, p, attr, afi, safi))
1203 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1204 else
1205 bgp_adj_out_unset (rn, peer, p, afi, safi);
1206 break;
1207 }
1208 return 0;
paul200df112005-06-01 11:17:05 +00001209}
paulfee0f4c2004-09-13 05:12:46 +00001210
paul200df112005-06-01 11:17:05 +00001211struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001212{
paul200df112005-06-01 11:17:05 +00001213 struct bgp *bgp;
1214 struct bgp_node *rn;
1215 afi_t afi;
1216 safi_t safi;
1217};
1218
1219static wq_item_status
1220bgp_process_rsclient (struct bgp_process_queue *pq)
1221{
1222 struct bgp *bgp = pq->bgp;
1223 struct bgp_node *rn = pq->rn;
1224 afi_t afi = pq->afi;
1225 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001226 struct bgp_info *new_select;
1227 struct bgp_info *old_select;
1228 struct bgp_info_pair old_and_new;
1229 struct attr attr;
paul1eb8ef22005-04-07 07:30:20 +00001230 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001231 struct peer *rsclient = rn->table->owner;
1232
1233 /* we shouldn't run if the clear_route_node queue is still running
1234 * or scheduled to run, or we can race with session coming up
1235 * and adding routes back before we've cleared them
1236 */
1237 if (bm->clear_node_queue && bm->clear_node_queue->thread)
1238 return WQ_QUEUE_BLOCKED;
1239
paulfee0f4c2004-09-13 05:12:46 +00001240 /* Best path selection. */
1241 bgp_best_selection (bgp, rn, &old_and_new);
1242 new_select = old_and_new.new;
1243 old_select = old_and_new.old;
1244
paul200df112005-06-01 11:17:05 +00001245 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1246 {
1247 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1248 {
1249 /* Nothing to do. */
1250 if (old_select && old_select == new_select)
1251 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1252 continue;
paulfee0f4c2004-09-13 05:12:46 +00001253
paul200df112005-06-01 11:17:05 +00001254 if (old_select)
1255 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1256 if (new_select)
1257 {
1258 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1259 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1260 }
paulfee0f4c2004-09-13 05:12:46 +00001261
paul200df112005-06-01 11:17:05 +00001262 bgp_process_announce_selected (rsclient, new_select, rn, &attr,
1263 afi, safi);
1264 }
1265 }
1266 else
1267 {
1268 bgp_process_announce_selected (rsclient, new_select, rn,
1269 &attr, afi, safi);
1270 }
paulfee0f4c2004-09-13 05:12:46 +00001271
paul200df112005-06-01 11:17:05 +00001272 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1273 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001274}
1275
paul200df112005-06-01 11:17:05 +00001276static wq_item_status
1277bgp_process_main (struct bgp_process_queue *pq)
1278{
1279 struct bgp *bgp = pq->bgp;
1280 struct bgp_node *rn = pq->rn;
1281 afi_t afi = pq->afi;
1282 safi_t safi = pq->safi;
1283 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001284 struct bgp_info *new_select;
1285 struct bgp_info *old_select;
1286 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001287 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001288 struct peer *peer;
1289 struct attr attr;
paul200df112005-06-01 11:17:05 +00001290
1291 /* we shouldn't run if the clear_route_node queue is still running
1292 * or scheduled to run, or we can race with session coming up
1293 * and adding routes back before we've cleared them
1294 */
1295 if (bm->clear_node_queue && bm->clear_node_queue->thread)
1296 return WQ_QUEUE_BLOCKED;
paulfee0f4c2004-09-13 05:12:46 +00001297
1298 /* Best path selection. */
1299 bgp_best_selection (bgp, rn, &old_and_new);
1300 old_select = old_and_new.old;
1301 new_select = old_and_new.new;
1302
1303 /* Nothing to do. */
1304 if (old_select && old_select == new_select)
1305 {
1306 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001307 {
1308 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1309 bgp_zebra_announce (p, old_select, bgp);
1310
1311 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1312 return WQ_SUCCESS;
1313 }
paulfee0f4c2004-09-13 05:12:46 +00001314 }
paul718e3742002-12-13 20:15:29 +00001315
hasso338b3422005-02-23 14:27:24 +00001316 if (old_select)
1317 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1318 if (new_select)
1319 {
1320 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1321 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1322 }
1323
1324
paul718e3742002-12-13 20:15:29 +00001325 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001326 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001327 {
paulfee0f4c2004-09-13 05:12:46 +00001328 bgp_process_announce_selected (peer, new_select, rn, &attr, afi, safi);
paul718e3742002-12-13 20:15:29 +00001329 }
1330
1331 /* FIB update. */
1332 if (safi == SAFI_UNICAST && ! bgp->name &&
1333 ! bgp_option_check (BGP_OPT_NO_FIB))
1334 {
1335 if (new_select
1336 && new_select->type == ZEBRA_ROUTE_BGP
1337 && new_select->sub_type == BGP_ROUTE_NORMAL)
1338 bgp_zebra_announce (p, new_select, bgp);
1339 else
1340 {
1341 /* Withdraw the route from the kernel. */
1342 if (old_select
1343 && old_select->type == ZEBRA_ROUTE_BGP
1344 && old_select->sub_type == BGP_ROUTE_NORMAL)
1345 bgp_zebra_withdraw (p, old_select);
1346 }
1347 }
paul200df112005-06-01 11:17:05 +00001348 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1349 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001350}
1351
paul200df112005-06-01 11:17:05 +00001352static void
1353bgp_processq_del (struct bgp_process_queue *pq)
1354{
1355 bgp_unlock_node (pq->rn);
1356 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1357}
1358
1359static void
1360bgp_process_queue_init (void)
1361{
1362 bm->process_main_queue
1363 = work_queue_new (bm->master, "process_main_queue");
1364 bm->process_rsclient_queue
1365 = work_queue_new (bm->master, "process_rsclient_queue");
1366
1367 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1368 {
1369 zlog_err ("%s: Failed to allocate work queue", __func__);
1370 exit (1);
1371 }
1372
1373 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1374 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1375 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1376 bm->process_rsclient_queue->spec.del_item_data
1377 = bm->process_main_queue->spec.del_item_data;
1378 bm->process_main_queue->spec.max_retries
1379 = bm->process_main_queue->spec.max_retries = 0;
1380 bm->process_rsclient_queue->spec.hold
1381 = bm->process_main_queue->spec.hold = 500;
1382 bm->process_rsclient_queue->spec.delay
1383 = bm->process_main_queue->spec.delay = 10;
1384}
1385
1386void
paulfee0f4c2004-09-13 05:12:46 +00001387bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1388{
paul200df112005-06-01 11:17:05 +00001389 struct bgp_process_queue *pqnode;
1390
1391 /* already scheduled for processing? */
1392 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1393 return;
1394
1395 if ( (bm->process_main_queue == NULL) ||
1396 (bm->process_rsclient_queue == NULL) )
1397 bgp_process_queue_init ();
1398
1399 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1400 sizeof (struct bgp_process_queue));
1401 if (!pqnode)
1402 return;
1403
1404 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1405 pqnode->bgp = bgp;
1406 pqnode->afi = afi;
1407 pqnode->safi = safi;
1408
paulfee0f4c2004-09-13 05:12:46 +00001409 switch (rn->table->type)
1410 {
paul200df112005-06-01 11:17:05 +00001411 case BGP_TABLE_MAIN:
1412 work_queue_add (bm->process_main_queue, pqnode);
1413 break;
1414 case BGP_TABLE_RSCLIENT:
1415 work_queue_add (bm->process_rsclient_queue, pqnode);
1416 break;
paulfee0f4c2004-09-13 05:12:46 +00001417 }
paul200df112005-06-01 11:17:05 +00001418
1419 return;
paulfee0f4c2004-09-13 05:12:46 +00001420}
hasso0a486e52005-02-01 20:57:17 +00001421
paul94f2b392005-06-28 12:44:16 +00001422static int
hasso0a486e52005-02-01 20:57:17 +00001423bgp_maximum_prefix_restart_timer (struct thread *thread)
1424{
1425 struct peer *peer;
1426
1427 peer = THREAD_ARG (thread);
1428 peer->t_pmax_restart = NULL;
1429
1430 if (BGP_DEBUG (events, EVENTS))
1431 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1432 peer->host);
1433
1434 peer_clear (peer);
1435
1436 return 0;
1437}
1438
paulfee0f4c2004-09-13 05:12:46 +00001439int
paul5228ad22004-06-04 17:58:18 +00001440bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1441 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001442{
hassoe0701b72004-05-20 09:19:34 +00001443 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1444 return 0;
1445
1446 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001447 {
hassoe0701b72004-05-20 09:19:34 +00001448 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1449 && ! always)
1450 return 0;
paul718e3742002-12-13 20:15:29 +00001451
hassoe0701b72004-05-20 09:19:34 +00001452 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001453 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1454 "limit %ld", afi_safi_print (afi, safi), peer->host,
1455 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001456 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001457
hassoe0701b72004-05-20 09:19:34 +00001458 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1459 return 0;
paul718e3742002-12-13 20:15:29 +00001460
hassoe0701b72004-05-20 09:19:34 +00001461 {
paul5228ad22004-06-04 17:58:18 +00001462 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001463
1464 if (safi == SAFI_MPLS_VPN)
1465 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001466
1467 ndata[0] = (afi >> 8);
1468 ndata[1] = afi;
1469 ndata[2] = safi;
1470 ndata[3] = (peer->pmax[afi][safi] >> 24);
1471 ndata[4] = (peer->pmax[afi][safi] >> 16);
1472 ndata[5] = (peer->pmax[afi][safi] >> 8);
1473 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001474
1475 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1476 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1477 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1478 }
hasso0a486e52005-02-01 20:57:17 +00001479
1480 /* restart timer start */
1481 if (peer->pmax_restart[afi][safi])
1482 {
1483 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1484
1485 if (BGP_DEBUG (events, EVENTS))
1486 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1487 peer->host, peer->v_pmax_restart);
1488
1489 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1490 peer->v_pmax_restart);
1491 }
1492
hassoe0701b72004-05-20 09:19:34 +00001493 return 1;
paul718e3742002-12-13 20:15:29 +00001494 }
hassoe0701b72004-05-20 09:19:34 +00001495 else
1496 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1497
1498 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1499 {
1500 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1501 && ! always)
1502 return 0;
1503
1504 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001505 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1506 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1507 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001508 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1509 }
1510 else
1511 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001512 return 0;
1513}
1514
paul94f2b392005-06-28 12:44:16 +00001515static void
paul718e3742002-12-13 20:15:29 +00001516bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1517 afi_t afi, safi_t safi)
1518{
1519 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1520 {
paulfee0f4c2004-09-13 05:12:46 +00001521 /* Ignore 'pcount' for RS-client tables */
1522 if ( rn->table->type == BGP_TABLE_MAIN)
1523 {
paul718e3742002-12-13 20:15:29 +00001524 peer->pcount[afi][safi]--;
1525 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001526 }
paul718e3742002-12-13 20:15:29 +00001527 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
1528 bgp_process (peer->bgp, rn, afi, safi);
1529 }
1530 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00001531}
1532
paul94f2b392005-06-28 12:44:16 +00001533static void
paul718e3742002-12-13 20:15:29 +00001534bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1535 afi_t afi, safi_t safi, int force)
1536{
1537 int valid;
1538 int status = BGP_DAMP_NONE;
1539
paulfee0f4c2004-09-13 05:12:46 +00001540 /* Ignore 'pcount' for RS-client tables */
1541 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY) &&
1542 rn->table->type == BGP_TABLE_MAIN)
paul718e3742002-12-13 20:15:29 +00001543 {
hasso93406d82005-02-02 14:40:33 +00001544 if (! CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1545 peer->pcount[afi][safi]--;
paul718e3742002-12-13 20:15:29 +00001546 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1547 }
1548
1549 if (! force)
1550 {
1551 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1552 && peer_sort (peer) == BGP_PEER_EBGP)
1553 status = bgp_damp_withdraw (ri, rn, afi, safi, 0);
1554
1555 if (status == BGP_DAMP_SUPPRESSED)
1556 return;
1557 }
1558
1559 valid = CHECK_FLAG (ri->flags, BGP_INFO_VALID);
1560 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
1561 bgp_process (peer->bgp, rn, afi, safi);
1562
1563 if (valid)
1564 SET_FLAG (ri->flags, BGP_INFO_VALID);
1565
1566 if (status != BGP_DAMP_USED)
paul200df112005-06-01 11:17:05 +00001567 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00001568}
1569
paul94f2b392005-06-28 12:44:16 +00001570static void
paulfee0f4c2004-09-13 05:12:46 +00001571bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1572 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1573 int sub_type, struct prefix_rd *prd, u_char *tag)
1574{
1575 struct bgp_node *rn;
1576 struct bgp *bgp;
1577 struct attr new_attr;
1578 struct attr *attr_new;
1579 struct attr *attr_new2;
1580 struct bgp_info *ri;
1581 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001582 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001583 char buf[SU_ADDRSTRLEN];
1584
1585 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1586 if (peer == rsclient)
1587 return;
1588
1589 bgp = peer->bgp;
1590 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1591
1592 /* Check previously received route. */
1593 for (ri = rn->info; ri; ri = ri->next)
1594 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1595 break;
1596
1597 /* AS path loop check. */
1598 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1599 {
1600 reason = "as-path contains our own AS;";
1601 goto filtered;
1602 }
1603
1604 /* Route reflector originator ID check. */
1605 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1606 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->originator_id))
1607 {
1608 reason = "originator is us;";
1609 goto filtered;
1610 }
1611
1612 new_attr = *attr;
1613
1614 /* Apply export policy. */
1615 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1616 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1617 {
1618 reason = "export-policy;";
1619 goto filtered;
1620 }
1621
1622 attr_new2 = bgp_attr_intern (&new_attr);
1623
1624 /* Apply import policy. */
1625 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1626 {
1627 bgp_attr_unintern (attr_new2);
1628
1629 reason = "import-policy;";
1630 goto filtered;
1631 }
1632
1633 attr_new = bgp_attr_intern (&new_attr);
1634 bgp_attr_unintern (attr_new2);
1635
1636 /* IPv4 unicast next hop check. */
1637 if (afi == AFI_IP && safi == SAFI_UNICAST)
1638 {
1639 /* Next hop must not be 0.0.0.0 nor Class E address. */
1640 if (new_attr.nexthop.s_addr == 0
1641 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1642 {
1643 bgp_attr_unintern (attr_new);
1644
1645 reason = "martian next-hop;";
1646 goto filtered;
1647 }
1648 }
1649
1650 /* If the update is implicit withdraw. */
1651 if (ri)
1652 {
1653 ri->uptime = time (NULL);
1654
1655 /* Same attribute comes in. */
1656 if (attrhash_cmp (ri->attr, attr_new))
1657 {
1658
1659 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1660
1661 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001662 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001663 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1664 peer->host,
1665 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1666 p->prefixlen, rsclient->host);
1667
1668 bgp_unlock_node (rn);
1669 bgp_attr_unintern (attr_new);
1670
1671 return;
1672 }
1673
1674 /* Received Logging. */
1675 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001676 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001677 peer->host,
1678 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1679 p->prefixlen, rsclient->host);
1680
1681 /* The attribute is changed. */
1682 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1683
1684 /* Update to new attribute. */
1685 bgp_attr_unintern (ri->attr);
1686 ri->attr = attr_new;
1687
1688 /* Update MPLS tag. */
1689 if (safi == SAFI_MPLS_VPN)
1690 memcpy (ri->tag, tag, 3);
1691
1692 SET_FLAG (ri->flags, BGP_INFO_VALID);
1693
1694 /* Process change. */
1695 bgp_process (bgp, rn, afi, safi);
1696 bgp_unlock_node (rn);
1697
1698 return;
1699 }
1700
1701 /* Received Logging. */
1702 if (BGP_DEBUG (update, UPDATE_IN))
1703 {
ajsd2c1f162004-12-08 21:10:20 +00001704 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001705 peer->host,
1706 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1707 p->prefixlen, rsclient->host);
1708 }
1709
1710 /* Make new BGP info. */
1711 new = bgp_info_new ();
1712 new->type = type;
1713 new->sub_type = sub_type;
1714 new->peer = peer;
1715 new->attr = attr_new;
1716 new->uptime = time (NULL);
1717
1718 /* Update MPLS tag. */
1719 if (safi == SAFI_MPLS_VPN)
1720 memcpy (new->tag, tag, 3);
1721
1722 SET_FLAG (new->flags, BGP_INFO_VALID);
1723
1724 /* Register new BGP information. */
1725 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001726
1727 /* route_node_get lock */
1728 bgp_unlock_node (rn);
1729
paulfee0f4c2004-09-13 05:12:46 +00001730 /* Process change. */
1731 bgp_process (bgp, rn, afi, safi);
1732
1733 return;
1734
1735 filtered:
1736
1737 /* This BGP update is filtered. Log the reason then update BGP entry. */
1738 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001739 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001740 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1741 peer->host,
1742 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1743 p->prefixlen, rsclient->host, reason);
1744
1745 if (ri)
1746 bgp_rib_withdraw (rn, ri, peer, afi, safi, 1);
1747
1748 bgp_unlock_node (rn);
1749
1750 return;
1751}
1752
paul94f2b392005-06-28 12:44:16 +00001753static void
paulfee0f4c2004-09-13 05:12:46 +00001754bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1755 struct peer *peer, struct prefix *p, int type, int sub_type,
1756 struct prefix_rd *prd, u_char *tag)
1757 {
1758 struct bgp_node *rn;
1759 struct bgp_info *ri;
1760 char buf[SU_ADDRSTRLEN];
1761
1762 if (rsclient == peer)
1763 return;
1764
1765 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1766
1767 /* Lookup withdrawn route. */
1768 for (ri = rn->info; ri; ri = ri->next)
1769 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1770 break;
1771
1772 /* Withdraw specified route from routing table. */
1773 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1774 bgp_rib_withdraw (rn, ri, peer, afi, safi, 0);
1775 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001776 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001777 "%s Can't find the route %s/%d", peer->host,
1778 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1779 p->prefixlen);
1780
1781 /* Unlock bgp_node_get() lock. */
1782 bgp_unlock_node (rn);
1783 }
1784
paul94f2b392005-06-28 12:44:16 +00001785static int
paulfee0f4c2004-09-13 05:12:46 +00001786bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001787 afi_t afi, safi_t safi, int type, int sub_type,
1788 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1789{
1790 int ret;
1791 int aspath_loop_count = 0;
1792 struct bgp_node *rn;
1793 struct bgp *bgp;
1794 struct attr new_attr;
1795 struct attr *attr_new;
1796 struct bgp_info *ri;
1797 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001798 const char *reason;
paul718e3742002-12-13 20:15:29 +00001799 char buf[SU_ADDRSTRLEN];
1800
1801 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00001802 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00001803
1804 /* When peer's soft reconfiguration enabled. Record input packet in
1805 Adj-RIBs-In. */
1806 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1807 && peer != bgp->peer_self && ! soft_reconfig)
1808 bgp_adj_in_set (rn, peer, attr);
1809
1810 /* Check previously received route. */
1811 for (ri = rn->info; ri; ri = ri->next)
1812 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1813 break;
1814
1815 /* AS path local-as loop check. */
1816 if (peer->change_local_as)
1817 {
1818 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
1819 aspath_loop_count = 1;
1820
1821 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
1822 {
1823 reason = "as-path contains our own AS;";
1824 goto filtered;
1825 }
1826 }
1827
1828 /* AS path loop check. */
1829 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
1830 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
1831 && aspath_loop_check(attr->aspath, bgp->confed_id)
1832 > peer->allowas_in[afi][safi]))
1833 {
1834 reason = "as-path contains our own AS;";
1835 goto filtered;
1836 }
1837
1838 /* Route reflector originator ID check. */
1839 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1840 && IPV4_ADDR_SAME (&bgp->router_id, &attr->originator_id))
1841 {
1842 reason = "originator is us;";
1843 goto filtered;
1844 }
1845
1846 /* Route reflector cluster ID check. */
1847 if (bgp_cluster_filter (peer, attr))
1848 {
1849 reason = "reflected from the same cluster;";
1850 goto filtered;
1851 }
1852
1853 /* Apply incoming filter. */
1854 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
1855 {
1856 reason = "filter;";
1857 goto filtered;
1858 }
1859
1860 /* Apply incoming route-map. */
1861 new_attr = *attr;
1862
1863 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
1864 {
1865 reason = "route-map;";
1866 goto filtered;
1867 }
1868
1869 /* IPv4 unicast next hop check. */
1870 if (afi == AFI_IP && safi == SAFI_UNICAST)
1871 {
1872 /* If the peer is EBGP and nexthop is not on connected route,
1873 discard it. */
1874 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
1875 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00001876 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00001877 {
1878 reason = "non-connected next-hop;";
1879 goto filtered;
1880 }
1881
1882 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
1883 must not be my own address. */
1884 if (bgp_nexthop_self (afi, &new_attr)
1885 || new_attr.nexthop.s_addr == 0
1886 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1887 {
1888 reason = "martian next-hop;";
1889 goto filtered;
1890 }
1891 }
1892
1893 attr_new = bgp_attr_intern (&new_attr);
1894
1895 /* If the update is implicit withdraw. */
1896 if (ri)
1897 {
1898 ri->uptime = time (NULL);
1899
1900 /* Same attribute comes in. */
1901 if (attrhash_cmp (ri->attr, attr_new))
1902 {
1903 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1904
1905 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1906 && peer_sort (peer) == BGP_PEER_EBGP
1907 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1908 {
1909 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001910 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00001911 peer->host,
1912 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1913 p->prefixlen);
1914
1915 peer->pcount[afi][safi]++;
1916 ret = bgp_damp_update (ri, rn, afi, safi);
1917 if (ret != BGP_DAMP_SUPPRESSED)
1918 {
1919 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1920 bgp_process (bgp, rn, afi, safi);
1921 }
1922 }
1923 else
1924 {
1925 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001926 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00001927 "%s rcvd %s/%d...duplicate ignored",
1928 peer->host,
1929 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1930 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00001931
1932 /* graceful restart STALE flag unset. */
1933 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1934 {
1935 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
1936 peer->pcount[afi][safi]++;
1937 }
paul718e3742002-12-13 20:15:29 +00001938 }
1939
1940 bgp_unlock_node (rn);
1941 bgp_attr_unintern (attr_new);
1942 return 0;
1943 }
1944
1945 /* Received Logging. */
1946 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001947 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00001948 peer->host,
1949 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1950 p->prefixlen);
1951
hasso93406d82005-02-02 14:40:33 +00001952 /* graceful restart STALE flag unset. */
1953 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1954 {
1955 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
1956 peer->pcount[afi][safi]++;
1957 }
1958
paul718e3742002-12-13 20:15:29 +00001959 /* The attribute is changed. */
1960 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1961
1962 /* Update bgp route dampening information. */
1963 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1964 && peer_sort (peer) == BGP_PEER_EBGP)
1965 {
1966 /* This is implicit withdraw so we should update dampening
1967 information. */
1968 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1969 bgp_damp_withdraw (ri, rn, afi, safi, 1);
1970 else
1971 peer->pcount[afi][safi]++;
1972 }
1973
1974 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
1975
1976 /* Update to new attribute. */
1977 bgp_attr_unintern (ri->attr);
1978 ri->attr = attr_new;
1979
1980 /* Update MPLS tag. */
1981 if (safi == SAFI_MPLS_VPN)
1982 memcpy (ri->tag, tag, 3);
1983
1984 /* Update bgp route dampening information. */
1985 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1986 && peer_sort (peer) == BGP_PEER_EBGP)
1987 {
1988 /* Now we do normal update dampening. */
1989 ret = bgp_damp_update (ri, rn, afi, safi);
1990 if (ret == BGP_DAMP_SUPPRESSED)
1991 {
1992 bgp_unlock_node (rn);
1993 return 0;
1994 }
1995 }
1996
1997 /* Nexthop reachability check. */
1998 if ((afi == AFI_IP || afi == AFI_IP6)
1999 && safi == SAFI_UNICAST
2000 && (peer_sort (peer) == BGP_PEER_IBGP
2001 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002002 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002003 {
2004 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
2005 SET_FLAG (ri->flags, BGP_INFO_VALID);
2006 else
2007 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2008 }
2009 else
2010 SET_FLAG (ri->flags, BGP_INFO_VALID);
2011
2012 /* Process change. */
2013 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2014
2015 bgp_process (bgp, rn, afi, safi);
2016 bgp_unlock_node (rn);
2017 return 0;
2018 }
2019
2020 /* Received Logging. */
2021 if (BGP_DEBUG (update, UPDATE_IN))
2022 {
ajsd2c1f162004-12-08 21:10:20 +00002023 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002024 peer->host,
2025 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2026 p->prefixlen);
2027 }
2028
2029 /* Increment prefix counter */
2030 peer->pcount[afi][safi]++;
2031
2032 /* Make new BGP info. */
2033 new = bgp_info_new ();
2034 new->type = type;
2035 new->sub_type = sub_type;
2036 new->peer = peer;
2037 new->attr = attr_new;
2038 new->uptime = time (NULL);
2039
2040 /* Update MPLS tag. */
2041 if (safi == SAFI_MPLS_VPN)
2042 memcpy (new->tag, tag, 3);
2043
2044 /* Nexthop reachability check. */
2045 if ((afi == AFI_IP || afi == AFI_IP6)
2046 && safi == SAFI_UNICAST
2047 && (peer_sort (peer) == BGP_PEER_IBGP
2048 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002049 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002050 {
2051 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
2052 SET_FLAG (new->flags, BGP_INFO_VALID);
2053 else
2054 UNSET_FLAG (new->flags, BGP_INFO_VALID);
2055 }
2056 else
2057 SET_FLAG (new->flags, BGP_INFO_VALID);
2058
2059 /* Aggregate address increment. */
2060 bgp_aggregate_increment (bgp, p, new, afi, safi);
2061
2062 /* Register new BGP information. */
2063 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002064
2065 /* route_node_get lock */
2066 bgp_unlock_node (rn);
2067
paul718e3742002-12-13 20:15:29 +00002068 /* If maximum prefix count is configured and current prefix
2069 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002070 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2071 return -1;
paul718e3742002-12-13 20:15:29 +00002072
2073 /* Process change. */
2074 bgp_process (bgp, rn, afi, safi);
2075
2076 return 0;
2077
2078 /* This BGP update is filtered. Log the reason then update BGP
2079 entry. */
2080 filtered:
2081 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002082 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002083 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2084 peer->host,
2085 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2086 p->prefixlen, reason);
2087
2088 if (ri)
2089 bgp_rib_withdraw (rn, ri, peer, afi, safi, 1);
2090
2091 bgp_unlock_node (rn);
2092
2093 return 0;
2094}
2095
2096int
paulfee0f4c2004-09-13 05:12:46 +00002097bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2098 afi_t afi, safi_t safi, int type, int sub_type,
2099 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2100{
2101 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002102 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002103 struct bgp *bgp;
2104 int ret;
2105
2106 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2107 soft_reconfig);
2108
2109 bgp = peer->bgp;
2110
2111 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002112 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002113 {
2114 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2115 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2116 sub_type, prd, tag);
2117 }
2118
2119 return ret;
2120}
2121
2122int
paul718e3742002-12-13 20:15:29 +00002123bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002124 afi_t afi, safi_t safi, int type, int sub_type,
2125 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002126{
2127 struct bgp *bgp;
2128 char buf[SU_ADDRSTRLEN];
2129 struct bgp_node *rn;
2130 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002131 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002132 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002133
2134 bgp = peer->bgp;
2135
paulfee0f4c2004-09-13 05:12:46 +00002136 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002137 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002138 {
2139 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2140 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2141 }
2142
paul718e3742002-12-13 20:15:29 +00002143 /* Logging. */
2144 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002145 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002146 peer->host,
2147 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2148 p->prefixlen);
2149
2150 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002151 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002152
2153 /* If peer is soft reconfiguration enabled. Record input packet for
2154 further calculation. */
2155 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2156 && peer != bgp->peer_self)
2157 bgp_adj_in_unset (rn, peer);
2158
2159 /* Lookup withdrawn route. */
2160 for (ri = rn->info; ri; ri = ri->next)
2161 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2162 break;
2163
2164 /* Withdraw specified route from routing table. */
2165 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2166 bgp_rib_withdraw (rn, ri, peer, afi, safi, 0);
2167 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002168 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002169 "%s Can't find the route %s/%d", peer->host,
2170 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2171 p->prefixlen);
2172
2173 /* Unlock bgp_node_get() lock. */
2174 bgp_unlock_node (rn);
2175
2176 return 0;
2177}
2178
2179void
2180bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2181{
2182 struct bgp *bgp;
2183 struct attr attr;
2184 struct aspath *aspath;
2185 struct prefix p;
2186 struct bgp_info binfo;
2187 struct peer *from;
2188 int ret = RMAP_DENYMATCH;
2189
2190 bgp = peer->bgp;
2191 from = bgp->peer_self;
2192
2193 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2194 aspath = attr.aspath;
2195 attr.local_pref = bgp->default_local_pref;
2196 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2197
2198 if (afi == AFI_IP)
2199 str2prefix ("0.0.0.0/0", &p);
2200#ifdef HAVE_IPV6
2201 else if (afi == AFI_IP6)
2202 {
2203 str2prefix ("::/0", &p);
2204
2205 /* IPv6 global nexthop must be included. */
2206 memcpy (&attr.mp_nexthop_global, &peer->nexthop.v6_global,
2207 IPV6_MAX_BYTELEN);
2208 attr.mp_nexthop_len = 16;
2209
2210 /* If the peer is on shared nextwork and we have link-local
2211 nexthop set it. */
2212 if (peer->shared_network
2213 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2214 {
2215 memcpy (&attr.mp_nexthop_local, &peer->nexthop.v6_local,
2216 IPV6_MAX_BYTELEN);
2217 attr.mp_nexthop_len = 32;
2218 }
2219 }
2220#endif /* HAVE_IPV6 */
2221 else
2222 return;
2223
2224 if (peer->default_rmap[afi][safi].name)
2225 {
2226 binfo.peer = bgp->peer_self;
2227 binfo.attr = &attr;
2228
paulfee0f4c2004-09-13 05:12:46 +00002229 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2230
paul718e3742002-12-13 20:15:29 +00002231 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2232 RMAP_BGP, &binfo);
2233
paulfee0f4c2004-09-13 05:12:46 +00002234 bgp->peer_self->rmap_type = 0;
2235
paul718e3742002-12-13 20:15:29 +00002236 if (ret == RMAP_DENYMATCH)
2237 {
2238 bgp_attr_flush (&attr);
2239 withdraw = 1;
2240 }
2241 }
2242
2243 if (withdraw)
2244 {
2245 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2246 bgp_default_withdraw_send (peer, afi, safi);
2247 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2248 }
2249 else
2250 {
2251 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2252 bgp_default_update_send (peer, &attr, afi, safi, from);
2253 }
2254
2255 aspath_unintern (aspath);
2256}
2257
2258static void
2259bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002260 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002261{
2262 struct bgp_node *rn;
2263 struct bgp_info *ri;
2264 struct attr attr;
2265
2266 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002267 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002268
2269 if (safi != SAFI_MPLS_VPN
2270 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2271 bgp_default_originate (peer, afi, safi, 0);
2272
2273 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2274 for (ri = rn->info; ri; ri = ri->next)
2275 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2276 {
paulfee0f4c2004-09-13 05:12:46 +00002277 if ( (rsclient) ?
2278 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2279 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002280 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2281 else
2282 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2283 }
2284}
2285
2286void
2287bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2288{
2289 struct bgp_node *rn;
2290 struct bgp_table *table;
2291
2292 if (peer->status != Established)
2293 return;
2294
2295 if (! peer->afc_nego[afi][safi])
2296 return;
2297
2298 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2299 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2300 return;
2301
2302 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002303 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002304 else
2305 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2306 rn = bgp_route_next(rn))
2307 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002308 bgp_announce_table (peer, afi, safi, table, 0);
2309
2310 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2311 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002312}
2313
2314void
2315bgp_announce_route_all (struct peer *peer)
2316{
2317 afi_t afi;
2318 safi_t safi;
2319
2320 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2321 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2322 bgp_announce_route (peer, afi, safi);
2323}
2324
2325static void
paulfee0f4c2004-09-13 05:12:46 +00002326bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2327 safi_t safi, struct bgp_table *table)
2328{
2329 struct bgp_node *rn;
2330 struct bgp_adj_in *ain;
2331
2332 if (! table)
2333 table = rsclient->bgp->rib[afi][safi];
2334
2335 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2336 for (ain = rn->adj_in; ain; ain = ain->next)
2337 {
2338 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2339 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2340 }
2341}
2342
2343void
2344bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2345{
2346 struct bgp_table *table;
2347 struct bgp_node *rn;
2348
2349 if (safi != SAFI_MPLS_VPN)
2350 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2351
2352 else
2353 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2354 rn = bgp_route_next (rn))
2355 if ((table = rn->info) != NULL)
2356 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2357}
2358
2359static void
paul718e3742002-12-13 20:15:29 +00002360bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2361 struct bgp_table *table)
2362{
2363 int ret;
2364 struct bgp_node *rn;
2365 struct bgp_adj_in *ain;
2366
2367 if (! table)
2368 table = peer->bgp->rib[afi][safi];
2369
2370 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2371 for (ain = rn->adj_in; ain; ain = ain->next)
2372 {
2373 if (ain->peer == peer)
2374 {
2375 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2376 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2377 NULL, NULL, 1);
2378 if (ret < 0)
2379 {
2380 bgp_unlock_node (rn);
2381 return;
2382 }
2383 continue;
2384 }
2385 }
2386}
2387
2388void
2389bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2390{
2391 struct bgp_node *rn;
2392 struct bgp_table *table;
2393
2394 if (peer->status != Established)
2395 return;
2396
2397 if (safi != SAFI_MPLS_VPN)
2398 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2399 else
2400 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2401 rn = bgp_route_next (rn))
2402 if ((table = rn->info) != NULL)
2403 bgp_soft_reconfig_table (peer, afi, safi, table);
2404}
2405
paul200df112005-06-01 11:17:05 +00002406struct bgp_clear_node_queue
2407{
2408 struct bgp_node *rn;
2409 struct peer *peer;
2410 afi_t afi;
2411 safi_t safi;
2412};
2413
2414static wq_item_status
2415bgp_clear_route_node (struct bgp_clear_node_queue *cq)
2416{
2417 struct bgp_adj_in *ain;
2418 struct bgp_adj_out *aout;
2419 struct bgp_info *ri;
2420
2421 assert (cq->rn && cq->peer);
2422
2423 for (ri = cq->rn->info; ri; ri = ri->next)
2424 if (ri->peer == cq->peer)
2425 {
2426 /* graceful restart STALE flag set. */
2427 if (CHECK_FLAG (cq->peer->sflags, PEER_STATUS_NSF_WAIT)
2428 && cq->peer->nsf[cq->afi][cq->safi]
2429 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2430 && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
2431 && ! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2432 {
2433 SET_FLAG (ri->flags, BGP_INFO_STALE);
2434 cq->peer->pcount[cq->afi][cq->safi]--;
2435 }
2436 else
2437 bgp_rib_remove (cq->rn, ri, cq->peer, cq->afi, cq->safi);
2438 break;
2439 }
2440 for (ain = cq->rn->adj_in; ain; ain = ain->next)
2441 if (ain->peer == cq->peer)
2442 {
2443 bgp_adj_in_remove (cq->rn, ain);
2444 bgp_unlock_node (cq->rn);
2445 break;
2446 }
2447 for (aout = cq->rn->adj_out; aout; aout = aout->next)
2448 if (aout->peer == cq->peer)
2449 {
2450 bgp_adj_out_remove (cq->rn, aout, cq->peer, cq->afi, cq->safi);
2451 bgp_unlock_node (cq->rn);
2452 break;
2453 }
2454 return WQ_SUCCESS;
2455}
2456
2457static void
2458bgp_clear_node_queue_del (struct bgp_clear_node_queue *cq)
2459{
2460 bgp_unlock_node (cq->rn);
2461 peer_unlock (cq->peer); /* bgp_clear_node_queue_del */
2462 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cq);
2463}
2464
2465static void
paul94f2b392005-06-28 12:44:16 +00002466bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002467{
2468 /* unplug the 2 processing queues */
2469 if (bm->process_main_queue)
2470 work_queue_unplug (bm->process_main_queue);
2471 if (bm->process_rsclient_queue)
2472 work_queue_unplug (bm->process_rsclient_queue);
2473}
2474
2475static void
2476bgp_clear_node_queue_init (void)
2477{
2478 if ( (bm->clear_node_queue
2479 = work_queue_new (bm->master, "clear_route_node")) == NULL)
2480 {
2481 zlog_err ("%s: Failed to allocate work queue", __func__);
2482 exit (1);
2483 }
2484 bm->clear_node_queue->spec.hold = 10;
2485 bm->clear_node_queue->spec.delay = 0; /* no gathering to be gained */
2486 bm->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2487 bm->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2488 bm->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2489 bm->clear_node_queue->spec.max_retries = 0;
2490}
2491
paul718e3742002-12-13 20:15:29 +00002492static void
2493bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002494 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002495{
paul200df112005-06-01 11:17:05 +00002496 struct bgp_clear_node_queue *cqnode;
paul718e3742002-12-13 20:15:29 +00002497 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002498
paul718e3742002-12-13 20:15:29 +00002499 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002500 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002501
hasso6cf159b2005-03-21 10:28:14 +00002502 /* If still no table => afi/safi isn't configured at all or smth. */
2503 if (! table)
2504 return;
2505
paul200df112005-06-01 11:17:05 +00002506 if (bm->clear_node_queue == NULL)
2507 bgp_clear_node_queue_init ();
2508
2509 /* plug the two bgp_process queues to avoid any chance of racing
2510 * with a session coming back up and adding routes before we've
2511 * cleared them all. We'll unplug them with completion callback.
2512 */
2513 if (bm->process_main_queue)
2514 work_queue_plug (bm->process_main_queue);
2515 if (bm->process_rsclient_queue)
2516 work_queue_plug (bm->process_rsclient_queue);
2517
paul718e3742002-12-13 20:15:29 +00002518 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2519 {
paul200df112005-06-01 11:17:05 +00002520 if (rn->info == NULL)
2521 continue;
2522
2523 if ( (cqnode = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2524 sizeof (struct bgp_clear_node_queue))) == NULL)
2525 continue;
2526
2527 cqnode->rn = bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2528 cqnode->afi = afi;
2529 cqnode->safi = safi;
2530 cqnode->peer = peer_lock (peer); /* bgp_clear_node_queue_del */
2531 work_queue_add (bm->clear_node_queue, cqnode);
paul718e3742002-12-13 20:15:29 +00002532 }
paul200df112005-06-01 11:17:05 +00002533 return;
paul718e3742002-12-13 20:15:29 +00002534}
2535
2536void
2537bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2538{
2539 struct bgp_node *rn;
2540 struct bgp_table *table;
paulfee0f4c2004-09-13 05:12:46 +00002541 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002542 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002543
paul718e3742002-12-13 20:15:29 +00002544 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002545 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002546 else
2547 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2548 rn = bgp_route_next (rn))
2549 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002550 bgp_clear_route_table (peer, afi, safi, table, NULL);
2551
paul1eb8ef22005-04-07 07:30:20 +00002552 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002553 {
2554 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2555 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2556 }
paul718e3742002-12-13 20:15:29 +00002557}
2558
2559void
2560bgp_clear_route_all (struct peer *peer)
2561{
2562 afi_t afi;
2563 safi_t safi;
2564
2565 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2566 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2567 bgp_clear_route (peer, afi, safi);
2568}
2569
2570void
2571bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2572{
2573 struct bgp_table *table;
2574 struct bgp_node *rn;
2575 struct bgp_adj_in *ain;
2576
2577 table = peer->bgp->rib[afi][safi];
2578
2579 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2580 for (ain = rn->adj_in; ain ; ain = ain->next)
2581 if (ain->peer == peer)
2582 {
2583 bgp_adj_in_remove (rn, ain);
2584 bgp_unlock_node (rn);
2585 break;
2586 }
2587}
hasso93406d82005-02-02 14:40:33 +00002588
2589void
2590bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2591{
2592 struct bgp_node *rn;
2593 struct bgp_info *ri;
2594 struct bgp_table *table;
2595
2596 table = peer->bgp->rib[afi][safi];
2597
2598 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2599 {
2600 for (ri = rn->info; ri; ri = ri->next)
2601 if (ri->peer == peer)
2602 {
2603 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2604 bgp_rib_remove (rn, ri, peer, afi, safi);
2605 break;
2606 }
2607 }
2608}
paul718e3742002-12-13 20:15:29 +00002609
2610/* Delete all kernel routes. */
2611void
paul545acaf2004-04-20 15:13:15 +00002612bgp_cleanup_routes ()
paul718e3742002-12-13 20:15:29 +00002613{
2614 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002615 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002616 struct bgp_node *rn;
2617 struct bgp_table *table;
2618 struct bgp_info *ri;
2619
paul1eb8ef22005-04-07 07:30:20 +00002620 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002621 {
2622 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2623
2624 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2625 for (ri = rn->info; ri; ri = ri->next)
2626 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2627 && ri->type == ZEBRA_ROUTE_BGP
2628 && ri->sub_type == BGP_ROUTE_NORMAL)
2629 bgp_zebra_withdraw (&rn->p, ri);
2630
2631 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2632
2633 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2634 for (ri = rn->info; ri; ri = ri->next)
2635 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2636 && ri->type == ZEBRA_ROUTE_BGP
2637 && ri->sub_type == BGP_ROUTE_NORMAL)
2638 bgp_zebra_withdraw (&rn->p, ri);
2639 }
2640}
2641
2642void
2643bgp_reset ()
2644{
2645 vty_reset ();
2646 bgp_zclient_reset ();
2647 access_list_reset ();
2648 prefix_list_reset ();
2649}
2650
2651/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2652 value. */
2653int
2654bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2655{
2656 u_char *pnt;
2657 u_char *lim;
2658 struct prefix p;
2659 int psize;
2660 int ret;
2661
2662 /* Check peer status. */
2663 if (peer->status != Established)
2664 return 0;
2665
2666 pnt = packet->nlri;
2667 lim = pnt + packet->length;
2668
2669 for (; pnt < lim; pnt += psize)
2670 {
2671 /* Clear prefix structure. */
2672 memset (&p, 0, sizeof (struct prefix));
2673
2674 /* Fetch prefix length. */
2675 p.prefixlen = *pnt++;
2676 p.family = afi2family (packet->afi);
2677
2678 /* Already checked in nlri_sanity_check(). We do double check
2679 here. */
2680 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2681 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2682 return -1;
2683
2684 /* Packet size overflow check. */
2685 psize = PSIZE (p.prefixlen);
2686
2687 /* When packet overflow occur return immediately. */
2688 if (pnt + psize > lim)
2689 return -1;
2690
2691 /* Fetch prefix from NLRI packet. */
2692 memcpy (&p.u.prefix, pnt, psize);
2693
2694 /* Check address. */
2695 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2696 {
2697 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
2698 {
paulf5ba3872004-07-09 12:11:31 +00002699 /*
2700 * From draft-ietf-idr-bgp4-22, Section 6.3:
2701 * If a BGP router receives an UPDATE message with a
2702 * semantically incorrect NLRI field, in which a prefix is
2703 * semantically incorrect (eg. an unexpected multicast IP
2704 * address), it should ignore the prefix.
2705 */
paul718e3742002-12-13 20:15:29 +00002706 zlog (peer->log, LOG_ERR,
2707 "IPv4 unicast NLRI is multicast address %s",
2708 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00002709
paul718e3742002-12-13 20:15:29 +00002710 return -1;
2711 }
2712 }
2713
2714#ifdef HAVE_IPV6
2715 /* Check address. */
2716 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
2717 {
2718 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2719 {
2720 char buf[BUFSIZ];
2721
2722 zlog (peer->log, LOG_WARNING,
2723 "IPv6 link-local NLRI received %s ignore this NLRI",
2724 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
2725
2726 continue;
2727 }
2728 }
2729#endif /* HAVE_IPV6 */
2730
2731 /* Normal process. */
2732 if (attr)
2733 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
2734 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
2735 else
2736 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
2737 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2738
2739 /* Address family configuration mismatch or maximum-prefix count
2740 overflow. */
2741 if (ret < 0)
2742 return -1;
2743 }
2744
2745 /* Packet length consistency check. */
2746 if (pnt != lim)
2747 return -1;
2748
2749 return 0;
2750}
2751
2752/* NLRI encode syntax check routine. */
2753int
2754bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
2755 bgp_size_t length)
2756{
2757 u_char *end;
2758 u_char prefixlen;
2759 int psize;
2760
2761 end = pnt + length;
2762
2763 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
2764 syntactic validity. If the field is syntactically incorrect,
2765 then the Error Subcode is set to Invalid Network Field. */
2766
2767 while (pnt < end)
2768 {
2769 prefixlen = *pnt++;
2770
2771 /* Prefix length check. */
2772 if ((afi == AFI_IP && prefixlen > 32)
2773 || (afi == AFI_IP6 && prefixlen > 128))
2774 {
2775 plog_err (peer->log,
2776 "%s [Error] Update packet error (wrong prefix length %d)",
2777 peer->host, prefixlen);
2778 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2779 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2780 return -1;
2781 }
2782
2783 /* Packet size overflow check. */
2784 psize = PSIZE (prefixlen);
2785
2786 if (pnt + psize > end)
2787 {
2788 plog_err (peer->log,
2789 "%s [Error] Update packet error"
2790 " (prefix data overflow prefix size is %d)",
2791 peer->host, psize);
2792 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2793 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2794 return -1;
2795 }
2796
2797 pnt += psize;
2798 }
2799
2800 /* Packet length consistency check. */
2801 if (pnt != end)
2802 {
2803 plog_err (peer->log,
2804 "%s [Error] Update packet error"
2805 " (prefix length mismatch with total length)",
2806 peer->host);
2807 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2808 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2809 return -1;
2810 }
2811 return 0;
2812}
2813
paul94f2b392005-06-28 12:44:16 +00002814static struct bgp_static *
paul718e3742002-12-13 20:15:29 +00002815bgp_static_new ()
2816{
2817 struct bgp_static *new;
2818 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
2819 memset (new, 0, sizeof (struct bgp_static));
2820 return new;
2821}
2822
paul94f2b392005-06-28 12:44:16 +00002823static void
paul718e3742002-12-13 20:15:29 +00002824bgp_static_free (struct bgp_static *bgp_static)
2825{
2826 if (bgp_static->rmap.name)
2827 free (bgp_static->rmap.name);
2828 XFREE (MTYPE_BGP_STATIC, bgp_static);
2829}
2830
paul94f2b392005-06-28 12:44:16 +00002831static void
paulfee0f4c2004-09-13 05:12:46 +00002832bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
2833 struct prefix *p, afi_t afi, safi_t safi)
2834{
2835 struct bgp_node *rn;
2836 struct bgp_info *ri;
2837
2838 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2839
2840 /* Check selected route and self inserted route. */
2841 for (ri = rn->info; ri; ri = ri->next)
2842 if (ri->peer == bgp->peer_self
2843 && ri->type == ZEBRA_ROUTE_BGP
2844 && ri->sub_type == BGP_ROUTE_STATIC)
2845 break;
2846
2847 /* Withdraw static BGP route from routing table. */
2848 if (ri)
2849 {
2850 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2851 bgp_process (bgp, rn, afi, safi);
2852 bgp_info_delete (rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00002853 }
2854
2855 /* Unlock bgp_node_lookup. */
2856 bgp_unlock_node (rn);
2857}
2858
paul94f2b392005-06-28 12:44:16 +00002859static void
paulfee0f4c2004-09-13 05:12:46 +00002860bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
2861 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
2862{
2863 struct bgp_node *rn;
2864 struct bgp_info *ri;
2865 struct bgp_info *new;
2866 struct bgp_info info;
2867 struct attr new_attr;
2868 struct attr *attr_new;
2869 struct attr attr;
2870 struct bgp *bgp;
2871 int ret;
2872 char buf[SU_ADDRSTRLEN];
2873
2874 bgp = rsclient->bgp;
2875
2876 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2877
2878 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2879 if (bgp_static)
2880 {
2881 attr.nexthop = bgp_static->igpnexthop;
2882 attr.med = bgp_static->igpmetric;
2883 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
2884 }
2885
2886 new_attr = attr;
2887
2888 /* Apply network route-map for export to this rsclient. */
2889 if (bgp_static->rmap.name)
2890 {
2891 info.peer = rsclient;
2892 info.attr = &new_attr;
2893
2894 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
2895 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
2896
2897 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
2898
2899 rsclient->rmap_type = 0;
2900
2901 if (ret == RMAP_DENYMATCH)
2902 {
2903 /* Free uninterned attribute. */
2904 bgp_attr_flush (&new_attr);
2905
2906 /* Unintern original. */
2907 aspath_unintern (attr.aspath);
2908 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2909
2910 return;
2911 }
2912 attr_new = bgp_attr_intern (&new_attr);
2913 }
2914 else
2915 attr_new = bgp_attr_intern (&attr);
2916
2917 new_attr = *attr_new;
2918
2919 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
2920
2921 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) == RMAP_DENY)
2922{
2923 /* This BGP update is filtered. Log the reason then update BGP entry. */
2924 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002925 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002926 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
2927 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2928 p->prefixlen, rsclient->host);
2929
2930 bgp->peer_self->rmap_type = 0;
2931
2932 bgp_attr_unintern (attr_new);
2933 aspath_unintern (attr.aspath);
2934
2935 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2936
2937 return;
2938 }
2939
2940 bgp->peer_self->rmap_type = 0;
2941
2942 bgp_attr_unintern (attr_new);
2943 attr_new = bgp_attr_intern (&new_attr);
2944
2945 for (ri = rn->info; ri; ri = ri->next)
2946 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
2947 && ri->sub_type == BGP_ROUTE_STATIC)
2948 break;
2949
2950 if (ri)
2951 {
2952 if (attrhash_cmp (ri->attr, attr_new))
2953 {
2954 bgp_unlock_node (rn);
2955 bgp_attr_unintern (attr_new);
2956 aspath_unintern (attr.aspath);
2957 return;
2958 }
2959 else
2960 {
2961 /* The attribute is changed. */
2962 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
2963
2964 /* Rewrite BGP route information. */
2965 bgp_attr_unintern (ri->attr);
2966 ri->attr = attr_new;
2967 ri->uptime = time (NULL);
2968
2969 /* Process change. */
2970 bgp_process (bgp, rn, afi, safi);
2971 bgp_unlock_node (rn);
2972 aspath_unintern (attr.aspath);
2973 return;
2974 }
2975}
2976
2977 /* Make new BGP info. */
2978 new = bgp_info_new ();
2979 new->type = ZEBRA_ROUTE_BGP;
2980 new->sub_type = BGP_ROUTE_STATIC;
2981 new->peer = bgp->peer_self;
2982 SET_FLAG (new->flags, BGP_INFO_VALID);
2983 new->attr = attr_new;
2984 new->uptime = time (NULL);
2985
2986 /* Register new BGP information. */
2987 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002988
2989 /* route_node_get lock */
2990 bgp_unlock_node (rn);
2991
paulfee0f4c2004-09-13 05:12:46 +00002992 /* Process change. */
2993 bgp_process (bgp, rn, afi, safi);
2994
2995 /* Unintern original. */
2996 aspath_unintern (attr.aspath);
2997}
2998
paul94f2b392005-06-28 12:44:16 +00002999static void
paulfee0f4c2004-09-13 05:12:46 +00003000bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003001 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3002{
3003 struct bgp_node *rn;
3004 struct bgp_info *ri;
3005 struct bgp_info *new;
3006 struct bgp_info info;
3007 struct attr attr;
paul286e1e72003-08-08 00:24:31 +00003008 struct attr attr_tmp;
paul718e3742002-12-13 20:15:29 +00003009 struct attr *attr_new;
3010 int ret;
3011
paulfee0f4c2004-09-13 05:12:46 +00003012 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003013
3014 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3015 if (bgp_static)
3016 {
3017 attr.nexthop = bgp_static->igpnexthop;
3018 attr.med = bgp_static->igpmetric;
3019 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3020 }
3021
3022 /* Apply route-map. */
3023 if (bgp_static->rmap.name)
3024 {
paul286e1e72003-08-08 00:24:31 +00003025 attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003026 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003027 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003028
paulfee0f4c2004-09-13 05:12:46 +00003029 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3030
paul718e3742002-12-13 20:15:29 +00003031 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003032
paulfee0f4c2004-09-13 05:12:46 +00003033 bgp->peer_self->rmap_type = 0;
3034
paul718e3742002-12-13 20:15:29 +00003035 if (ret == RMAP_DENYMATCH)
3036 {
3037 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003038 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003039
3040 /* Unintern original. */
3041 aspath_unintern (attr.aspath);
3042 bgp_static_withdraw (bgp, p, afi, safi);
3043 return;
3044 }
paul286e1e72003-08-08 00:24:31 +00003045 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003046 }
paul286e1e72003-08-08 00:24:31 +00003047 else
3048 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003049
3050 for (ri = rn->info; ri; ri = ri->next)
3051 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3052 && ri->sub_type == BGP_ROUTE_STATIC)
3053 break;
3054
3055 if (ri)
3056 {
3057 if (attrhash_cmp (ri->attr, attr_new))
3058 {
3059 bgp_unlock_node (rn);
3060 bgp_attr_unintern (attr_new);
3061 aspath_unintern (attr.aspath);
3062 return;
3063 }
3064 else
3065 {
3066 /* The attribute is changed. */
3067 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3068
3069 /* Rewrite BGP route information. */
3070 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3071 bgp_attr_unintern (ri->attr);
3072 ri->attr = attr_new;
3073 ri->uptime = time (NULL);
3074
3075 /* Process change. */
3076 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3077 bgp_process (bgp, rn, afi, safi);
3078 bgp_unlock_node (rn);
3079 aspath_unintern (attr.aspath);
3080 return;
3081 }
3082 }
3083
3084 /* Make new BGP info. */
3085 new = bgp_info_new ();
3086 new->type = ZEBRA_ROUTE_BGP;
3087 new->sub_type = BGP_ROUTE_STATIC;
3088 new->peer = bgp->peer_self;
3089 SET_FLAG (new->flags, BGP_INFO_VALID);
3090 new->attr = attr_new;
3091 new->uptime = time (NULL);
3092
3093 /* Aggregate address increment. */
3094 bgp_aggregate_increment (bgp, p, new, afi, safi);
3095
3096 /* Register new BGP information. */
3097 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003098
3099 /* route_node_get lock */
3100 bgp_unlock_node (rn);
3101
paul718e3742002-12-13 20:15:29 +00003102 /* Process change. */
3103 bgp_process (bgp, rn, afi, safi);
3104
3105 /* Unintern original. */
3106 aspath_unintern (attr.aspath);
3107}
3108
3109void
paulfee0f4c2004-09-13 05:12:46 +00003110bgp_static_update (struct bgp *bgp, struct prefix *p,
3111 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3112{
3113 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003114 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003115
3116 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3117
paul1eb8ef22005-04-07 07:30:20 +00003118 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003119 {
3120 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
3121 }
3122}
3123
paul94f2b392005-06-28 12:44:16 +00003124static void
paul718e3742002-12-13 20:15:29 +00003125bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3126 u_char safi, struct prefix_rd *prd, u_char *tag)
3127{
3128 struct bgp_node *rn;
3129 struct bgp_info *new;
3130
paulfee0f4c2004-09-13 05:12:46 +00003131 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003132
3133 /* Make new BGP info. */
3134 new = bgp_info_new ();
3135 new->type = ZEBRA_ROUTE_BGP;
3136 new->sub_type = BGP_ROUTE_STATIC;
3137 new->peer = bgp->peer_self;
3138 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3139 SET_FLAG (new->flags, BGP_INFO_VALID);
3140 new->uptime = time (NULL);
3141 memcpy (new->tag, tag, 3);
3142
3143 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003144 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003145
3146 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003147 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003148
paul200df112005-06-01 11:17:05 +00003149 /* route_node_get lock */
3150 bgp_unlock_node (rn);
3151
paul718e3742002-12-13 20:15:29 +00003152 /* Process change. */
3153 bgp_process (bgp, rn, afi, safi);
3154}
3155
3156void
3157bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3158 safi_t safi)
3159{
3160 struct bgp_node *rn;
3161 struct bgp_info *ri;
3162
paulfee0f4c2004-09-13 05:12:46 +00003163 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003164
3165 /* Check selected route and self inserted route. */
3166 for (ri = rn->info; ri; ri = ri->next)
3167 if (ri->peer == bgp->peer_self
3168 && ri->type == ZEBRA_ROUTE_BGP
3169 && ri->sub_type == BGP_ROUTE_STATIC)
3170 break;
3171
3172 /* Withdraw static BGP route from routing table. */
3173 if (ri)
3174 {
3175 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3176 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3177 bgp_process (bgp, rn, afi, safi);
3178 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003179 }
3180
3181 /* Unlock bgp_node_lookup. */
3182 bgp_unlock_node (rn);
3183}
3184
3185void
paulfee0f4c2004-09-13 05:12:46 +00003186bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3187{
3188 struct bgp_static *bgp_static;
3189 struct bgp *bgp;
3190 struct bgp_node *rn;
3191 struct prefix *p;
3192
3193 bgp = rsclient->bgp;
3194
3195 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3196 if ((bgp_static = rn->info) != NULL)
3197 {
3198 p = &rn->p;
3199
3200 bgp_static_update_rsclient (rsclient, p, bgp_static,
3201 afi, safi);
3202 }
3203}
3204
paul94f2b392005-06-28 12:44:16 +00003205static void
paul718e3742002-12-13 20:15:29 +00003206bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3207 u_char safi, struct prefix_rd *prd, u_char *tag)
3208{
3209 struct bgp_node *rn;
3210 struct bgp_info *ri;
3211
paulfee0f4c2004-09-13 05:12:46 +00003212 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003213
3214 /* Check selected route and self inserted route. */
3215 for (ri = rn->info; ri; ri = ri->next)
3216 if (ri->peer == bgp->peer_self
3217 && ri->type == ZEBRA_ROUTE_BGP
3218 && ri->sub_type == BGP_ROUTE_STATIC)
3219 break;
3220
3221 /* Withdraw static BGP route from routing table. */
3222 if (ri)
3223 {
3224 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3226 bgp_process (bgp, rn, afi, safi);
3227 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003228 }
3229
3230 /* Unlock bgp_node_lookup. */
3231 bgp_unlock_node (rn);
3232}
3233
3234/* Configure static BGP network. When user don't run zebra, static
3235 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003236static int
paulfd79ac92004-10-13 05:06:08 +00003237bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3238 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003239{
3240 int ret;
3241 struct prefix p;
3242 struct bgp_static *bgp_static;
3243 struct bgp_node *rn;
3244 int need_update = 0;
3245
3246 /* Convert IP prefix string to struct prefix. */
3247 ret = str2prefix (ip_str, &p);
3248 if (! ret)
3249 {
3250 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3251 return CMD_WARNING;
3252 }
3253#ifdef HAVE_IPV6
3254 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3255 {
3256 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3257 VTY_NEWLINE);
3258 return CMD_WARNING;
3259 }
3260#endif /* HAVE_IPV6 */
3261
3262 apply_mask (&p);
3263
3264 /* Set BGP static route configuration. */
3265 rn = bgp_node_get (bgp->route[afi][safi], &p);
3266
3267 if (rn->info)
3268 {
3269 /* Configuration change. */
3270 bgp_static = rn->info;
3271
3272 /* Check previous routes are installed into BGP. */
3273 if (! bgp_static->backdoor && bgp_static->valid)
3274 need_update = 1;
3275
3276 bgp_static->backdoor = backdoor;
3277 if (rmap)
3278 {
3279 if (bgp_static->rmap.name)
3280 free (bgp_static->rmap.name);
3281 bgp_static->rmap.name = strdup (rmap);
3282 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3283 }
3284 else
3285 {
3286 if (bgp_static->rmap.name)
3287 free (bgp_static->rmap.name);
3288 bgp_static->rmap.name = NULL;
3289 bgp_static->rmap.map = NULL;
3290 bgp_static->valid = 0;
3291 }
3292 bgp_unlock_node (rn);
3293 }
3294 else
3295 {
3296 /* New configuration. */
3297 bgp_static = bgp_static_new ();
3298 bgp_static->backdoor = backdoor;
3299 bgp_static->valid = 0;
3300 bgp_static->igpmetric = 0;
3301 bgp_static->igpnexthop.s_addr = 0;
3302 if (rmap)
3303 {
3304 if (bgp_static->rmap.name)
3305 free (bgp_static->rmap.name);
3306 bgp_static->rmap.name = strdup (rmap);
3307 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3308 }
3309 rn->info = bgp_static;
3310 }
3311
3312 /* If BGP scan is not enabled, we should install this route here. */
3313 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3314 {
3315 bgp_static->valid = 1;
3316
3317 if (need_update)
3318 bgp_static_withdraw (bgp, &p, afi, safi);
3319
3320 if (! bgp_static->backdoor)
3321 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3322 }
3323
3324 return CMD_SUCCESS;
3325}
3326
3327/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003328static int
paulfd79ac92004-10-13 05:06:08 +00003329bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003330 u_int16_t afi, u_char safi)
3331{
3332 int ret;
3333 struct prefix p;
3334 struct bgp_static *bgp_static;
3335 struct bgp_node *rn;
3336
3337 /* Convert IP prefix string to struct prefix. */
3338 ret = str2prefix (ip_str, &p);
3339 if (! ret)
3340 {
3341 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3342 return CMD_WARNING;
3343 }
3344#ifdef HAVE_IPV6
3345 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3346 {
3347 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3348 VTY_NEWLINE);
3349 return CMD_WARNING;
3350 }
3351#endif /* HAVE_IPV6 */
3352
3353 apply_mask (&p);
3354
3355 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3356 if (! rn)
3357 {
3358 vty_out (vty, "%% Can't find specified static route configuration.%s",
3359 VTY_NEWLINE);
3360 return CMD_WARNING;
3361 }
3362
3363 bgp_static = rn->info;
3364
3365 /* Update BGP RIB. */
3366 if (! bgp_static->backdoor)
3367 bgp_static_withdraw (bgp, &p, afi, safi);
3368
3369 /* Clear configuration. */
3370 bgp_static_free (bgp_static);
3371 rn->info = NULL;
3372 bgp_unlock_node (rn);
3373 bgp_unlock_node (rn);
3374
3375 return CMD_SUCCESS;
3376}
3377
3378/* Called from bgp_delete(). Delete all static routes from the BGP
3379 instance. */
3380void
3381bgp_static_delete (struct bgp *bgp)
3382{
3383 afi_t afi;
3384 safi_t safi;
3385 struct bgp_node *rn;
3386 struct bgp_node *rm;
3387 struct bgp_table *table;
3388 struct bgp_static *bgp_static;
3389
3390 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3391 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3392 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3393 if (rn->info != NULL)
3394 {
3395 if (safi == SAFI_MPLS_VPN)
3396 {
3397 table = rn->info;
3398
3399 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3400 {
3401 bgp_static = rn->info;
3402 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3403 AFI_IP, SAFI_MPLS_VPN,
3404 (struct prefix_rd *)&rn->p,
3405 bgp_static->tag);
3406 bgp_static_free (bgp_static);
3407 rn->info = NULL;
3408 bgp_unlock_node (rn);
3409 }
3410 }
3411 else
3412 {
3413 bgp_static = rn->info;
3414 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3415 bgp_static_free (bgp_static);
3416 rn->info = NULL;
3417 bgp_unlock_node (rn);
3418 }
3419 }
3420}
3421
3422int
paulfd79ac92004-10-13 05:06:08 +00003423bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3424 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003425{
3426 int ret;
3427 struct prefix p;
3428 struct prefix_rd prd;
3429 struct bgp *bgp;
3430 struct bgp_node *prn;
3431 struct bgp_node *rn;
3432 struct bgp_table *table;
3433 struct bgp_static *bgp_static;
3434 u_char tag[3];
3435
3436 bgp = vty->index;
3437
3438 ret = str2prefix (ip_str, &p);
3439 if (! ret)
3440 {
3441 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3442 return CMD_WARNING;
3443 }
3444 apply_mask (&p);
3445
3446 ret = str2prefix_rd (rd_str, &prd);
3447 if (! ret)
3448 {
3449 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3450 return CMD_WARNING;
3451 }
3452
3453 ret = str2tag (tag_str, tag);
3454 if (! ret)
3455 {
3456 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3457 return CMD_WARNING;
3458 }
3459
3460 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3461 (struct prefix *)&prd);
3462 if (prn->info == NULL)
3463 prn->info = bgp_table_init ();
3464 else
3465 bgp_unlock_node (prn);
3466 table = prn->info;
3467
3468 rn = bgp_node_get (table, &p);
3469
3470 if (rn->info)
3471 {
3472 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3473 bgp_unlock_node (rn);
3474 }
3475 else
3476 {
3477 /* New configuration. */
3478 bgp_static = bgp_static_new ();
3479 bgp_static->valid = 1;
3480 memcpy (bgp_static->tag, tag, 3);
3481 rn->info = bgp_static;
3482
3483 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3484 }
3485
3486 return CMD_SUCCESS;
3487}
3488
3489/* Configure static BGP network. */
3490int
paulfd79ac92004-10-13 05:06:08 +00003491bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3492 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003493{
3494 int ret;
3495 struct bgp *bgp;
3496 struct prefix p;
3497 struct prefix_rd prd;
3498 struct bgp_node *prn;
3499 struct bgp_node *rn;
3500 struct bgp_table *table;
3501 struct bgp_static *bgp_static;
3502 u_char tag[3];
3503
3504 bgp = vty->index;
3505
3506 /* Convert IP prefix string to struct prefix. */
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)
3532 prn->info = bgp_table_init ();
3533 else
3534 bgp_unlock_node (prn);
3535 table = prn->info;
3536
3537 rn = bgp_node_lookup (table, &p);
3538
3539 if (rn)
3540 {
3541 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3542
3543 bgp_static = rn->info;
3544 bgp_static_free (bgp_static);
3545 rn->info = NULL;
3546 bgp_unlock_node (rn);
3547 bgp_unlock_node (rn);
3548 }
3549 else
3550 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3551
3552 return CMD_SUCCESS;
3553}
3554
3555DEFUN (bgp_network,
3556 bgp_network_cmd,
3557 "network A.B.C.D/M",
3558 "Specify a network to announce via BGP\n"
3559 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3560{
3561 return bgp_static_set (vty, vty->index, argv[0],
3562 AFI_IP, bgp_node_safi (vty), NULL, 0);
3563}
3564
3565DEFUN (bgp_network_route_map,
3566 bgp_network_route_map_cmd,
3567 "network A.B.C.D/M route-map WORD",
3568 "Specify a network to announce via BGP\n"
3569 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3570 "Route-map to modify the attributes\n"
3571 "Name of the route map\n")
3572{
3573 return bgp_static_set (vty, vty->index, argv[0],
3574 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3575}
3576
3577DEFUN (bgp_network_backdoor,
3578 bgp_network_backdoor_cmd,
3579 "network A.B.C.D/M backdoor",
3580 "Specify a network to announce via BGP\n"
3581 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3582 "Specify a BGP backdoor route\n")
3583{
3584 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
3585}
3586
3587DEFUN (bgp_network_mask,
3588 bgp_network_mask_cmd,
3589 "network A.B.C.D mask A.B.C.D",
3590 "Specify a network to announce via BGP\n"
3591 "Network number\n"
3592 "Network mask\n"
3593 "Network mask\n")
3594{
3595 int ret;
3596 char prefix_str[BUFSIZ];
3597
3598 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3599 if (! ret)
3600 {
3601 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3602 return CMD_WARNING;
3603 }
3604
3605 return bgp_static_set (vty, vty->index, prefix_str,
3606 AFI_IP, bgp_node_safi (vty), NULL, 0);
3607}
3608
3609DEFUN (bgp_network_mask_route_map,
3610 bgp_network_mask_route_map_cmd,
3611 "network A.B.C.D mask A.B.C.D route-map WORD",
3612 "Specify a network to announce via BGP\n"
3613 "Network number\n"
3614 "Network mask\n"
3615 "Network mask\n"
3616 "Route-map to modify the attributes\n"
3617 "Name of the route map\n")
3618{
3619 int ret;
3620 char prefix_str[BUFSIZ];
3621
3622 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3623 if (! ret)
3624 {
3625 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3626 return CMD_WARNING;
3627 }
3628
3629 return bgp_static_set (vty, vty->index, prefix_str,
3630 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3631}
3632
3633DEFUN (bgp_network_mask_backdoor,
3634 bgp_network_mask_backdoor_cmd,
3635 "network A.B.C.D mask A.B.C.D backdoor",
3636 "Specify a network to announce via BGP\n"
3637 "Network number\n"
3638 "Network mask\n"
3639 "Network mask\n"
3640 "Specify a BGP backdoor route\n")
3641{
3642 int ret;
3643 char prefix_str[BUFSIZ];
3644
3645 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3646 if (! ret)
3647 {
3648 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3649 return CMD_WARNING;
3650 }
3651
3652 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3653}
3654
3655DEFUN (bgp_network_mask_natural,
3656 bgp_network_mask_natural_cmd,
3657 "network A.B.C.D",
3658 "Specify a network to announce via BGP\n"
3659 "Network number\n")
3660{
3661 int ret;
3662 char prefix_str[BUFSIZ];
3663
3664 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3665 if (! ret)
3666 {
3667 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3668 return CMD_WARNING;
3669 }
3670
3671 return bgp_static_set (vty, vty->index, prefix_str,
3672 AFI_IP, bgp_node_safi (vty), NULL, 0);
3673}
3674
3675DEFUN (bgp_network_mask_natural_route_map,
3676 bgp_network_mask_natural_route_map_cmd,
3677 "network A.B.C.D route-map WORD",
3678 "Specify a network to announce via BGP\n"
3679 "Network number\n"
3680 "Route-map to modify the attributes\n"
3681 "Name of the route map\n")
3682{
3683 int ret;
3684 char prefix_str[BUFSIZ];
3685
3686 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3687 if (! ret)
3688 {
3689 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3690 return CMD_WARNING;
3691 }
3692
3693 return bgp_static_set (vty, vty->index, prefix_str,
3694 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3695}
3696
3697DEFUN (bgp_network_mask_natural_backdoor,
3698 bgp_network_mask_natural_backdoor_cmd,
3699 "network A.B.C.D backdoor",
3700 "Specify a network to announce via BGP\n"
3701 "Network number\n"
3702 "Specify a BGP backdoor route\n")
3703{
3704 int ret;
3705 char prefix_str[BUFSIZ];
3706
3707 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3708 if (! ret)
3709 {
3710 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3711 return CMD_WARNING;
3712 }
3713
3714 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3715}
3716
3717DEFUN (no_bgp_network,
3718 no_bgp_network_cmd,
3719 "no network A.B.C.D/M",
3720 NO_STR
3721 "Specify a network to announce via BGP\n"
3722 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3723{
3724 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
3725 bgp_node_safi (vty));
3726}
3727
3728ALIAS (no_bgp_network,
3729 no_bgp_network_route_map_cmd,
3730 "no network A.B.C.D/M route-map WORD",
3731 NO_STR
3732 "Specify a network to announce via BGP\n"
3733 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3734 "Route-map to modify the attributes\n"
3735 "Name of the route map\n")
3736
3737ALIAS (no_bgp_network,
3738 no_bgp_network_backdoor_cmd,
3739 "no network A.B.C.D/M backdoor",
3740 NO_STR
3741 "Specify a network to announce via BGP\n"
3742 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3743 "Specify a BGP backdoor route\n")
3744
3745DEFUN (no_bgp_network_mask,
3746 no_bgp_network_mask_cmd,
3747 "no network A.B.C.D mask A.B.C.D",
3748 NO_STR
3749 "Specify a network to announce via BGP\n"
3750 "Network number\n"
3751 "Network mask\n"
3752 "Network mask\n")
3753{
3754 int ret;
3755 char prefix_str[BUFSIZ];
3756
3757 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3758 if (! ret)
3759 {
3760 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3761 return CMD_WARNING;
3762 }
3763
3764 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3765 bgp_node_safi (vty));
3766}
3767
3768ALIAS (no_bgp_network_mask,
3769 no_bgp_network_mask_route_map_cmd,
3770 "no network A.B.C.D mask A.B.C.D route-map WORD",
3771 NO_STR
3772 "Specify a network to announce via BGP\n"
3773 "Network number\n"
3774 "Network mask\n"
3775 "Network mask\n"
3776 "Route-map to modify the attributes\n"
3777 "Name of the route map\n")
3778
3779ALIAS (no_bgp_network_mask,
3780 no_bgp_network_mask_backdoor_cmd,
3781 "no network A.B.C.D mask A.B.C.D backdoor",
3782 NO_STR
3783 "Specify a network to announce via BGP\n"
3784 "Network number\n"
3785 "Network mask\n"
3786 "Network mask\n"
3787 "Specify a BGP backdoor route\n")
3788
3789DEFUN (no_bgp_network_mask_natural,
3790 no_bgp_network_mask_natural_cmd,
3791 "no network A.B.C.D",
3792 NO_STR
3793 "Specify a network to announce via BGP\n"
3794 "Network number\n")
3795{
3796 int ret;
3797 char prefix_str[BUFSIZ];
3798
3799 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3800 if (! ret)
3801 {
3802 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3803 return CMD_WARNING;
3804 }
3805
3806 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3807 bgp_node_safi (vty));
3808}
3809
3810ALIAS (no_bgp_network_mask_natural,
3811 no_bgp_network_mask_natural_route_map_cmd,
3812 "no network A.B.C.D route-map WORD",
3813 NO_STR
3814 "Specify a network to announce via BGP\n"
3815 "Network number\n"
3816 "Route-map to modify the attributes\n"
3817 "Name of the route map\n")
3818
3819ALIAS (no_bgp_network_mask_natural,
3820 no_bgp_network_mask_natural_backdoor_cmd,
3821 "no network A.B.C.D backdoor",
3822 NO_STR
3823 "Specify a network to announce via BGP\n"
3824 "Network number\n"
3825 "Specify a BGP backdoor route\n")
3826
3827#ifdef HAVE_IPV6
3828DEFUN (ipv6_bgp_network,
3829 ipv6_bgp_network_cmd,
3830 "network X:X::X:X/M",
3831 "Specify a network to announce via BGP\n"
3832 "IPv6 prefix <network>/<length>\n")
3833{
3834 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
3835}
3836
3837DEFUN (ipv6_bgp_network_route_map,
3838 ipv6_bgp_network_route_map_cmd,
3839 "network X:X::X:X/M route-map WORD",
3840 "Specify a network to announce via BGP\n"
3841 "IPv6 prefix <network>/<length>\n"
3842 "Route-map to modify the attributes\n"
3843 "Name of the route map\n")
3844{
3845 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
3846 bgp_node_safi (vty), argv[1], 0);
3847}
3848
3849DEFUN (no_ipv6_bgp_network,
3850 no_ipv6_bgp_network_cmd,
3851 "no network X:X::X:X/M",
3852 NO_STR
3853 "Specify a network to announce via BGP\n"
3854 "IPv6 prefix <network>/<length>\n")
3855{
3856 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
3857}
3858
3859ALIAS (no_ipv6_bgp_network,
3860 no_ipv6_bgp_network_route_map_cmd,
3861 "no network X:X::X:X/M route-map WORD",
3862 NO_STR
3863 "Specify a network to announce via BGP\n"
3864 "IPv6 prefix <network>/<length>\n"
3865 "Route-map to modify the attributes\n"
3866 "Name of the route map\n")
3867
3868ALIAS (ipv6_bgp_network,
3869 old_ipv6_bgp_network_cmd,
3870 "ipv6 bgp network X:X::X:X/M",
3871 IPV6_STR
3872 BGP_STR
3873 "Specify a network to announce via BGP\n"
3874 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3875
3876ALIAS (no_ipv6_bgp_network,
3877 old_no_ipv6_bgp_network_cmd,
3878 "no ipv6 bgp network X:X::X:X/M",
3879 NO_STR
3880 IPV6_STR
3881 BGP_STR
3882 "Specify a network to announce via BGP\n"
3883 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3884#endif /* HAVE_IPV6 */
3885
3886/* Aggreagete address:
3887
3888 advertise-map Set condition to advertise attribute
3889 as-set Generate AS set path information
3890 attribute-map Set attributes of aggregate
3891 route-map Set parameters of aggregate
3892 summary-only Filter more specific routes from updates
3893 suppress-map Conditionally filter more specific routes from updates
3894 <cr>
3895 */
3896struct bgp_aggregate
3897{
3898 /* Summary-only flag. */
3899 u_char summary_only;
3900
3901 /* AS set generation. */
3902 u_char as_set;
3903
3904 /* Route-map for aggregated route. */
3905 struct route_map *map;
3906
3907 /* Suppress-count. */
3908 unsigned long count;
3909
3910 /* SAFI configuration. */
3911 safi_t safi;
3912};
3913
paul94f2b392005-06-28 12:44:16 +00003914static struct bgp_aggregate *
paul718e3742002-12-13 20:15:29 +00003915bgp_aggregate_new ()
3916{
3917 struct bgp_aggregate *new;
3918 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
3919 memset (new, 0, sizeof (struct bgp_aggregate));
3920 return new;
3921}
3922
paul94f2b392005-06-28 12:44:16 +00003923static void
paul718e3742002-12-13 20:15:29 +00003924bgp_aggregate_free (struct bgp_aggregate *aggregate)
3925{
3926 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
3927}
3928
paul94f2b392005-06-28 12:44:16 +00003929static void
paul718e3742002-12-13 20:15:29 +00003930bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
3931 afi_t afi, safi_t safi, struct bgp_info *del,
3932 struct bgp_aggregate *aggregate)
3933{
3934 struct bgp_table *table;
3935 struct bgp_node *top;
3936 struct bgp_node *rn;
3937 u_char origin;
3938 struct aspath *aspath = NULL;
3939 struct aspath *asmerge = NULL;
3940 struct community *community = NULL;
3941 struct community *commerge = NULL;
3942 struct in_addr nexthop;
3943 u_int32_t med = 0;
3944 struct bgp_info *ri;
3945 struct bgp_info *new;
3946 int first = 1;
3947 unsigned long match = 0;
3948
3949 /* Record adding route's nexthop and med. */
3950 if (rinew)
3951 {
3952 nexthop = rinew->attr->nexthop;
3953 med = rinew->attr->med;
3954 }
3955
3956 /* ORIGIN attribute: If at least one route among routes that are
3957 aggregated has ORIGIN with the value INCOMPLETE, then the
3958 aggregated route must have the ORIGIN attribute with the value
3959 INCOMPLETE. Otherwise, if at least one route among routes that
3960 are aggregated has ORIGIN with the value EGP, then the aggregated
3961 route must have the origin attribute with the value EGP. In all
3962 other case the value of the ORIGIN attribute of the aggregated
3963 route is INTERNAL. */
3964 origin = BGP_ORIGIN_IGP;
3965
3966 table = bgp->rib[afi][safi];
3967
3968 top = bgp_node_get (table, p);
3969 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
3970 if (rn->p.prefixlen > p->prefixlen)
3971 {
3972 match = 0;
3973
3974 for (ri = rn->info; ri; ri = ri->next)
3975 {
3976 if (BGP_INFO_HOLDDOWN (ri))
3977 continue;
3978
3979 if (del && ri == del)
3980 continue;
3981
3982 if (! rinew && first)
3983 {
3984 nexthop = ri->attr->nexthop;
3985 med = ri->attr->med;
3986 first = 0;
3987 }
3988
3989#ifdef AGGREGATE_NEXTHOP_CHECK
3990 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
3991 || ri->attr->med != med)
3992 {
3993 if (aspath)
3994 aspath_free (aspath);
3995 if (community)
3996 community_free (community);
3997 bgp_unlock_node (rn);
3998 bgp_unlock_node (top);
3999 return;
4000 }
4001#endif /* AGGREGATE_NEXTHOP_CHECK */
4002
4003 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4004 {
4005 if (aggregate->summary_only)
4006 {
4007 ri->suppress++;
4008 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4009 match++;
4010 }
4011
4012 aggregate->count++;
4013
4014 if (aggregate->as_set)
4015 {
4016 if (origin < ri->attr->origin)
4017 origin = ri->attr->origin;
4018
4019 if (aspath)
4020 {
4021 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4022 aspath_free (aspath);
4023 aspath = asmerge;
4024 }
4025 else
4026 aspath = aspath_dup (ri->attr->aspath);
4027
4028 if (ri->attr->community)
4029 {
4030 if (community)
4031 {
4032 commerge = community_merge (community,
4033 ri->attr->community);
4034 community = community_uniq_sort (commerge);
4035 community_free (commerge);
4036 }
4037 else
4038 community = community_dup (ri->attr->community);
4039 }
4040 }
4041 }
4042 }
4043 if (match)
4044 bgp_process (bgp, rn, afi, safi);
4045 }
4046 bgp_unlock_node (top);
4047
4048 if (rinew)
4049 {
4050 aggregate->count++;
4051
4052 if (aggregate->summary_only)
4053 rinew->suppress++;
4054
4055 if (aggregate->as_set)
4056 {
4057 if (origin < rinew->attr->origin)
4058 origin = rinew->attr->origin;
4059
4060 if (aspath)
4061 {
4062 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4063 aspath_free (aspath);
4064 aspath = asmerge;
4065 }
4066 else
4067 aspath = aspath_dup (rinew->attr->aspath);
4068
4069 if (rinew->attr->community)
4070 {
4071 if (community)
4072 {
4073 commerge = community_merge (community,
4074 rinew->attr->community);
4075 community = community_uniq_sort (commerge);
4076 community_free (commerge);
4077 }
4078 else
4079 community = community_dup (rinew->attr->community);
4080 }
4081 }
4082 }
4083
4084 if (aggregate->count > 0)
4085 {
4086 rn = bgp_node_get (table, p);
4087 new = bgp_info_new ();
4088 new->type = ZEBRA_ROUTE_BGP;
4089 new->sub_type = BGP_ROUTE_AGGREGATE;
4090 new->peer = bgp->peer_self;
4091 SET_FLAG (new->flags, BGP_INFO_VALID);
4092 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4093 new->uptime = time (NULL);
4094
4095 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004096 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004097 bgp_process (bgp, rn, afi, safi);
4098 }
4099 else
4100 {
4101 if (aspath)
4102 aspath_free (aspath);
4103 if (community)
4104 community_free (community);
4105 }
4106}
4107
4108void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4109 struct bgp_aggregate *);
4110
4111void
4112bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4113 struct bgp_info *ri, afi_t afi, safi_t safi)
4114{
4115 struct bgp_node *child;
4116 struct bgp_node *rn;
4117 struct bgp_aggregate *aggregate;
4118
4119 /* MPLS-VPN aggregation is not yet supported. */
4120 if (safi == SAFI_MPLS_VPN)
4121 return;
4122
4123 if (p->prefixlen == 0)
4124 return;
4125
4126 if (BGP_INFO_HOLDDOWN (ri))
4127 return;
4128
4129 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4130
4131 /* Aggregate address configuration check. */
4132 for (rn = child; rn; rn = rn->parent)
4133 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4134 {
4135 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004136 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004137 }
4138 bgp_unlock_node (child);
4139}
4140
4141void
4142bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4143 struct bgp_info *del, afi_t afi, safi_t safi)
4144{
4145 struct bgp_node *child;
4146 struct bgp_node *rn;
4147 struct bgp_aggregate *aggregate;
4148
4149 /* MPLS-VPN aggregation is not yet supported. */
4150 if (safi == SAFI_MPLS_VPN)
4151 return;
4152
4153 if (p->prefixlen == 0)
4154 return;
4155
4156 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4157
4158 /* Aggregate address configuration check. */
4159 for (rn = child; rn; rn = rn->parent)
4160 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4161 {
4162 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004163 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004164 }
4165 bgp_unlock_node (child);
4166}
4167
paul94f2b392005-06-28 12:44:16 +00004168static void
paul718e3742002-12-13 20:15:29 +00004169bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4170 struct bgp_aggregate *aggregate)
4171{
4172 struct bgp_table *table;
4173 struct bgp_node *top;
4174 struct bgp_node *rn;
4175 struct bgp_info *new;
4176 struct bgp_info *ri;
4177 unsigned long match;
4178 u_char origin = BGP_ORIGIN_IGP;
4179 struct aspath *aspath = NULL;
4180 struct aspath *asmerge = NULL;
4181 struct community *community = NULL;
4182 struct community *commerge = NULL;
4183
4184 table = bgp->rib[afi][safi];
4185
4186 /* Sanity check. */
4187 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4188 return;
4189 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4190 return;
4191
4192 /* If routes exists below this node, generate aggregate routes. */
4193 top = bgp_node_get (table, p);
4194 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4195 if (rn->p.prefixlen > p->prefixlen)
4196 {
4197 match = 0;
4198
4199 for (ri = rn->info; ri; ri = ri->next)
4200 {
4201 if (BGP_INFO_HOLDDOWN (ri))
4202 continue;
4203
4204 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4205 {
4206 /* summary-only aggregate route suppress aggregated
4207 route announcement. */
4208 if (aggregate->summary_only)
4209 {
4210 ri->suppress++;
4211 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4212 match++;
4213 }
4214 /* as-set aggregate route generate origin, as path,
4215 community aggregation. */
4216 if (aggregate->as_set)
4217 {
4218 if (origin < ri->attr->origin)
4219 origin = ri->attr->origin;
4220
4221 if (aspath)
4222 {
4223 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4224 aspath_free (aspath);
4225 aspath = asmerge;
4226 }
4227 else
4228 aspath = aspath_dup (ri->attr->aspath);
4229
4230 if (ri->attr->community)
4231 {
4232 if (community)
4233 {
4234 commerge = community_merge (community,
4235 ri->attr->community);
4236 community = community_uniq_sort (commerge);
4237 community_free (commerge);
4238 }
4239 else
4240 community = community_dup (ri->attr->community);
4241 }
4242 }
4243 aggregate->count++;
4244 }
4245 }
4246
4247 /* If this node is suppressed, process the change. */
4248 if (match)
4249 bgp_process (bgp, rn, afi, safi);
4250 }
4251 bgp_unlock_node (top);
4252
4253 /* Add aggregate route to BGP table. */
4254 if (aggregate->count)
4255 {
4256 rn = bgp_node_get (table, p);
4257
4258 new = bgp_info_new ();
4259 new->type = ZEBRA_ROUTE_BGP;
4260 new->sub_type = BGP_ROUTE_AGGREGATE;
4261 new->peer = bgp->peer_self;
4262 SET_FLAG (new->flags, BGP_INFO_VALID);
4263 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4264 new->uptime = time (NULL);
4265
4266 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004267 bgp_unlock_node (rn);
4268
paul718e3742002-12-13 20:15:29 +00004269 /* Process change. */
4270 bgp_process (bgp, rn, afi, safi);
4271 }
4272}
4273
4274void
4275bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4276 safi_t safi, struct bgp_aggregate *aggregate)
4277{
4278 struct bgp_table *table;
4279 struct bgp_node *top;
4280 struct bgp_node *rn;
4281 struct bgp_info *ri;
4282 unsigned long match;
4283
4284 table = bgp->rib[afi][safi];
4285
4286 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4287 return;
4288 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4289 return;
4290
4291 /* If routes exists below this node, generate aggregate routes. */
4292 top = bgp_node_get (table, p);
4293 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4294 if (rn->p.prefixlen > p->prefixlen)
4295 {
4296 match = 0;
4297
4298 for (ri = rn->info; ri; ri = ri->next)
4299 {
4300 if (BGP_INFO_HOLDDOWN (ri))
4301 continue;
4302
4303 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4304 {
4305 if (aggregate->summary_only)
4306 {
4307 ri->suppress--;
4308
4309 if (ri->suppress == 0)
4310 {
4311 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4312 match++;
4313 }
4314 }
4315 aggregate->count--;
4316 }
4317 }
4318
4319 /* If this node is suppressed, process the change. */
4320 if (match)
4321 bgp_process (bgp, rn, afi, safi);
4322 }
4323 bgp_unlock_node (top);
4324
4325 /* Delete aggregate route from BGP table. */
4326 rn = bgp_node_get (table, p);
4327
4328 for (ri = rn->info; ri; ri = ri->next)
4329 if (ri->peer == bgp->peer_self
4330 && ri->type == ZEBRA_ROUTE_BGP
4331 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4332 break;
4333
4334 /* Withdraw static BGP route from routing table. */
4335 if (ri)
4336 {
4337 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4338 bgp_process (bgp, rn, afi, safi);
4339 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004340 }
4341
4342 /* Unlock bgp_node_lookup. */
4343 bgp_unlock_node (rn);
4344}
4345
4346/* Aggregate route attribute. */
4347#define AGGREGATE_SUMMARY_ONLY 1
4348#define AGGREGATE_AS_SET 1
4349
paul94f2b392005-06-28 12:44:16 +00004350static int
paulfd79ac92004-10-13 05:06:08 +00004351bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4352 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004353 u_char summary_only, u_char as_set)
4354{
4355 int ret;
4356 struct prefix p;
4357 struct bgp_node *rn;
4358 struct bgp *bgp;
4359 struct bgp_aggregate *aggregate;
4360
4361 /* Convert string to prefix structure. */
4362 ret = str2prefix (prefix_str, &p);
4363 if (!ret)
4364 {
4365 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4366 return CMD_WARNING;
4367 }
4368 apply_mask (&p);
4369
4370 /* Get BGP structure. */
4371 bgp = vty->index;
4372
4373 /* Old configuration check. */
4374 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4375
4376 if (rn->info)
4377 {
4378 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4379 bgp_unlock_node (rn);
4380 return CMD_WARNING;
4381 }
4382
4383 /* Make aggregate address structure. */
4384 aggregate = bgp_aggregate_new ();
4385 aggregate->summary_only = summary_only;
4386 aggregate->as_set = as_set;
4387 aggregate->safi = safi;
4388 rn->info = aggregate;
4389
4390 /* Aggregate address insert into BGP routing table. */
4391 if (safi & SAFI_UNICAST)
4392 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4393 if (safi & SAFI_MULTICAST)
4394 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4395
4396 return CMD_SUCCESS;
4397}
4398
paul94f2b392005-06-28 12:44:16 +00004399static int
paulfd79ac92004-10-13 05:06:08 +00004400bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4401 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004402{
4403 int ret;
4404 struct prefix p;
4405 struct bgp_node *rn;
4406 struct bgp *bgp;
4407 struct bgp_aggregate *aggregate;
4408
4409 /* Convert string to prefix structure. */
4410 ret = str2prefix (prefix_str, &p);
4411 if (!ret)
4412 {
4413 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4414 return CMD_WARNING;
4415 }
4416 apply_mask (&p);
4417
4418 /* Get BGP structure. */
4419 bgp = vty->index;
4420
4421 /* Old configuration check. */
4422 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4423 if (! rn)
4424 {
4425 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4426 VTY_NEWLINE);
4427 return CMD_WARNING;
4428 }
4429
4430 aggregate = rn->info;
4431 if (aggregate->safi & SAFI_UNICAST)
4432 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4433 if (aggregate->safi & SAFI_MULTICAST)
4434 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4435
4436 /* Unlock aggregate address configuration. */
4437 rn->info = NULL;
4438 bgp_aggregate_free (aggregate);
4439 bgp_unlock_node (rn);
4440 bgp_unlock_node (rn);
4441
4442 return CMD_SUCCESS;
4443}
4444
4445DEFUN (aggregate_address,
4446 aggregate_address_cmd,
4447 "aggregate-address A.B.C.D/M",
4448 "Configure BGP aggregate entries\n"
4449 "Aggregate prefix\n")
4450{
4451 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4452}
4453
4454DEFUN (aggregate_address_mask,
4455 aggregate_address_mask_cmd,
4456 "aggregate-address A.B.C.D A.B.C.D",
4457 "Configure BGP aggregate entries\n"
4458 "Aggregate address\n"
4459 "Aggregate mask\n")
4460{
4461 int ret;
4462 char prefix_str[BUFSIZ];
4463
4464 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4465
4466 if (! ret)
4467 {
4468 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4469 return CMD_WARNING;
4470 }
4471
4472 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4473 0, 0);
4474}
4475
4476DEFUN (aggregate_address_summary_only,
4477 aggregate_address_summary_only_cmd,
4478 "aggregate-address A.B.C.D/M summary-only",
4479 "Configure BGP aggregate entries\n"
4480 "Aggregate prefix\n"
4481 "Filter more specific routes from updates\n")
4482{
4483 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4484 AGGREGATE_SUMMARY_ONLY, 0);
4485}
4486
4487DEFUN (aggregate_address_mask_summary_only,
4488 aggregate_address_mask_summary_only_cmd,
4489 "aggregate-address A.B.C.D A.B.C.D summary-only",
4490 "Configure BGP aggregate entries\n"
4491 "Aggregate address\n"
4492 "Aggregate mask\n"
4493 "Filter more specific routes from updates\n")
4494{
4495 int ret;
4496 char prefix_str[BUFSIZ];
4497
4498 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4499
4500 if (! ret)
4501 {
4502 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4503 return CMD_WARNING;
4504 }
4505
4506 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4507 AGGREGATE_SUMMARY_ONLY, 0);
4508}
4509
4510DEFUN (aggregate_address_as_set,
4511 aggregate_address_as_set_cmd,
4512 "aggregate-address A.B.C.D/M as-set",
4513 "Configure BGP aggregate entries\n"
4514 "Aggregate prefix\n"
4515 "Generate AS set path information\n")
4516{
4517 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4518 0, AGGREGATE_AS_SET);
4519}
4520
4521DEFUN (aggregate_address_mask_as_set,
4522 aggregate_address_mask_as_set_cmd,
4523 "aggregate-address A.B.C.D A.B.C.D as-set",
4524 "Configure BGP aggregate entries\n"
4525 "Aggregate address\n"
4526 "Aggregate mask\n"
4527 "Generate AS set path information\n")
4528{
4529 int ret;
4530 char prefix_str[BUFSIZ];
4531
4532 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4533
4534 if (! ret)
4535 {
4536 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4537 return CMD_WARNING;
4538 }
4539
4540 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4541 0, AGGREGATE_AS_SET);
4542}
4543
4544
4545DEFUN (aggregate_address_as_set_summary,
4546 aggregate_address_as_set_summary_cmd,
4547 "aggregate-address A.B.C.D/M as-set summary-only",
4548 "Configure BGP aggregate entries\n"
4549 "Aggregate prefix\n"
4550 "Generate AS set path information\n"
4551 "Filter more specific routes from updates\n")
4552{
4553 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4554 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4555}
4556
4557ALIAS (aggregate_address_as_set_summary,
4558 aggregate_address_summary_as_set_cmd,
4559 "aggregate-address A.B.C.D/M summary-only as-set",
4560 "Configure BGP aggregate entries\n"
4561 "Aggregate prefix\n"
4562 "Filter more specific routes from updates\n"
4563 "Generate AS set path information\n")
4564
4565DEFUN (aggregate_address_mask_as_set_summary,
4566 aggregate_address_mask_as_set_summary_cmd,
4567 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4568 "Configure BGP aggregate entries\n"
4569 "Aggregate address\n"
4570 "Aggregate mask\n"
4571 "Generate AS set path information\n"
4572 "Filter more specific routes from updates\n")
4573{
4574 int ret;
4575 char prefix_str[BUFSIZ];
4576
4577 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4578
4579 if (! ret)
4580 {
4581 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4582 return CMD_WARNING;
4583 }
4584
4585 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4586 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4587}
4588
4589ALIAS (aggregate_address_mask_as_set_summary,
4590 aggregate_address_mask_summary_as_set_cmd,
4591 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4592 "Configure BGP aggregate entries\n"
4593 "Aggregate address\n"
4594 "Aggregate mask\n"
4595 "Filter more specific routes from updates\n"
4596 "Generate AS set path information\n")
4597
4598DEFUN (no_aggregate_address,
4599 no_aggregate_address_cmd,
4600 "no aggregate-address A.B.C.D/M",
4601 NO_STR
4602 "Configure BGP aggregate entries\n"
4603 "Aggregate prefix\n")
4604{
4605 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4606}
4607
4608ALIAS (no_aggregate_address,
4609 no_aggregate_address_summary_only_cmd,
4610 "no aggregate-address A.B.C.D/M summary-only",
4611 NO_STR
4612 "Configure BGP aggregate entries\n"
4613 "Aggregate prefix\n"
4614 "Filter more specific routes from updates\n")
4615
4616ALIAS (no_aggregate_address,
4617 no_aggregate_address_as_set_cmd,
4618 "no aggregate-address A.B.C.D/M as-set",
4619 NO_STR
4620 "Configure BGP aggregate entries\n"
4621 "Aggregate prefix\n"
4622 "Generate AS set path information\n")
4623
4624ALIAS (no_aggregate_address,
4625 no_aggregate_address_as_set_summary_cmd,
4626 "no aggregate-address A.B.C.D/M as-set summary-only",
4627 NO_STR
4628 "Configure BGP aggregate entries\n"
4629 "Aggregate prefix\n"
4630 "Generate AS set path information\n"
4631 "Filter more specific routes from updates\n")
4632
4633ALIAS (no_aggregate_address,
4634 no_aggregate_address_summary_as_set_cmd,
4635 "no aggregate-address A.B.C.D/M summary-only as-set",
4636 NO_STR
4637 "Configure BGP aggregate entries\n"
4638 "Aggregate prefix\n"
4639 "Filter more specific routes from updates\n"
4640 "Generate AS set path information\n")
4641
4642DEFUN (no_aggregate_address_mask,
4643 no_aggregate_address_mask_cmd,
4644 "no aggregate-address A.B.C.D A.B.C.D",
4645 NO_STR
4646 "Configure BGP aggregate entries\n"
4647 "Aggregate address\n"
4648 "Aggregate mask\n")
4649{
4650 int ret;
4651 char prefix_str[BUFSIZ];
4652
4653 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4654
4655 if (! ret)
4656 {
4657 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4658 return CMD_WARNING;
4659 }
4660
4661 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4662}
4663
4664ALIAS (no_aggregate_address_mask,
4665 no_aggregate_address_mask_summary_only_cmd,
4666 "no aggregate-address A.B.C.D A.B.C.D summary-only",
4667 NO_STR
4668 "Configure BGP aggregate entries\n"
4669 "Aggregate address\n"
4670 "Aggregate mask\n"
4671 "Filter more specific routes from updates\n")
4672
4673ALIAS (no_aggregate_address_mask,
4674 no_aggregate_address_mask_as_set_cmd,
4675 "no aggregate-address A.B.C.D A.B.C.D as-set",
4676 NO_STR
4677 "Configure BGP aggregate entries\n"
4678 "Aggregate address\n"
4679 "Aggregate mask\n"
4680 "Generate AS set path information\n")
4681
4682ALIAS (no_aggregate_address_mask,
4683 no_aggregate_address_mask_as_set_summary_cmd,
4684 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4685 NO_STR
4686 "Configure BGP aggregate entries\n"
4687 "Aggregate address\n"
4688 "Aggregate mask\n"
4689 "Generate AS set path information\n"
4690 "Filter more specific routes from updates\n")
4691
4692ALIAS (no_aggregate_address_mask,
4693 no_aggregate_address_mask_summary_as_set_cmd,
4694 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4695 NO_STR
4696 "Configure BGP aggregate entries\n"
4697 "Aggregate address\n"
4698 "Aggregate mask\n"
4699 "Filter more specific routes from updates\n"
4700 "Generate AS set path information\n")
4701
4702#ifdef HAVE_IPV6
4703DEFUN (ipv6_aggregate_address,
4704 ipv6_aggregate_address_cmd,
4705 "aggregate-address X:X::X:X/M",
4706 "Configure BGP aggregate entries\n"
4707 "Aggregate prefix\n")
4708{
4709 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4710}
4711
4712DEFUN (ipv6_aggregate_address_summary_only,
4713 ipv6_aggregate_address_summary_only_cmd,
4714 "aggregate-address X:X::X:X/M summary-only",
4715 "Configure BGP aggregate entries\n"
4716 "Aggregate prefix\n"
4717 "Filter more specific routes from updates\n")
4718{
4719 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4720 AGGREGATE_SUMMARY_ONLY, 0);
4721}
4722
4723DEFUN (no_ipv6_aggregate_address,
4724 no_ipv6_aggregate_address_cmd,
4725 "no aggregate-address X:X::X:X/M",
4726 NO_STR
4727 "Configure BGP aggregate entries\n"
4728 "Aggregate prefix\n")
4729{
4730 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4731}
4732
4733DEFUN (no_ipv6_aggregate_address_summary_only,
4734 no_ipv6_aggregate_address_summary_only_cmd,
4735 "no aggregate-address X:X::X:X/M summary-only",
4736 NO_STR
4737 "Configure BGP aggregate entries\n"
4738 "Aggregate prefix\n"
4739 "Filter more specific routes from updates\n")
4740{
4741 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4742}
4743
4744ALIAS (ipv6_aggregate_address,
4745 old_ipv6_aggregate_address_cmd,
4746 "ipv6 bgp aggregate-address X:X::X:X/M",
4747 IPV6_STR
4748 BGP_STR
4749 "Configure BGP aggregate entries\n"
4750 "Aggregate prefix\n")
4751
4752ALIAS (ipv6_aggregate_address_summary_only,
4753 old_ipv6_aggregate_address_summary_only_cmd,
4754 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4755 IPV6_STR
4756 BGP_STR
4757 "Configure BGP aggregate entries\n"
4758 "Aggregate prefix\n"
4759 "Filter more specific routes from updates\n")
4760
4761ALIAS (no_ipv6_aggregate_address,
4762 old_no_ipv6_aggregate_address_cmd,
4763 "no ipv6 bgp aggregate-address X:X::X:X/M",
4764 NO_STR
4765 IPV6_STR
4766 BGP_STR
4767 "Configure BGP aggregate entries\n"
4768 "Aggregate prefix\n")
4769
4770ALIAS (no_ipv6_aggregate_address_summary_only,
4771 old_no_ipv6_aggregate_address_summary_only_cmd,
4772 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4773 NO_STR
4774 IPV6_STR
4775 BGP_STR
4776 "Configure BGP aggregate entries\n"
4777 "Aggregate prefix\n"
4778 "Filter more specific routes from updates\n")
4779#endif /* HAVE_IPV6 */
4780
4781/* Redistribute route treatment. */
4782void
4783bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4784 u_int32_t metric, u_char type)
4785{
4786 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004787 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004788 struct bgp_info *new;
4789 struct bgp_info *bi;
4790 struct bgp_info info;
4791 struct bgp_node *bn;
4792 struct attr attr;
4793 struct attr attr_new;
4794 struct attr *new_attr;
4795 afi_t afi;
4796 int ret;
4797
4798 /* Make default attribute. */
4799 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4800 if (nexthop)
4801 attr.nexthop = *nexthop;
4802
4803 attr.med = metric;
4804 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4805
paul1eb8ef22005-04-07 07:30:20 +00004806 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004807 {
4808 afi = family2afi (p->family);
4809
4810 if (bgp->redist[afi][type])
4811 {
4812 /* Copy attribute for modification. */
4813 attr_new = attr;
4814
4815 if (bgp->redist_metric_flag[afi][type])
4816 attr_new.med = bgp->redist_metric[afi][type];
4817
4818 /* Apply route-map. */
4819 if (bgp->rmap[afi][type].map)
4820 {
4821 info.peer = bgp->peer_self;
4822 info.attr = &attr_new;
4823
paulfee0f4c2004-09-13 05:12:46 +00004824 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
4825
paul718e3742002-12-13 20:15:29 +00004826 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
4827 &info);
paulfee0f4c2004-09-13 05:12:46 +00004828
4829 bgp->peer_self->rmap_type = 0;
4830
paul718e3742002-12-13 20:15:29 +00004831 if (ret == RMAP_DENYMATCH)
4832 {
4833 /* Free uninterned attribute. */
4834 bgp_attr_flush (&attr_new);
4835
4836 /* Unintern original. */
4837 aspath_unintern (attr.aspath);
4838 bgp_redistribute_delete (p, type);
4839 return;
4840 }
4841 }
4842
paulfee0f4c2004-09-13 05:12:46 +00004843 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004844 new_attr = bgp_attr_intern (&attr_new);
4845
4846 for (bi = bn->info; bi; bi = bi->next)
4847 if (bi->peer == bgp->peer_self
4848 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
4849 break;
4850
4851 if (bi)
4852 {
4853 if (attrhash_cmp (bi->attr, new_attr))
4854 {
4855 bgp_attr_unintern (new_attr);
4856 aspath_unintern (attr.aspath);
4857 bgp_unlock_node (bn);
4858 return;
4859 }
4860 else
4861 {
4862 /* The attribute is changed. */
4863 SET_FLAG (bi->flags, BGP_INFO_ATTR_CHANGED);
4864
4865 /* Rewrite BGP route information. */
4866 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
4867 bgp_attr_unintern (bi->attr);
4868 bi->attr = new_attr;
4869 bi->uptime = time (NULL);
4870
4871 /* Process change. */
4872 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
4873 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4874 bgp_unlock_node (bn);
4875 aspath_unintern (attr.aspath);
4876 return;
4877 }
4878 }
4879
4880 new = bgp_info_new ();
4881 new->type = type;
4882 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
4883 new->peer = bgp->peer_self;
4884 SET_FLAG (new->flags, BGP_INFO_VALID);
4885 new->attr = new_attr;
4886 new->uptime = time (NULL);
4887
4888 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
4889 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00004890 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00004891 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4892 }
4893 }
4894
4895 /* Unintern original. */
4896 aspath_unintern (attr.aspath);
4897}
4898
4899void
4900bgp_redistribute_delete (struct prefix *p, u_char type)
4901{
4902 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004903 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004904 afi_t afi;
4905 struct bgp_node *rn;
4906 struct bgp_info *ri;
4907
paul1eb8ef22005-04-07 07:30:20 +00004908 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004909 {
4910 afi = family2afi (p->family);
4911
4912 if (bgp->redist[afi][type])
4913 {
paulfee0f4c2004-09-13 05:12:46 +00004914 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004915
4916 for (ri = rn->info; ri; ri = ri->next)
4917 if (ri->peer == bgp->peer_self
4918 && ri->type == type)
4919 break;
4920
4921 if (ri)
4922 {
4923 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
4924 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4925 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4926 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004927 }
4928 bgp_unlock_node (rn);
4929 }
4930 }
4931}
4932
4933/* Withdraw specified route type's route. */
4934void
4935bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
4936{
4937 struct bgp_node *rn;
4938 struct bgp_info *ri;
4939 struct bgp_table *table;
4940
4941 table = bgp->rib[afi][SAFI_UNICAST];
4942
4943 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4944 {
4945 for (ri = rn->info; ri; ri = ri->next)
4946 if (ri->peer == bgp->peer_self
4947 && ri->type == type)
4948 break;
4949
4950 if (ri)
4951 {
4952 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
4953 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4954 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4955 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004956 }
4957 }
4958}
4959
4960/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00004961static void
paul718e3742002-12-13 20:15:29 +00004962route_vty_out_route (struct prefix *p, struct vty *vty)
4963{
4964 int len;
4965 u_int32_t destination;
4966 char buf[BUFSIZ];
4967
4968 if (p->family == AF_INET)
4969 {
4970 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
4971 destination = ntohl (p->u.prefix4.s_addr);
4972
4973 if ((IN_CLASSC (destination) && p->prefixlen == 24)
4974 || (IN_CLASSB (destination) && p->prefixlen == 16)
4975 || (IN_CLASSA (destination) && p->prefixlen == 8)
4976 || p->u.prefix4.s_addr == 0)
4977 {
4978 /* When mask is natural, mask is not displayed. */
4979 }
4980 else
4981 len += vty_out (vty, "/%d", p->prefixlen);
4982 }
4983 else
4984 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
4985 p->prefixlen);
4986
4987 len = 17 - len;
4988 if (len < 1)
4989 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
4990 else
4991 vty_out (vty, "%*s", len, " ");
4992}
4993
paul718e3742002-12-13 20:15:29 +00004994enum bgp_display_type
4995{
4996 normal_list,
4997};
4998
4999/* called from terminal list command */
ajs5a646652004-11-05 01:25:55 +00005000void
paul718e3742002-12-13 20:15:29 +00005001route_vty_out (struct vty *vty, struct prefix *p,
5002 struct bgp_info *binfo, int display, safi_t safi)
5003{
5004 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005005
5006 /* Route status display. */
hasso93406d82005-02-02 14:40:33 +00005007 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5008 vty_out (vty, "S");
5009 else if (binfo->suppress)
paul718e3742002-12-13 20:15:29 +00005010 vty_out (vty, "s");
5011 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5012 vty_out (vty, "*");
5013 else
5014 vty_out (vty, " ");
5015
5016 /* Selected */
5017 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5018 vty_out (vty, "h");
5019 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5020 vty_out (vty, "d");
5021 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5022 vty_out (vty, ">");
5023 else
5024 vty_out (vty, " ");
5025
5026 /* Internal route. */
5027 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5028 vty_out (vty, "i");
5029 else
5030 vty_out (vty, " ");
5031
5032 /* print prefix and mask */
5033 if (! display)
5034 route_vty_out_route (p, vty);
5035 else
5036 vty_out (vty, "%*s", 17, " ");
5037
5038 /* Print attribute */
5039 attr = binfo->attr;
5040 if (attr)
5041 {
5042 if (p->family == AF_INET)
5043 {
5044 if (safi == SAFI_MPLS_VPN)
5045 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5046 else
5047 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5048 }
5049#ifdef HAVE_IPV6
5050 else if (p->family == AF_INET6)
5051 {
5052 int len;
5053 char buf[BUFSIZ];
5054
5055 len = vty_out (vty, "%s",
5056 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5057 len = 16 - len;
5058 if (len < 1)
5059 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5060 else
5061 vty_out (vty, "%*s", len, " ");
5062 }
5063#endif /* HAVE_IPV6 */
5064
5065 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5066 vty_out (vty, "%10d", attr->med);
5067 else
5068 vty_out (vty, " ");
5069
5070 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5071 vty_out (vty, "%7d", attr->local_pref);
5072 else
5073 vty_out (vty, " ");
5074
5075 vty_out (vty, "%7u ",attr->weight);
5076
5077 /* Print aspath */
5078 if (attr->aspath)
5079 aspath_print_vty (vty, attr->aspath);
5080
5081 /* Print origin */
5082 if (strlen (attr->aspath->str) == 0)
5083 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5084 else
5085 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5086 }
5087 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005088}
5089
5090/* called from terminal list command */
5091void
5092route_vty_out_tmp (struct vty *vty, struct prefix *p,
5093 struct attr *attr, safi_t safi)
5094{
5095 /* Route status display. */
5096 vty_out (vty, "*");
5097 vty_out (vty, ">");
5098 vty_out (vty, " ");
5099
5100 /* print prefix and mask */
5101 route_vty_out_route (p, vty);
5102
5103 /* Print attribute */
5104 if (attr)
5105 {
5106 if (p->family == AF_INET)
5107 {
5108 if (safi == SAFI_MPLS_VPN)
5109 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5110 else
5111 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5112 }
5113#ifdef HAVE_IPV6
5114 else if (p->family == AF_INET6)
5115 {
5116 int len;
5117 char buf[BUFSIZ];
5118
5119 len = vty_out (vty, "%s",
5120 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5121 len = 16 - len;
5122 if (len < 1)
5123 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5124 else
5125 vty_out (vty, "%*s", len, " ");
5126 }
5127#endif /* HAVE_IPV6 */
5128
5129 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5130 vty_out (vty, "%10d", attr->med);
5131 else
5132 vty_out (vty, " ");
5133
5134 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5135 vty_out (vty, "%7d", attr->local_pref);
5136 else
5137 vty_out (vty, " ");
5138
5139 vty_out (vty, "%7d ",attr->weight);
5140
5141 /* Print aspath */
5142 if (attr->aspath)
5143 aspath_print_vty (vty, attr->aspath);
5144
5145 /* Print origin */
5146 if (strlen (attr->aspath->str) == 0)
5147 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5148 else
5149 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5150 }
5151
5152 vty_out (vty, "%s", VTY_NEWLINE);
5153}
5154
ajs5a646652004-11-05 01:25:55 +00005155void
paul718e3742002-12-13 20:15:29 +00005156route_vty_out_tag (struct vty *vty, struct prefix *p,
5157 struct bgp_info *binfo, int display, safi_t safi)
5158{
5159 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005160 u_int32_t label = 0;
5161
paul718e3742002-12-13 20:15:29 +00005162 /* Route status display. */
5163 if (binfo->suppress)
5164 vty_out (vty, "s");
5165 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5166 vty_out (vty, "*");
5167 else
5168 vty_out (vty, " ");
5169
5170 /* Selected */
5171 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5172 vty_out (vty, "h");
5173 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5174 vty_out (vty, "d");
5175 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5176 vty_out (vty, ">");
5177 else
5178 vty_out (vty, " ");
5179
5180 /* Internal route. */
5181 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5182 vty_out (vty, "i");
5183 else
5184 vty_out (vty, " ");
5185
5186 /* print prefix and mask */
5187 if (! display)
5188 route_vty_out_route (p, vty);
5189 else
5190 vty_out (vty, "%*s", 17, " ");
5191
5192 /* Print attribute */
5193 attr = binfo->attr;
5194 if (attr)
5195 {
5196 if (p->family == AF_INET)
5197 {
5198 if (safi == SAFI_MPLS_VPN)
5199 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5200 else
5201 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5202 }
5203#ifdef HAVE_IPV6
5204 else if (p->family == AF_INET6)
5205 {
5206 char buf[BUFSIZ];
5207 char buf1[BUFSIZ];
5208 if (attr->mp_nexthop_len == 16)
5209 vty_out (vty, "%s",
5210 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5211 else if (attr->mp_nexthop_len == 32)
5212 vty_out (vty, "%s(%s)",
5213 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
5214 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
5215
5216 }
5217#endif /* HAVE_IPV6 */
5218 }
5219
5220 label = decode_label (binfo->tag);
5221
5222 vty_out (vty, "notag/%d", label);
5223
5224 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005225}
5226
5227/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005228static void
paul718e3742002-12-13 20:15:29 +00005229damp_route_vty_out (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 int len;
5234
paul718e3742002-12-13 20:15:29 +00005235 /* Route status display. */
5236 if (binfo->suppress)
5237 vty_out (vty, "s");
5238 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5239 vty_out (vty, "*");
5240 else
5241 vty_out (vty, " ");
5242
5243 /* Selected */
5244 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5245 vty_out (vty, "h");
5246 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5247 vty_out (vty, "d");
5248 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5249 vty_out (vty, ">");
5250 else
5251 vty_out (vty, " ");
5252
5253 vty_out (vty, " ");
5254
5255 /* print prefix and mask */
5256 if (! display)
5257 route_vty_out_route (p, vty);
5258 else
5259 vty_out (vty, "%*s", 17, " ");
5260
5261 len = vty_out (vty, "%s", binfo->peer->host);
5262 len = 17 - len;
5263 if (len < 1)
5264 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5265 else
5266 vty_out (vty, "%*s", len, " ");
5267
5268 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5269
5270 /* Print attribute */
5271 attr = binfo->attr;
5272 if (attr)
5273 {
5274 /* Print aspath */
5275 if (attr->aspath)
5276 aspath_print_vty (vty, attr->aspath);
5277
5278 /* Print origin */
5279 if (strlen (attr->aspath->str) == 0)
5280 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5281 else
5282 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5283 }
5284 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005285}
5286
5287#define BGP_UPTIME_LEN 25
5288
5289/* flap route */
ajs5a646652004-11-05 01:25:55 +00005290static void
paul718e3742002-12-13 20:15:29 +00005291flap_route_vty_out (struct vty *vty, struct prefix *p,
5292 struct bgp_info *binfo, int display, safi_t safi)
5293{
5294 struct attr *attr;
5295 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005296 char timebuf[BGP_UPTIME_LEN];
5297 int len;
5298
paul718e3742002-12-13 20:15:29 +00005299 bdi = binfo->damp_info;
5300
5301 /* Route status display. */
5302 if (binfo->suppress)
5303 vty_out (vty, "s");
5304 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5305 vty_out (vty, "*");
5306 else
5307 vty_out (vty, " ");
5308
5309 /* Selected */
5310 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5311 vty_out (vty, "h");
5312 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5313 vty_out (vty, "d");
5314 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5315 vty_out (vty, ">");
5316 else
5317 vty_out (vty, " ");
5318
5319 vty_out (vty, " ");
5320
5321 /* print prefix and mask */
5322 if (! display)
5323 route_vty_out_route (p, vty);
5324 else
5325 vty_out (vty, "%*s", 17, " ");
5326
5327 len = vty_out (vty, "%s", binfo->peer->host);
5328 len = 16 - len;
5329 if (len < 1)
5330 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5331 else
5332 vty_out (vty, "%*s", len, " ");
5333
5334 len = vty_out (vty, "%d", bdi->flap);
5335 len = 5 - len;
5336 if (len < 1)
5337 vty_out (vty, " ");
5338 else
5339 vty_out (vty, "%*s ", len, " ");
5340
5341 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5342 timebuf, BGP_UPTIME_LEN));
5343
5344 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5345 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5346 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5347 else
5348 vty_out (vty, "%*s ", 8, " ");
5349
5350 /* Print attribute */
5351 attr = binfo->attr;
5352 if (attr)
5353 {
5354 /* Print aspath */
5355 if (attr->aspath)
5356 aspath_print_vty (vty, attr->aspath);
5357
5358 /* Print origin */
5359 if (strlen (attr->aspath->str) == 0)
5360 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5361 else
5362 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5363 }
5364 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005365}
5366
paul94f2b392005-06-28 12:44:16 +00005367static void
paul718e3742002-12-13 20:15:29 +00005368route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5369 struct bgp_info *binfo, afi_t afi, safi_t safi)
5370{
5371 char buf[INET6_ADDRSTRLEN];
5372 char buf1[BUFSIZ];
5373 struct attr *attr;
5374 int sockunion_vty_out (struct vty *, union sockunion *);
5375
5376 attr = binfo->attr;
5377
5378 if (attr)
5379 {
5380 /* Line1 display AS-path, Aggregator */
5381 if (attr->aspath)
5382 {
5383 vty_out (vty, " ");
5384 if (attr->aspath->length == 0)
5385 vty_out (vty, "Local");
5386 else
5387 aspath_print_vty (vty, attr->aspath);
5388 }
5389
hasso93406d82005-02-02 14:40:33 +00005390 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5391 vty_out (vty, ", (stale)");
5392 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5393 vty_out (vty, ", (aggregated by %d %s)", attr->aggregator_as,
5394 inet_ntoa (attr->aggregator_addr));
5395 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5396 vty_out (vty, ", (Received from a RR-client)");
5397 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5398 vty_out (vty, ", (Received from a RS-client)");
5399 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5400 vty_out (vty, ", (history entry)");
5401 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5402 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005403 vty_out (vty, "%s", VTY_NEWLINE);
5404
5405 /* Line2 display Next-hop, Neighbor, Router-id */
5406 if (p->family == AF_INET)
5407 {
5408 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5409 inet_ntoa (attr->mp_nexthop_global_in) :
5410 inet_ntoa (attr->nexthop));
5411 }
5412#ifdef HAVE_IPV6
5413 else
5414 {
5415 vty_out (vty, " %s",
5416 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5417 buf, INET6_ADDRSTRLEN));
5418 }
5419#endif /* HAVE_IPV6 */
5420
5421 if (binfo->peer == bgp->peer_self)
5422 {
5423 vty_out (vty, " from %s ",
5424 p->family == AF_INET ? "0.0.0.0" : "::");
5425 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5426 }
5427 else
5428 {
5429 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5430 vty_out (vty, " (inaccessible)");
5431 else if (binfo->igpmetric)
5432 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005433 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005434 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5435 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5436 else
5437 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5438 }
5439 vty_out (vty, "%s", VTY_NEWLINE);
5440
5441#ifdef HAVE_IPV6
5442 /* display nexthop local */
5443 if (attr->mp_nexthop_len == 32)
5444 {
5445 vty_out (vty, " (%s)%s",
5446 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5447 buf, INET6_ADDRSTRLEN),
5448 VTY_NEWLINE);
5449 }
5450#endif /* HAVE_IPV6 */
5451
5452 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5453 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5454
5455 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5456 vty_out (vty, ", metric %d", attr->med);
5457
5458 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5459 vty_out (vty, ", localpref %d", attr->local_pref);
5460 else
5461 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5462
5463 if (attr->weight != 0)
5464 vty_out (vty, ", weight %d", attr->weight);
5465
5466 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5467 vty_out (vty, ", valid");
5468
5469 if (binfo->peer != bgp->peer_self)
5470 {
5471 if (binfo->peer->as == binfo->peer->local_as)
5472 vty_out (vty, ", internal");
5473 else
5474 vty_out (vty, ", %s",
5475 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5476 }
5477 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5478 vty_out (vty, ", aggregated, local");
5479 else if (binfo->type != ZEBRA_ROUTE_BGP)
5480 vty_out (vty, ", sourced");
5481 else
5482 vty_out (vty, ", sourced, local");
5483
5484 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5485 vty_out (vty, ", atomic-aggregate");
5486
5487 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5488 vty_out (vty, ", best");
5489
5490 vty_out (vty, "%s", VTY_NEWLINE);
5491
5492 /* Line 4 display Community */
5493 if (attr->community)
5494 vty_out (vty, " Community: %s%s", attr->community->str,
5495 VTY_NEWLINE);
5496
5497 /* Line 5 display Extended-community */
5498 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5499 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5500 VTY_NEWLINE);
5501
5502 /* Line 6 display Originator, Cluster-id */
5503 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5504 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5505 {
5506 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5507 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5508
5509 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5510 {
5511 int i;
5512 vty_out (vty, ", Cluster list: ");
5513 for (i = 0; i < attr->cluster->length / 4; i++)
5514 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5515 }
5516 vty_out (vty, "%s", VTY_NEWLINE);
5517 }
5518
5519 if (binfo->damp_info)
5520 bgp_damp_info_vty (vty, binfo);
5521
5522 /* Line 7 display Uptime */
5523 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5524 }
5525 vty_out (vty, "%s", VTY_NEWLINE);
5526}
5527
hasso93406d82005-02-02 14:40:33 +00005528#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,%s r RIB-failure, S Stale%s"
5529#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005530#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5531#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5532#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5533
5534enum bgp_show_type
5535{
5536 bgp_show_type_normal,
5537 bgp_show_type_regexp,
5538 bgp_show_type_prefix_list,
5539 bgp_show_type_filter_list,
5540 bgp_show_type_route_map,
5541 bgp_show_type_neighbor,
5542 bgp_show_type_cidr_only,
5543 bgp_show_type_prefix_longer,
5544 bgp_show_type_community_all,
5545 bgp_show_type_community,
5546 bgp_show_type_community_exact,
5547 bgp_show_type_community_list,
5548 bgp_show_type_community_list_exact,
5549 bgp_show_type_flap_statistics,
5550 bgp_show_type_flap_address,
5551 bgp_show_type_flap_prefix,
5552 bgp_show_type_flap_cidr_only,
5553 bgp_show_type_flap_regexp,
5554 bgp_show_type_flap_filter_list,
5555 bgp_show_type_flap_prefix_list,
5556 bgp_show_type_flap_prefix_longer,
5557 bgp_show_type_flap_route_map,
5558 bgp_show_type_flap_neighbor,
5559 bgp_show_type_dampend_paths,
5560 bgp_show_type_damp_neighbor
5561};
5562
ajs5a646652004-11-05 01:25:55 +00005563static int
paulfee0f4c2004-09-13 05:12:46 +00005564bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00005565 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00005566{
paul718e3742002-12-13 20:15:29 +00005567 struct bgp_info *ri;
5568 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005569 int header = 1;
paul718e3742002-12-13 20:15:29 +00005570 int display;
ajs5a646652004-11-05 01:25:55 +00005571 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00005572
5573 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00005574 output_count = 0;
paul718e3742002-12-13 20:15:29 +00005575
paul718e3742002-12-13 20:15:29 +00005576 /* Start processing of routes. */
5577 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5578 if (rn->info != NULL)
5579 {
5580 display = 0;
5581
5582 for (ri = rn->info; ri; ri = ri->next)
5583 {
ajs5a646652004-11-05 01:25:55 +00005584 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00005585 || type == bgp_show_type_flap_address
5586 || type == bgp_show_type_flap_prefix
5587 || type == bgp_show_type_flap_cidr_only
5588 || type == bgp_show_type_flap_regexp
5589 || type == bgp_show_type_flap_filter_list
5590 || type == bgp_show_type_flap_prefix_list
5591 || type == bgp_show_type_flap_prefix_longer
5592 || type == bgp_show_type_flap_route_map
5593 || type == bgp_show_type_flap_neighbor
5594 || type == bgp_show_type_dampend_paths
5595 || type == bgp_show_type_damp_neighbor)
5596 {
5597 if (! ri->damp_info)
5598 continue;
5599 }
5600 if (type == bgp_show_type_regexp
5601 || type == bgp_show_type_flap_regexp)
5602 {
ajs5a646652004-11-05 01:25:55 +00005603 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00005604
5605 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5606 continue;
5607 }
5608 if (type == bgp_show_type_prefix_list
5609 || type == bgp_show_type_flap_prefix_list)
5610 {
ajs5a646652004-11-05 01:25:55 +00005611 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00005612
5613 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5614 continue;
5615 }
5616 if (type == bgp_show_type_filter_list
5617 || type == bgp_show_type_flap_filter_list)
5618 {
ajs5a646652004-11-05 01:25:55 +00005619 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00005620
5621 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5622 continue;
5623 }
5624 if (type == bgp_show_type_route_map
5625 || type == bgp_show_type_flap_route_map)
5626 {
ajs5a646652004-11-05 01:25:55 +00005627 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00005628 struct bgp_info binfo;
5629 struct attr dummy_attr;
5630 int ret;
5631
5632 dummy_attr = *ri->attr;
5633 binfo.peer = ri->peer;
5634 binfo.attr = &dummy_attr;
5635
5636 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5637
5638 if (ret == RMAP_DENYMATCH)
5639 continue;
5640 }
5641 if (type == bgp_show_type_neighbor
5642 || type == bgp_show_type_flap_neighbor
5643 || type == bgp_show_type_damp_neighbor)
5644 {
ajs5a646652004-11-05 01:25:55 +00005645 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00005646
5647 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5648 continue;
5649 }
5650 if (type == bgp_show_type_cidr_only
5651 || type == bgp_show_type_flap_cidr_only)
5652 {
5653 u_int32_t destination;
5654
5655 destination = ntohl (rn->p.u.prefix4.s_addr);
5656 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5657 continue;
5658 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5659 continue;
5660 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5661 continue;
5662 }
5663 if (type == bgp_show_type_prefix_longer
5664 || type == bgp_show_type_flap_prefix_longer)
5665 {
ajs5a646652004-11-05 01:25:55 +00005666 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005667
5668 if (! prefix_match (p, &rn->p))
5669 continue;
5670 }
5671 if (type == bgp_show_type_community_all)
5672 {
5673 if (! ri->attr->community)
5674 continue;
5675 }
5676 if (type == bgp_show_type_community)
5677 {
ajs5a646652004-11-05 01:25:55 +00005678 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005679
5680 if (! ri->attr->community ||
5681 ! community_match (ri->attr->community, com))
5682 continue;
5683 }
5684 if (type == bgp_show_type_community_exact)
5685 {
ajs5a646652004-11-05 01:25:55 +00005686 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005687
5688 if (! ri->attr->community ||
5689 ! community_cmp (ri->attr->community, com))
5690 continue;
5691 }
5692 if (type == bgp_show_type_community_list)
5693 {
ajs5a646652004-11-05 01:25:55 +00005694 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005695
5696 if (! community_list_match (ri->attr->community, list))
5697 continue;
5698 }
5699 if (type == bgp_show_type_community_list_exact)
5700 {
ajs5a646652004-11-05 01:25:55 +00005701 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005702
5703 if (! community_list_exact_match (ri->attr->community, list))
5704 continue;
5705 }
5706 if (type == bgp_show_type_flap_address
5707 || type == bgp_show_type_flap_prefix)
5708 {
ajs5a646652004-11-05 01:25:55 +00005709 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005710
5711 if (! prefix_match (&rn->p, p))
5712 continue;
5713
5714 if (type == bgp_show_type_flap_prefix)
5715 if (p->prefixlen != rn->p.prefixlen)
5716 continue;
5717 }
5718 if (type == bgp_show_type_dampend_paths
5719 || type == bgp_show_type_damp_neighbor)
5720 {
5721 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5722 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5723 continue;
5724 }
5725
5726 if (header)
5727 {
hasso93406d82005-02-02 14:40:33 +00005728 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
5729 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
5730 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005731 if (type == bgp_show_type_dampend_paths
5732 || type == bgp_show_type_damp_neighbor)
5733 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5734 else if (type == bgp_show_type_flap_statistics
5735 || type == bgp_show_type_flap_address
5736 || type == bgp_show_type_flap_prefix
5737 || type == bgp_show_type_flap_cidr_only
5738 || type == bgp_show_type_flap_regexp
5739 || type == bgp_show_type_flap_filter_list
5740 || type == bgp_show_type_flap_prefix_list
5741 || type == bgp_show_type_flap_prefix_longer
5742 || type == bgp_show_type_flap_route_map
5743 || type == bgp_show_type_flap_neighbor)
5744 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5745 else
5746 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005747 header = 0;
5748 }
5749
5750 if (type == bgp_show_type_dampend_paths
5751 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00005752 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005753 else if (type == bgp_show_type_flap_statistics
5754 || type == bgp_show_type_flap_address
5755 || type == bgp_show_type_flap_prefix
5756 || type == bgp_show_type_flap_cidr_only
5757 || type == bgp_show_type_flap_regexp
5758 || type == bgp_show_type_flap_filter_list
5759 || type == bgp_show_type_flap_prefix_list
5760 || type == bgp_show_type_flap_prefix_longer
5761 || type == bgp_show_type_flap_route_map
5762 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00005763 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005764 else
ajs5a646652004-11-05 01:25:55 +00005765 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005766 display++;
5767 }
5768 if (display)
ajs5a646652004-11-05 01:25:55 +00005769 output_count++;
paul718e3742002-12-13 20:15:29 +00005770 }
5771
5772 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00005773 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00005774 {
5775 if (type == bgp_show_type_normal)
5776 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5777 }
5778 else
5779 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00005780 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005781
5782 return CMD_SUCCESS;
5783}
5784
ajs5a646652004-11-05 01:25:55 +00005785static int
paulfee0f4c2004-09-13 05:12:46 +00005786bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00005787 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00005788{
5789 struct bgp_table *table;
5790
5791 if (bgp == NULL) {
5792 bgp = bgp_get_default ();
5793 }
5794
5795 if (bgp == NULL)
5796 {
5797 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5798 return CMD_WARNING;
5799 }
5800
5801
5802 table = bgp->rib[afi][safi];
5803
ajs5a646652004-11-05 01:25:55 +00005804 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00005805}
5806
paul718e3742002-12-13 20:15:29 +00005807/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00005808static void
paul718e3742002-12-13 20:15:29 +00005809route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5810 struct bgp_node *rn,
5811 struct prefix_rd *prd, afi_t afi, safi_t safi)
5812{
5813 struct bgp_info *ri;
5814 struct prefix *p;
5815 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00005816 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005817 char buf1[INET6_ADDRSTRLEN];
5818 char buf2[INET6_ADDRSTRLEN];
5819 int count = 0;
5820 int best = 0;
5821 int suppress = 0;
5822 int no_export = 0;
5823 int no_advertise = 0;
5824 int local_as = 0;
5825 int first = 0;
5826
5827 p = &rn->p;
5828 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5829 (safi == SAFI_MPLS_VPN ?
5830 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5831 safi == SAFI_MPLS_VPN ? ":" : "",
5832 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5833 p->prefixlen, VTY_NEWLINE);
5834
5835 for (ri = rn->info; ri; ri = ri->next)
5836 {
5837 count++;
5838 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5839 {
5840 best = count;
5841 if (ri->suppress)
5842 suppress = 1;
5843 if (ri->attr->community != NULL)
5844 {
5845 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5846 no_advertise = 1;
5847 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5848 no_export = 1;
5849 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5850 local_as = 1;
5851 }
5852 }
5853 }
5854
5855 vty_out (vty, "Paths: (%d available", count);
5856 if (best)
5857 {
5858 vty_out (vty, ", best #%d", best);
5859 if (safi == SAFI_UNICAST)
5860 vty_out (vty, ", table Default-IP-Routing-Table");
5861 }
5862 else
5863 vty_out (vty, ", no best path");
5864 if (no_advertise)
5865 vty_out (vty, ", not advertised to any peer");
5866 else if (no_export)
5867 vty_out (vty, ", not advertised to EBGP peer");
5868 else if (local_as)
5869 vty_out (vty, ", not advertised outside local AS");
5870 if (suppress)
5871 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5872 vty_out (vty, ")%s", VTY_NEWLINE);
5873
5874 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00005875 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00005876 {
5877 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5878 {
5879 if (! first)
5880 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5881 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5882 first = 1;
5883 }
5884 }
5885 if (! first)
5886 vty_out (vty, " Not advertised to any peer");
5887 vty_out (vty, "%s", VTY_NEWLINE);
5888}
5889
5890/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00005891static int
paulfee0f4c2004-09-13 05:12:46 +00005892bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00005893 struct bgp_table *rib, const char *ip_str,
5894 afi_t afi, safi_t safi, struct prefix_rd *prd,
5895 int prefix_check)
paul718e3742002-12-13 20:15:29 +00005896{
5897 int ret;
5898 int header;
5899 int display = 0;
5900 struct prefix match;
5901 struct bgp_node *rn;
5902 struct bgp_node *rm;
5903 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00005904 struct bgp_table *table;
5905
paul718e3742002-12-13 20:15:29 +00005906 /* Check IP address argument. */
5907 ret = str2prefix (ip_str, &match);
5908 if (! ret)
5909 {
5910 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5911 return CMD_WARNING;
5912 }
5913
5914 match.family = afi2family (afi);
5915
5916 if (safi == SAFI_MPLS_VPN)
5917 {
paulfee0f4c2004-09-13 05:12:46 +00005918 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00005919 {
5920 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5921 continue;
5922
5923 if ((table = rn->info) != NULL)
5924 {
5925 header = 1;
5926
5927 if ((rm = bgp_node_match (table, &match)) != NULL)
5928 {
5929 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5930 continue;
5931
5932 for (ri = rm->info; ri; ri = ri->next)
5933 {
5934 if (header)
5935 {
5936 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5937 AFI_IP, SAFI_MPLS_VPN);
5938
5939 header = 0;
5940 }
5941 display++;
5942 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5943 }
5944 }
5945 }
5946 }
5947 }
5948 else
5949 {
5950 header = 1;
5951
paulfee0f4c2004-09-13 05:12:46 +00005952 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00005953 {
5954 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5955 {
5956 for (ri = rn->info; ri; ri = ri->next)
5957 {
5958 if (header)
5959 {
5960 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
5961 header = 0;
5962 }
5963 display++;
5964 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
5965 }
5966 }
5967 }
5968 }
5969
5970 if (! display)
5971 {
5972 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5973 return CMD_WARNING;
5974 }
5975
5976 return CMD_SUCCESS;
5977}
5978
paulfee0f4c2004-09-13 05:12:46 +00005979/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00005980static int
paulfd79ac92004-10-13 05:06:08 +00005981bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00005982 afi_t afi, safi_t safi, struct prefix_rd *prd,
5983 int prefix_check)
5984{
5985 struct bgp *bgp;
5986
5987 /* BGP structure lookup. */
5988 if (view_name)
5989 {
5990 bgp = bgp_lookup_by_name (view_name);
5991 if (bgp == NULL)
5992 {
5993 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
5994 return CMD_WARNING;
5995 }
5996 }
5997 else
5998 {
5999 bgp = bgp_get_default ();
6000 if (bgp == NULL)
6001 {
6002 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6003 return CMD_WARNING;
6004 }
6005 }
6006
6007 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6008 afi, safi, prd, prefix_check);
6009}
6010
paul718e3742002-12-13 20:15:29 +00006011/* BGP route print out function. */
6012DEFUN (show_ip_bgp,
6013 show_ip_bgp_cmd,
6014 "show ip bgp",
6015 SHOW_STR
6016 IP_STR
6017 BGP_STR)
6018{
ajs5a646652004-11-05 01:25:55 +00006019 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006020}
6021
6022DEFUN (show_ip_bgp_ipv4,
6023 show_ip_bgp_ipv4_cmd,
6024 "show ip bgp ipv4 (unicast|multicast)",
6025 SHOW_STR
6026 IP_STR
6027 BGP_STR
6028 "Address family\n"
6029 "Address Family modifier\n"
6030 "Address Family modifier\n")
6031{
6032 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006033 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6034 NULL);
paul718e3742002-12-13 20:15:29 +00006035
ajs5a646652004-11-05 01:25:55 +00006036 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006037}
6038
6039DEFUN (show_ip_bgp_route,
6040 show_ip_bgp_route_cmd,
6041 "show ip bgp A.B.C.D",
6042 SHOW_STR
6043 IP_STR
6044 BGP_STR
6045 "Network in the BGP routing table to display\n")
6046{
6047 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6048}
6049
6050DEFUN (show_ip_bgp_ipv4_route,
6051 show_ip_bgp_ipv4_route_cmd,
6052 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6053 SHOW_STR
6054 IP_STR
6055 BGP_STR
6056 "Address family\n"
6057 "Address Family modifier\n"
6058 "Address Family modifier\n"
6059 "Network in the BGP routing table to display\n")
6060{
6061 if (strncmp (argv[0], "m", 1) == 0)
6062 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6063
6064 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6065}
6066
6067DEFUN (show_ip_bgp_vpnv4_all_route,
6068 show_ip_bgp_vpnv4_all_route_cmd,
6069 "show ip bgp vpnv4 all A.B.C.D",
6070 SHOW_STR
6071 IP_STR
6072 BGP_STR
6073 "Display VPNv4 NLRI specific information\n"
6074 "Display information about all VPNv4 NLRIs\n"
6075 "Network in the BGP routing table to display\n")
6076{
6077 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6078}
6079
6080DEFUN (show_ip_bgp_vpnv4_rd_route,
6081 show_ip_bgp_vpnv4_rd_route_cmd,
6082 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6083 SHOW_STR
6084 IP_STR
6085 BGP_STR
6086 "Display VPNv4 NLRI specific information\n"
6087 "Display information for a route distinguisher\n"
6088 "VPN Route Distinguisher\n"
6089 "Network in the BGP routing table to display\n")
6090{
6091 int ret;
6092 struct prefix_rd prd;
6093
6094 ret = str2prefix_rd (argv[0], &prd);
6095 if (! ret)
6096 {
6097 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6098 return CMD_WARNING;
6099 }
6100 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6101}
6102
6103DEFUN (show_ip_bgp_prefix,
6104 show_ip_bgp_prefix_cmd,
6105 "show ip bgp A.B.C.D/M",
6106 SHOW_STR
6107 IP_STR
6108 BGP_STR
6109 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6110{
6111 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6112}
6113
6114DEFUN (show_ip_bgp_ipv4_prefix,
6115 show_ip_bgp_ipv4_prefix_cmd,
6116 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6117 SHOW_STR
6118 IP_STR
6119 BGP_STR
6120 "Address family\n"
6121 "Address Family modifier\n"
6122 "Address Family modifier\n"
6123 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6124{
6125 if (strncmp (argv[0], "m", 1) == 0)
6126 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6127
6128 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6129}
6130
6131DEFUN (show_ip_bgp_vpnv4_all_prefix,
6132 show_ip_bgp_vpnv4_all_prefix_cmd,
6133 "show ip bgp vpnv4 all A.B.C.D/M",
6134 SHOW_STR
6135 IP_STR
6136 BGP_STR
6137 "Display VPNv4 NLRI specific information\n"
6138 "Display information about all VPNv4 NLRIs\n"
6139 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6140{
6141 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6142}
6143
6144DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6145 show_ip_bgp_vpnv4_rd_prefix_cmd,
6146 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6147 SHOW_STR
6148 IP_STR
6149 BGP_STR
6150 "Display VPNv4 NLRI specific information\n"
6151 "Display information for a route distinguisher\n"
6152 "VPN Route Distinguisher\n"
6153 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6154{
6155 int ret;
6156 struct prefix_rd prd;
6157
6158 ret = str2prefix_rd (argv[0], &prd);
6159 if (! ret)
6160 {
6161 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6162 return CMD_WARNING;
6163 }
6164 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6165}
6166
6167DEFUN (show_ip_bgp_view,
6168 show_ip_bgp_view_cmd,
6169 "show ip bgp view WORD",
6170 SHOW_STR
6171 IP_STR
6172 BGP_STR
6173 "BGP view\n"
6174 "BGP view name\n")
6175{
paulbb46e942003-10-24 19:02:03 +00006176 struct bgp *bgp;
6177
6178 /* BGP structure lookup. */
6179 bgp = bgp_lookup_by_name (argv[0]);
6180 if (bgp == NULL)
6181 {
6182 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6183 return CMD_WARNING;
6184 }
6185
ajs5a646652004-11-05 01:25:55 +00006186 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006187}
6188
6189DEFUN (show_ip_bgp_view_route,
6190 show_ip_bgp_view_route_cmd,
6191 "show ip bgp view WORD A.B.C.D",
6192 SHOW_STR
6193 IP_STR
6194 BGP_STR
6195 "BGP view\n"
6196 "BGP view name\n"
6197 "Network in the BGP routing table to display\n")
6198{
6199 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6200}
6201
6202DEFUN (show_ip_bgp_view_prefix,
6203 show_ip_bgp_view_prefix_cmd,
6204 "show ip bgp view WORD A.B.C.D/M",
6205 SHOW_STR
6206 IP_STR
6207 BGP_STR
6208 "BGP view\n"
6209 "BGP view name\n"
6210 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6211{
6212 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6213}
6214
6215#ifdef HAVE_IPV6
6216DEFUN (show_bgp,
6217 show_bgp_cmd,
6218 "show bgp",
6219 SHOW_STR
6220 BGP_STR)
6221{
ajs5a646652004-11-05 01:25:55 +00006222 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6223 NULL);
paul718e3742002-12-13 20:15:29 +00006224}
6225
6226ALIAS (show_bgp,
6227 show_bgp_ipv6_cmd,
6228 "show bgp ipv6",
6229 SHOW_STR
6230 BGP_STR
6231 "Address family\n")
6232
6233/* old command */
6234DEFUN (show_ipv6_bgp,
6235 show_ipv6_bgp_cmd,
6236 "show ipv6 bgp",
6237 SHOW_STR
6238 IP_STR
6239 BGP_STR)
6240{
ajs5a646652004-11-05 01:25:55 +00006241 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6242 NULL);
paul718e3742002-12-13 20:15:29 +00006243}
6244
6245DEFUN (show_bgp_route,
6246 show_bgp_route_cmd,
6247 "show bgp X:X::X:X",
6248 SHOW_STR
6249 BGP_STR
6250 "Network in the BGP routing table to display\n")
6251{
6252 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6253}
6254
6255ALIAS (show_bgp_route,
6256 show_bgp_ipv6_route_cmd,
6257 "show bgp ipv6 X:X::X:X",
6258 SHOW_STR
6259 BGP_STR
6260 "Address family\n"
6261 "Network in the BGP routing table to display\n")
6262
6263/* old command */
6264DEFUN (show_ipv6_bgp_route,
6265 show_ipv6_bgp_route_cmd,
6266 "show ipv6 bgp X:X::X:X",
6267 SHOW_STR
6268 IP_STR
6269 BGP_STR
6270 "Network in the BGP routing table to display\n")
6271{
6272 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6273}
6274
6275DEFUN (show_bgp_prefix,
6276 show_bgp_prefix_cmd,
6277 "show bgp X:X::X:X/M",
6278 SHOW_STR
6279 BGP_STR
6280 "IPv6 prefix <network>/<length>\n")
6281{
6282 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6283}
6284
6285ALIAS (show_bgp_prefix,
6286 show_bgp_ipv6_prefix_cmd,
6287 "show bgp ipv6 X:X::X:X/M",
6288 SHOW_STR
6289 BGP_STR
6290 "Address family\n"
6291 "IPv6 prefix <network>/<length>\n")
6292
6293/* old command */
6294DEFUN (show_ipv6_bgp_prefix,
6295 show_ipv6_bgp_prefix_cmd,
6296 "show ipv6 bgp X:X::X:X/M",
6297 SHOW_STR
6298 IP_STR
6299 BGP_STR
6300 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6301{
6302 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6303}
6304
paulbb46e942003-10-24 19:02:03 +00006305DEFUN (show_bgp_view,
6306 show_bgp_view_cmd,
6307 "show bgp view WORD",
6308 SHOW_STR
6309 BGP_STR
6310 "BGP view\n"
6311 "View name\n")
6312{
6313 struct bgp *bgp;
6314
6315 /* BGP structure lookup. */
6316 bgp = bgp_lookup_by_name (argv[0]);
6317 if (bgp == NULL)
6318 {
6319 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6320 return CMD_WARNING;
6321 }
6322
ajs5a646652004-11-05 01:25:55 +00006323 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006324}
6325
6326ALIAS (show_bgp_view,
6327 show_bgp_view_ipv6_cmd,
6328 "show bgp view WORD ipv6",
6329 SHOW_STR
6330 BGP_STR
6331 "BGP view\n"
6332 "View name\n"
6333 "Address family\n")
6334
6335DEFUN (show_bgp_view_route,
6336 show_bgp_view_route_cmd,
6337 "show bgp view WORD X:X::X:X",
6338 SHOW_STR
6339 BGP_STR
6340 "BGP view\n"
6341 "View name\n"
6342 "Network in the BGP routing table to display\n")
6343{
6344 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6345}
6346
6347ALIAS (show_bgp_view_route,
6348 show_bgp_view_ipv6_route_cmd,
6349 "show bgp view WORD ipv6 X:X::X:X",
6350 SHOW_STR
6351 BGP_STR
6352 "BGP view\n"
6353 "View name\n"
6354 "Address family\n"
6355 "Network in the BGP routing table to display\n")
6356
6357DEFUN (show_bgp_view_prefix,
6358 show_bgp_view_prefix_cmd,
6359 "show bgp view WORD X:X::X:X/M",
6360 SHOW_STR
6361 BGP_STR
6362 "BGP view\n"
6363 "View name\n"
6364 "IPv6 prefix <network>/<length>\n")
6365{
6366 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6367}
6368
6369ALIAS (show_bgp_view_prefix,
6370 show_bgp_view_ipv6_prefix_cmd,
6371 "show bgp view WORD ipv6 X:X::X:X/M",
6372 SHOW_STR
6373 BGP_STR
6374 "BGP view\n"
6375 "View name\n"
6376 "Address family\n"
6377 "IPv6 prefix <network>/<length>\n")
6378
paul718e3742002-12-13 20:15:29 +00006379/* old command */
6380DEFUN (show_ipv6_mbgp,
6381 show_ipv6_mbgp_cmd,
6382 "show ipv6 mbgp",
6383 SHOW_STR
6384 IP_STR
6385 MBGP_STR)
6386{
ajs5a646652004-11-05 01:25:55 +00006387 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6388 NULL);
paul718e3742002-12-13 20:15:29 +00006389}
6390
6391/* old command */
6392DEFUN (show_ipv6_mbgp_route,
6393 show_ipv6_mbgp_route_cmd,
6394 "show ipv6 mbgp X:X::X:X",
6395 SHOW_STR
6396 IP_STR
6397 MBGP_STR
6398 "Network in the MBGP routing table to display\n")
6399{
6400 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6401}
6402
6403/* old command */
6404DEFUN (show_ipv6_mbgp_prefix,
6405 show_ipv6_mbgp_prefix_cmd,
6406 "show ipv6 mbgp X:X::X:X/M",
6407 SHOW_STR
6408 IP_STR
6409 MBGP_STR
6410 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6411{
6412 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6413}
6414#endif
6415
paul718e3742002-12-13 20:15:29 +00006416
paul94f2b392005-06-28 12:44:16 +00006417static int
paulfd79ac92004-10-13 05:06:08 +00006418bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006419 safi_t safi, enum bgp_show_type type)
6420{
6421 int i;
6422 struct buffer *b;
6423 char *regstr;
6424 int first;
6425 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006426 int rc;
paul718e3742002-12-13 20:15:29 +00006427
6428 first = 0;
6429 b = buffer_new (1024);
6430 for (i = 0; i < argc; i++)
6431 {
6432 if (first)
6433 buffer_putc (b, ' ');
6434 else
6435 {
6436 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6437 continue;
6438 first = 1;
6439 }
6440
6441 buffer_putstr (b, argv[i]);
6442 }
6443 buffer_putc (b, '\0');
6444
6445 regstr = buffer_getstr (b);
6446 buffer_free (b);
6447
6448 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006449 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006450 if (! regex)
6451 {
6452 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6453 VTY_NEWLINE);
6454 return CMD_WARNING;
6455 }
6456
ajs5a646652004-11-05 01:25:55 +00006457 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6458 bgp_regex_free (regex);
6459 return rc;
paul718e3742002-12-13 20:15:29 +00006460}
6461
6462DEFUN (show_ip_bgp_regexp,
6463 show_ip_bgp_regexp_cmd,
6464 "show ip bgp regexp .LINE",
6465 SHOW_STR
6466 IP_STR
6467 BGP_STR
6468 "Display routes matching the AS path regular expression\n"
6469 "A regular-expression to match the BGP AS paths\n")
6470{
6471 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6472 bgp_show_type_regexp);
6473}
6474
6475DEFUN (show_ip_bgp_flap_regexp,
6476 show_ip_bgp_flap_regexp_cmd,
6477 "show ip bgp flap-statistics regexp .LINE",
6478 SHOW_STR
6479 IP_STR
6480 BGP_STR
6481 "Display flap statistics of routes\n"
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_flap_regexp);
6487}
6488
6489DEFUN (show_ip_bgp_ipv4_regexp,
6490 show_ip_bgp_ipv4_regexp_cmd,
6491 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6492 SHOW_STR
6493 IP_STR
6494 BGP_STR
6495 "Address family\n"
6496 "Address Family modifier\n"
6497 "Address Family modifier\n"
6498 "Display routes matching the AS path regular expression\n"
6499 "A regular-expression to match the BGP AS paths\n")
6500{
6501 if (strncmp (argv[0], "m", 1) == 0)
6502 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6503 bgp_show_type_regexp);
6504
6505 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6506 bgp_show_type_regexp);
6507}
6508
6509#ifdef HAVE_IPV6
6510DEFUN (show_bgp_regexp,
6511 show_bgp_regexp_cmd,
6512 "show bgp regexp .LINE",
6513 SHOW_STR
6514 BGP_STR
6515 "Display routes matching the AS path regular expression\n"
6516 "A regular-expression to match the BGP AS paths\n")
6517{
6518 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6519 bgp_show_type_regexp);
6520}
6521
6522ALIAS (show_bgp_regexp,
6523 show_bgp_ipv6_regexp_cmd,
6524 "show bgp ipv6 regexp .LINE",
6525 SHOW_STR
6526 BGP_STR
6527 "Address family\n"
6528 "Display routes matching the AS path regular expression\n"
6529 "A regular-expression to match the BGP AS paths\n")
6530
6531/* old command */
6532DEFUN (show_ipv6_bgp_regexp,
6533 show_ipv6_bgp_regexp_cmd,
6534 "show ipv6 bgp regexp .LINE",
6535 SHOW_STR
6536 IP_STR
6537 BGP_STR
6538 "Display routes matching the AS path regular expression\n"
6539 "A regular-expression to match the BGP AS paths\n")
6540{
6541 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6542 bgp_show_type_regexp);
6543}
6544
6545/* old command */
6546DEFUN (show_ipv6_mbgp_regexp,
6547 show_ipv6_mbgp_regexp_cmd,
6548 "show ipv6 mbgp 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 MBGP AS paths\n")
6554{
6555 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6556 bgp_show_type_regexp);
6557}
6558#endif /* HAVE_IPV6 */
6559
paul94f2b392005-06-28 12:44:16 +00006560static int
paulfd79ac92004-10-13 05:06:08 +00006561bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006562 safi_t safi, enum bgp_show_type type)
6563{
6564 struct prefix_list *plist;
6565
6566 plist = prefix_list_lookup (afi, prefix_list_str);
6567 if (plist == NULL)
6568 {
6569 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6570 prefix_list_str, VTY_NEWLINE);
6571 return CMD_WARNING;
6572 }
6573
ajs5a646652004-11-05 01:25:55 +00006574 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00006575}
6576
6577DEFUN (show_ip_bgp_prefix_list,
6578 show_ip_bgp_prefix_list_cmd,
6579 "show ip bgp prefix-list WORD",
6580 SHOW_STR
6581 IP_STR
6582 BGP_STR
6583 "Display routes conforming to the prefix-list\n"
6584 "IP prefix-list name\n")
6585{
6586 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6587 bgp_show_type_prefix_list);
6588}
6589
6590DEFUN (show_ip_bgp_flap_prefix_list,
6591 show_ip_bgp_flap_prefix_list_cmd,
6592 "show ip bgp flap-statistics prefix-list WORD",
6593 SHOW_STR
6594 IP_STR
6595 BGP_STR
6596 "Display flap statistics of routes\n"
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_flap_prefix_list);
6602}
6603
6604DEFUN (show_ip_bgp_ipv4_prefix_list,
6605 show_ip_bgp_ipv4_prefix_list_cmd,
6606 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6607 SHOW_STR
6608 IP_STR
6609 BGP_STR
6610 "Address family\n"
6611 "Address Family modifier\n"
6612 "Address Family modifier\n"
6613 "Display routes conforming to the prefix-list\n"
6614 "IP prefix-list name\n")
6615{
6616 if (strncmp (argv[0], "m", 1) == 0)
6617 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6618 bgp_show_type_prefix_list);
6619
6620 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6621 bgp_show_type_prefix_list);
6622}
6623
6624#ifdef HAVE_IPV6
6625DEFUN (show_bgp_prefix_list,
6626 show_bgp_prefix_list_cmd,
6627 "show bgp prefix-list WORD",
6628 SHOW_STR
6629 BGP_STR
6630 "Display routes conforming to the prefix-list\n"
6631 "IPv6 prefix-list name\n")
6632{
6633 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6634 bgp_show_type_prefix_list);
6635}
6636
6637ALIAS (show_bgp_prefix_list,
6638 show_bgp_ipv6_prefix_list_cmd,
6639 "show bgp ipv6 prefix-list WORD",
6640 SHOW_STR
6641 BGP_STR
6642 "Address family\n"
6643 "Display routes conforming to the prefix-list\n"
6644 "IPv6 prefix-list name\n")
6645
6646/* old command */
6647DEFUN (show_ipv6_bgp_prefix_list,
6648 show_ipv6_bgp_prefix_list_cmd,
6649 "show ipv6 bgp prefix-list WORD",
6650 SHOW_STR
6651 IPV6_STR
6652 BGP_STR
6653 "Display routes matching the prefix-list\n"
6654 "IPv6 prefix-list name\n")
6655{
6656 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6657 bgp_show_type_prefix_list);
6658}
6659
6660/* old command */
6661DEFUN (show_ipv6_mbgp_prefix_list,
6662 show_ipv6_mbgp_prefix_list_cmd,
6663 "show ipv6 mbgp prefix-list WORD",
6664 SHOW_STR
6665 IPV6_STR
6666 MBGP_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_MULTICAST,
6671 bgp_show_type_prefix_list);
6672}
6673#endif /* HAVE_IPV6 */
6674
paul94f2b392005-06-28 12:44:16 +00006675static int
paulfd79ac92004-10-13 05:06:08 +00006676bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006677 safi_t safi, enum bgp_show_type type)
6678{
6679 struct as_list *as_list;
6680
6681 as_list = as_list_lookup (filter);
6682 if (as_list == NULL)
6683 {
6684 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6685 return CMD_WARNING;
6686 }
6687
ajs5a646652004-11-05 01:25:55 +00006688 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00006689}
6690
6691DEFUN (show_ip_bgp_filter_list,
6692 show_ip_bgp_filter_list_cmd,
6693 "show ip bgp filter-list WORD",
6694 SHOW_STR
6695 IP_STR
6696 BGP_STR
6697 "Display routes conforming to the filter-list\n"
6698 "Regular expression access list name\n")
6699{
6700 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6701 bgp_show_type_filter_list);
6702}
6703
6704DEFUN (show_ip_bgp_flap_filter_list,
6705 show_ip_bgp_flap_filter_list_cmd,
6706 "show ip bgp flap-statistics filter-list WORD",
6707 SHOW_STR
6708 IP_STR
6709 BGP_STR
6710 "Display flap statistics of routes\n"
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_flap_filter_list);
6716}
6717
6718DEFUN (show_ip_bgp_ipv4_filter_list,
6719 show_ip_bgp_ipv4_filter_list_cmd,
6720 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6721 SHOW_STR
6722 IP_STR
6723 BGP_STR
6724 "Address family\n"
6725 "Address Family modifier\n"
6726 "Address Family modifier\n"
6727 "Display routes conforming to the filter-list\n"
6728 "Regular expression access list name\n")
6729{
6730 if (strncmp (argv[0], "m", 1) == 0)
6731 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6732 bgp_show_type_filter_list);
6733
6734 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6735 bgp_show_type_filter_list);
6736}
6737
6738#ifdef HAVE_IPV6
6739DEFUN (show_bgp_filter_list,
6740 show_bgp_filter_list_cmd,
6741 "show bgp filter-list WORD",
6742 SHOW_STR
6743 BGP_STR
6744 "Display routes conforming to the filter-list\n"
6745 "Regular expression access list name\n")
6746{
6747 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6748 bgp_show_type_filter_list);
6749}
6750
6751ALIAS (show_bgp_filter_list,
6752 show_bgp_ipv6_filter_list_cmd,
6753 "show bgp ipv6 filter-list WORD",
6754 SHOW_STR
6755 BGP_STR
6756 "Address family\n"
6757 "Display routes conforming to the filter-list\n"
6758 "Regular expression access list name\n")
6759
6760/* old command */
6761DEFUN (show_ipv6_bgp_filter_list,
6762 show_ipv6_bgp_filter_list_cmd,
6763 "show ipv6 bgp filter-list WORD",
6764 SHOW_STR
6765 IPV6_STR
6766 BGP_STR
6767 "Display routes conforming to the filter-list\n"
6768 "Regular expression access list name\n")
6769{
6770 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6771 bgp_show_type_filter_list);
6772}
6773
6774/* old command */
6775DEFUN (show_ipv6_mbgp_filter_list,
6776 show_ipv6_mbgp_filter_list_cmd,
6777 "show ipv6 mbgp filter-list WORD",
6778 SHOW_STR
6779 IPV6_STR
6780 MBGP_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_MULTICAST,
6785 bgp_show_type_filter_list);
6786}
6787#endif /* HAVE_IPV6 */
6788
paul94f2b392005-06-28 12:44:16 +00006789static int
paulfd79ac92004-10-13 05:06:08 +00006790bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006791 safi_t safi, enum bgp_show_type type)
6792{
6793 struct route_map *rmap;
6794
6795 rmap = route_map_lookup_by_name (rmap_str);
6796 if (! rmap)
6797 {
6798 vty_out (vty, "%% %s is not a valid route-map name%s",
6799 rmap_str, VTY_NEWLINE);
6800 return CMD_WARNING;
6801 }
6802
ajs5a646652004-11-05 01:25:55 +00006803 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00006804}
6805
6806DEFUN (show_ip_bgp_route_map,
6807 show_ip_bgp_route_map_cmd,
6808 "show ip bgp route-map WORD",
6809 SHOW_STR
6810 IP_STR
6811 BGP_STR
6812 "Display routes matching the route-map\n"
6813 "A route-map to match on\n")
6814{
6815 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6816 bgp_show_type_route_map);
6817}
6818
6819DEFUN (show_ip_bgp_flap_route_map,
6820 show_ip_bgp_flap_route_map_cmd,
6821 "show ip bgp flap-statistics route-map WORD",
6822 SHOW_STR
6823 IP_STR
6824 BGP_STR
6825 "Display flap statistics of routes\n"
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_flap_route_map);
6831}
6832
6833DEFUN (show_ip_bgp_ipv4_route_map,
6834 show_ip_bgp_ipv4_route_map_cmd,
6835 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6836 SHOW_STR
6837 IP_STR
6838 BGP_STR
6839 "Address family\n"
6840 "Address Family modifier\n"
6841 "Address Family modifier\n"
6842 "Display routes matching the route-map\n"
6843 "A route-map to match on\n")
6844{
6845 if (strncmp (argv[0], "m", 1) == 0)
6846 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6847 bgp_show_type_route_map);
6848
6849 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6850 bgp_show_type_route_map);
6851}
6852
6853DEFUN (show_bgp_route_map,
6854 show_bgp_route_map_cmd,
6855 "show bgp route-map WORD",
6856 SHOW_STR
6857 BGP_STR
6858 "Display routes matching the route-map\n"
6859 "A route-map to match on\n")
6860{
6861 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6862 bgp_show_type_route_map);
6863}
6864
6865ALIAS (show_bgp_route_map,
6866 show_bgp_ipv6_route_map_cmd,
6867 "show bgp ipv6 route-map WORD",
6868 SHOW_STR
6869 BGP_STR
6870 "Address family\n"
6871 "Display routes matching the route-map\n"
6872 "A route-map to match on\n")
6873
6874DEFUN (show_ip_bgp_cidr_only,
6875 show_ip_bgp_cidr_only_cmd,
6876 "show ip bgp cidr-only",
6877 SHOW_STR
6878 IP_STR
6879 BGP_STR
6880 "Display only routes with non-natural netmasks\n")
6881{
6882 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006883 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006884}
6885
6886DEFUN (show_ip_bgp_flap_cidr_only,
6887 show_ip_bgp_flap_cidr_only_cmd,
6888 "show ip bgp flap-statistics cidr-only",
6889 SHOW_STR
6890 IP_STR
6891 BGP_STR
6892 "Display flap statistics of routes\n"
6893 "Display only routes with non-natural netmasks\n")
6894{
6895 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006896 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006897}
6898
6899DEFUN (show_ip_bgp_ipv4_cidr_only,
6900 show_ip_bgp_ipv4_cidr_only_cmd,
6901 "show ip bgp ipv4 (unicast|multicast) cidr-only",
6902 SHOW_STR
6903 IP_STR
6904 BGP_STR
6905 "Address family\n"
6906 "Address Family modifier\n"
6907 "Address Family modifier\n"
6908 "Display only routes with non-natural netmasks\n")
6909{
6910 if (strncmp (argv[0], "m", 1) == 0)
6911 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006912 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006913
6914 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006915 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006916}
6917
6918DEFUN (show_ip_bgp_community_all,
6919 show_ip_bgp_community_all_cmd,
6920 "show ip bgp community",
6921 SHOW_STR
6922 IP_STR
6923 BGP_STR
6924 "Display routes matching the communities\n")
6925{
6926 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006927 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006928}
6929
6930DEFUN (show_ip_bgp_ipv4_community_all,
6931 show_ip_bgp_ipv4_community_all_cmd,
6932 "show ip bgp ipv4 (unicast|multicast) community",
6933 SHOW_STR
6934 IP_STR
6935 BGP_STR
6936 "Address family\n"
6937 "Address Family modifier\n"
6938 "Address Family modifier\n"
6939 "Display routes matching the communities\n")
6940{
6941 if (strncmp (argv[0], "m", 1) == 0)
6942 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006943 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006944
6945 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006946 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006947}
6948
6949#ifdef HAVE_IPV6
6950DEFUN (show_bgp_community_all,
6951 show_bgp_community_all_cmd,
6952 "show bgp community",
6953 SHOW_STR
6954 BGP_STR
6955 "Display routes matching the communities\n")
6956{
6957 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006958 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006959}
6960
6961ALIAS (show_bgp_community_all,
6962 show_bgp_ipv6_community_all_cmd,
6963 "show bgp ipv6 community",
6964 SHOW_STR
6965 BGP_STR
6966 "Address family\n"
6967 "Display routes matching the communities\n")
6968
6969/* old command */
6970DEFUN (show_ipv6_bgp_community_all,
6971 show_ipv6_bgp_community_all_cmd,
6972 "show ipv6 bgp community",
6973 SHOW_STR
6974 IPV6_STR
6975 BGP_STR
6976 "Display routes matching the communities\n")
6977{
6978 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006979 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006980}
6981
6982/* old command */
6983DEFUN (show_ipv6_mbgp_community_all,
6984 show_ipv6_mbgp_community_all_cmd,
6985 "show ipv6 mbgp community",
6986 SHOW_STR
6987 IPV6_STR
6988 MBGP_STR
6989 "Display routes matching the communities\n")
6990{
6991 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006992 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006993}
6994#endif /* HAVE_IPV6 */
6995
paul94f2b392005-06-28 12:44:16 +00006996static int
paulfd79ac92004-10-13 05:06:08 +00006997bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
6998 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00006999{
7000 struct community *com;
7001 struct buffer *b;
7002 int i;
7003 char *str;
7004 int first = 0;
7005
7006 b = buffer_new (1024);
7007 for (i = 0; i < argc; i++)
7008 {
7009 if (first)
7010 buffer_putc (b, ' ');
7011 else
7012 {
7013 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7014 continue;
7015 first = 1;
7016 }
7017
7018 buffer_putstr (b, argv[i]);
7019 }
7020 buffer_putc (b, '\0');
7021
7022 str = buffer_getstr (b);
7023 buffer_free (b);
7024
7025 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007026 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007027 if (! com)
7028 {
7029 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7030 return CMD_WARNING;
7031 }
7032
ajs5a646652004-11-05 01:25:55 +00007033 return bgp_show (vty, NULL, afi, safi,
7034 (exact ? bgp_show_type_community_exact :
7035 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007036}
7037
7038DEFUN (show_ip_bgp_community,
7039 show_ip_bgp_community_cmd,
7040 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7041 SHOW_STR
7042 IP_STR
7043 BGP_STR
7044 "Display routes matching the communities\n"
7045 "community number\n"
7046 "Do not send outside local AS (well-known community)\n"
7047 "Do not advertise to any peer (well-known community)\n"
7048 "Do not export to next AS (well-known community)\n")
7049{
7050 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7051}
7052
7053ALIAS (show_ip_bgp_community,
7054 show_ip_bgp_community2_cmd,
7055 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7056 SHOW_STR
7057 IP_STR
7058 BGP_STR
7059 "Display routes matching the communities\n"
7060 "community number\n"
7061 "Do not send outside local AS (well-known community)\n"
7062 "Do not advertise to any peer (well-known community)\n"
7063 "Do not export to next AS (well-known community)\n"
7064 "community number\n"
7065 "Do not send outside local AS (well-known community)\n"
7066 "Do not advertise to any peer (well-known community)\n"
7067 "Do not export to next AS (well-known community)\n")
7068
7069ALIAS (show_ip_bgp_community,
7070 show_ip_bgp_community3_cmd,
7071 "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)",
7072 SHOW_STR
7073 IP_STR
7074 BGP_STR
7075 "Display routes matching the communities\n"
7076 "community number\n"
7077 "Do not send outside local AS (well-known community)\n"
7078 "Do not advertise to any peer (well-known community)\n"
7079 "Do not export to next AS (well-known community)\n"
7080 "community number\n"
7081 "Do not send outside local AS (well-known community)\n"
7082 "Do not advertise to any peer (well-known community)\n"
7083 "Do not export to next AS (well-known community)\n"
7084 "community number\n"
7085 "Do not send outside local AS (well-known community)\n"
7086 "Do not advertise to any peer (well-known community)\n"
7087 "Do not export to next AS (well-known community)\n")
7088
7089ALIAS (show_ip_bgp_community,
7090 show_ip_bgp_community4_cmd,
7091 "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)",
7092 SHOW_STR
7093 IP_STR
7094 BGP_STR
7095 "Display routes matching the communities\n"
7096 "community number\n"
7097 "Do not send outside local AS (well-known community)\n"
7098 "Do not advertise to any peer (well-known community)\n"
7099 "Do not export to next AS (well-known community)\n"
7100 "community number\n"
7101 "Do not send outside local AS (well-known community)\n"
7102 "Do not advertise to any peer (well-known community)\n"
7103 "Do not export to next AS (well-known community)\n"
7104 "community number\n"
7105 "Do not send outside local AS (well-known community)\n"
7106 "Do not advertise to any peer (well-known community)\n"
7107 "Do not export to next AS (well-known community)\n"
7108 "community number\n"
7109 "Do not send outside local AS (well-known community)\n"
7110 "Do not advertise to any peer (well-known community)\n"
7111 "Do not export to next AS (well-known community)\n")
7112
7113DEFUN (show_ip_bgp_ipv4_community,
7114 show_ip_bgp_ipv4_community_cmd,
7115 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7116 SHOW_STR
7117 IP_STR
7118 BGP_STR
7119 "Address family\n"
7120 "Address Family modifier\n"
7121 "Address Family modifier\n"
7122 "Display routes matching the communities\n"
7123 "community number\n"
7124 "Do not send outside local AS (well-known community)\n"
7125 "Do not advertise to any peer (well-known community)\n"
7126 "Do not export to next AS (well-known community)\n")
7127{
7128 if (strncmp (argv[0], "m", 1) == 0)
7129 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7130
7131 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7132}
7133
7134ALIAS (show_ip_bgp_ipv4_community,
7135 show_ip_bgp_ipv4_community2_cmd,
7136 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7137 SHOW_STR
7138 IP_STR
7139 BGP_STR
7140 "Address family\n"
7141 "Address Family modifier\n"
7142 "Address Family modifier\n"
7143 "Display routes matching the communities\n"
7144 "community number\n"
7145 "Do not send outside local AS (well-known community)\n"
7146 "Do not advertise to any peer (well-known community)\n"
7147 "Do not export to next AS (well-known community)\n"
7148 "community number\n"
7149 "Do not send outside local AS (well-known community)\n"
7150 "Do not advertise to any peer (well-known community)\n"
7151 "Do not export to next AS (well-known community)\n")
7152
7153ALIAS (show_ip_bgp_ipv4_community,
7154 show_ip_bgp_ipv4_community3_cmd,
7155 "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)",
7156 SHOW_STR
7157 IP_STR
7158 BGP_STR
7159 "Address family\n"
7160 "Address Family modifier\n"
7161 "Address Family modifier\n"
7162 "Display routes matching the communities\n"
7163 "community number\n"
7164 "Do not send outside local AS (well-known community)\n"
7165 "Do not advertise to any peer (well-known community)\n"
7166 "Do not export to next AS (well-known community)\n"
7167 "community number\n"
7168 "Do not send outside local AS (well-known community)\n"
7169 "Do not advertise to any peer (well-known community)\n"
7170 "Do not export to next AS (well-known community)\n"
7171 "community number\n"
7172 "Do not send outside local AS (well-known community)\n"
7173 "Do not advertise to any peer (well-known community)\n"
7174 "Do not export to next AS (well-known community)\n")
7175
7176ALIAS (show_ip_bgp_ipv4_community,
7177 show_ip_bgp_ipv4_community4_cmd,
7178 "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)",
7179 SHOW_STR
7180 IP_STR
7181 BGP_STR
7182 "Address family\n"
7183 "Address Family modifier\n"
7184 "Address Family modifier\n"
7185 "Display routes matching the communities\n"
7186 "community number\n"
7187 "Do not send outside local AS (well-known community)\n"
7188 "Do not advertise to any peer (well-known community)\n"
7189 "Do not export to next AS (well-known community)\n"
7190 "community number\n"
7191 "Do not send outside local AS (well-known community)\n"
7192 "Do not advertise to any peer (well-known community)\n"
7193 "Do not export to next AS (well-known community)\n"
7194 "community number\n"
7195 "Do not send outside local AS (well-known community)\n"
7196 "Do not advertise to any peer (well-known community)\n"
7197 "Do not export to next AS (well-known community)\n"
7198 "community number\n"
7199 "Do not send outside local AS (well-known community)\n"
7200 "Do not advertise to any peer (well-known community)\n"
7201 "Do not export to next AS (well-known community)\n")
7202
7203DEFUN (show_ip_bgp_community_exact,
7204 show_ip_bgp_community_exact_cmd,
7205 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7206 SHOW_STR
7207 IP_STR
7208 BGP_STR
7209 "Display routes matching the communities\n"
7210 "community number\n"
7211 "Do not send outside local AS (well-known community)\n"
7212 "Do not advertise to any peer (well-known community)\n"
7213 "Do not export to next AS (well-known community)\n"
7214 "Exact match of the communities")
7215{
7216 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7217}
7218
7219ALIAS (show_ip_bgp_community_exact,
7220 show_ip_bgp_community2_exact_cmd,
7221 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7222 SHOW_STR
7223 IP_STR
7224 BGP_STR
7225 "Display routes matching the communities\n"
7226 "community number\n"
7227 "Do not send outside local AS (well-known community)\n"
7228 "Do not advertise to any peer (well-known community)\n"
7229 "Do not export to next AS (well-known community)\n"
7230 "community number\n"
7231 "Do not send outside local AS (well-known community)\n"
7232 "Do not advertise to any peer (well-known community)\n"
7233 "Do not export to next AS (well-known community)\n"
7234 "Exact match of the communities")
7235
7236ALIAS (show_ip_bgp_community_exact,
7237 show_ip_bgp_community3_exact_cmd,
7238 "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",
7239 SHOW_STR
7240 IP_STR
7241 BGP_STR
7242 "Display routes matching the communities\n"
7243 "community number\n"
7244 "Do not send outside local AS (well-known community)\n"
7245 "Do not advertise to any peer (well-known community)\n"
7246 "Do not export to next AS (well-known community)\n"
7247 "community number\n"
7248 "Do not send outside local AS (well-known community)\n"
7249 "Do not advertise to any peer (well-known community)\n"
7250 "Do not export to next AS (well-known community)\n"
7251 "community number\n"
7252 "Do not send outside local AS (well-known community)\n"
7253 "Do not advertise to any peer (well-known community)\n"
7254 "Do not export to next AS (well-known community)\n"
7255 "Exact match of the communities")
7256
7257ALIAS (show_ip_bgp_community_exact,
7258 show_ip_bgp_community4_exact_cmd,
7259 "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",
7260 SHOW_STR
7261 IP_STR
7262 BGP_STR
7263 "Display routes matching the communities\n"
7264 "community number\n"
7265 "Do not send outside local AS (well-known community)\n"
7266 "Do not advertise to any peer (well-known community)\n"
7267 "Do not export to next AS (well-known community)\n"
7268 "community number\n"
7269 "Do not send outside local AS (well-known community)\n"
7270 "Do not advertise to any peer (well-known community)\n"
7271 "Do not export to next AS (well-known community)\n"
7272 "community number\n"
7273 "Do not send outside local AS (well-known community)\n"
7274 "Do not advertise to any peer (well-known community)\n"
7275 "Do not export to next AS (well-known community)\n"
7276 "community number\n"
7277 "Do not send outside local AS (well-known community)\n"
7278 "Do not advertise to any peer (well-known community)\n"
7279 "Do not export to next AS (well-known community)\n"
7280 "Exact match of the communities")
7281
7282DEFUN (show_ip_bgp_ipv4_community_exact,
7283 show_ip_bgp_ipv4_community_exact_cmd,
7284 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7285 SHOW_STR
7286 IP_STR
7287 BGP_STR
7288 "Address family\n"
7289 "Address Family modifier\n"
7290 "Address Family modifier\n"
7291 "Display routes matching the communities\n"
7292 "community number\n"
7293 "Do not send outside local AS (well-known community)\n"
7294 "Do not advertise to any peer (well-known community)\n"
7295 "Do not export to next AS (well-known community)\n"
7296 "Exact match of the communities")
7297{
7298 if (strncmp (argv[0], "m", 1) == 0)
7299 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7300
7301 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7302}
7303
7304ALIAS (show_ip_bgp_ipv4_community_exact,
7305 show_ip_bgp_ipv4_community2_exact_cmd,
7306 "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",
7307 SHOW_STR
7308 IP_STR
7309 BGP_STR
7310 "Address family\n"
7311 "Address Family modifier\n"
7312 "Address Family modifier\n"
7313 "Display routes matching the communities\n"
7314 "community number\n"
7315 "Do not send outside local AS (well-known community)\n"
7316 "Do not advertise to any peer (well-known community)\n"
7317 "Do not export to next AS (well-known community)\n"
7318 "community number\n"
7319 "Do not send outside local AS (well-known community)\n"
7320 "Do not advertise to any peer (well-known community)\n"
7321 "Do not export to next AS (well-known community)\n"
7322 "Exact match of the communities")
7323
7324ALIAS (show_ip_bgp_ipv4_community_exact,
7325 show_ip_bgp_ipv4_community3_exact_cmd,
7326 "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",
7327 SHOW_STR
7328 IP_STR
7329 BGP_STR
7330 "Address family\n"
7331 "Address Family modifier\n"
7332 "Address Family modifier\n"
7333 "Display routes matching the communities\n"
7334 "community number\n"
7335 "Do not send outside local AS (well-known community)\n"
7336 "Do not advertise to any peer (well-known community)\n"
7337 "Do not export to next AS (well-known community)\n"
7338 "community number\n"
7339 "Do not send outside local AS (well-known community)\n"
7340 "Do not advertise to any peer (well-known community)\n"
7341 "Do not export to next AS (well-known community)\n"
7342 "community number\n"
7343 "Do not send outside local AS (well-known community)\n"
7344 "Do not advertise to any peer (well-known community)\n"
7345 "Do not export to next AS (well-known community)\n"
7346 "Exact match of the communities")
7347
7348ALIAS (show_ip_bgp_ipv4_community_exact,
7349 show_ip_bgp_ipv4_community4_exact_cmd,
7350 "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",
7351 SHOW_STR
7352 IP_STR
7353 BGP_STR
7354 "Address family\n"
7355 "Address Family modifier\n"
7356 "Address Family modifier\n"
7357 "Display routes matching the communities\n"
7358 "community number\n"
7359 "Do not send outside local AS (well-known community)\n"
7360 "Do not advertise to any peer (well-known community)\n"
7361 "Do not export to next AS (well-known community)\n"
7362 "community number\n"
7363 "Do not send outside local AS (well-known community)\n"
7364 "Do not advertise to any peer (well-known community)\n"
7365 "Do not export to next AS (well-known community)\n"
7366 "community number\n"
7367 "Do not send outside local AS (well-known community)\n"
7368 "Do not advertise to any peer (well-known community)\n"
7369 "Do not export to next AS (well-known community)\n"
7370 "community number\n"
7371 "Do not send outside local AS (well-known community)\n"
7372 "Do not advertise to any peer (well-known community)\n"
7373 "Do not export to next AS (well-known community)\n"
7374 "Exact match of the communities")
7375
7376#ifdef HAVE_IPV6
7377DEFUN (show_bgp_community,
7378 show_bgp_community_cmd,
7379 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7380 SHOW_STR
7381 BGP_STR
7382 "Display routes matching the communities\n"
7383 "community number\n"
7384 "Do not send outside local AS (well-known community)\n"
7385 "Do not advertise to any peer (well-known community)\n"
7386 "Do not export to next AS (well-known community)\n")
7387{
7388 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7389}
7390
7391ALIAS (show_bgp_community,
7392 show_bgp_ipv6_community_cmd,
7393 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7394 SHOW_STR
7395 BGP_STR
7396 "Address family\n"
7397 "Display routes matching the communities\n"
7398 "community number\n"
7399 "Do not send outside local AS (well-known community)\n"
7400 "Do not advertise to any peer (well-known community)\n"
7401 "Do not export to next AS (well-known community)\n")
7402
7403ALIAS (show_bgp_community,
7404 show_bgp_community2_cmd,
7405 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7406 SHOW_STR
7407 BGP_STR
7408 "Display routes matching the communities\n"
7409 "community number\n"
7410 "Do not send outside local AS (well-known community)\n"
7411 "Do not advertise to any peer (well-known community)\n"
7412 "Do not export to next AS (well-known community)\n"
7413 "community number\n"
7414 "Do not send outside local AS (well-known community)\n"
7415 "Do not advertise to any peer (well-known community)\n"
7416 "Do not export to next AS (well-known community)\n")
7417
7418ALIAS (show_bgp_community,
7419 show_bgp_ipv6_community2_cmd,
7420 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7421 SHOW_STR
7422 BGP_STR
7423 "Address family\n"
7424 "Display routes matching the communities\n"
7425 "community number\n"
7426 "Do not send outside local AS (well-known community)\n"
7427 "Do not advertise to any peer (well-known community)\n"
7428 "Do not export to next AS (well-known community)\n"
7429 "community number\n"
7430 "Do not send outside local AS (well-known community)\n"
7431 "Do not advertise to any peer (well-known community)\n"
7432 "Do not export to next AS (well-known community)\n")
7433
7434ALIAS (show_bgp_community,
7435 show_bgp_community3_cmd,
7436 "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)",
7437 SHOW_STR
7438 BGP_STR
7439 "Display routes matching the communities\n"
7440 "community number\n"
7441 "Do not send outside local AS (well-known community)\n"
7442 "Do not advertise to any peer (well-known community)\n"
7443 "Do not export to next AS (well-known community)\n"
7444 "community number\n"
7445 "Do not send outside local AS (well-known community)\n"
7446 "Do not advertise to any peer (well-known community)\n"
7447 "Do not export to next AS (well-known community)\n"
7448 "community number\n"
7449 "Do not send outside local AS (well-known community)\n"
7450 "Do not advertise to any peer (well-known community)\n"
7451 "Do not export to next AS (well-known community)\n")
7452
7453ALIAS (show_bgp_community,
7454 show_bgp_ipv6_community3_cmd,
7455 "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)",
7456 SHOW_STR
7457 BGP_STR
7458 "Address family\n"
7459 "Display routes matching the communities\n"
7460 "community number\n"
7461 "Do not send outside local AS (well-known community)\n"
7462 "Do not advertise to any peer (well-known community)\n"
7463 "Do not export to next AS (well-known community)\n"
7464 "community number\n"
7465 "Do not send outside local AS (well-known community)\n"
7466 "Do not advertise to any peer (well-known community)\n"
7467 "Do not export to next AS (well-known community)\n"
7468 "community number\n"
7469 "Do not send outside local AS (well-known community)\n"
7470 "Do not advertise to any peer (well-known community)\n"
7471 "Do not export to next AS (well-known community)\n")
7472
7473ALIAS (show_bgp_community,
7474 show_bgp_community4_cmd,
7475 "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)",
7476 SHOW_STR
7477 BGP_STR
7478 "Display routes matching the communities\n"
7479 "community number\n"
7480 "Do not send outside local AS (well-known community)\n"
7481 "Do not advertise to any peer (well-known community)\n"
7482 "Do not export to next AS (well-known community)\n"
7483 "community number\n"
7484 "Do not send outside local AS (well-known community)\n"
7485 "Do not advertise to any peer (well-known community)\n"
7486 "Do not export to next AS (well-known community)\n"
7487 "community number\n"
7488 "Do not send outside local AS (well-known community)\n"
7489 "Do not advertise to any peer (well-known community)\n"
7490 "Do not export to next AS (well-known community)\n"
7491 "community number\n"
7492 "Do not send outside local AS (well-known community)\n"
7493 "Do not advertise to any peer (well-known community)\n"
7494 "Do not export to next AS (well-known community)\n")
7495
7496ALIAS (show_bgp_community,
7497 show_bgp_ipv6_community4_cmd,
7498 "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)",
7499 SHOW_STR
7500 BGP_STR
7501 "Address family\n"
7502 "Display routes matching the communities\n"
7503 "community number\n"
7504 "Do not send outside local AS (well-known community)\n"
7505 "Do not advertise to any peer (well-known community)\n"
7506 "Do not export to next AS (well-known community)\n"
7507 "community number\n"
7508 "Do not send outside local AS (well-known community)\n"
7509 "Do not advertise to any peer (well-known community)\n"
7510 "Do not export to next AS (well-known community)\n"
7511 "community number\n"
7512 "Do not send outside local AS (well-known community)\n"
7513 "Do not advertise to any peer (well-known community)\n"
7514 "Do not export to next AS (well-known community)\n"
7515 "community number\n"
7516 "Do not send outside local AS (well-known community)\n"
7517 "Do not advertise to any peer (well-known community)\n"
7518 "Do not export to next AS (well-known community)\n")
7519
7520/* old command */
7521DEFUN (show_ipv6_bgp_community,
7522 show_ipv6_bgp_community_cmd,
7523 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7524 SHOW_STR
7525 IPV6_STR
7526 BGP_STR
7527 "Display routes matching the communities\n"
7528 "community number\n"
7529 "Do not send outside local AS (well-known community)\n"
7530 "Do not advertise to any peer (well-known community)\n"
7531 "Do not export to next AS (well-known community)\n")
7532{
7533 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7534}
7535
7536/* old command */
7537ALIAS (show_ipv6_bgp_community,
7538 show_ipv6_bgp_community2_cmd,
7539 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7540 SHOW_STR
7541 IPV6_STR
7542 BGP_STR
7543 "Display routes matching the communities\n"
7544 "community number\n"
7545 "Do not send outside local AS (well-known community)\n"
7546 "Do not advertise to any peer (well-known community)\n"
7547 "Do not export to next AS (well-known community)\n"
7548 "community number\n"
7549 "Do not send outside local AS (well-known community)\n"
7550 "Do not advertise to any peer (well-known community)\n"
7551 "Do not export to next AS (well-known community)\n")
7552
7553/* old command */
7554ALIAS (show_ipv6_bgp_community,
7555 show_ipv6_bgp_community3_cmd,
7556 "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)",
7557 SHOW_STR
7558 IPV6_STR
7559 BGP_STR
7560 "Display routes matching the communities\n"
7561 "community number\n"
7562 "Do not send outside local AS (well-known community)\n"
7563 "Do not advertise to any peer (well-known community)\n"
7564 "Do not export to next AS (well-known community)\n"
7565 "community number\n"
7566 "Do not send outside local AS (well-known community)\n"
7567 "Do not advertise to any peer (well-known community)\n"
7568 "Do not export to next AS (well-known community)\n"
7569 "community number\n"
7570 "Do not send outside local AS (well-known community)\n"
7571 "Do not advertise to any peer (well-known community)\n"
7572 "Do not export to next AS (well-known community)\n")
7573
7574/* old command */
7575ALIAS (show_ipv6_bgp_community,
7576 show_ipv6_bgp_community4_cmd,
7577 "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)",
7578 SHOW_STR
7579 IPV6_STR
7580 BGP_STR
7581 "Display routes matching the communities\n"
7582 "community number\n"
7583 "Do not send outside local AS (well-known community)\n"
7584 "Do not advertise to any peer (well-known community)\n"
7585 "Do not export to next AS (well-known community)\n"
7586 "community number\n"
7587 "Do not send outside local AS (well-known community)\n"
7588 "Do not advertise to any peer (well-known community)\n"
7589 "Do not export to next AS (well-known community)\n"
7590 "community number\n"
7591 "Do not send outside local AS (well-known community)\n"
7592 "Do not advertise to any peer (well-known community)\n"
7593 "Do not export to next AS (well-known community)\n"
7594 "community number\n"
7595 "Do not send outside local AS (well-known community)\n"
7596 "Do not advertise to any peer (well-known community)\n"
7597 "Do not export to next AS (well-known community)\n")
7598
7599DEFUN (show_bgp_community_exact,
7600 show_bgp_community_exact_cmd,
7601 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7602 SHOW_STR
7603 BGP_STR
7604 "Display routes matching the communities\n"
7605 "community number\n"
7606 "Do not send outside local AS (well-known community)\n"
7607 "Do not advertise to any peer (well-known community)\n"
7608 "Do not export to next AS (well-known community)\n"
7609 "Exact match of the communities")
7610{
7611 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7612}
7613
7614ALIAS (show_bgp_community_exact,
7615 show_bgp_ipv6_community_exact_cmd,
7616 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7617 SHOW_STR
7618 BGP_STR
7619 "Address family\n"
7620 "Display routes matching the communities\n"
7621 "community number\n"
7622 "Do not send outside local AS (well-known community)\n"
7623 "Do not advertise to any peer (well-known community)\n"
7624 "Do not export to next AS (well-known community)\n"
7625 "Exact match of the communities")
7626
7627ALIAS (show_bgp_community_exact,
7628 show_bgp_community2_exact_cmd,
7629 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7630 SHOW_STR
7631 BGP_STR
7632 "Display routes matching the communities\n"
7633 "community number\n"
7634 "Do not send outside local AS (well-known community)\n"
7635 "Do not advertise to any peer (well-known community)\n"
7636 "Do not export to next AS (well-known community)\n"
7637 "community number\n"
7638 "Do not send outside local AS (well-known community)\n"
7639 "Do not advertise to any peer (well-known community)\n"
7640 "Do not export to next AS (well-known community)\n"
7641 "Exact match of the communities")
7642
7643ALIAS (show_bgp_community_exact,
7644 show_bgp_ipv6_community2_exact_cmd,
7645 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7646 SHOW_STR
7647 BGP_STR
7648 "Address family\n"
7649 "Display routes matching the communities\n"
7650 "community number\n"
7651 "Do not send outside local AS (well-known community)\n"
7652 "Do not advertise to any peer (well-known community)\n"
7653 "Do not export to next AS (well-known community)\n"
7654 "community number\n"
7655 "Do not send outside local AS (well-known community)\n"
7656 "Do not advertise to any peer (well-known community)\n"
7657 "Do not export to next AS (well-known community)\n"
7658 "Exact match of the communities")
7659
7660ALIAS (show_bgp_community_exact,
7661 show_bgp_community3_exact_cmd,
7662 "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",
7663 SHOW_STR
7664 BGP_STR
7665 "Display routes matching the communities\n"
7666 "community number\n"
7667 "Do not send outside local AS (well-known community)\n"
7668 "Do not advertise to any peer (well-known community)\n"
7669 "Do not export to next AS (well-known community)\n"
7670 "community number\n"
7671 "Do not send outside local AS (well-known community)\n"
7672 "Do not advertise to any peer (well-known community)\n"
7673 "Do not export to next AS (well-known community)\n"
7674 "community number\n"
7675 "Do not send outside local AS (well-known community)\n"
7676 "Do not advertise to any peer (well-known community)\n"
7677 "Do not export to next AS (well-known community)\n"
7678 "Exact match of the communities")
7679
7680ALIAS (show_bgp_community_exact,
7681 show_bgp_ipv6_community3_exact_cmd,
7682 "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",
7683 SHOW_STR
7684 BGP_STR
7685 "Address family\n"
7686 "Display routes matching the communities\n"
7687 "community number\n"
7688 "Do not send outside local AS (well-known community)\n"
7689 "Do not advertise to any peer (well-known community)\n"
7690 "Do not export to next AS (well-known community)\n"
7691 "community number\n"
7692 "Do not send outside local AS (well-known community)\n"
7693 "Do not advertise to any peer (well-known community)\n"
7694 "Do not export to next AS (well-known community)\n"
7695 "community number\n"
7696 "Do not send outside local AS (well-known community)\n"
7697 "Do not advertise to any peer (well-known community)\n"
7698 "Do not export to next AS (well-known community)\n"
7699 "Exact match of the communities")
7700
7701ALIAS (show_bgp_community_exact,
7702 show_bgp_community4_exact_cmd,
7703 "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",
7704 SHOW_STR
7705 BGP_STR
7706 "Display routes matching the communities\n"
7707 "community number\n"
7708 "Do not send outside local AS (well-known community)\n"
7709 "Do not advertise to any peer (well-known community)\n"
7710 "Do not export to next AS (well-known community)\n"
7711 "community number\n"
7712 "Do not send outside local AS (well-known community)\n"
7713 "Do not advertise to any peer (well-known community)\n"
7714 "Do not export to next AS (well-known community)\n"
7715 "community number\n"
7716 "Do not send outside local AS (well-known community)\n"
7717 "Do not advertise to any peer (well-known community)\n"
7718 "Do not export to next AS (well-known community)\n"
7719 "community number\n"
7720 "Do not send outside local AS (well-known community)\n"
7721 "Do not advertise to any peer (well-known community)\n"
7722 "Do not export to next AS (well-known community)\n"
7723 "Exact match of the communities")
7724
7725ALIAS (show_bgp_community_exact,
7726 show_bgp_ipv6_community4_exact_cmd,
7727 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7728 SHOW_STR
7729 BGP_STR
7730 "Address family\n"
7731 "Display routes matching the communities\n"
7732 "community number\n"
7733 "Do not send outside local AS (well-known community)\n"
7734 "Do not advertise to any peer (well-known community)\n"
7735 "Do not export to next AS (well-known community)\n"
7736 "community number\n"
7737 "Do not send outside local AS (well-known community)\n"
7738 "Do not advertise to any peer (well-known community)\n"
7739 "Do not export to next AS (well-known community)\n"
7740 "community number\n"
7741 "Do not send outside local AS (well-known community)\n"
7742 "Do not advertise to any peer (well-known community)\n"
7743 "Do not export to next AS (well-known community)\n"
7744 "community number\n"
7745 "Do not send outside local AS (well-known community)\n"
7746 "Do not advertise to any peer (well-known community)\n"
7747 "Do not export to next AS (well-known community)\n"
7748 "Exact match of the communities")
7749
7750/* old command */
7751DEFUN (show_ipv6_bgp_community_exact,
7752 show_ipv6_bgp_community_exact_cmd,
7753 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7754 SHOW_STR
7755 IPV6_STR
7756 BGP_STR
7757 "Display routes matching the communities\n"
7758 "community number\n"
7759 "Do not send outside local AS (well-known community)\n"
7760 "Do not advertise to any peer (well-known community)\n"
7761 "Do not export to next AS (well-known community)\n"
7762 "Exact match of the communities")
7763{
7764 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7765}
7766
7767/* old command */
7768ALIAS (show_ipv6_bgp_community_exact,
7769 show_ipv6_bgp_community2_exact_cmd,
7770 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7771 SHOW_STR
7772 IPV6_STR
7773 BGP_STR
7774 "Display routes matching the communities\n"
7775 "community number\n"
7776 "Do not send outside local AS (well-known community)\n"
7777 "Do not advertise to any peer (well-known community)\n"
7778 "Do not export to next AS (well-known community)\n"
7779 "community number\n"
7780 "Do not send outside local AS (well-known community)\n"
7781 "Do not advertise to any peer (well-known community)\n"
7782 "Do not export to next AS (well-known community)\n"
7783 "Exact match of the communities")
7784
7785/* old command */
7786ALIAS (show_ipv6_bgp_community_exact,
7787 show_ipv6_bgp_community3_exact_cmd,
7788 "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",
7789 SHOW_STR
7790 IPV6_STR
7791 BGP_STR
7792 "Display routes matching the communities\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 "community number\n"
7798 "Do not send outside local AS (well-known community)\n"
7799 "Do not advertise to any peer (well-known community)\n"
7800 "Do not export to next AS (well-known community)\n"
7801 "community number\n"
7802 "Do not send outside local AS (well-known community)\n"
7803 "Do not advertise to any peer (well-known community)\n"
7804 "Do not export to next AS (well-known community)\n"
7805 "Exact match of the communities")
7806
7807/* old command */
7808ALIAS (show_ipv6_bgp_community_exact,
7809 show_ipv6_bgp_community4_exact_cmd,
7810 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7811 SHOW_STR
7812 IPV6_STR
7813 BGP_STR
7814 "Display routes matching the communities\n"
7815 "community number\n"
7816 "Do not send outside local AS (well-known community)\n"
7817 "Do not advertise to any peer (well-known community)\n"
7818 "Do not export to next AS (well-known community)\n"
7819 "community number\n"
7820 "Do not send outside local AS (well-known community)\n"
7821 "Do not advertise to any peer (well-known community)\n"
7822 "Do not export to next AS (well-known community)\n"
7823 "community number\n"
7824 "Do not send outside local AS (well-known community)\n"
7825 "Do not advertise to any peer (well-known community)\n"
7826 "Do not export to next AS (well-known community)\n"
7827 "community number\n"
7828 "Do not send outside local AS (well-known community)\n"
7829 "Do not advertise to any peer (well-known community)\n"
7830 "Do not export to next AS (well-known community)\n"
7831 "Exact match of the communities")
7832
7833/* old command */
7834DEFUN (show_ipv6_mbgp_community,
7835 show_ipv6_mbgp_community_cmd,
7836 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7837 SHOW_STR
7838 IPV6_STR
7839 MBGP_STR
7840 "Display routes matching the communities\n"
7841 "community number\n"
7842 "Do not send outside local AS (well-known community)\n"
7843 "Do not advertise to any peer (well-known community)\n"
7844 "Do not export to next AS (well-known community)\n")
7845{
7846 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7847}
7848
7849/* old command */
7850ALIAS (show_ipv6_mbgp_community,
7851 show_ipv6_mbgp_community2_cmd,
7852 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7853 SHOW_STR
7854 IPV6_STR
7855 MBGP_STR
7856 "Display routes matching the communities\n"
7857 "community number\n"
7858 "Do not send outside local AS (well-known community)\n"
7859 "Do not advertise to any peer (well-known community)\n"
7860 "Do not export to next AS (well-known community)\n"
7861 "community number\n"
7862 "Do not send outside local AS (well-known community)\n"
7863 "Do not advertise to any peer (well-known community)\n"
7864 "Do not export to next AS (well-known community)\n")
7865
7866/* old command */
7867ALIAS (show_ipv6_mbgp_community,
7868 show_ipv6_mbgp_community3_cmd,
7869 "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)",
7870 SHOW_STR
7871 IPV6_STR
7872 MBGP_STR
7873 "Display routes matching the communities\n"
7874 "community number\n"
7875 "Do not send outside local AS (well-known community)\n"
7876 "Do not advertise to any peer (well-known community)\n"
7877 "Do not export to next AS (well-known community)\n"
7878 "community number\n"
7879 "Do not send outside local AS (well-known community)\n"
7880 "Do not advertise to any peer (well-known community)\n"
7881 "Do not export to next AS (well-known community)\n"
7882 "community number\n"
7883 "Do not send outside local AS (well-known community)\n"
7884 "Do not advertise to any peer (well-known community)\n"
7885 "Do not export to next AS (well-known community)\n")
7886
7887/* old command */
7888ALIAS (show_ipv6_mbgp_community,
7889 show_ipv6_mbgp_community4_cmd,
7890 "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)",
7891 SHOW_STR
7892 IPV6_STR
7893 MBGP_STR
7894 "Display routes matching the communities\n"
7895 "community number\n"
7896 "Do not send outside local AS (well-known community)\n"
7897 "Do not advertise to any peer (well-known community)\n"
7898 "Do not export to next AS (well-known community)\n"
7899 "community number\n"
7900 "Do not send outside local AS (well-known community)\n"
7901 "Do not advertise to any peer (well-known community)\n"
7902 "Do not export to next AS (well-known community)\n"
7903 "community number\n"
7904 "Do not send outside local AS (well-known community)\n"
7905 "Do not advertise to any peer (well-known community)\n"
7906 "Do not export to next AS (well-known community)\n"
7907 "community number\n"
7908 "Do not send outside local AS (well-known community)\n"
7909 "Do not advertise to any peer (well-known community)\n"
7910 "Do not export to next AS (well-known community)\n")
7911
7912/* old command */
7913DEFUN (show_ipv6_mbgp_community_exact,
7914 show_ipv6_mbgp_community_exact_cmd,
7915 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7916 SHOW_STR
7917 IPV6_STR
7918 MBGP_STR
7919 "Display routes matching the communities\n"
7920 "community number\n"
7921 "Do not send outside local AS (well-known community)\n"
7922 "Do not advertise to any peer (well-known community)\n"
7923 "Do not export to next AS (well-known community)\n"
7924 "Exact match of the communities")
7925{
7926 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7927}
7928
7929/* old command */
7930ALIAS (show_ipv6_mbgp_community_exact,
7931 show_ipv6_mbgp_community2_exact_cmd,
7932 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7933 SHOW_STR
7934 IPV6_STR
7935 MBGP_STR
7936 "Display routes matching the communities\n"
7937 "community number\n"
7938 "Do not send outside local AS (well-known community)\n"
7939 "Do not advertise to any peer (well-known community)\n"
7940 "Do not export to next AS (well-known community)\n"
7941 "community number\n"
7942 "Do not send outside local AS (well-known community)\n"
7943 "Do not advertise to any peer (well-known community)\n"
7944 "Do not export to next AS (well-known community)\n"
7945 "Exact match of the communities")
7946
7947/* old command */
7948ALIAS (show_ipv6_mbgp_community_exact,
7949 show_ipv6_mbgp_community3_exact_cmd,
7950 "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",
7951 SHOW_STR
7952 IPV6_STR
7953 MBGP_STR
7954 "Display routes matching the communities\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 "community number\n"
7960 "Do not send outside local AS (well-known community)\n"
7961 "Do not advertise to any peer (well-known community)\n"
7962 "Do not export to next AS (well-known community)\n"
7963 "community number\n"
7964 "Do not send outside local AS (well-known community)\n"
7965 "Do not advertise to any peer (well-known community)\n"
7966 "Do not export to next AS (well-known community)\n"
7967 "Exact match of the communities")
7968
7969/* old command */
7970ALIAS (show_ipv6_mbgp_community_exact,
7971 show_ipv6_mbgp_community4_exact_cmd,
7972 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7973 SHOW_STR
7974 IPV6_STR
7975 MBGP_STR
7976 "Display routes matching the communities\n"
7977 "community number\n"
7978 "Do not send outside local AS (well-known community)\n"
7979 "Do not advertise to any peer (well-known community)\n"
7980 "Do not export to next AS (well-known community)\n"
7981 "community number\n"
7982 "Do not send outside local AS (well-known community)\n"
7983 "Do not advertise to any peer (well-known community)\n"
7984 "Do not export to next AS (well-known community)\n"
7985 "community number\n"
7986 "Do not send outside local AS (well-known community)\n"
7987 "Do not advertise to any peer (well-known community)\n"
7988 "Do not export to next AS (well-known community)\n"
7989 "community number\n"
7990 "Do not send outside local AS (well-known community)\n"
7991 "Do not advertise to any peer (well-known community)\n"
7992 "Do not export to next AS (well-known community)\n"
7993 "Exact match of the communities")
7994#endif /* HAVE_IPV6 */
7995
paul94f2b392005-06-28 12:44:16 +00007996static int
paulfd79ac92004-10-13 05:06:08 +00007997bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00007998 u_int16_t afi, u_char safi)
7999{
8000 struct community_list *list;
8001
hassofee6e4e2005-02-02 16:29:31 +00008002 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008003 if (list == NULL)
8004 {
8005 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8006 VTY_NEWLINE);
8007 return CMD_WARNING;
8008 }
8009
ajs5a646652004-11-05 01:25:55 +00008010 return bgp_show (vty, NULL, afi, safi,
8011 (exact ? bgp_show_type_community_list_exact :
8012 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008013}
8014
8015DEFUN (show_ip_bgp_community_list,
8016 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008017 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008018 SHOW_STR
8019 IP_STR
8020 BGP_STR
8021 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008022 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008023 "community-list name\n")
8024{
8025 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8026}
8027
8028DEFUN (show_ip_bgp_ipv4_community_list,
8029 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008030 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008031 SHOW_STR
8032 IP_STR
8033 BGP_STR
8034 "Address family\n"
8035 "Address Family modifier\n"
8036 "Address Family modifier\n"
8037 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008038 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008039 "community-list name\n")
8040{
8041 if (strncmp (argv[0], "m", 1) == 0)
8042 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8043
8044 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8045}
8046
8047DEFUN (show_ip_bgp_community_list_exact,
8048 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008049 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008050 SHOW_STR
8051 IP_STR
8052 BGP_STR
8053 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008054 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008055 "community-list name\n"
8056 "Exact match of the communities\n")
8057{
8058 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8059}
8060
8061DEFUN (show_ip_bgp_ipv4_community_list_exact,
8062 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008063 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008064 SHOW_STR
8065 IP_STR
8066 BGP_STR
8067 "Address family\n"
8068 "Address Family modifier\n"
8069 "Address Family modifier\n"
8070 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008071 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008072 "community-list name\n"
8073 "Exact match of the communities\n")
8074{
8075 if (strncmp (argv[0], "m", 1) == 0)
8076 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8077
8078 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8079}
8080
8081#ifdef HAVE_IPV6
8082DEFUN (show_bgp_community_list,
8083 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008084 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008085 SHOW_STR
8086 BGP_STR
8087 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008088 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008089 "community-list name\n")
8090{
8091 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8092}
8093
8094ALIAS (show_bgp_community_list,
8095 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008096 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008097 SHOW_STR
8098 BGP_STR
8099 "Address family\n"
8100 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008101 "community-list number\n"
8102 "community-list name\n");
paul718e3742002-12-13 20:15:29 +00008103
8104/* old command */
8105DEFUN (show_ipv6_bgp_community_list,
8106 show_ipv6_bgp_community_list_cmd,
8107 "show ipv6 bgp community-list WORD",
8108 SHOW_STR
8109 IPV6_STR
8110 BGP_STR
8111 "Display routes matching the community-list\n"
8112 "community-list name\n")
8113{
8114 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8115}
8116
8117/* old command */
8118DEFUN (show_ipv6_mbgp_community_list,
8119 show_ipv6_mbgp_community_list_cmd,
8120 "show ipv6 mbgp community-list WORD",
8121 SHOW_STR
8122 IPV6_STR
8123 MBGP_STR
8124 "Display routes matching the community-list\n"
8125 "community-list name\n")
8126{
8127 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8128}
8129
8130DEFUN (show_bgp_community_list_exact,
8131 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008132 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008133 SHOW_STR
8134 BGP_STR
8135 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008136 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008137 "community-list name\n"
8138 "Exact match of the communities\n")
8139{
8140 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8141}
8142
8143ALIAS (show_bgp_community_list_exact,
8144 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008145 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008146 SHOW_STR
8147 BGP_STR
8148 "Address family\n"
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/* old command */
8155DEFUN (show_ipv6_bgp_community_list_exact,
8156 show_ipv6_bgp_community_list_exact_cmd,
8157 "show ipv6 bgp community-list WORD exact-match",
8158 SHOW_STR
8159 IPV6_STR
8160 BGP_STR
8161 "Display routes matching the community-list\n"
8162 "community-list name\n"
8163 "Exact match of the communities\n")
8164{
8165 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8166}
8167
8168/* old command */
8169DEFUN (show_ipv6_mbgp_community_list_exact,
8170 show_ipv6_mbgp_community_list_exact_cmd,
8171 "show ipv6 mbgp community-list WORD exact-match",
8172 SHOW_STR
8173 IPV6_STR
8174 MBGP_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_MULTICAST);
8180}
8181#endif /* HAVE_IPV6 */
8182
paul94f2b392005-06-28 12:44:16 +00008183static int
paulfd79ac92004-10-13 05:06:08 +00008184bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008185 safi_t safi, enum bgp_show_type type)
8186{
8187 int ret;
8188 struct prefix *p;
8189
8190 p = prefix_new();
8191
8192 ret = str2prefix (prefix, p);
8193 if (! ret)
8194 {
8195 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8196 return CMD_WARNING;
8197 }
8198
ajs5a646652004-11-05 01:25:55 +00008199 ret = bgp_show (vty, NULL, afi, safi, type, p);
8200 prefix_free(p);
8201 return ret;
paul718e3742002-12-13 20:15:29 +00008202}
8203
8204DEFUN (show_ip_bgp_prefix_longer,
8205 show_ip_bgp_prefix_longer_cmd,
8206 "show ip bgp A.B.C.D/M longer-prefixes",
8207 SHOW_STR
8208 IP_STR
8209 BGP_STR
8210 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8211 "Display route and more specific routes\n")
8212{
8213 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8214 bgp_show_type_prefix_longer);
8215}
8216
8217DEFUN (show_ip_bgp_flap_prefix_longer,
8218 show_ip_bgp_flap_prefix_longer_cmd,
8219 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8220 SHOW_STR
8221 IP_STR
8222 BGP_STR
8223 "Display flap statistics of routes\n"
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_flap_prefix_longer);
8229}
8230
8231DEFUN (show_ip_bgp_ipv4_prefix_longer,
8232 show_ip_bgp_ipv4_prefix_longer_cmd,
8233 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8234 SHOW_STR
8235 IP_STR
8236 BGP_STR
8237 "Address family\n"
8238 "Address Family modifier\n"
8239 "Address Family modifier\n"
8240 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8241 "Display route and more specific routes\n")
8242{
8243 if (strncmp (argv[0], "m", 1) == 0)
8244 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8245 bgp_show_type_prefix_longer);
8246
8247 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8248 bgp_show_type_prefix_longer);
8249}
8250
8251DEFUN (show_ip_bgp_flap_address,
8252 show_ip_bgp_flap_address_cmd,
8253 "show ip bgp flap-statistics A.B.C.D",
8254 SHOW_STR
8255 IP_STR
8256 BGP_STR
8257 "Display flap statistics of routes\n"
8258 "Network in the BGP routing table to display\n")
8259{
8260 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8261 bgp_show_type_flap_address);
8262}
8263
8264DEFUN (show_ip_bgp_flap_prefix,
8265 show_ip_bgp_flap_prefix_cmd,
8266 "show ip bgp flap-statistics A.B.C.D/M",
8267 SHOW_STR
8268 IP_STR
8269 BGP_STR
8270 "Display flap statistics of routes\n"
8271 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8272{
8273 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8274 bgp_show_type_flap_prefix);
8275}
8276#ifdef HAVE_IPV6
8277DEFUN (show_bgp_prefix_longer,
8278 show_bgp_prefix_longer_cmd,
8279 "show bgp X:X::X:X/M longer-prefixes",
8280 SHOW_STR
8281 BGP_STR
8282 "IPv6 prefix <network>/<length>\n"
8283 "Display route and more specific routes\n")
8284{
8285 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8286 bgp_show_type_prefix_longer);
8287}
8288
8289ALIAS (show_bgp_prefix_longer,
8290 show_bgp_ipv6_prefix_longer_cmd,
8291 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8292 SHOW_STR
8293 BGP_STR
8294 "Address family\n"
8295 "IPv6 prefix <network>/<length>\n"
8296 "Display route and more specific routes\n")
8297
8298/* old command */
8299DEFUN (show_ipv6_bgp_prefix_longer,
8300 show_ipv6_bgp_prefix_longer_cmd,
8301 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8302 SHOW_STR
8303 IPV6_STR
8304 BGP_STR
8305 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8306 "Display route and more specific routes\n")
8307{
8308 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8309 bgp_show_type_prefix_longer);
8310}
8311
8312/* old command */
8313DEFUN (show_ipv6_mbgp_prefix_longer,
8314 show_ipv6_mbgp_prefix_longer_cmd,
8315 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8316 SHOW_STR
8317 IPV6_STR
8318 MBGP_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_MULTICAST,
8323 bgp_show_type_prefix_longer);
8324}
8325#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008326
paul94f2b392005-06-28 12:44:16 +00008327static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008328peer_lookup_in_view (struct vty *vty, const char *view_name,
8329 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008330{
8331 int ret;
8332 struct bgp *bgp;
8333 struct peer *peer;
8334 union sockunion su;
8335
8336 /* BGP structure lookup. */
8337 if (view_name)
8338 {
8339 bgp = bgp_lookup_by_name (view_name);
8340 if (! bgp)
8341 {
8342 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8343 return NULL;
8344 }
8345 }
paul5228ad22004-06-04 17:58:18 +00008346 else
paulbb46e942003-10-24 19:02:03 +00008347 {
8348 bgp = bgp_get_default ();
8349 if (! bgp)
8350 {
8351 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8352 return NULL;
8353 }
8354 }
8355
8356 /* Get peer sockunion. */
8357 ret = str2sockunion (ip_str, &su);
8358 if (ret < 0)
8359 {
8360 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8361 return NULL;
8362 }
8363
8364 /* Peer structure lookup. */
8365 peer = peer_lookup (bgp, &su);
8366 if (! peer)
8367 {
8368 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8369 return NULL;
8370 }
8371
8372 return peer;
8373}
8374
paul94f2b392005-06-28 12:44:16 +00008375static void
paul718e3742002-12-13 20:15:29 +00008376show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
8377 int in)
8378{
8379 struct bgp_table *table;
8380 struct bgp_adj_in *ain;
8381 struct bgp_adj_out *adj;
8382 unsigned long output_count;
8383 struct bgp_node *rn;
8384 int header1 = 1;
8385 struct bgp *bgp;
8386 int header2 = 1;
8387
paulbb46e942003-10-24 19:02:03 +00008388 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00008389
8390 if (! bgp)
8391 return;
8392
8393 table = bgp->rib[afi][safi];
8394
8395 output_count = 0;
8396
8397 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
8398 PEER_STATUS_DEFAULT_ORIGINATE))
8399 {
8400 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 +00008401 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8402 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008403
8404 vty_out (vty, "Originating default network 0.0.0.0%s%s",
8405 VTY_NEWLINE, VTY_NEWLINE);
8406 header1 = 0;
8407 }
8408
8409 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8410 if (in)
8411 {
8412 for (ain = rn->adj_in; ain; ain = ain->next)
8413 if (ain->peer == peer)
8414 {
8415 if (header1)
8416 {
8417 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 +00008418 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8419 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008420 header1 = 0;
8421 }
8422 if (header2)
8423 {
8424 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8425 header2 = 0;
8426 }
8427 if (ain->attr)
8428 {
8429 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
8430 output_count++;
8431 }
8432 }
8433 }
8434 else
8435 {
8436 for (adj = rn->adj_out; adj; adj = adj->next)
8437 if (adj->peer == peer)
8438 {
8439 if (header1)
8440 {
8441 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 +00008442 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8443 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008444 header1 = 0;
8445 }
8446 if (header2)
8447 {
8448 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8449 header2 = 0;
8450 }
8451 if (adj->attr)
8452 {
8453 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
8454 output_count++;
8455 }
8456 }
8457 }
8458
8459 if (output_count != 0)
8460 vty_out (vty, "%sTotal number of prefixes %ld%s",
8461 VTY_NEWLINE, output_count, VTY_NEWLINE);
8462}
8463
paul94f2b392005-06-28 12:44:16 +00008464static int
paulbb46e942003-10-24 19:02:03 +00008465peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
8466{
paul718e3742002-12-13 20:15:29 +00008467 if (! peer || ! peer->afc[afi][safi])
8468 {
8469 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8470 return CMD_WARNING;
8471 }
8472
8473 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8474 {
8475 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
8476 VTY_NEWLINE);
8477 return CMD_WARNING;
8478 }
8479
8480 show_adj_route (vty, peer, afi, safi, in);
8481
8482 return CMD_SUCCESS;
8483}
8484
8485DEFUN (show_ip_bgp_neighbor_advertised_route,
8486 show_ip_bgp_neighbor_advertised_route_cmd,
8487 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8488 SHOW_STR
8489 IP_STR
8490 BGP_STR
8491 "Detailed information on TCP and BGP neighbor connections\n"
8492 "Neighbor to display information about\n"
8493 "Neighbor to display information about\n"
8494 "Display the routes advertised to a BGP neighbor\n")
8495{
paulbb46e942003-10-24 19:02:03 +00008496 struct peer *peer;
8497
8498 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8499 if (! peer)
8500 return CMD_WARNING;
8501
8502 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008503}
8504
8505DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
8506 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
8507 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8508 SHOW_STR
8509 IP_STR
8510 BGP_STR
8511 "Address family\n"
8512 "Address Family modifier\n"
8513 "Address Family modifier\n"
8514 "Detailed information on TCP and BGP neighbor connections\n"
8515 "Neighbor to display information about\n"
8516 "Neighbor to display information about\n"
8517 "Display the routes advertised to a BGP neighbor\n")
8518{
paulbb46e942003-10-24 19:02:03 +00008519 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008520
paulbb46e942003-10-24 19:02:03 +00008521 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8522 if (! peer)
8523 return CMD_WARNING;
8524
8525 if (strncmp (argv[0], "m", 1) == 0)
8526 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
8527
8528 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008529}
8530
8531#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008532DEFUN (show_bgp_view_neighbor_advertised_route,
8533 show_bgp_view_neighbor_advertised_route_cmd,
8534 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8535 SHOW_STR
8536 BGP_STR
8537 "BGP view\n"
8538 "View name\n"
8539 "Detailed information on TCP and BGP neighbor connections\n"
8540 "Neighbor to display information about\n"
8541 "Neighbor to display information about\n"
8542 "Display the routes advertised to a BGP neighbor\n")
8543{
8544 struct peer *peer;
8545
8546 if (argc == 2)
8547 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8548 else
8549 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8550
8551 if (! peer)
8552 return CMD_WARNING;
8553
8554 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
8555}
8556
8557ALIAS (show_bgp_view_neighbor_advertised_route,
8558 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
8559 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8560 SHOW_STR
8561 BGP_STR
8562 "BGP view\n"
8563 "View name\n"
8564 "Address family\n"
8565 "Detailed information on TCP and BGP neighbor connections\n"
8566 "Neighbor to display information about\n"
8567 "Neighbor to display information about\n"
8568 "Display the routes advertised to a BGP neighbor\n")
8569
8570DEFUN (show_bgp_view_neighbor_received_routes,
8571 show_bgp_view_neighbor_received_routes_cmd,
8572 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
8573 SHOW_STR
8574 BGP_STR
8575 "BGP view\n"
8576 "View name\n"
8577 "Detailed information on TCP and BGP neighbor connections\n"
8578 "Neighbor to display information about\n"
8579 "Neighbor to display information about\n"
8580 "Display the received routes from neighbor\n")
8581{
8582 struct peer *peer;
8583
8584 if (argc == 2)
8585 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8586 else
8587 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8588
8589 if (! peer)
8590 return CMD_WARNING;
8591
8592 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
8593}
8594
8595ALIAS (show_bgp_view_neighbor_received_routes,
8596 show_bgp_view_ipv6_neighbor_received_routes_cmd,
8597 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8598 SHOW_STR
8599 BGP_STR
8600 "BGP view\n"
8601 "View name\n"
8602 "Address family\n"
8603 "Detailed information on TCP and BGP neighbor connections\n"
8604 "Neighbor to display information about\n"
8605 "Neighbor to display information about\n"
8606 "Display the received routes from neighbor\n")
8607
8608ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008609 show_bgp_neighbor_advertised_route_cmd,
8610 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8611 SHOW_STR
8612 BGP_STR
8613 "Detailed information on TCP and BGP neighbor connections\n"
8614 "Neighbor to display information about\n"
8615 "Neighbor to display information about\n"
8616 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008617
8618ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008619 show_bgp_ipv6_neighbor_advertised_route_cmd,
8620 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8621 SHOW_STR
8622 BGP_STR
8623 "Address family\n"
8624 "Detailed information on TCP and BGP neighbor connections\n"
8625 "Neighbor to display information about\n"
8626 "Neighbor to display information about\n"
8627 "Display the routes advertised to a BGP neighbor\n")
8628
8629/* old command */
paulbb46e942003-10-24 19:02:03 +00008630ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008631 ipv6_bgp_neighbor_advertised_route_cmd,
8632 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8633 SHOW_STR
8634 IPV6_STR
8635 BGP_STR
8636 "Detailed information on TCP and BGP neighbor connections\n"
8637 "Neighbor to display information about\n"
8638 "Neighbor to display information about\n"
8639 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008640
paul718e3742002-12-13 20:15:29 +00008641/* old command */
8642DEFUN (ipv6_mbgp_neighbor_advertised_route,
8643 ipv6_mbgp_neighbor_advertised_route_cmd,
8644 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8645 SHOW_STR
8646 IPV6_STR
8647 MBGP_STR
8648 "Detailed information on TCP and BGP neighbor connections\n"
8649 "Neighbor to display information about\n"
8650 "Neighbor to display information about\n"
8651 "Display the routes advertised to a BGP neighbor\n")
8652{
paulbb46e942003-10-24 19:02:03 +00008653 struct peer *peer;
8654
8655 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8656 if (! peer)
8657 return CMD_WARNING;
8658
8659 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00008660}
8661#endif /* HAVE_IPV6 */
8662
8663DEFUN (show_ip_bgp_neighbor_received_routes,
8664 show_ip_bgp_neighbor_received_routes_cmd,
8665 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8666 SHOW_STR
8667 IP_STR
8668 BGP_STR
8669 "Detailed information on TCP and BGP neighbor connections\n"
8670 "Neighbor to display information about\n"
8671 "Neighbor to display information about\n"
8672 "Display the received routes from neighbor\n")
8673{
paulbb46e942003-10-24 19:02:03 +00008674 struct peer *peer;
8675
8676 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8677 if (! peer)
8678 return CMD_WARNING;
8679
8680 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008681}
8682
8683DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
8684 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
8685 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
8686 SHOW_STR
8687 IP_STR
8688 BGP_STR
8689 "Address family\n"
8690 "Address Family modifier\n"
8691 "Address Family modifier\n"
8692 "Detailed information on TCP and BGP neighbor connections\n"
8693 "Neighbor to display information about\n"
8694 "Neighbor to display information about\n"
8695 "Display the received routes from neighbor\n")
8696{
paulbb46e942003-10-24 19:02:03 +00008697 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008698
paulbb46e942003-10-24 19:02:03 +00008699 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8700 if (! peer)
8701 return CMD_WARNING;
8702
8703 if (strncmp (argv[0], "m", 1) == 0)
8704 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
8705
8706 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008707}
8708
8709DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
8710 show_ip_bgp_neighbor_received_prefix_filter_cmd,
8711 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8712 SHOW_STR
8713 IP_STR
8714 BGP_STR
8715 "Detailed information on TCP and BGP neighbor connections\n"
8716 "Neighbor to display information about\n"
8717 "Neighbor to display information about\n"
8718 "Display information received from a BGP neighbor\n"
8719 "Display the prefixlist filter\n")
8720{
8721 char name[BUFSIZ];
8722 union sockunion *su;
8723 struct peer *peer;
8724 int count;
8725
8726 su = sockunion_str2su (argv[0]);
8727 if (su == NULL)
8728 return CMD_WARNING;
8729
8730 peer = peer_lookup (NULL, su);
8731 if (! peer)
8732 return CMD_WARNING;
8733
8734 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8735 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8736 if (count)
8737 {
8738 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8739 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8740 }
8741
8742 return CMD_SUCCESS;
8743}
8744
8745DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
8746 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
8747 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8748 SHOW_STR
8749 IP_STR
8750 BGP_STR
8751 "Address family\n"
8752 "Address Family modifier\n"
8753 "Address Family modifier\n"
8754 "Detailed information on TCP and BGP neighbor connections\n"
8755 "Neighbor to display information about\n"
8756 "Neighbor to display information about\n"
8757 "Display information received from a BGP neighbor\n"
8758 "Display the prefixlist filter\n")
8759{
8760 char name[BUFSIZ];
8761 union sockunion *su;
8762 struct peer *peer;
8763 int count;
8764
8765 su = sockunion_str2su (argv[1]);
8766 if (su == NULL)
8767 return CMD_WARNING;
8768
8769 peer = peer_lookup (NULL, su);
8770 if (! peer)
8771 return CMD_WARNING;
8772
8773 if (strncmp (argv[0], "m", 1) == 0)
8774 {
8775 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
8776 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8777 if (count)
8778 {
8779 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
8780 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8781 }
8782 }
8783 else
8784 {
8785 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8786 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8787 if (count)
8788 {
8789 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8790 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8791 }
8792 }
8793
8794 return CMD_SUCCESS;
8795}
8796
8797
8798#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008799ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008800 show_bgp_neighbor_received_routes_cmd,
8801 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8802 SHOW_STR
8803 BGP_STR
8804 "Detailed information on TCP and BGP neighbor connections\n"
8805 "Neighbor to display information about\n"
8806 "Neighbor to display information about\n"
8807 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008808
paulbb46e942003-10-24 19:02:03 +00008809ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008810 show_bgp_ipv6_neighbor_received_routes_cmd,
8811 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8812 SHOW_STR
8813 BGP_STR
8814 "Address family\n"
8815 "Detailed information on TCP and BGP neighbor connections\n"
8816 "Neighbor to display information about\n"
8817 "Neighbor to display information about\n"
8818 "Display the received routes from neighbor\n")
8819
8820DEFUN (show_bgp_neighbor_received_prefix_filter,
8821 show_bgp_neighbor_received_prefix_filter_cmd,
8822 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8823 SHOW_STR
8824 BGP_STR
8825 "Detailed information on TCP and BGP neighbor connections\n"
8826 "Neighbor to display information about\n"
8827 "Neighbor to display information about\n"
8828 "Display information received from a BGP neighbor\n"
8829 "Display the prefixlist filter\n")
8830{
8831 char name[BUFSIZ];
8832 union sockunion *su;
8833 struct peer *peer;
8834 int count;
8835
8836 su = sockunion_str2su (argv[0]);
8837 if (su == NULL)
8838 return CMD_WARNING;
8839
8840 peer = peer_lookup (NULL, su);
8841 if (! peer)
8842 return CMD_WARNING;
8843
8844 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8845 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8846 if (count)
8847 {
8848 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8849 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8850 }
8851
8852 return CMD_SUCCESS;
8853}
8854
8855ALIAS (show_bgp_neighbor_received_prefix_filter,
8856 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
8857 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8858 SHOW_STR
8859 BGP_STR
8860 "Address family\n"
8861 "Detailed information on TCP and BGP neighbor connections\n"
8862 "Neighbor to display information about\n"
8863 "Neighbor to display information about\n"
8864 "Display information received from a BGP neighbor\n"
8865 "Display the prefixlist filter\n")
8866
8867/* old command */
paulbb46e942003-10-24 19:02:03 +00008868ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008869 ipv6_bgp_neighbor_received_routes_cmd,
8870 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8871 SHOW_STR
8872 IPV6_STR
8873 BGP_STR
8874 "Detailed information on TCP and BGP neighbor connections\n"
8875 "Neighbor to display information about\n"
8876 "Neighbor to display information about\n"
8877 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008878
8879/* old command */
8880DEFUN (ipv6_mbgp_neighbor_received_routes,
8881 ipv6_mbgp_neighbor_received_routes_cmd,
8882 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8883 SHOW_STR
8884 IPV6_STR
8885 MBGP_STR
8886 "Detailed information on TCP and BGP neighbor connections\n"
8887 "Neighbor to display information about\n"
8888 "Neighbor to display information about\n"
8889 "Display the received routes from neighbor\n")
8890{
paulbb46e942003-10-24 19:02:03 +00008891 struct peer *peer;
8892
8893 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8894 if (! peer)
8895 return CMD_WARNING;
8896
8897 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00008898}
paulbb46e942003-10-24 19:02:03 +00008899
8900DEFUN (show_bgp_view_neighbor_received_prefix_filter,
8901 show_bgp_view_neighbor_received_prefix_filter_cmd,
8902 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8903 SHOW_STR
8904 BGP_STR
8905 "BGP view\n"
8906 "View name\n"
8907 "Detailed information on TCP and BGP neighbor connections\n"
8908 "Neighbor to display information about\n"
8909 "Neighbor to display information about\n"
8910 "Display information received from a BGP neighbor\n"
8911 "Display the prefixlist filter\n")
8912{
8913 char name[BUFSIZ];
8914 union sockunion *su;
8915 struct peer *peer;
8916 struct bgp *bgp;
8917 int count;
8918
8919 /* BGP structure lookup. */
8920 bgp = bgp_lookup_by_name (argv[0]);
8921 if (bgp == NULL)
8922 {
8923 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8924 return CMD_WARNING;
8925 }
8926
8927 su = sockunion_str2su (argv[1]);
8928 if (su == NULL)
8929 return CMD_WARNING;
8930
8931 peer = peer_lookup (bgp, su);
8932 if (! peer)
8933 return CMD_WARNING;
8934
8935 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8936 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8937 if (count)
8938 {
8939 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8940 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8941 }
8942
8943 return CMD_SUCCESS;
8944}
8945
8946ALIAS (show_bgp_view_neighbor_received_prefix_filter,
8947 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
8948 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8949 SHOW_STR
8950 BGP_STR
8951 "BGP view\n"
8952 "View name\n"
8953 "Address family\n"
8954 "Detailed information on TCP and BGP neighbor connections\n"
8955 "Neighbor to display information about\n"
8956 "Neighbor to display information about\n"
8957 "Display information received from a BGP neighbor\n"
8958 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00008959#endif /* HAVE_IPV6 */
8960
paul94f2b392005-06-28 12:44:16 +00008961static int
paulbb46e942003-10-24 19:02:03 +00008962bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008963 safi_t safi, enum bgp_show_type type)
8964{
paul718e3742002-12-13 20:15:29 +00008965 if (! peer || ! peer->afc[afi][safi])
8966 {
8967 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008968 return CMD_WARNING;
8969 }
8970
ajs5a646652004-11-05 01:25:55 +00008971 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +00008972}
8973
8974DEFUN (show_ip_bgp_neighbor_routes,
8975 show_ip_bgp_neighbor_routes_cmd,
8976 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
8977 SHOW_STR
8978 IP_STR
8979 BGP_STR
8980 "Detailed information on TCP and BGP neighbor connections\n"
8981 "Neighbor to display information about\n"
8982 "Neighbor to display information about\n"
8983 "Display routes learned from neighbor\n")
8984{
paulbb46e942003-10-24 19:02:03 +00008985 struct peer *peer;
8986
8987 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8988 if (! peer)
8989 return CMD_WARNING;
8990
8991 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008992 bgp_show_type_neighbor);
8993}
8994
8995DEFUN (show_ip_bgp_neighbor_flap,
8996 show_ip_bgp_neighbor_flap_cmd,
8997 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
8998 SHOW_STR
8999 IP_STR
9000 BGP_STR
9001 "Detailed information on TCP and BGP neighbor connections\n"
9002 "Neighbor to display information about\n"
9003 "Neighbor to display information about\n"
9004 "Display flap statistics of the routes learned from neighbor\n")
9005{
paulbb46e942003-10-24 19:02:03 +00009006 struct peer *peer;
9007
9008 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9009 if (! peer)
9010 return CMD_WARNING;
9011
9012 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009013 bgp_show_type_flap_neighbor);
9014}
9015
9016DEFUN (show_ip_bgp_neighbor_damp,
9017 show_ip_bgp_neighbor_damp_cmd,
9018 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9019 SHOW_STR
9020 IP_STR
9021 BGP_STR
9022 "Detailed information on TCP and BGP neighbor connections\n"
9023 "Neighbor to display information about\n"
9024 "Neighbor to display information about\n"
9025 "Display the dampened routes received from neighbor\n")
9026{
paulbb46e942003-10-24 19:02:03 +00009027 struct peer *peer;
9028
9029 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9030 if (! peer)
9031 return CMD_WARNING;
9032
9033 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009034 bgp_show_type_damp_neighbor);
9035}
9036
9037DEFUN (show_ip_bgp_ipv4_neighbor_routes,
9038 show_ip_bgp_ipv4_neighbor_routes_cmd,
9039 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
9040 SHOW_STR
9041 IP_STR
9042 BGP_STR
9043 "Address family\n"
9044 "Address Family modifier\n"
9045 "Address Family modifier\n"
9046 "Detailed information on TCP and BGP neighbor connections\n"
9047 "Neighbor to display information about\n"
9048 "Neighbor to display information about\n"
9049 "Display routes learned from neighbor\n")
9050{
paulbb46e942003-10-24 19:02:03 +00009051 struct peer *peer;
9052
9053 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9054 if (! peer)
9055 return CMD_WARNING;
9056
paul718e3742002-12-13 20:15:29 +00009057 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00009058 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009059 bgp_show_type_neighbor);
9060
paulbb46e942003-10-24 19:02:03 +00009061 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009062 bgp_show_type_neighbor);
9063}
paulbb46e942003-10-24 19:02:03 +00009064
paulfee0f4c2004-09-13 05:12:46 +00009065DEFUN (show_ip_bgp_view_rsclient,
9066 show_ip_bgp_view_rsclient_cmd,
9067 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9068 SHOW_STR
9069 IP_STR
9070 BGP_STR
9071 "BGP view\n"
9072 "BGP view name\n"
9073 "Information about Route Server Client\n"
9074 NEIGHBOR_ADDR_STR)
9075{
9076 struct bgp_table *table;
9077 struct peer *peer;
9078
9079 if (argc == 2)
9080 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9081 else
9082 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9083
9084 if (! peer)
9085 return CMD_WARNING;
9086
9087 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9088 {
9089 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9090 VTY_NEWLINE);
9091 return CMD_WARNING;
9092 }
9093
9094 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9095 PEER_FLAG_RSERVER_CLIENT))
9096 {
9097 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9098 VTY_NEWLINE);
9099 return CMD_WARNING;
9100 }
9101
9102 table = peer->rib[AFI_IP][SAFI_UNICAST];
9103
ajs5a646652004-11-05 01:25:55 +00009104 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009105}
9106
9107ALIAS (show_ip_bgp_view_rsclient,
9108 show_ip_bgp_rsclient_cmd,
9109 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
9110 SHOW_STR
9111 IP_STR
9112 BGP_STR
9113 "Information about Route Server Client\n"
9114 NEIGHBOR_ADDR_STR)
9115
9116DEFUN (show_ip_bgp_view_rsclient_route,
9117 show_ip_bgp_view_rsclient_route_cmd,
9118 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9119 SHOW_STR
9120 IP_STR
9121 BGP_STR
9122 "BGP view\n"
9123 "BGP view name\n"
9124 "Information about Route Server Client\n"
9125 NEIGHBOR_ADDR_STR
9126 "Network in the BGP routing table to display\n")
9127{
9128 struct bgp *bgp;
9129 struct peer *peer;
9130
9131 /* BGP structure lookup. */
9132 if (argc == 3)
9133 {
9134 bgp = bgp_lookup_by_name (argv[0]);
9135 if (bgp == NULL)
9136 {
9137 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9138 return CMD_WARNING;
9139 }
9140 }
9141 else
9142 {
9143 bgp = bgp_get_default ();
9144 if (bgp == NULL)
9145 {
9146 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9147 return CMD_WARNING;
9148 }
9149 }
9150
9151 if (argc == 3)
9152 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9153 else
9154 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9155
9156 if (! peer)
9157 return CMD_WARNING;
9158
9159 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9160 {
9161 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9162 VTY_NEWLINE);
9163 return CMD_WARNING;
9164}
9165
9166 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9167 PEER_FLAG_RSERVER_CLIENT))
9168 {
9169 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9170 VTY_NEWLINE);
9171 return CMD_WARNING;
9172 }
9173
9174 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9175 (argc == 3) ? argv[2] : argv[1],
9176 AFI_IP, SAFI_UNICAST, NULL, 0);
9177}
9178
9179ALIAS (show_ip_bgp_view_rsclient_route,
9180 show_ip_bgp_rsclient_route_cmd,
9181 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9182 SHOW_STR
9183 IP_STR
9184 BGP_STR
9185 "Information about Route Server Client\n"
9186 NEIGHBOR_ADDR_STR
9187 "Network in the BGP routing table to display\n")
9188
9189DEFUN (show_ip_bgp_view_rsclient_prefix,
9190 show_ip_bgp_view_rsclient_prefix_cmd,
9191 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9192 SHOW_STR
9193 IP_STR
9194 BGP_STR
9195 "BGP view\n"
9196 "BGP view name\n"
9197 "Information about Route Server Client\n"
9198 NEIGHBOR_ADDR_STR
9199 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9200{
9201 struct bgp *bgp;
9202 struct peer *peer;
9203
9204 /* BGP structure lookup. */
9205 if (argc == 3)
9206 {
9207 bgp = bgp_lookup_by_name (argv[0]);
9208 if (bgp == NULL)
9209 {
9210 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9211 return CMD_WARNING;
9212 }
9213 }
9214 else
9215 {
9216 bgp = bgp_get_default ();
9217 if (bgp == NULL)
9218 {
9219 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9220 return CMD_WARNING;
9221 }
9222 }
9223
9224 if (argc == 3)
9225 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9226 else
9227 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9228
9229 if (! peer)
9230 return CMD_WARNING;
9231
9232 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9233 {
9234 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9235 VTY_NEWLINE);
9236 return CMD_WARNING;
9237}
9238
9239 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9240 PEER_FLAG_RSERVER_CLIENT))
9241{
9242 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9243 VTY_NEWLINE);
9244 return CMD_WARNING;
9245 }
9246
9247 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9248 (argc == 3) ? argv[2] : argv[1],
9249 AFI_IP, SAFI_UNICAST, NULL, 1);
9250}
9251
9252ALIAS (show_ip_bgp_view_rsclient_prefix,
9253 show_ip_bgp_rsclient_prefix_cmd,
9254 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9255 SHOW_STR
9256 IP_STR
9257 BGP_STR
9258 "Information about Route Server Client\n"
9259 NEIGHBOR_ADDR_STR
9260 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9261
9262
paul718e3742002-12-13 20:15:29 +00009263#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009264DEFUN (show_bgp_view_neighbor_routes,
9265 show_bgp_view_neighbor_routes_cmd,
9266 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
9267 SHOW_STR
9268 BGP_STR
9269 "BGP view\n"
9270 "BGP view name\n"
9271 "Detailed information on TCP and BGP neighbor connections\n"
9272 "Neighbor to display information about\n"
9273 "Neighbor to display information about\n"
9274 "Display routes learned from neighbor\n")
9275{
9276 struct peer *peer;
9277
9278 if (argc == 2)
9279 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9280 else
9281 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9282
9283 if (! peer)
9284 return CMD_WARNING;
9285
9286 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9287 bgp_show_type_neighbor);
9288}
9289
9290ALIAS (show_bgp_view_neighbor_routes,
9291 show_bgp_view_ipv6_neighbor_routes_cmd,
9292 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9293 SHOW_STR
9294 BGP_STR
9295 "BGP view\n"
9296 "BGP view name\n"
9297 "Address family\n"
9298 "Detailed information on TCP and BGP neighbor connections\n"
9299 "Neighbor to display information about\n"
9300 "Neighbor to display information about\n"
9301 "Display routes learned from neighbor\n")
9302
9303DEFUN (show_bgp_view_neighbor_damp,
9304 show_bgp_view_neighbor_damp_cmd,
9305 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9306 SHOW_STR
9307 BGP_STR
9308 "BGP view\n"
9309 "BGP view name\n"
9310 "Detailed information on TCP and BGP neighbor connections\n"
9311 "Neighbor to display information about\n"
9312 "Neighbor to display information about\n"
9313 "Display the dampened routes received from neighbor\n")
9314{
9315 struct peer *peer;
9316
9317 if (argc == 2)
9318 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9319 else
9320 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9321
9322 if (! peer)
9323 return CMD_WARNING;
9324
9325 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9326 bgp_show_type_damp_neighbor);
9327}
9328
9329ALIAS (show_bgp_view_neighbor_damp,
9330 show_bgp_view_ipv6_neighbor_damp_cmd,
9331 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9332 SHOW_STR
9333 BGP_STR
9334 "BGP view\n"
9335 "BGP view name\n"
9336 "Address family\n"
9337 "Detailed information on TCP and BGP neighbor connections\n"
9338 "Neighbor to display information about\n"
9339 "Neighbor to display information about\n"
9340 "Display the dampened routes received from neighbor\n")
9341
9342DEFUN (show_bgp_view_neighbor_flap,
9343 show_bgp_view_neighbor_flap_cmd,
9344 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9345 SHOW_STR
9346 BGP_STR
9347 "BGP view\n"
9348 "BGP view name\n"
9349 "Detailed information on TCP and BGP neighbor connections\n"
9350 "Neighbor to display information about\n"
9351 "Neighbor to display information about\n"
9352 "Display flap statistics of the routes learned from neighbor\n")
9353{
9354 struct peer *peer;
9355
9356 if (argc == 2)
9357 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9358 else
9359 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9360
9361 if (! peer)
9362 return CMD_WARNING;
9363
9364 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9365 bgp_show_type_flap_neighbor);
9366}
9367
9368ALIAS (show_bgp_view_neighbor_flap,
9369 show_bgp_view_ipv6_neighbor_flap_cmd,
9370 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9371 SHOW_STR
9372 BGP_STR
9373 "BGP view\n"
9374 "BGP view name\n"
9375 "Address family\n"
9376 "Detailed information on TCP and BGP neighbor connections\n"
9377 "Neighbor to display information about\n"
9378 "Neighbor to display information about\n"
9379 "Display flap statistics of the routes learned from neighbor\n")
9380
9381ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009382 show_bgp_neighbor_routes_cmd,
9383 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
9384 SHOW_STR
9385 BGP_STR
9386 "Detailed information on TCP and BGP neighbor connections\n"
9387 "Neighbor to display information about\n"
9388 "Neighbor to display information about\n"
9389 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009390
paulbb46e942003-10-24 19:02:03 +00009391
9392ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009393 show_bgp_ipv6_neighbor_routes_cmd,
9394 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9395 SHOW_STR
9396 BGP_STR
9397 "Address family\n"
9398 "Detailed information on TCP and BGP neighbor connections\n"
9399 "Neighbor to display information about\n"
9400 "Neighbor to display information about\n"
9401 "Display routes learned from neighbor\n")
9402
9403/* old command */
paulbb46e942003-10-24 19:02:03 +00009404ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009405 ipv6_bgp_neighbor_routes_cmd,
9406 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
9407 SHOW_STR
9408 IPV6_STR
9409 BGP_STR
9410 "Detailed information on TCP and BGP neighbor connections\n"
9411 "Neighbor to display information about\n"
9412 "Neighbor to display information about\n"
9413 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009414
9415/* old command */
9416DEFUN (ipv6_mbgp_neighbor_routes,
9417 ipv6_mbgp_neighbor_routes_cmd,
9418 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
9419 SHOW_STR
9420 IPV6_STR
9421 MBGP_STR
9422 "Detailed information on TCP and BGP neighbor connections\n"
9423 "Neighbor to display information about\n"
9424 "Neighbor to display information about\n"
9425 "Display routes learned from neighbor\n")
9426{
paulbb46e942003-10-24 19:02:03 +00009427 struct peer *peer;
9428
9429 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9430 if (! peer)
9431 return CMD_WARNING;
9432
9433 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009434 bgp_show_type_neighbor);
9435}
paulbb46e942003-10-24 19:02:03 +00009436
9437ALIAS (show_bgp_view_neighbor_flap,
9438 show_bgp_neighbor_flap_cmd,
9439 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9440 SHOW_STR
9441 BGP_STR
9442 "Detailed information on TCP and BGP neighbor connections\n"
9443 "Neighbor to display information about\n"
9444 "Neighbor to display information about\n"
9445 "Display flap statistics of the routes learned from neighbor\n")
9446
9447ALIAS (show_bgp_view_neighbor_flap,
9448 show_bgp_ipv6_neighbor_flap_cmd,
9449 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9450 SHOW_STR
9451 BGP_STR
9452 "Address family\n"
9453 "Detailed information on TCP and BGP neighbor connections\n"
9454 "Neighbor to display information about\n"
9455 "Neighbor to display information about\n"
9456 "Display flap statistics of the routes learned from neighbor\n")
9457
9458ALIAS (show_bgp_view_neighbor_damp,
9459 show_bgp_neighbor_damp_cmd,
9460 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9461 SHOW_STR
9462 BGP_STR
9463 "Detailed information on TCP and BGP neighbor connections\n"
9464 "Neighbor to display information about\n"
9465 "Neighbor to display information about\n"
9466 "Display the dampened routes received from neighbor\n")
9467
9468ALIAS (show_bgp_view_neighbor_damp,
9469 show_bgp_ipv6_neighbor_damp_cmd,
9470 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9471 SHOW_STR
9472 BGP_STR
9473 "Address family\n"
9474 "Detailed information on TCP and BGP neighbor connections\n"
9475 "Neighbor to display information about\n"
9476 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +00009477 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +00009478
9479DEFUN (show_bgp_view_rsclient,
9480 show_bgp_view_rsclient_cmd,
9481 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9482 SHOW_STR
9483 BGP_STR
9484 "BGP view\n"
9485 "BGP view name\n"
9486 "Information about Route Server Client\n"
9487 NEIGHBOR_ADDR_STR)
9488{
9489 struct bgp_table *table;
9490 struct peer *peer;
9491
9492 if (argc == 2)
9493 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9494 else
9495 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9496
9497 if (! peer)
9498 return CMD_WARNING;
9499
9500 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9501 {
9502 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9503 VTY_NEWLINE);
9504 return CMD_WARNING;
9505 }
9506
9507 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9508 PEER_FLAG_RSERVER_CLIENT))
9509 {
9510 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9511 VTY_NEWLINE);
9512 return CMD_WARNING;
9513 }
9514
9515 table = peer->rib[AFI_IP6][SAFI_UNICAST];
9516
ajs5a646652004-11-05 01:25:55 +00009517 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009518}
9519
9520ALIAS (show_bgp_view_rsclient,
9521 show_bgp_rsclient_cmd,
9522 "show bgp rsclient (A.B.C.D|X:X::X:X)",
9523 SHOW_STR
9524 BGP_STR
9525 "Information about Route Server Client\n"
9526 NEIGHBOR_ADDR_STR)
9527
9528DEFUN (show_bgp_view_rsclient_route,
9529 show_bgp_view_rsclient_route_cmd,
9530 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9531 SHOW_STR
9532 BGP_STR
9533 "BGP view\n"
9534 "BGP view name\n"
9535 "Information about Route Server Client\n"
9536 NEIGHBOR_ADDR_STR
9537 "Network in the BGP routing table to display\n")
9538{
9539 struct bgp *bgp;
9540 struct peer *peer;
9541
9542 /* BGP structure lookup. */
9543 if (argc == 3)
9544 {
9545 bgp = bgp_lookup_by_name (argv[0]);
9546 if (bgp == NULL)
9547 {
9548 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9549 return CMD_WARNING;
9550 }
9551 }
9552 else
9553 {
9554 bgp = bgp_get_default ();
9555 if (bgp == NULL)
9556 {
9557 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9558 return CMD_WARNING;
9559 }
9560 }
9561
9562 if (argc == 3)
9563 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9564 else
9565 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9566
9567 if (! peer)
9568 return CMD_WARNING;
9569
9570 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9571 {
9572 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9573 VTY_NEWLINE);
9574 return CMD_WARNING;
9575 }
9576
9577 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9578 PEER_FLAG_RSERVER_CLIENT))
9579 {
9580 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9581 VTY_NEWLINE);
9582 return CMD_WARNING;
9583 }
9584
9585 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9586 (argc == 3) ? argv[2] : argv[1],
9587 AFI_IP6, SAFI_UNICAST, NULL, 0);
9588}
9589
9590ALIAS (show_bgp_view_rsclient_route,
9591 show_bgp_rsclient_route_cmd,
9592 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9593 SHOW_STR
9594 BGP_STR
9595 "Information about Route Server Client\n"
9596 NEIGHBOR_ADDR_STR
9597 "Network in the BGP routing table to display\n")
9598
9599DEFUN (show_bgp_view_rsclient_prefix,
9600 show_bgp_view_rsclient_prefix_cmd,
9601 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9602 SHOW_STR
9603 BGP_STR
9604 "BGP view\n"
9605 "BGP view name\n"
9606 "Information about Route Server Client\n"
9607 NEIGHBOR_ADDR_STR
9608 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9609{
9610 struct bgp *bgp;
9611 struct peer *peer;
9612
9613 /* BGP structure lookup. */
9614 if (argc == 3)
9615 {
9616 bgp = bgp_lookup_by_name (argv[0]);
9617 if (bgp == NULL)
9618 {
9619 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9620 return CMD_WARNING;
9621 }
9622 }
9623 else
9624 {
9625 bgp = bgp_get_default ();
9626 if (bgp == NULL)
9627 {
9628 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9629 return CMD_WARNING;
9630 }
9631 }
9632
9633 if (argc == 3)
9634 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9635 else
9636 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9637
9638 if (! peer)
9639 return CMD_WARNING;
9640
9641 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9642 {
9643 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9644 VTY_NEWLINE);
9645 return CMD_WARNING;
9646 }
9647
9648 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9649 PEER_FLAG_RSERVER_CLIENT))
9650 {
9651 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9652 VTY_NEWLINE);
9653 return CMD_WARNING;
9654 }
9655
9656 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9657 (argc == 3) ? argv[2] : argv[1],
9658 AFI_IP6, SAFI_UNICAST, NULL, 1);
9659}
9660
9661ALIAS (show_bgp_view_rsclient_prefix,
9662 show_bgp_rsclient_prefix_cmd,
9663 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9664 SHOW_STR
9665 BGP_STR
9666 "Information about Route Server Client\n"
9667 NEIGHBOR_ADDR_STR
9668 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9669
paul718e3742002-12-13 20:15:29 +00009670#endif /* HAVE_IPV6 */
9671
9672struct bgp_table *bgp_distance_table;
9673
9674struct bgp_distance
9675{
9676 /* Distance value for the IP source prefix. */
9677 u_char distance;
9678
9679 /* Name of the access-list to be matched. */
9680 char *access_list;
9681};
9682
paul94f2b392005-06-28 12:44:16 +00009683static struct bgp_distance *
paul718e3742002-12-13 20:15:29 +00009684bgp_distance_new ()
9685{
9686 struct bgp_distance *new;
9687 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
9688 memset (new, 0, sizeof (struct bgp_distance));
9689 return new;
9690}
9691
paul94f2b392005-06-28 12:44:16 +00009692static void
paul718e3742002-12-13 20:15:29 +00009693bgp_distance_free (struct bgp_distance *bdistance)
9694{
9695 XFREE (MTYPE_BGP_DISTANCE, bdistance);
9696}
9697
paul94f2b392005-06-28 12:44:16 +00009698static int
paulfd79ac92004-10-13 05:06:08 +00009699bgp_distance_set (struct vty *vty, const char *distance_str,
9700 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009701{
9702 int ret;
9703 struct prefix_ipv4 p;
9704 u_char distance;
9705 struct bgp_node *rn;
9706 struct bgp_distance *bdistance;
9707
9708 ret = str2prefix_ipv4 (ip_str, &p);
9709 if (ret == 0)
9710 {
9711 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9712 return CMD_WARNING;
9713 }
9714
9715 distance = atoi (distance_str);
9716
9717 /* Get BGP distance node. */
9718 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
9719 if (rn->info)
9720 {
9721 bdistance = rn->info;
9722 bgp_unlock_node (rn);
9723 }
9724 else
9725 {
9726 bdistance = bgp_distance_new ();
9727 rn->info = bdistance;
9728 }
9729
9730 /* Set distance value. */
9731 bdistance->distance = distance;
9732
9733 /* Reset access-list configuration. */
9734 if (bdistance->access_list)
9735 {
9736 free (bdistance->access_list);
9737 bdistance->access_list = NULL;
9738 }
9739 if (access_list_str)
9740 bdistance->access_list = strdup (access_list_str);
9741
9742 return CMD_SUCCESS;
9743}
9744
paul94f2b392005-06-28 12:44:16 +00009745static int
paulfd79ac92004-10-13 05:06:08 +00009746bgp_distance_unset (struct vty *vty, const char *distance_str,
9747 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009748{
9749 int ret;
9750 struct prefix_ipv4 p;
9751 u_char distance;
9752 struct bgp_node *rn;
9753 struct bgp_distance *bdistance;
9754
9755 ret = str2prefix_ipv4 (ip_str, &p);
9756 if (ret == 0)
9757 {
9758 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9759 return CMD_WARNING;
9760 }
9761
9762 distance = atoi (distance_str);
9763
9764 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
9765 if (! rn)
9766 {
9767 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
9768 return CMD_WARNING;
9769 }
9770
9771 bdistance = rn->info;
9772
9773 if (bdistance->access_list)
9774 free (bdistance->access_list);
9775 bgp_distance_free (bdistance);
9776
9777 rn->info = NULL;
9778 bgp_unlock_node (rn);
9779 bgp_unlock_node (rn);
9780
9781 return CMD_SUCCESS;
9782}
9783
paul94f2b392005-06-28 12:44:16 +00009784static void
paul718e3742002-12-13 20:15:29 +00009785bgp_distance_reset ()
9786{
9787 struct bgp_node *rn;
9788 struct bgp_distance *bdistance;
9789
9790 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
9791 if ((bdistance = rn->info) != NULL)
9792 {
9793 if (bdistance->access_list)
9794 free (bdistance->access_list);
9795 bgp_distance_free (bdistance);
9796 rn->info = NULL;
9797 bgp_unlock_node (rn);
9798 }
9799}
9800
9801/* Apply BGP information to distance method. */
9802u_char
9803bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
9804{
9805 struct bgp_node *rn;
9806 struct prefix_ipv4 q;
9807 struct peer *peer;
9808 struct bgp_distance *bdistance;
9809 struct access_list *alist;
9810 struct bgp_static *bgp_static;
9811
9812 if (! bgp)
9813 return 0;
9814
9815 if (p->family != AF_INET)
9816 return 0;
9817
9818 peer = rinfo->peer;
9819
9820 if (peer->su.sa.sa_family != AF_INET)
9821 return 0;
9822
9823 memset (&q, 0, sizeof (struct prefix_ipv4));
9824 q.family = AF_INET;
9825 q.prefix = peer->su.sin.sin_addr;
9826 q.prefixlen = IPV4_MAX_BITLEN;
9827
9828 /* Check source address. */
9829 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
9830 if (rn)
9831 {
9832 bdistance = rn->info;
9833 bgp_unlock_node (rn);
9834
9835 if (bdistance->access_list)
9836 {
9837 alist = access_list_lookup (AFI_IP, bdistance->access_list);
9838 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
9839 return bdistance->distance;
9840 }
9841 else
9842 return bdistance->distance;
9843 }
9844
9845 /* Backdoor check. */
9846 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
9847 if (rn)
9848 {
9849 bgp_static = rn->info;
9850 bgp_unlock_node (rn);
9851
9852 if (bgp_static->backdoor)
9853 {
9854 if (bgp->distance_local)
9855 return bgp->distance_local;
9856 else
9857 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9858 }
9859 }
9860
9861 if (peer_sort (peer) == BGP_PEER_EBGP)
9862 {
9863 if (bgp->distance_ebgp)
9864 return bgp->distance_ebgp;
9865 return ZEBRA_EBGP_DISTANCE_DEFAULT;
9866 }
9867 else
9868 {
9869 if (bgp->distance_ibgp)
9870 return bgp->distance_ibgp;
9871 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9872 }
9873}
9874
9875DEFUN (bgp_distance,
9876 bgp_distance_cmd,
9877 "distance bgp <1-255> <1-255> <1-255>",
9878 "Define an administrative distance\n"
9879 "BGP distance\n"
9880 "Distance for routes external to the AS\n"
9881 "Distance for routes internal to the AS\n"
9882 "Distance for local routes\n")
9883{
9884 struct bgp *bgp;
9885
9886 bgp = vty->index;
9887
9888 bgp->distance_ebgp = atoi (argv[0]);
9889 bgp->distance_ibgp = atoi (argv[1]);
9890 bgp->distance_local = atoi (argv[2]);
9891 return CMD_SUCCESS;
9892}
9893
9894DEFUN (no_bgp_distance,
9895 no_bgp_distance_cmd,
9896 "no distance bgp <1-255> <1-255> <1-255>",
9897 NO_STR
9898 "Define an administrative distance\n"
9899 "BGP distance\n"
9900 "Distance for routes external to the AS\n"
9901 "Distance for routes internal to the AS\n"
9902 "Distance for local routes\n")
9903{
9904 struct bgp *bgp;
9905
9906 bgp = vty->index;
9907
9908 bgp->distance_ebgp= 0;
9909 bgp->distance_ibgp = 0;
9910 bgp->distance_local = 0;
9911 return CMD_SUCCESS;
9912}
9913
9914ALIAS (no_bgp_distance,
9915 no_bgp_distance2_cmd,
9916 "no distance bgp",
9917 NO_STR
9918 "Define an administrative distance\n"
9919 "BGP distance\n")
9920
9921DEFUN (bgp_distance_source,
9922 bgp_distance_source_cmd,
9923 "distance <1-255> A.B.C.D/M",
9924 "Define an administrative distance\n"
9925 "Administrative distance\n"
9926 "IP source prefix\n")
9927{
9928 bgp_distance_set (vty, argv[0], argv[1], NULL);
9929 return CMD_SUCCESS;
9930}
9931
9932DEFUN (no_bgp_distance_source,
9933 no_bgp_distance_source_cmd,
9934 "no distance <1-255> A.B.C.D/M",
9935 NO_STR
9936 "Define an administrative distance\n"
9937 "Administrative distance\n"
9938 "IP source prefix\n")
9939{
9940 bgp_distance_unset (vty, argv[0], argv[1], NULL);
9941 return CMD_SUCCESS;
9942}
9943
9944DEFUN (bgp_distance_source_access_list,
9945 bgp_distance_source_access_list_cmd,
9946 "distance <1-255> A.B.C.D/M WORD",
9947 "Define an administrative distance\n"
9948 "Administrative distance\n"
9949 "IP source prefix\n"
9950 "Access list name\n")
9951{
9952 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
9953 return CMD_SUCCESS;
9954}
9955
9956DEFUN (no_bgp_distance_source_access_list,
9957 no_bgp_distance_source_access_list_cmd,
9958 "no distance <1-255> A.B.C.D/M WORD",
9959 NO_STR
9960 "Define an administrative distance\n"
9961 "Administrative distance\n"
9962 "IP source prefix\n"
9963 "Access list name\n")
9964{
9965 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
9966 return CMD_SUCCESS;
9967}
9968
9969DEFUN (bgp_damp_set,
9970 bgp_damp_set_cmd,
9971 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
9972 "BGP Specific commands\n"
9973 "Enable route-flap dampening\n"
9974 "Half-life time for the penalty\n"
9975 "Value to start reusing a route\n"
9976 "Value to start suppressing a route\n"
9977 "Maximum duration to suppress a stable route\n")
9978{
9979 struct bgp *bgp;
9980 int half = DEFAULT_HALF_LIFE * 60;
9981 int reuse = DEFAULT_REUSE;
9982 int suppress = DEFAULT_SUPPRESS;
9983 int max = 4 * half;
9984
9985 if (argc == 4)
9986 {
9987 half = atoi (argv[0]) * 60;
9988 reuse = atoi (argv[1]);
9989 suppress = atoi (argv[2]);
9990 max = atoi (argv[3]) * 60;
9991 }
9992 else if (argc == 1)
9993 {
9994 half = atoi (argv[0]) * 60;
9995 max = 4 * half;
9996 }
9997
9998 bgp = vty->index;
9999 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
10000 half, reuse, suppress, max);
10001}
10002
10003ALIAS (bgp_damp_set,
10004 bgp_damp_set2_cmd,
10005 "bgp dampening <1-45>",
10006 "BGP Specific commands\n"
10007 "Enable route-flap dampening\n"
10008 "Half-life time for the penalty\n")
10009
10010ALIAS (bgp_damp_set,
10011 bgp_damp_set3_cmd,
10012 "bgp dampening",
10013 "BGP Specific commands\n"
10014 "Enable route-flap dampening\n")
10015
10016DEFUN (bgp_damp_unset,
10017 bgp_damp_unset_cmd,
10018 "no bgp dampening",
10019 NO_STR
10020 "BGP Specific commands\n"
10021 "Enable route-flap dampening\n")
10022{
10023 struct bgp *bgp;
10024
10025 bgp = vty->index;
10026 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
10027}
10028
10029ALIAS (bgp_damp_unset,
10030 bgp_damp_unset2_cmd,
10031 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10032 NO_STR
10033 "BGP Specific commands\n"
10034 "Enable route-flap dampening\n"
10035 "Half-life time for the penalty\n"
10036 "Value to start reusing a route\n"
10037 "Value to start suppressing a route\n"
10038 "Maximum duration to suppress a stable route\n")
10039
10040DEFUN (show_ip_bgp_dampened_paths,
10041 show_ip_bgp_dampened_paths_cmd,
10042 "show ip bgp dampened-paths",
10043 SHOW_STR
10044 IP_STR
10045 BGP_STR
10046 "Display paths suppressed due to dampening\n")
10047{
ajs5a646652004-11-05 01:25:55 +000010048 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
10049 NULL);
paul718e3742002-12-13 20:15:29 +000010050}
10051
10052DEFUN (show_ip_bgp_flap_statistics,
10053 show_ip_bgp_flap_statistics_cmd,
10054 "show ip bgp flap-statistics",
10055 SHOW_STR
10056 IP_STR
10057 BGP_STR
10058 "Display flap statistics of routes\n")
10059{
ajs5a646652004-11-05 01:25:55 +000010060 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10061 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000010062}
10063
10064/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000010065static int
paulfd79ac92004-10-13 05:06:08 +000010066bgp_clear_damp_route (struct vty *vty, const char *view_name,
10067 const char *ip_str, afi_t afi, safi_t safi,
10068 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000010069{
10070 int ret;
10071 struct prefix match;
10072 struct bgp_node *rn;
10073 struct bgp_node *rm;
10074 struct bgp_info *ri;
10075 struct bgp_info *ri_temp;
10076 struct bgp *bgp;
10077 struct bgp_table *table;
10078
10079 /* BGP structure lookup. */
10080 if (view_name)
10081 {
10082 bgp = bgp_lookup_by_name (view_name);
10083 if (bgp == NULL)
10084 {
10085 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10086 return CMD_WARNING;
10087 }
10088 }
10089 else
10090 {
10091 bgp = bgp_get_default ();
10092 if (bgp == NULL)
10093 {
10094 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
10095 return CMD_WARNING;
10096 }
10097 }
10098
10099 /* Check IP address argument. */
10100 ret = str2prefix (ip_str, &match);
10101 if (! ret)
10102 {
10103 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
10104 return CMD_WARNING;
10105 }
10106
10107 match.family = afi2family (afi);
10108
10109 if (safi == SAFI_MPLS_VPN)
10110 {
10111 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
10112 {
10113 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
10114 continue;
10115
10116 if ((table = rn->info) != NULL)
10117 if ((rm = bgp_node_match (table, &match)) != NULL)
10118 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
10119 {
10120 ri = rm->info;
10121 while (ri)
10122 {
10123 if (ri->damp_info)
10124 {
10125 ri_temp = ri->next;
10126 bgp_damp_info_free (ri->damp_info, 1);
10127 ri = ri_temp;
10128 }
10129 else
10130 ri = ri->next;
10131 }
10132 }
10133 }
10134 }
10135 else
10136 {
10137 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
10138 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
10139 {
10140 ri = rn->info;
10141 while (ri)
10142 {
10143 if (ri->damp_info)
10144 {
10145 ri_temp = ri->next;
10146 bgp_damp_info_free (ri->damp_info, 1);
10147 ri = ri_temp;
10148 }
10149 else
10150 ri = ri->next;
10151 }
10152 }
10153 }
10154
10155 return CMD_SUCCESS;
10156}
10157
10158DEFUN (clear_ip_bgp_dampening,
10159 clear_ip_bgp_dampening_cmd,
10160 "clear ip bgp dampening",
10161 CLEAR_STR
10162 IP_STR
10163 BGP_STR
10164 "Clear route flap dampening information\n")
10165{
10166 bgp_damp_info_clean ();
10167 return CMD_SUCCESS;
10168}
10169
10170DEFUN (clear_ip_bgp_dampening_prefix,
10171 clear_ip_bgp_dampening_prefix_cmd,
10172 "clear ip bgp dampening A.B.C.D/M",
10173 CLEAR_STR
10174 IP_STR
10175 BGP_STR
10176 "Clear route flap dampening information\n"
10177 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10178{
10179 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10180 SAFI_UNICAST, NULL, 1);
10181}
10182
10183DEFUN (clear_ip_bgp_dampening_address,
10184 clear_ip_bgp_dampening_address_cmd,
10185 "clear ip bgp dampening A.B.C.D",
10186 CLEAR_STR
10187 IP_STR
10188 BGP_STR
10189 "Clear route flap dampening information\n"
10190 "Network to clear damping information\n")
10191{
10192 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10193 SAFI_UNICAST, NULL, 0);
10194}
10195
10196DEFUN (clear_ip_bgp_dampening_address_mask,
10197 clear_ip_bgp_dampening_address_mask_cmd,
10198 "clear ip bgp dampening A.B.C.D A.B.C.D",
10199 CLEAR_STR
10200 IP_STR
10201 BGP_STR
10202 "Clear route flap dampening information\n"
10203 "Network to clear damping information\n"
10204 "Network mask\n")
10205{
10206 int ret;
10207 char prefix_str[BUFSIZ];
10208
10209 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
10210 if (! ret)
10211 {
10212 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
10213 return CMD_WARNING;
10214 }
10215
10216 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
10217 SAFI_UNICAST, NULL, 0);
10218}
10219
paul94f2b392005-06-28 12:44:16 +000010220static int
paul718e3742002-12-13 20:15:29 +000010221bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
10222 afi_t afi, safi_t safi, int *write)
10223{
10224 struct bgp_node *prn;
10225 struct bgp_node *rn;
10226 struct bgp_table *table;
10227 struct prefix *p;
10228 struct prefix_rd *prd;
10229 struct bgp_static *bgp_static;
10230 u_int32_t label;
10231 char buf[SU_ADDRSTRLEN];
10232 char rdbuf[RD_ADDRSTRLEN];
10233
10234 /* Network configuration. */
10235 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
10236 if ((table = prn->info) != NULL)
10237 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10238 if ((bgp_static = rn->info) != NULL)
10239 {
10240 p = &rn->p;
10241 prd = (struct prefix_rd *) &prn->p;
10242
10243 /* "address-family" display. */
10244 bgp_config_write_family_header (vty, afi, safi, write);
10245
10246 /* "network" configuration display. */
10247 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
10248 label = decode_label (bgp_static->tag);
10249
10250 vty_out (vty, " network %s/%d rd %s tag %d",
10251 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10252 p->prefixlen,
10253 rdbuf, label);
10254 vty_out (vty, "%s", VTY_NEWLINE);
10255 }
10256 return 0;
10257}
10258
10259/* Configuration of static route announcement and aggregate
10260 information. */
10261int
10262bgp_config_write_network (struct vty *vty, struct bgp *bgp,
10263 afi_t afi, safi_t safi, int *write)
10264{
10265 struct bgp_node *rn;
10266 struct prefix *p;
10267 struct bgp_static *bgp_static;
10268 struct bgp_aggregate *bgp_aggregate;
10269 char buf[SU_ADDRSTRLEN];
10270
10271 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
10272 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
10273
10274 /* Network configuration. */
10275 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
10276 if ((bgp_static = rn->info) != NULL)
10277 {
10278 p = &rn->p;
10279
10280 /* "address-family" display. */
10281 bgp_config_write_family_header (vty, afi, safi, write);
10282
10283 /* "network" configuration display. */
10284 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10285 {
10286 u_int32_t destination;
10287 struct in_addr netmask;
10288
10289 destination = ntohl (p->u.prefix4.s_addr);
10290 masklen2ip (p->prefixlen, &netmask);
10291 vty_out (vty, " network %s",
10292 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
10293
10294 if ((IN_CLASSC (destination) && p->prefixlen == 24)
10295 || (IN_CLASSB (destination) && p->prefixlen == 16)
10296 || (IN_CLASSA (destination) && p->prefixlen == 8)
10297 || p->u.prefix4.s_addr == 0)
10298 {
10299 /* Natural mask is not display. */
10300 }
10301 else
10302 vty_out (vty, " mask %s", inet_ntoa (netmask));
10303 }
10304 else
10305 {
10306 vty_out (vty, " network %s/%d",
10307 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10308 p->prefixlen);
10309 }
10310
10311 if (bgp_static->rmap.name)
10312 vty_out (vty, " route-map %s", bgp_static->rmap.name);
10313 else if (bgp_static->backdoor)
10314 vty_out (vty, " backdoor");
10315
10316 vty_out (vty, "%s", VTY_NEWLINE);
10317 }
10318
10319 /* Aggregate-address configuration. */
10320 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
10321 if ((bgp_aggregate = rn->info) != NULL)
10322 {
10323 p = &rn->p;
10324
10325 /* "address-family" display. */
10326 bgp_config_write_family_header (vty, afi, safi, write);
10327
10328 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10329 {
10330 struct in_addr netmask;
10331
10332 masklen2ip (p->prefixlen, &netmask);
10333 vty_out (vty, " aggregate-address %s %s",
10334 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10335 inet_ntoa (netmask));
10336 }
10337 else
10338 {
10339 vty_out (vty, " aggregate-address %s/%d",
10340 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10341 p->prefixlen);
10342 }
10343
10344 if (bgp_aggregate->as_set)
10345 vty_out (vty, " as-set");
10346
10347 if (bgp_aggregate->summary_only)
10348 vty_out (vty, " summary-only");
10349
10350 vty_out (vty, "%s", VTY_NEWLINE);
10351 }
10352
10353 return 0;
10354}
10355
10356int
10357bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
10358{
10359 struct bgp_node *rn;
10360 struct bgp_distance *bdistance;
10361
10362 /* Distance configuration. */
10363 if (bgp->distance_ebgp
10364 && bgp->distance_ibgp
10365 && bgp->distance_local
10366 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
10367 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
10368 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
10369 vty_out (vty, " distance bgp %d %d %d%s",
10370 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
10371 VTY_NEWLINE);
10372
10373 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10374 if ((bdistance = rn->info) != NULL)
10375 {
10376 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
10377 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
10378 bdistance->access_list ? bdistance->access_list : "",
10379 VTY_NEWLINE);
10380 }
10381
10382 return 0;
10383}
10384
10385/* Allocate routing table structure and install commands. */
10386void
10387bgp_route_init ()
10388{
10389 /* Init BGP distance table. */
10390 bgp_distance_table = bgp_table_init ();
10391
10392 /* IPv4 BGP commands. */
10393 install_element (BGP_NODE, &bgp_network_cmd);
10394 install_element (BGP_NODE, &bgp_network_mask_cmd);
10395 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
10396 install_element (BGP_NODE, &bgp_network_route_map_cmd);
10397 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
10398 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
10399 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
10400 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
10401 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
10402 install_element (BGP_NODE, &no_bgp_network_cmd);
10403 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
10404 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
10405 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
10406 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
10407 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10408 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
10409 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
10410 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
10411
10412 install_element (BGP_NODE, &aggregate_address_cmd);
10413 install_element (BGP_NODE, &aggregate_address_mask_cmd);
10414 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
10415 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
10416 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
10417 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
10418 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
10419 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
10420 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
10421 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
10422 install_element (BGP_NODE, &no_aggregate_address_cmd);
10423 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
10424 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
10425 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
10426 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
10427 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
10428 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
10429 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
10430 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10431 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10432
10433 /* IPv4 unicast configuration. */
10434 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
10435 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
10436 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
10437 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
10438 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
10439 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
10440 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
10441 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
10442 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
10443 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
10444 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
10445 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10446 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
10447 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
10448 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
10449 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
10450 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
10451 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
10452 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
10453 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
10454 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
10455 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
10456 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
10457 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
10458 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
10459 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
10460 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
10461 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
10462 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
10463 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
10464 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10465 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10466
10467 /* IPv4 multicast configuration. */
10468 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
10469 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
10470 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
10471 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
10472 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
10473 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
10474 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
10475 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
10476 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
10477 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
10478 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
10479 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10480 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
10481 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
10482 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
10483 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
10484 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
10485 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
10486 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
10487 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
10488 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
10489 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
10490 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
10491 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
10492 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
10493 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
10494 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
10495 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
10496 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
10497 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
10498 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10499 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10500
10501 install_element (VIEW_NODE, &show_ip_bgp_cmd);
10502 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
10503 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
10504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
10505 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10506 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10507 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
10508 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10509 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10510 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10511 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
10512 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
10513 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
10514 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
10515 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10516 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
10517 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10518 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
10519 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10520 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
10521 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10522 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
10523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10524 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
10525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10526 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
10527 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
10528 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
10529 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
10530 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
10531 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
10532 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
10533 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
10534 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
10535 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
10536 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
10537 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
10538 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10539 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10540 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10541 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10542 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
10543 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10544 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
10545 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10546 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
10547 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10548 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10549 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10550 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10551 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10552 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
10553 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10554 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10555 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10556 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
10557 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
10558 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
10559 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
10560 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10561 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
10562 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
10563 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10564 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10565 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
10566 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
10567 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010568 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
10569 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
10570 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10571 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
10572 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10573 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010574
10575 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
10576 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
10577 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
10578 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
10579 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10580 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10581 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
10582 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10583 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10584 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10585 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
10586 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
10587 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
10588 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
10589 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10590 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
10591 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10592 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
10593 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10594 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
10595 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10596 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
10597 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10598 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
10599 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10600 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
10601 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
10602 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
10603 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
10604 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
10605 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
10606 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
10607 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
10608 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
10609 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
10610 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
10611 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
10612 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10613 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10614 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10615 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10616 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
10617 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10618 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
10619 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10620 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
10621 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10622 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10623 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10624 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10625 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10626 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
10627 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10628 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10629 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10630 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
10631 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
10632 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
10633 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
10634 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10635 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
10636 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
10637 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10638 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10639 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
10640 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
10641 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010642 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
10643 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
10644 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10645 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
10646 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10647 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010648
10649 /* BGP dampening clear commands */
10650 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
10651 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
10652 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
10653 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
10654
10655#ifdef HAVE_IPV6
10656 /* New config IPv6 BGP commands. */
10657 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
10658 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
10659 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
10660 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
10661
10662 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
10663 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
10664 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
10665 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
10666
10667 /* Old config IPv6 BGP commands. */
10668 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
10669 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
10670
10671 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
10672 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
10673 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
10674 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
10675
10676 install_element (VIEW_NODE, &show_bgp_cmd);
10677 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
10678 install_element (VIEW_NODE, &show_bgp_route_cmd);
10679 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
10680 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
10681 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
10682 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
10683 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
10684 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
10685 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
10686 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
10687 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
10688 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
10689 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
10690 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
10691 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
10692 install_element (VIEW_NODE, &show_bgp_community_cmd);
10693 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
10694 install_element (VIEW_NODE, &show_bgp_community2_cmd);
10695 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
10696 install_element (VIEW_NODE, &show_bgp_community3_cmd);
10697 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
10698 install_element (VIEW_NODE, &show_bgp_community4_cmd);
10699 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
10700 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
10701 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
10702 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
10703 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
10704 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
10705 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
10706 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
10707 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
10708 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
10709 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
10710 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
10711 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10712 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
10713 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10714 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
10715 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10716 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
10717 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10718 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
10719 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10720 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10721 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010722 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
10723 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10724 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
10725 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010726 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
10727 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
10728 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010729 install_element (VIEW_NODE, &show_bgp_view_cmd);
10730 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
10731 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
10732 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
10733 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
10734 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
10735 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10736 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10737 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10738 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10739 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
10740 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10741 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10742 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10743 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
10744 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10745 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
10746 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010747 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
10748 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
10749 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010750
10751 install_element (ENABLE_NODE, &show_bgp_cmd);
10752 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
10753 install_element (ENABLE_NODE, &show_bgp_route_cmd);
10754 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
10755 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
10756 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
10757 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
10758 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
10759 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
10760 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
10761 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
10762 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
10763 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
10764 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
10765 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
10766 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
10767 install_element (ENABLE_NODE, &show_bgp_community_cmd);
10768 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
10769 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
10770 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
10771 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
10772 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
10773 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
10774 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
10775 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
10776 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
10777 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
10778 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
10779 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
10780 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
10781 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
10782 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
10783 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
10784 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
10785 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
10786 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10787 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
10788 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10789 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
10790 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10791 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
10792 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10793 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
10794 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10795 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10796 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010797 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
10798 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10799 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
10800 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010801 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
10802 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
10803 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010804 install_element (ENABLE_NODE, &show_bgp_view_cmd);
10805 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
10806 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
10807 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
10808 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
10809 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
10810 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10811 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10812 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10813 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10814 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
10815 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10816 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10817 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10818 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
10819 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10820 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
10821 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010822 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
10823 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
10824 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010825
10826 /* old command */
10827 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
10828 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
10829 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
10830 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
10831 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
10832 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
10833 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
10834 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
10835 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
10836 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
10837 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
10838 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
10839 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
10840 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
10841 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
10842 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
10843 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10844 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10845 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
10846 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
10847 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
10848 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
10849 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10850 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
10851 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
10852 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
10853 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
10854 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
10855 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
10856 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
10857 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10858 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10859 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10860 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
10861 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10862 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000010863
paul718e3742002-12-13 20:15:29 +000010864 /* old command */
10865 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
10866 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
10867 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
10868 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
10869 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
10870 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
10871 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
10872 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
10873 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
10874 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
10875 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
10876 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
10877 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
10878 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
10879 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
10880 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
10881 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10882 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10883 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
10884 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
10885 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
10886 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
10887 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10888 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
10889 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
10890 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
10891 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
10892 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
10893 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
10894 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
10895 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10896 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10897 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10898 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
10899 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10900 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
10901
10902 /* old command */
10903 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10904 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10905 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10906 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10907
10908 /* old command */
10909 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10910 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10911 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10912 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10913
10914 /* old command */
10915 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
10916 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
10917 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10918 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10919#endif /* HAVE_IPV6 */
10920
10921 install_element (BGP_NODE, &bgp_distance_cmd);
10922 install_element (BGP_NODE, &no_bgp_distance_cmd);
10923 install_element (BGP_NODE, &no_bgp_distance2_cmd);
10924 install_element (BGP_NODE, &bgp_distance_source_cmd);
10925 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
10926 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
10927 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
10928
10929 install_element (BGP_NODE, &bgp_damp_set_cmd);
10930 install_element (BGP_NODE, &bgp_damp_set2_cmd);
10931 install_element (BGP_NODE, &bgp_damp_set3_cmd);
10932 install_element (BGP_NODE, &bgp_damp_unset_cmd);
10933 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
10934 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
10935 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
10936 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
10937 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
10938 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
10939}