blob: 862fd4333e60e7270680fe9d5e68eedab1ba21a2 [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
paulb40d9392005-08-22 22:34:41 +0000167/* Do the actual removal of info from RIB, for use by bgp_process
168 completion callback *only* */
169static void
170bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000171{
172 if (ri->next)
173 ri->next->prev = ri->prev;
174 if (ri->prev)
175 ri->prev->next = ri->next;
176 else
177 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000178
179 bgp_info_unlock (ri);
180 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000181}
182
paulb40d9392005-08-22 22:34:41 +0000183void
184bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
185{
186 /* leave info in place for now in place for now,
187 * bgp_process will reap it later. */
188 SET_FLAG (ri->flags, BGP_INFO_REMOVED);
189 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
190}
191
paul718e3742002-12-13 20:15:29 +0000192/* Get MED value. If MED value is missing and "bgp bestpath
193 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000194static u_int32_t
paul718e3742002-12-13 20:15:29 +0000195bgp_med_value (struct attr *attr, struct bgp *bgp)
196{
197 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
198 return attr->med;
199 else
200 {
201 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000202 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000203 else
204 return 0;
205 }
206}
207
208/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000209static int
paul718e3742002-12-13 20:15:29 +0000210bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
211{
212 u_int32_t new_pref;
213 u_int32_t exist_pref;
214 u_int32_t new_med;
215 u_int32_t exist_med;
216 struct in_addr new_id;
217 struct in_addr exist_id;
218 int new_cluster;
219 int exist_cluster;
220 int internal_as_route = 0;
221 int confed_as_route = 0;
222 int ret;
223
224 /* 0. Null check. */
225 if (new == NULL)
226 return 0;
227 if (exist == NULL)
228 return 1;
229
230 /* 1. Weight check. */
231 if (new->attr->weight > exist->attr->weight)
232 return 1;
233 if (new->attr->weight < exist->attr->weight)
234 return 0;
235
236 /* 2. Local preference check. */
237 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
238 new_pref = new->attr->local_pref;
239 else
240 new_pref = bgp->default_local_pref;
241
242 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
243 exist_pref = exist->attr->local_pref;
244 else
245 exist_pref = bgp->default_local_pref;
246
247 if (new_pref > exist_pref)
248 return 1;
249 if (new_pref < exist_pref)
250 return 0;
251
252 /* 3. Local route check. */
253 if (new->sub_type == BGP_ROUTE_STATIC)
254 return 1;
255 if (exist->sub_type == BGP_ROUTE_STATIC)
256 return 0;
257
258 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
259 return 1;
260 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
261 return 0;
262
263 if (new->sub_type == BGP_ROUTE_AGGREGATE)
264 return 1;
265 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
266 return 0;
267
268 /* 4. AS path length check. */
269 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
270 {
hasso68118452005-04-08 15:40:36 +0000271 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
272 {
273 if ((new->attr->aspath->count +
274 new->attr->aspath->confed_count)
275 < (exist->attr->aspath->count +
276 exist->attr->aspath->confed_count))
277 return 1;
278 if ((new->attr->aspath->count +
279 new->attr->aspath->confed_count)
280 > (exist->attr->aspath->count +
281 exist->attr->aspath->confed_count))
282 return 0;
283 }
284 else
285 {
286 if (new->attr->aspath->count < exist->attr->aspath->count)
287 return 1;
288 if (new->attr->aspath->count > exist->attr->aspath->count)
289 return 0;
290 }
paul718e3742002-12-13 20:15:29 +0000291 }
292
293 /* 5. Origin check. */
294 if (new->attr->origin < exist->attr->origin)
295 return 1;
296 if (new->attr->origin > exist->attr->origin)
297 return 0;
298
299 /* 6. MED check. */
300 internal_as_route = (new->attr->aspath->length == 0
301 && exist->attr->aspath->length == 0);
302 confed_as_route = (new->attr->aspath->length > 0
303 && exist->attr->aspath->length > 0
304 && new->attr->aspath->count == 0
305 && exist->attr->aspath->count == 0);
306
307 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
308 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
309 && confed_as_route)
310 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
311 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
312 || internal_as_route)
313 {
314 new_med = bgp_med_value (new->attr, bgp);
315 exist_med = bgp_med_value (exist->attr, bgp);
316
317 if (new_med < exist_med)
318 return 1;
319 if (new_med > exist_med)
320 return 0;
321 }
322
323 /* 7. Peer type check. */
324 if (peer_sort (new->peer) == BGP_PEER_EBGP
325 && peer_sort (exist->peer) == BGP_PEER_IBGP)
326 return 1;
327 if (peer_sort (new->peer) == BGP_PEER_EBGP
328 && peer_sort (exist->peer) == BGP_PEER_CONFED)
329 return 1;
330 if (peer_sort (new->peer) == BGP_PEER_IBGP
331 && peer_sort (exist->peer) == BGP_PEER_EBGP)
332 return 0;
333 if (peer_sort (new->peer) == BGP_PEER_CONFED
334 && peer_sort (exist->peer) == BGP_PEER_EBGP)
335 return 0;
336
337 /* 8. IGP metric check. */
338 if (new->igpmetric < exist->igpmetric)
339 return 1;
340 if (new->igpmetric > exist->igpmetric)
341 return 0;
342
343 /* 9. Maximum path check. */
344
345 /* 10. If both paths are external, prefer the path that was received
346 first (the oldest one). This step minimizes route-flap, since a
347 newer path won't displace an older one, even if it was the
348 preferred route based on the additional decision criteria below. */
349 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
350 && peer_sort (new->peer) == BGP_PEER_EBGP
351 && peer_sort (exist->peer) == BGP_PEER_EBGP)
352 {
353 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
354 return 1;
355 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
356 return 0;
357 }
358
359 /* 11. Rourter-ID comparision. */
360 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
361 new_id.s_addr = new->attr->originator_id.s_addr;
362 else
363 new_id.s_addr = new->peer->remote_id.s_addr;
364 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
365 exist_id.s_addr = exist->attr->originator_id.s_addr;
366 else
367 exist_id.s_addr = exist->peer->remote_id.s_addr;
368
369 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
370 return 1;
371 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
372 return 0;
373
374 /* 12. Cluster length comparision. */
375 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
376 new_cluster = new->attr->cluster->length;
377 else
378 new_cluster = 0;
379 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
380 exist_cluster = exist->attr->cluster->length;
381 else
382 exist_cluster = 0;
383
384 if (new_cluster < exist_cluster)
385 return 1;
386 if (new_cluster > exist_cluster)
387 return 0;
388
389 /* 13. Neighbor address comparision. */
390 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
391
392 if (ret == 1)
393 return 0;
394 if (ret == -1)
395 return 1;
396
397 return 1;
398}
399
paul94f2b392005-06-28 12:44:16 +0000400static enum filter_type
paul718e3742002-12-13 20:15:29 +0000401bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
402 afi_t afi, safi_t safi)
403{
404 struct bgp_filter *filter;
405
406 filter = &peer->filter[afi][safi];
407
408 if (DISTRIBUTE_IN_NAME (filter))
409 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
410 return FILTER_DENY;
411
412 if (PREFIX_LIST_IN_NAME (filter))
413 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
414 return FILTER_DENY;
415
416 if (FILTER_LIST_IN_NAME (filter))
417 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
418 return FILTER_DENY;
419
420 return FILTER_PERMIT;
421}
422
paul94f2b392005-06-28 12:44:16 +0000423static enum filter_type
paul718e3742002-12-13 20:15:29 +0000424bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
425 afi_t afi, safi_t safi)
426{
427 struct bgp_filter *filter;
428
429 filter = &peer->filter[afi][safi];
430
431 if (DISTRIBUTE_OUT_NAME (filter))
432 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
433 return FILTER_DENY;
434
435 if (PREFIX_LIST_OUT_NAME (filter))
436 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
437 return FILTER_DENY;
438
439 if (FILTER_LIST_OUT_NAME (filter))
440 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
441 return FILTER_DENY;
442
443 return FILTER_PERMIT;
444}
445
446/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000447static int
paul718e3742002-12-13 20:15:29 +0000448bgp_community_filter (struct peer *peer, struct attr *attr)
449{
450 if (attr->community)
451 {
452 /* NO_ADVERTISE check. */
453 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
454 return 1;
455
456 /* NO_EXPORT check. */
457 if (peer_sort (peer) == BGP_PEER_EBGP &&
458 community_include (attr->community, COMMUNITY_NO_EXPORT))
459 return 1;
460
461 /* NO_EXPORT_SUBCONFED check. */
462 if (peer_sort (peer) == BGP_PEER_EBGP
463 || peer_sort (peer) == BGP_PEER_CONFED)
464 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
465 return 1;
466 }
467 return 0;
468}
469
470/* Route reflection loop check. */
471static int
472bgp_cluster_filter (struct peer *peer, struct attr *attr)
473{
474 struct in_addr cluster_id;
475
476 if (attr->cluster)
477 {
478 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
479 cluster_id = peer->bgp->cluster_id;
480 else
481 cluster_id = peer->bgp->router_id;
482
483 if (cluster_loop_check (attr->cluster, cluster_id))
484 return 1;
485 }
486 return 0;
487}
488
paul94f2b392005-06-28 12:44:16 +0000489static int
paul718e3742002-12-13 20:15:29 +0000490bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
491 afi_t afi, safi_t safi)
492{
493 struct bgp_filter *filter;
494 struct bgp_info info;
495 route_map_result_t ret;
496
497 filter = &peer->filter[afi][safi];
498
499 /* Apply default weight value. */
500 attr->weight = peer->weight;
501
502 /* Route map apply. */
503 if (ROUTE_MAP_IN_NAME (filter))
504 {
505 /* Duplicate current value to new strucutre for modification. */
506 info.peer = peer;
507 info.attr = attr;
508
paulac41b2a2003-08-12 05:32:27 +0000509 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
510
paul718e3742002-12-13 20:15:29 +0000511 /* Apply BGP route map to the attribute. */
512 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000513
514 peer->rmap_type = 0;
515
paul718e3742002-12-13 20:15:29 +0000516 if (ret == RMAP_DENYMATCH)
517 {
518 /* Free newly generated AS path and community by route-map. */
519 bgp_attr_flush (attr);
520 return RMAP_DENY;
521 }
522 }
523 return RMAP_PERMIT;
524}
525
paul94f2b392005-06-28 12:44:16 +0000526static int
paulfee0f4c2004-09-13 05:12:46 +0000527bgp_export_modifier (struct peer *rsclient, struct peer *peer,
528 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
529{
530 struct bgp_filter *filter;
531 struct bgp_info info;
532 route_map_result_t ret;
533
534 filter = &peer->filter[afi][safi];
535
536 /* Route map apply. */
537 if (ROUTE_MAP_EXPORT_NAME (filter))
538 {
539 /* Duplicate current value to new strucutre for modification. */
540 info.peer = rsclient;
541 info.attr = attr;
542
543 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
544
545 /* Apply BGP route map to the attribute. */
546 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
547
548 rsclient->rmap_type = 0;
549
550 if (ret == RMAP_DENYMATCH)
551 {
552 /* Free newly generated AS path and community by route-map. */
553 bgp_attr_flush (attr);
554 return RMAP_DENY;
555 }
556 }
557 return RMAP_PERMIT;
558}
559
paul94f2b392005-06-28 12:44:16 +0000560static int
paulfee0f4c2004-09-13 05:12:46 +0000561bgp_import_modifier (struct peer *rsclient, struct peer *peer,
562 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
563{
564 struct bgp_filter *filter;
565 struct bgp_info info;
566 route_map_result_t ret;
567
568 filter = &rsclient->filter[afi][safi];
569
570 /* Apply default weight value. */
571 attr->weight = peer->weight;
572
573 /* Route map apply. */
574 if (ROUTE_MAP_IMPORT_NAME (filter))
575 {
576 /* Duplicate current value to new strucutre for modification. */
577 info.peer = peer;
578 info.attr = attr;
579
580 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
581
582 /* Apply BGP route map to the attribute. */
583 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
584
585 peer->rmap_type = 0;
586
587 if (ret == RMAP_DENYMATCH)
588 {
589 /* Free newly generated AS path and community by route-map. */
590 bgp_attr_flush (attr);
591 return RMAP_DENY;
592 }
593 }
594 return RMAP_PERMIT;
595}
596
paul94f2b392005-06-28 12:44:16 +0000597static int
paul718e3742002-12-13 20:15:29 +0000598bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
599 struct attr *attr, afi_t afi, safi_t safi)
600{
601 int ret;
602 char buf[SU_ADDRSTRLEN];
603 struct bgp_filter *filter;
604 struct bgp_info info;
605 struct peer *from;
606 struct bgp *bgp;
607 struct attr dummy_attr;
608 int transparent;
609 int reflect;
610
611 from = ri->peer;
612 filter = &peer->filter[afi][safi];
613 bgp = peer->bgp;
614
615#ifdef DISABLE_BGP_ANNOUNCE
616 return 0;
617#endif
618
paulfee0f4c2004-09-13 05:12:46 +0000619 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
620 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
621 return 0;
622
paul718e3742002-12-13 20:15:29 +0000623 /* Do not send back route to sender. */
624 if (from == peer)
625 return 0;
626
paul35be31b2004-05-01 18:17:04 +0000627 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
628 if (p->family == AF_INET
629 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
630 return 0;
631#ifdef HAVE_IPV6
632 if (p->family == AF_INET6
633 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
634 return 0;
635#endif
636
paul718e3742002-12-13 20:15:29 +0000637 /* Aggregate-address suppress check. */
638 if (ri->suppress)
639 if (! UNSUPPRESS_MAP_NAME (filter))
640 return 0;
641
642 /* Default route check. */
643 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
644 {
645 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
646 return 0;
647#ifdef HAVE_IPV6
648 else if (p->family == AF_INET6 && p->prefixlen == 0)
649 return 0;
650#endif /* HAVE_IPV6 */
651 }
652
paul286e1e72003-08-08 00:24:31 +0000653 /* Transparency check. */
654 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
655 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
656 transparent = 1;
657 else
658 transparent = 0;
659
paul718e3742002-12-13 20:15:29 +0000660 /* If community is not disabled check the no-export and local. */
paul286e1e72003-08-08 00:24:31 +0000661 if (! transparent && bgp_community_filter (peer, ri->attr))
paul718e3742002-12-13 20:15:29 +0000662 return 0;
663
664 /* If the attribute has originator-id and it is same as remote
665 peer's id. */
666 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
667 {
668 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->originator_id))
669 {
670 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000671 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000672 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
673 peer->host,
674 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
675 p->prefixlen);
676 return 0;
677 }
678 }
679
680 /* ORF prefix-list filter check */
681 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
682 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
683 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
684 if (peer->orf_plist[afi][safi])
685 {
686 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
687 return 0;
688 }
689
690 /* Output filter check. */
691 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
692 {
693 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000694 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000695 "%s [Update:SEND] %s/%d is filtered",
696 peer->host,
697 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
698 p->prefixlen);
699 return 0;
700 }
701
702#ifdef BGP_SEND_ASPATH_CHECK
703 /* AS path loop check. */
704 if (aspath_loop_check (ri->attr->aspath, peer->as))
705 {
706 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000707 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000708 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
709 peer->host, peer->as);
710 return 0;
711 }
712#endif /* BGP_SEND_ASPATH_CHECK */
713
714 /* If we're a CONFED we need to loop check the CONFED ID too */
715 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
716 {
717 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
718 {
719 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000720 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000721 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
722 peer->host,
723 bgp->confed_id);
724 return 0;
725 }
726 }
727
728 /* Route-Reflect check. */
729 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
730 reflect = 1;
731 else
732 reflect = 0;
733
734 /* IBGP reflection check. */
735 if (reflect)
736 {
737 /* A route from a Client peer. */
738 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
739 {
740 /* Reflect to all the Non-Client peers and also to the
741 Client peers other than the originator. Originator check
742 is already done. So there is noting to do. */
743 /* no bgp client-to-client reflection check. */
744 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
745 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
746 return 0;
747 }
748 else
749 {
750 /* A route from a Non-client peer. Reflect to all other
751 clients. */
752 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
753 return 0;
754 }
755 }
756
757 /* For modify attribute, copy it to temporary structure. */
758 *attr = *ri->attr;
759
760 /* If local-preference is not set. */
761 if ((peer_sort (peer) == BGP_PEER_IBGP
762 || peer_sort (peer) == BGP_PEER_CONFED)
763 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
764 {
765 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
766 attr->local_pref = bgp->default_local_pref;
767 }
768
paul718e3742002-12-13 20:15:29 +0000769 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
770 if (peer_sort (peer) == BGP_PEER_EBGP
771 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
772 {
773 if (ri->peer != bgp->peer_self && ! transparent
774 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
775 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
776 }
777
778 /* next-hop-set */
779 if (transparent || reflect
780 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
781 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000782#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000783 || (p->family == AF_INET6 &&
784 ! IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000785#endif /* HAVE_IPV6 */
786 )))
paul718e3742002-12-13 20:15:29 +0000787 {
788 /* NEXT-HOP Unchanged. */
789 }
790 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
791 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
792#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000793 || (p->family == AF_INET6 &&
794 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000795#endif /* HAVE_IPV6 */
796 || (peer_sort (peer) == BGP_PEER_EBGP
797 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
798 {
799 /* Set IPv4 nexthop. */
800 if (p->family == AF_INET)
801 {
802 if (safi == SAFI_MPLS_VPN)
803 memcpy (&attr->mp_nexthop_global_in, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
804 else
805 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
806 }
807#ifdef HAVE_IPV6
808 /* Set IPv6 nexthop. */
809 if (p->family == AF_INET6)
810 {
811 /* IPv6 global nexthop must be included. */
812 memcpy (&attr->mp_nexthop_global, &peer->nexthop.v6_global,
813 IPV6_MAX_BYTELEN);
814 attr->mp_nexthop_len = 16;
815 }
816#endif /* HAVE_IPV6 */
817 }
818
819#ifdef HAVE_IPV6
820 if (p->family == AF_INET6)
821 {
paulfee0f4c2004-09-13 05:12:46 +0000822 /* Left nexthop_local unchanged if so configured. */
823 if ( CHECK_FLAG (peer->af_flags[afi][safi],
824 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
825 {
826 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
827 attr->mp_nexthop_len=32;
828 else
829 attr->mp_nexthop_len=16;
830 }
831
832 /* Default nexthop_local treatment for non-RS-Clients */
833 else
834 {
paul718e3742002-12-13 20:15:29 +0000835 /* Link-local address should not be transit to different peer. */
836 attr->mp_nexthop_len = 16;
837
838 /* Set link-local address for shared network peer. */
839 if (peer->shared_network
840 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
841 {
842 memcpy (&attr->mp_nexthop_local, &peer->nexthop.v6_local,
843 IPV6_MAX_BYTELEN);
844 attr->mp_nexthop_len = 32;
845 }
846
847 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
848 address.*/
849 if (reflect)
850 attr->mp_nexthop_len = 16;
851
852 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
853 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
854 attr->mp_nexthop_len = 16;
855 }
paulfee0f4c2004-09-13 05:12:46 +0000856
857 }
paul718e3742002-12-13 20:15:29 +0000858#endif /* HAVE_IPV6 */
859
860 /* If this is EBGP peer and remove-private-AS is set. */
861 if (peer_sort (peer) == BGP_PEER_EBGP
862 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
863 && aspath_private_as_check (attr->aspath))
864 attr->aspath = aspath_empty_get ();
865
866 /* Route map & unsuppress-map apply. */
867 if (ROUTE_MAP_OUT_NAME (filter)
868 || ri->suppress)
869 {
870 info.peer = peer;
871 info.attr = attr;
872
873 /* The route reflector is not allowed to modify the attributes
874 of the reflected IBGP routes. */
875 if (peer_sort (from) == BGP_PEER_IBGP
876 && peer_sort (peer) == BGP_PEER_IBGP)
877 {
878 dummy_attr = *attr;
879 info.attr = &dummy_attr;
880 }
paulac41b2a2003-08-12 05:32:27 +0000881
882 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
883
paul718e3742002-12-13 20:15:29 +0000884 if (ri->suppress)
885 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
886 else
887 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
888
paulac41b2a2003-08-12 05:32:27 +0000889 peer->rmap_type = 0;
890
paul718e3742002-12-13 20:15:29 +0000891 if (ret == RMAP_DENYMATCH)
892 {
893 bgp_attr_flush (attr);
894 return 0;
895 }
896 }
897 return 1;
898}
899
paul94f2b392005-06-28 12:44:16 +0000900static int
paulfee0f4c2004-09-13 05:12:46 +0000901bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
902 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000903{
paulfee0f4c2004-09-13 05:12:46 +0000904 int ret;
905 char buf[SU_ADDRSTRLEN];
906 struct bgp_filter *filter;
907 struct bgp_info info;
908 struct peer *from;
909 struct bgp *bgp;
910
911 from = ri->peer;
912 filter = &rsclient->filter[afi][safi];
913 bgp = rsclient->bgp;
914
915#ifdef DISABLE_BGP_ANNOUNCE
916 return 0;
917#endif
918
919 /* Do not send back route to sender. */
920 if (from == rsclient)
921 return 0;
922
923 /* Aggregate-address suppress check. */
924 if (ri->suppress)
925 if (! UNSUPPRESS_MAP_NAME (filter))
926 return 0;
927
928 /* Default route check. */
929 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
930 PEER_STATUS_DEFAULT_ORIGINATE))
931 {
932 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
933 return 0;
934#ifdef HAVE_IPV6
935 else if (p->family == AF_INET6 && p->prefixlen == 0)
936 return 0;
937#endif /* HAVE_IPV6 */
938 }
939
940 /* If the attribute has originator-id and it is same as remote
941 peer's id. */
942 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
943 {
944 if (IPV4_ADDR_SAME (&rsclient->remote_id, &ri->attr->originator_id))
945 {
946 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000947 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000948 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
949 rsclient->host,
950 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
951 p->prefixlen);
952 return 0;
953 }
954 }
955
956 /* ORF prefix-list filter check */
957 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
958 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
959 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
960 if (rsclient->orf_plist[afi][safi])
961 {
962 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
963 return 0;
964 }
965
966 /* Output filter check. */
967 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
968 {
969 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000970 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000971 "%s [Update:SEND] %s/%d is filtered",
972 rsclient->host,
973 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
974 p->prefixlen);
975 return 0;
976 }
977
978#ifdef BGP_SEND_ASPATH_CHECK
979 /* AS path loop check. */
980 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
981 {
982 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000983 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000984 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
985 rsclient->host, rsclient->as);
986 return 0;
987 }
988#endif /* BGP_SEND_ASPATH_CHECK */
989
990 /* For modify attribute, copy it to temporary structure. */
991 *attr = *ri->attr;
992
993 /* next-hop-set */
994 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
995#ifdef HAVE_IPV6
996 || (p->family == AF_INET6 &&
997 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
998#endif /* HAVE_IPV6 */
999 )
1000 {
1001 /* Set IPv4 nexthop. */
1002 if (p->family == AF_INET)
1003 {
1004 if (safi == SAFI_MPLS_VPN)
1005 memcpy (&attr->mp_nexthop_global_in, &rsclient->nexthop.v4,
1006 IPV4_MAX_BYTELEN);
1007 else
1008 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1009 }
1010#ifdef HAVE_IPV6
1011 /* Set IPv6 nexthop. */
1012 if (p->family == AF_INET6)
1013 {
1014 /* IPv6 global nexthop must be included. */
1015 memcpy (&attr->mp_nexthop_global, &rsclient->nexthop.v6_global,
1016
1017 IPV6_MAX_BYTELEN);
1018 attr->mp_nexthop_len = 16;
1019 }
1020#endif /* HAVE_IPV6 */
1021 }
1022
1023#ifdef HAVE_IPV6
1024 if (p->family == AF_INET6)
1025 {
1026 /* Left nexthop_local unchanged if so configured. */
1027 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1028 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1029 {
1030 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1031 attr->mp_nexthop_len=32;
1032 else
1033 attr->mp_nexthop_len=16;
1034 }
1035
1036 /* Default nexthop_local treatment for RS-Clients */
1037 else
1038 {
1039 /* Announcer and RS-Client are both in the same network */
1040 if (rsclient->shared_network && from->shared_network &&
1041 (rsclient->ifindex == from->ifindex))
1042 {
1043 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1044 attr->mp_nexthop_len=32;
1045 else
1046 attr->mp_nexthop_len=16;
1047 }
1048
1049 /* Set link-local address for shared network peer. */
1050 else if (rsclient->shared_network
1051 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1052 {
1053 memcpy (&attr->mp_nexthop_local, &rsclient->nexthop.v6_local,
1054 IPV6_MAX_BYTELEN);
1055 attr->mp_nexthop_len = 32;
1056 }
1057
1058 else
1059 attr->mp_nexthop_len = 16;
1060 }
1061
1062 }
1063#endif /* HAVE_IPV6 */
1064
1065
1066 /* If this is EBGP peer and remove-private-AS is set. */
1067 if (peer_sort (rsclient) == BGP_PEER_EBGP
1068 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1069 && aspath_private_as_check (attr->aspath))
1070 attr->aspath = aspath_empty_get ();
1071
1072 /* Route map & unsuppress-map apply. */
1073 if (ROUTE_MAP_OUT_NAME (filter) || ri->suppress)
1074 {
1075 info.peer = rsclient;
1076 info.attr = attr;
1077
1078 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1079
1080 if (ri->suppress)
1081 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1082 else
1083 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1084
1085 rsclient->rmap_type = 0;
1086
1087 if (ret == RMAP_DENYMATCH)
1088 {
1089 bgp_attr_flush (attr);
1090 return 0;
1091 }
1092 }
1093
1094 return 1;
1095}
1096
1097struct bgp_info_pair
1098{
1099 struct bgp_info *old;
1100 struct bgp_info *new;
1101};
1102
paul94f2b392005-06-28 12:44:16 +00001103static void
paulfee0f4c2004-09-13 05:12:46 +00001104bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1105{
paul718e3742002-12-13 20:15:29 +00001106 struct bgp_info *new_select;
1107 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001108 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001109 struct bgp_info *ri1;
1110 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001111 struct bgp_info *nextri = NULL;
1112
paul718e3742002-12-13 20:15:29 +00001113 /* bgp deterministic-med */
1114 new_select = NULL;
1115 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1116 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1117 {
1118 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1119 continue;
1120 if (BGP_INFO_HOLDDOWN (ri1))
1121 continue;
1122
1123 new_select = ri1;
1124 if (ri1->next)
1125 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1126 {
1127 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1128 continue;
1129 if (BGP_INFO_HOLDDOWN (ri2))
1130 continue;
1131
1132 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1133 || aspath_cmp_left_confed (ri1->attr->aspath,
1134 ri2->attr->aspath))
1135 {
1136 if (bgp_info_cmp (bgp, ri2, new_select))
1137 {
1138 UNSET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
1139 new_select = ri2;
1140 }
1141
1142 SET_FLAG (ri2->flags, BGP_INFO_DMED_CHECK);
1143 }
1144 }
1145 SET_FLAG (new_select->flags, BGP_INFO_DMED_CHECK);
1146 SET_FLAG (new_select->flags, BGP_INFO_DMED_SELECTED);
1147 }
1148
1149 /* Check old selected route and new selected route. */
1150 old_select = NULL;
1151 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001152 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001153 {
1154 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1155 old_select = ri;
1156
1157 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001158 {
1159 /* reap REMOVED routes, if needs be
1160 * selected route must stay for a while longer though
1161 */
1162 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1163 && (ri != old_select))
1164 bgp_info_reap (rn, ri);
1165
1166 continue;
1167 }
paul718e3742002-12-13 20:15:29 +00001168
1169 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1170 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1171 {
1172 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
1173 continue;
1174 }
1175 UNSET_FLAG (ri->flags, BGP_INFO_DMED_CHECK);
1176 UNSET_FLAG (ri->flags, BGP_INFO_DMED_SELECTED);
1177
1178 if (bgp_info_cmp (bgp, ri, new_select))
1179 new_select = ri;
1180 }
paulb40d9392005-08-22 22:34:41 +00001181
paulfee0f4c2004-09-13 05:12:46 +00001182 result->old = old_select;
1183 result->new = new_select;
1184
1185 return;
1186}
1187
paul94f2b392005-06-28 12:44:16 +00001188static int
paulfee0f4c2004-09-13 05:12:46 +00001189bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1190 struct bgp_node *rn, struct attr *attr, afi_t afi, safi_t safi)
1191 {
1192 struct prefix *p;
1193
1194 p = &rn->p;
1195
1196 /* Announce route to Established peer. */
1197 if (peer->status != Established)
1198 return 0;
1199
1200 /* Address family configuration check. */
1201 if (! peer->afc_nego[afi][safi])
1202 return 0;
1203
1204 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1205 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1206 PEER_STATUS_ORF_WAIT_REFRESH))
1207 return 0;
1208
1209 switch (rn->table->type)
1210 {
1211 case BGP_TABLE_MAIN:
1212 /* Announcement to peer->conf. If the route is filtered,
1213 withdraw it. */
1214 if (selected && bgp_announce_check (selected, peer, p, attr, afi, safi))
1215 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1216 else
1217 bgp_adj_out_unset (rn, peer, p, afi, safi);
1218 break;
1219 case BGP_TABLE_RSCLIENT:
1220 /* Announcement to peer->conf. If the route is filtered,
1221 withdraw it. */
1222 if (selected && bgp_announce_check_rsclient
1223 (selected, peer, p, attr, afi, safi))
1224 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1225 else
1226 bgp_adj_out_unset (rn, peer, p, afi, safi);
1227 break;
1228 }
1229 return 0;
paul200df112005-06-01 11:17:05 +00001230}
paulfee0f4c2004-09-13 05:12:46 +00001231
paul200df112005-06-01 11:17:05 +00001232struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001233{
paul200df112005-06-01 11:17:05 +00001234 struct bgp *bgp;
1235 struct bgp_node *rn;
1236 afi_t afi;
1237 safi_t safi;
1238};
1239
1240static wq_item_status
1241bgp_process_rsclient (struct bgp_process_queue *pq)
1242{
1243 struct bgp *bgp = pq->bgp;
1244 struct bgp_node *rn = pq->rn;
1245 afi_t afi = pq->afi;
1246 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001247 struct bgp_info *new_select;
1248 struct bgp_info *old_select;
1249 struct bgp_info_pair old_and_new;
1250 struct attr attr;
paul1eb8ef22005-04-07 07:30:20 +00001251 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001252 struct peer *rsclient = rn->table->owner;
1253
1254 /* we shouldn't run if the clear_route_node queue is still running
1255 * or scheduled to run, or we can race with session coming up
1256 * and adding routes back before we've cleared them
1257 */
1258 if (bm->clear_node_queue && bm->clear_node_queue->thread)
1259 return WQ_QUEUE_BLOCKED;
1260
paulfee0f4c2004-09-13 05:12:46 +00001261 /* Best path selection. */
1262 bgp_best_selection (bgp, rn, &old_and_new);
1263 new_select = old_and_new.new;
1264 old_select = old_and_new.old;
1265
paul200df112005-06-01 11:17:05 +00001266 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1267 {
1268 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1269 {
1270 /* Nothing to do. */
1271 if (old_select && old_select == new_select)
1272 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1273 continue;
paulfee0f4c2004-09-13 05:12:46 +00001274
paul200df112005-06-01 11:17:05 +00001275 if (old_select)
1276 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1277 if (new_select)
1278 {
1279 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1280 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1281 }
paulfee0f4c2004-09-13 05:12:46 +00001282
paul200df112005-06-01 11:17:05 +00001283 bgp_process_announce_selected (rsclient, new_select, rn, &attr,
1284 afi, safi);
1285 }
1286 }
1287 else
1288 {
1289 bgp_process_announce_selected (rsclient, new_select, rn,
1290 &attr, afi, safi);
1291 }
paulfee0f4c2004-09-13 05:12:46 +00001292
paulb40d9392005-08-22 22:34:41 +00001293 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1294 bgp_info_reap (rn, old_select);
1295
paul200df112005-06-01 11:17:05 +00001296 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1297 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001298}
1299
paul200df112005-06-01 11:17:05 +00001300static wq_item_status
1301bgp_process_main (struct bgp_process_queue *pq)
1302{
1303 struct bgp *bgp = pq->bgp;
1304 struct bgp_node *rn = pq->rn;
1305 afi_t afi = pq->afi;
1306 safi_t safi = pq->safi;
1307 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001308 struct bgp_info *new_select;
1309 struct bgp_info *old_select;
1310 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001311 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001312 struct peer *peer;
1313 struct attr attr;
paul200df112005-06-01 11:17:05 +00001314
1315 /* we shouldn't run if the clear_route_node queue is still running
1316 * or scheduled to run, or we can race with session coming up
1317 * and adding routes back before we've cleared them
1318 */
1319 if (bm->clear_node_queue && bm->clear_node_queue->thread)
1320 return WQ_QUEUE_BLOCKED;
paulfee0f4c2004-09-13 05:12:46 +00001321
1322 /* Best path selection. */
1323 bgp_best_selection (bgp, rn, &old_and_new);
1324 old_select = old_and_new.old;
1325 new_select = old_and_new.new;
1326
1327 /* Nothing to do. */
1328 if (old_select && old_select == new_select)
1329 {
1330 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001331 {
1332 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1333 bgp_zebra_announce (p, old_select, bgp);
1334
1335 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1336 return WQ_SUCCESS;
1337 }
paulfee0f4c2004-09-13 05:12:46 +00001338 }
paul718e3742002-12-13 20:15:29 +00001339
hasso338b3422005-02-23 14:27:24 +00001340 if (old_select)
1341 UNSET_FLAG (old_select->flags, BGP_INFO_SELECTED);
1342 if (new_select)
1343 {
1344 SET_FLAG (new_select->flags, BGP_INFO_SELECTED);
1345 UNSET_FLAG (new_select->flags, BGP_INFO_ATTR_CHANGED);
1346 }
1347
1348
paul718e3742002-12-13 20:15:29 +00001349 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001350 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001351 {
paulfee0f4c2004-09-13 05:12:46 +00001352 bgp_process_announce_selected (peer, new_select, rn, &attr, afi, safi);
paul718e3742002-12-13 20:15:29 +00001353 }
1354
1355 /* FIB update. */
1356 if (safi == SAFI_UNICAST && ! bgp->name &&
1357 ! bgp_option_check (BGP_OPT_NO_FIB))
1358 {
1359 if (new_select
1360 && new_select->type == ZEBRA_ROUTE_BGP
1361 && new_select->sub_type == BGP_ROUTE_NORMAL)
1362 bgp_zebra_announce (p, new_select, bgp);
1363 else
1364 {
1365 /* Withdraw the route from the kernel. */
1366 if (old_select
1367 && old_select->type == ZEBRA_ROUTE_BGP
1368 && old_select->sub_type == BGP_ROUTE_NORMAL)
1369 bgp_zebra_withdraw (p, old_select);
1370 }
1371 }
paulb40d9392005-08-22 22:34:41 +00001372
1373 /* Reap old select bgp_info, it it has been removed */
1374 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1375 bgp_info_reap (rn, old_select);
1376
paul200df112005-06-01 11:17:05 +00001377 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1378 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001379}
1380
paul200df112005-06-01 11:17:05 +00001381static void
1382bgp_processq_del (struct bgp_process_queue *pq)
1383{
1384 bgp_unlock_node (pq->rn);
1385 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1386}
1387
1388static void
1389bgp_process_queue_init (void)
1390{
1391 bm->process_main_queue
1392 = work_queue_new (bm->master, "process_main_queue");
1393 bm->process_rsclient_queue
1394 = work_queue_new (bm->master, "process_rsclient_queue");
1395
1396 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1397 {
1398 zlog_err ("%s: Failed to allocate work queue", __func__);
1399 exit (1);
1400 }
1401
1402 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1403 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1404 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1405 bm->process_rsclient_queue->spec.del_item_data
1406 = bm->process_main_queue->spec.del_item_data;
1407 bm->process_main_queue->spec.max_retries
1408 = bm->process_main_queue->spec.max_retries = 0;
1409 bm->process_rsclient_queue->spec.hold
1410 = bm->process_main_queue->spec.hold = 500;
1411 bm->process_rsclient_queue->spec.delay
1412 = bm->process_main_queue->spec.delay = 10;
1413}
1414
1415void
paulfee0f4c2004-09-13 05:12:46 +00001416bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1417{
paul200df112005-06-01 11:17:05 +00001418 struct bgp_process_queue *pqnode;
1419
1420 /* already scheduled for processing? */
1421 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1422 return;
1423
1424 if ( (bm->process_main_queue == NULL) ||
1425 (bm->process_rsclient_queue == NULL) )
1426 bgp_process_queue_init ();
1427
1428 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1429 sizeof (struct bgp_process_queue));
1430 if (!pqnode)
1431 return;
1432
1433 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1434 pqnode->bgp = bgp;
1435 pqnode->afi = afi;
1436 pqnode->safi = safi;
1437
paulfee0f4c2004-09-13 05:12:46 +00001438 switch (rn->table->type)
1439 {
paul200df112005-06-01 11:17:05 +00001440 case BGP_TABLE_MAIN:
1441 work_queue_add (bm->process_main_queue, pqnode);
1442 break;
1443 case BGP_TABLE_RSCLIENT:
1444 work_queue_add (bm->process_rsclient_queue, pqnode);
1445 break;
paulfee0f4c2004-09-13 05:12:46 +00001446 }
paul200df112005-06-01 11:17:05 +00001447
1448 return;
paulfee0f4c2004-09-13 05:12:46 +00001449}
hasso0a486e52005-02-01 20:57:17 +00001450
paul94f2b392005-06-28 12:44:16 +00001451static int
hasso0a486e52005-02-01 20:57:17 +00001452bgp_maximum_prefix_restart_timer (struct thread *thread)
1453{
1454 struct peer *peer;
1455
1456 peer = THREAD_ARG (thread);
1457 peer->t_pmax_restart = NULL;
1458
1459 if (BGP_DEBUG (events, EVENTS))
1460 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1461 peer->host);
1462
1463 peer_clear (peer);
1464
1465 return 0;
1466}
1467
paulfee0f4c2004-09-13 05:12:46 +00001468int
paul5228ad22004-06-04 17:58:18 +00001469bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1470 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001471{
hassoe0701b72004-05-20 09:19:34 +00001472 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1473 return 0;
1474
1475 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001476 {
hassoe0701b72004-05-20 09:19:34 +00001477 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1478 && ! always)
1479 return 0;
paul718e3742002-12-13 20:15:29 +00001480
hassoe0701b72004-05-20 09:19:34 +00001481 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001482 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1483 "limit %ld", afi_safi_print (afi, safi), peer->host,
1484 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001485 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001486
hassoe0701b72004-05-20 09:19:34 +00001487 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1488 return 0;
paul718e3742002-12-13 20:15:29 +00001489
hassoe0701b72004-05-20 09:19:34 +00001490 {
paul5228ad22004-06-04 17:58:18 +00001491 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001492
1493 if (safi == SAFI_MPLS_VPN)
1494 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001495
1496 ndata[0] = (afi >> 8);
1497 ndata[1] = afi;
1498 ndata[2] = safi;
1499 ndata[3] = (peer->pmax[afi][safi] >> 24);
1500 ndata[4] = (peer->pmax[afi][safi] >> 16);
1501 ndata[5] = (peer->pmax[afi][safi] >> 8);
1502 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001503
1504 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1505 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1506 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1507 }
hasso0a486e52005-02-01 20:57:17 +00001508
1509 /* restart timer start */
1510 if (peer->pmax_restart[afi][safi])
1511 {
1512 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1513
1514 if (BGP_DEBUG (events, EVENTS))
1515 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1516 peer->host, peer->v_pmax_restart);
1517
1518 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1519 peer->v_pmax_restart);
1520 }
1521
hassoe0701b72004-05-20 09:19:34 +00001522 return 1;
paul718e3742002-12-13 20:15:29 +00001523 }
hassoe0701b72004-05-20 09:19:34 +00001524 else
1525 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1526
1527 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1528 {
1529 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1530 && ! always)
1531 return 0;
1532
1533 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001534 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1535 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1536 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001537 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1538 }
1539 else
1540 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001541 return 0;
1542}
1543
paulb40d9392005-08-22 22:34:41 +00001544/* Unconditionally remove the route from the RIB, without taking
1545 * damping into consideration (eg, because the session went down)
1546 */
paul94f2b392005-06-28 12:44:16 +00001547static void
paul718e3742002-12-13 20:15:29 +00001548bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1549 afi_t afi, safi_t safi)
1550{
paulb40d9392005-08-22 22:34:41 +00001551 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
1552 && rn->table->type == BGP_TABLE_MAIN)
paul718e3742002-12-13 20:15:29 +00001553 {
paulfee0f4c2004-09-13 05:12:46 +00001554 /* Ignore 'pcount' for RS-client tables */
1555 if ( rn->table->type == BGP_TABLE_MAIN)
1556 {
paulb40d9392005-08-22 22:34:41 +00001557 peer->pcount[afi][safi]--;
1558 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001559 }
paul718e3742002-12-13 20:15:29 +00001560 }
paulb40d9392005-08-22 22:34:41 +00001561 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001562 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00001563}
1564
paul94f2b392005-06-28 12:44:16 +00001565static void
paul718e3742002-12-13 20:15:29 +00001566bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001567 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001568{
1569 int valid;
1570 int status = BGP_DAMP_NONE;
1571
paulb40d9392005-08-22 22:34:41 +00001572 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
1573 && rn->table->type == BGP_TABLE_MAIN)
paul718e3742002-12-13 20:15:29 +00001574 {
paulb40d9392005-08-22 22:34:41 +00001575 /* Ignore 'pcount' for RS-client tables */
1576 if ( rn->table->type == BGP_TABLE_MAIN)
1577 {
1578 peer->pcount[afi][safi]--;
1579 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1580 }
paul718e3742002-12-13 20:15:29 +00001581 }
paulb40d9392005-08-22 22:34:41 +00001582
1583 /* apply dampening, if result is suppressed, we'll be retaining
1584 * the bgp_info in the RIB for historical reference.
1585 */
1586 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1587 && peer_sort (peer) == BGP_PEER_EBGP)
1588 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1589 == BGP_DAMP_SUPPRESSED)
1590 return;
paul718e3742002-12-13 20:15:29 +00001591
paul718e3742002-12-13 20:15:29 +00001592 bgp_process (peer->bgp, rn, afi, safi);
1593
paul718e3742002-12-13 20:15:29 +00001594 if (status != BGP_DAMP_USED)
paul200df112005-06-01 11:17:05 +00001595 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00001596}
1597
paul94f2b392005-06-28 12:44:16 +00001598static void
paulfee0f4c2004-09-13 05:12:46 +00001599bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1600 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1601 int sub_type, struct prefix_rd *prd, u_char *tag)
1602{
1603 struct bgp_node *rn;
1604 struct bgp *bgp;
1605 struct attr new_attr;
1606 struct attr *attr_new;
1607 struct attr *attr_new2;
1608 struct bgp_info *ri;
1609 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001610 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001611 char buf[SU_ADDRSTRLEN];
1612
1613 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1614 if (peer == rsclient)
1615 return;
1616
1617 bgp = peer->bgp;
1618 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1619
1620 /* Check previously received route. */
1621 for (ri = rn->info; ri; ri = ri->next)
1622 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1623 break;
1624
1625 /* AS path loop check. */
1626 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1627 {
1628 reason = "as-path contains our own AS;";
1629 goto filtered;
1630 }
1631
1632 /* Route reflector originator ID check. */
1633 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1634 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->originator_id))
1635 {
1636 reason = "originator is us;";
1637 goto filtered;
1638 }
1639
1640 new_attr = *attr;
1641
1642 /* Apply export policy. */
1643 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1644 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1645 {
1646 reason = "export-policy;";
1647 goto filtered;
1648 }
1649
1650 attr_new2 = bgp_attr_intern (&new_attr);
1651
1652 /* Apply import policy. */
1653 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1654 {
1655 bgp_attr_unintern (attr_new2);
1656
1657 reason = "import-policy;";
1658 goto filtered;
1659 }
1660
1661 attr_new = bgp_attr_intern (&new_attr);
1662 bgp_attr_unintern (attr_new2);
1663
1664 /* IPv4 unicast next hop check. */
1665 if (afi == AFI_IP && safi == SAFI_UNICAST)
1666 {
1667 /* Next hop must not be 0.0.0.0 nor Class E address. */
1668 if (new_attr.nexthop.s_addr == 0
1669 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1670 {
1671 bgp_attr_unintern (attr_new);
1672
1673 reason = "martian next-hop;";
1674 goto filtered;
1675 }
1676 }
1677
1678 /* If the update is implicit withdraw. */
1679 if (ri)
1680 {
1681 ri->uptime = time (NULL);
1682
1683 /* Same attribute comes in. */
1684 if (attrhash_cmp (ri->attr, attr_new))
1685 {
1686
1687 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1688
1689 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001690 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001691 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1692 peer->host,
1693 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1694 p->prefixlen, rsclient->host);
1695
1696 bgp_unlock_node (rn);
1697 bgp_attr_unintern (attr_new);
1698
1699 return;
1700 }
1701
1702 /* Received Logging. */
1703 if (BGP_DEBUG (update, UPDATE_IN))
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 /* The attribute is changed. */
1710 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1711
1712 /* Update to new attribute. */
1713 bgp_attr_unintern (ri->attr);
1714 ri->attr = attr_new;
1715
1716 /* Update MPLS tag. */
1717 if (safi == SAFI_MPLS_VPN)
1718 memcpy (ri->tag, tag, 3);
1719
1720 SET_FLAG (ri->flags, BGP_INFO_VALID);
1721
1722 /* Process change. */
1723 bgp_process (bgp, rn, afi, safi);
1724 bgp_unlock_node (rn);
1725
1726 return;
1727 }
1728
1729 /* Received Logging. */
1730 if (BGP_DEBUG (update, UPDATE_IN))
1731 {
ajsd2c1f162004-12-08 21:10:20 +00001732 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001733 peer->host,
1734 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1735 p->prefixlen, rsclient->host);
1736 }
1737
1738 /* Make new BGP info. */
1739 new = bgp_info_new ();
1740 new->type = type;
1741 new->sub_type = sub_type;
1742 new->peer = peer;
1743 new->attr = attr_new;
1744 new->uptime = time (NULL);
1745
1746 /* Update MPLS tag. */
1747 if (safi == SAFI_MPLS_VPN)
1748 memcpy (new->tag, tag, 3);
1749
1750 SET_FLAG (new->flags, BGP_INFO_VALID);
1751
1752 /* Register new BGP information. */
1753 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001754
1755 /* route_node_get lock */
1756 bgp_unlock_node (rn);
1757
paulfee0f4c2004-09-13 05:12:46 +00001758 /* Process change. */
1759 bgp_process (bgp, rn, afi, safi);
1760
1761 return;
1762
1763 filtered:
1764
1765 /* This BGP update is filtered. Log the reason then update BGP entry. */
1766 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001767 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001768 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1769 peer->host,
1770 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1771 p->prefixlen, rsclient->host, reason);
1772
1773 if (ri)
paulb40d9392005-08-22 22:34:41 +00001774 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001775
1776 bgp_unlock_node (rn);
1777
1778 return;
1779}
1780
paul94f2b392005-06-28 12:44:16 +00001781static void
paulfee0f4c2004-09-13 05:12:46 +00001782bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1783 struct peer *peer, struct prefix *p, int type, int sub_type,
1784 struct prefix_rd *prd, u_char *tag)
1785 {
1786 struct bgp_node *rn;
1787 struct bgp_info *ri;
1788 char buf[SU_ADDRSTRLEN];
1789
1790 if (rsclient == peer)
1791 return;
1792
1793 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1794
1795 /* Lookup withdrawn route. */
1796 for (ri = rn->info; ri; ri = ri->next)
1797 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1798 break;
1799
1800 /* Withdraw specified route from routing table. */
1801 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001802 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001803 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001804 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001805 "%s Can't find the route %s/%d", peer->host,
1806 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1807 p->prefixlen);
1808
1809 /* Unlock bgp_node_get() lock. */
1810 bgp_unlock_node (rn);
1811 }
1812
paul94f2b392005-06-28 12:44:16 +00001813static int
paulfee0f4c2004-09-13 05:12:46 +00001814bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001815 afi_t afi, safi_t safi, int type, int sub_type,
1816 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1817{
1818 int ret;
1819 int aspath_loop_count = 0;
1820 struct bgp_node *rn;
1821 struct bgp *bgp;
1822 struct attr new_attr;
1823 struct attr *attr_new;
1824 struct bgp_info *ri;
1825 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001826 const char *reason;
paul718e3742002-12-13 20:15:29 +00001827 char buf[SU_ADDRSTRLEN];
1828
1829 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00001830 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00001831
1832 /* When peer's soft reconfiguration enabled. Record input packet in
1833 Adj-RIBs-In. */
1834 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1835 && peer != bgp->peer_self && ! soft_reconfig)
1836 bgp_adj_in_set (rn, peer, attr);
1837
1838 /* Check previously received route. */
1839 for (ri = rn->info; ri; ri = ri->next)
1840 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1841 break;
1842
1843 /* AS path local-as loop check. */
1844 if (peer->change_local_as)
1845 {
1846 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
1847 aspath_loop_count = 1;
1848
1849 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
1850 {
1851 reason = "as-path contains our own AS;";
1852 goto filtered;
1853 }
1854 }
1855
1856 /* AS path loop check. */
1857 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
1858 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
1859 && aspath_loop_check(attr->aspath, bgp->confed_id)
1860 > peer->allowas_in[afi][safi]))
1861 {
1862 reason = "as-path contains our own AS;";
1863 goto filtered;
1864 }
1865
1866 /* Route reflector originator ID check. */
1867 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1868 && IPV4_ADDR_SAME (&bgp->router_id, &attr->originator_id))
1869 {
1870 reason = "originator is us;";
1871 goto filtered;
1872 }
1873
1874 /* Route reflector cluster ID check. */
1875 if (bgp_cluster_filter (peer, attr))
1876 {
1877 reason = "reflected from the same cluster;";
1878 goto filtered;
1879 }
1880
1881 /* Apply incoming filter. */
1882 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
1883 {
1884 reason = "filter;";
1885 goto filtered;
1886 }
1887
1888 /* Apply incoming route-map. */
1889 new_attr = *attr;
1890
1891 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
1892 {
1893 reason = "route-map;";
1894 goto filtered;
1895 }
1896
1897 /* IPv4 unicast next hop check. */
1898 if (afi == AFI_IP && safi == SAFI_UNICAST)
1899 {
1900 /* If the peer is EBGP and nexthop is not on connected route,
1901 discard it. */
1902 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
1903 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00001904 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00001905 {
1906 reason = "non-connected next-hop;";
1907 goto filtered;
1908 }
1909
1910 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
1911 must not be my own address. */
1912 if (bgp_nexthop_self (afi, &new_attr)
1913 || new_attr.nexthop.s_addr == 0
1914 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1915 {
1916 reason = "martian next-hop;";
1917 goto filtered;
1918 }
1919 }
1920
1921 attr_new = bgp_attr_intern (&new_attr);
1922
1923 /* If the update is implicit withdraw. */
1924 if (ri)
1925 {
1926 ri->uptime = time (NULL);
1927
1928 /* Same attribute comes in. */
1929 if (attrhash_cmp (ri->attr, attr_new))
1930 {
1931 UNSET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1932
1933 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1934 && peer_sort (peer) == BGP_PEER_EBGP
1935 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1936 {
1937 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001938 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00001939 peer->host,
1940 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1941 p->prefixlen);
1942
1943 peer->pcount[afi][safi]++;
1944 ret = bgp_damp_update (ri, rn, afi, safi);
1945 if (ret != BGP_DAMP_SUPPRESSED)
1946 {
1947 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1948 bgp_process (bgp, rn, afi, safi);
1949 }
1950 }
1951 else
1952 {
1953 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001954 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00001955 "%s rcvd %s/%d...duplicate ignored",
1956 peer->host,
1957 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1958 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00001959
1960 /* graceful restart STALE flag unset. */
1961 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1962 {
1963 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
1964 peer->pcount[afi][safi]++;
1965 }
paul718e3742002-12-13 20:15:29 +00001966 }
1967
1968 bgp_unlock_node (rn);
1969 bgp_attr_unintern (attr_new);
1970 return 0;
1971 }
1972
1973 /* Received Logging. */
1974 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001975 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00001976 peer->host,
1977 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1978 p->prefixlen);
1979
hasso93406d82005-02-02 14:40:33 +00001980 /* graceful restart STALE flag unset. */
1981 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
1982 {
1983 UNSET_FLAG (ri->flags, BGP_INFO_STALE);
1984 peer->pcount[afi][safi]++;
1985 }
1986
paul718e3742002-12-13 20:15:29 +00001987 /* The attribute is changed. */
1988 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1989
1990 /* Update bgp route dampening information. */
1991 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1992 && peer_sort (peer) == BGP_PEER_EBGP)
1993 {
1994 /* This is implicit withdraw so we should update dampening
1995 information. */
1996 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1997 bgp_damp_withdraw (ri, rn, afi, safi, 1);
1998 else
1999 peer->pcount[afi][safi]++;
2000 }
2001
2002 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2003
2004 /* Update to new attribute. */
2005 bgp_attr_unintern (ri->attr);
2006 ri->attr = attr_new;
2007
2008 /* Update MPLS tag. */
2009 if (safi == SAFI_MPLS_VPN)
2010 memcpy (ri->tag, tag, 3);
2011
2012 /* Update bgp route dampening information. */
2013 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2014 && peer_sort (peer) == BGP_PEER_EBGP)
2015 {
2016 /* Now we do normal update dampening. */
2017 ret = bgp_damp_update (ri, rn, afi, safi);
2018 if (ret == BGP_DAMP_SUPPRESSED)
2019 {
2020 bgp_unlock_node (rn);
2021 return 0;
2022 }
2023 }
2024
2025 /* Nexthop reachability check. */
2026 if ((afi == AFI_IP || afi == AFI_IP6)
2027 && safi == SAFI_UNICAST
2028 && (peer_sort (peer) == BGP_PEER_IBGP
2029 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002030 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002031 {
2032 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
2033 SET_FLAG (ri->flags, BGP_INFO_VALID);
2034 else
2035 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2036 }
2037 else
2038 SET_FLAG (ri->flags, BGP_INFO_VALID);
2039
2040 /* Process change. */
2041 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2042
2043 bgp_process (bgp, rn, afi, safi);
2044 bgp_unlock_node (rn);
2045 return 0;
2046 }
2047
2048 /* Received Logging. */
2049 if (BGP_DEBUG (update, UPDATE_IN))
2050 {
ajsd2c1f162004-12-08 21:10:20 +00002051 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002052 peer->host,
2053 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2054 p->prefixlen);
2055 }
2056
2057 /* Increment prefix counter */
2058 peer->pcount[afi][safi]++;
2059
2060 /* Make new BGP info. */
2061 new = bgp_info_new ();
2062 new->type = type;
2063 new->sub_type = sub_type;
2064 new->peer = peer;
2065 new->attr = attr_new;
2066 new->uptime = time (NULL);
2067
2068 /* Update MPLS tag. */
2069 if (safi == SAFI_MPLS_VPN)
2070 memcpy (new->tag, tag, 3);
2071
2072 /* Nexthop reachability check. */
2073 if ((afi == AFI_IP || afi == AFI_IP6)
2074 && safi == SAFI_UNICAST
2075 && (peer_sort (peer) == BGP_PEER_IBGP
2076 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002077 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002078 {
2079 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
2080 SET_FLAG (new->flags, BGP_INFO_VALID);
2081 else
2082 UNSET_FLAG (new->flags, BGP_INFO_VALID);
2083 }
2084 else
2085 SET_FLAG (new->flags, BGP_INFO_VALID);
2086
2087 /* Aggregate address increment. */
2088 bgp_aggregate_increment (bgp, p, new, afi, safi);
2089
2090 /* Register new BGP information. */
2091 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002092
2093 /* route_node_get lock */
2094 bgp_unlock_node (rn);
2095
paul718e3742002-12-13 20:15:29 +00002096 /* If maximum prefix count is configured and current prefix
2097 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002098 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2099 return -1;
paul718e3742002-12-13 20:15:29 +00002100
2101 /* Process change. */
2102 bgp_process (bgp, rn, afi, safi);
2103
2104 return 0;
2105
2106 /* This BGP update is filtered. Log the reason then update BGP
2107 entry. */
2108 filtered:
2109 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002110 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002111 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2112 peer->host,
2113 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2114 p->prefixlen, reason);
2115
2116 if (ri)
paulb40d9392005-08-22 22:34:41 +00002117 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002118
2119 bgp_unlock_node (rn);
2120
2121 return 0;
2122}
2123
2124int
paulfee0f4c2004-09-13 05:12:46 +00002125bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2126 afi_t afi, safi_t safi, int type, int sub_type,
2127 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2128{
2129 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002130 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002131 struct bgp *bgp;
2132 int ret;
2133
2134 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2135 soft_reconfig);
2136
2137 bgp = peer->bgp;
2138
2139 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002140 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002141 {
2142 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2143 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2144 sub_type, prd, tag);
2145 }
2146
2147 return ret;
2148}
2149
2150int
paul718e3742002-12-13 20:15:29 +00002151bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002152 afi_t afi, safi_t safi, int type, int sub_type,
2153 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002154{
2155 struct bgp *bgp;
2156 char buf[SU_ADDRSTRLEN];
2157 struct bgp_node *rn;
2158 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002159 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002160 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002161
2162 bgp = peer->bgp;
2163
paulfee0f4c2004-09-13 05:12:46 +00002164 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002165 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002166 {
2167 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2168 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2169 }
2170
paul718e3742002-12-13 20:15:29 +00002171 /* Logging. */
2172 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002173 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002174 peer->host,
2175 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2176 p->prefixlen);
2177
2178 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002179 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002180
2181 /* If peer is soft reconfiguration enabled. Record input packet for
2182 further calculation. */
2183 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2184 && peer != bgp->peer_self)
2185 bgp_adj_in_unset (rn, peer);
2186
2187 /* Lookup withdrawn route. */
2188 for (ri = rn->info; ri; ri = ri->next)
2189 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2190 break;
2191
2192 /* Withdraw specified route from routing table. */
2193 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002194 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002195 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002196 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002197 "%s Can't find the route %s/%d", peer->host,
2198 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2199 p->prefixlen);
2200
2201 /* Unlock bgp_node_get() lock. */
2202 bgp_unlock_node (rn);
2203
2204 return 0;
2205}
2206
2207void
2208bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2209{
2210 struct bgp *bgp;
2211 struct attr attr;
2212 struct aspath *aspath;
2213 struct prefix p;
2214 struct bgp_info binfo;
2215 struct peer *from;
2216 int ret = RMAP_DENYMATCH;
2217
2218 bgp = peer->bgp;
2219 from = bgp->peer_self;
2220
2221 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2222 aspath = attr.aspath;
2223 attr.local_pref = bgp->default_local_pref;
2224 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2225
2226 if (afi == AFI_IP)
2227 str2prefix ("0.0.0.0/0", &p);
2228#ifdef HAVE_IPV6
2229 else if (afi == AFI_IP6)
2230 {
2231 str2prefix ("::/0", &p);
2232
2233 /* IPv6 global nexthop must be included. */
2234 memcpy (&attr.mp_nexthop_global, &peer->nexthop.v6_global,
2235 IPV6_MAX_BYTELEN);
2236 attr.mp_nexthop_len = 16;
2237
2238 /* If the peer is on shared nextwork and we have link-local
2239 nexthop set it. */
2240 if (peer->shared_network
2241 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2242 {
2243 memcpy (&attr.mp_nexthop_local, &peer->nexthop.v6_local,
2244 IPV6_MAX_BYTELEN);
2245 attr.mp_nexthop_len = 32;
2246 }
2247 }
2248#endif /* HAVE_IPV6 */
2249 else
2250 return;
2251
2252 if (peer->default_rmap[afi][safi].name)
2253 {
2254 binfo.peer = bgp->peer_self;
2255 binfo.attr = &attr;
2256
paulfee0f4c2004-09-13 05:12:46 +00002257 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2258
paul718e3742002-12-13 20:15:29 +00002259 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2260 RMAP_BGP, &binfo);
2261
paulfee0f4c2004-09-13 05:12:46 +00002262 bgp->peer_self->rmap_type = 0;
2263
paul718e3742002-12-13 20:15:29 +00002264 if (ret == RMAP_DENYMATCH)
2265 {
2266 bgp_attr_flush (&attr);
2267 withdraw = 1;
2268 }
2269 }
2270
2271 if (withdraw)
2272 {
2273 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2274 bgp_default_withdraw_send (peer, afi, safi);
2275 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2276 }
2277 else
2278 {
2279 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2280 bgp_default_update_send (peer, &attr, afi, safi, from);
2281 }
2282
2283 aspath_unintern (aspath);
2284}
2285
2286static void
2287bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002288 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002289{
2290 struct bgp_node *rn;
2291 struct bgp_info *ri;
2292 struct attr attr;
2293
2294 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002295 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002296
2297 if (safi != SAFI_MPLS_VPN
2298 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2299 bgp_default_originate (peer, afi, safi, 0);
2300
2301 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2302 for (ri = rn->info; ri; ri = ri->next)
2303 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2304 {
paulfee0f4c2004-09-13 05:12:46 +00002305 if ( (rsclient) ?
2306 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2307 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002308 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2309 else
2310 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2311 }
2312}
2313
2314void
2315bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2316{
2317 struct bgp_node *rn;
2318 struct bgp_table *table;
2319
2320 if (peer->status != Established)
2321 return;
2322
2323 if (! peer->afc_nego[afi][safi])
2324 return;
2325
2326 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2327 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2328 return;
2329
2330 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002331 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002332 else
2333 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2334 rn = bgp_route_next(rn))
2335 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002336 bgp_announce_table (peer, afi, safi, table, 0);
2337
2338 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2339 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002340}
2341
2342void
2343bgp_announce_route_all (struct peer *peer)
2344{
2345 afi_t afi;
2346 safi_t safi;
2347
2348 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2349 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2350 bgp_announce_route (peer, afi, safi);
2351}
2352
2353static void
paulfee0f4c2004-09-13 05:12:46 +00002354bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2355 safi_t safi, struct bgp_table *table)
2356{
2357 struct bgp_node *rn;
2358 struct bgp_adj_in *ain;
2359
2360 if (! table)
2361 table = rsclient->bgp->rib[afi][safi];
2362
2363 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2364 for (ain = rn->adj_in; ain; ain = ain->next)
2365 {
2366 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2367 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2368 }
2369}
2370
2371void
2372bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2373{
2374 struct bgp_table *table;
2375 struct bgp_node *rn;
2376
2377 if (safi != SAFI_MPLS_VPN)
2378 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2379
2380 else
2381 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2382 rn = bgp_route_next (rn))
2383 if ((table = rn->info) != NULL)
2384 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2385}
2386
2387static void
paul718e3742002-12-13 20:15:29 +00002388bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2389 struct bgp_table *table)
2390{
2391 int ret;
2392 struct bgp_node *rn;
2393 struct bgp_adj_in *ain;
2394
2395 if (! table)
2396 table = peer->bgp->rib[afi][safi];
2397
2398 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2399 for (ain = rn->adj_in; ain; ain = ain->next)
2400 {
2401 if (ain->peer == peer)
2402 {
2403 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2404 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2405 NULL, NULL, 1);
2406 if (ret < 0)
2407 {
2408 bgp_unlock_node (rn);
2409 return;
2410 }
2411 continue;
2412 }
2413 }
2414}
2415
2416void
2417bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2418{
2419 struct bgp_node *rn;
2420 struct bgp_table *table;
2421
2422 if (peer->status != Established)
2423 return;
2424
2425 if (safi != SAFI_MPLS_VPN)
2426 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2427 else
2428 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2429 rn = bgp_route_next (rn))
2430 if ((table = rn->info) != NULL)
2431 bgp_soft_reconfig_table (peer, afi, safi, table);
2432}
2433
paul200df112005-06-01 11:17:05 +00002434struct bgp_clear_node_queue
2435{
2436 struct bgp_node *rn;
2437 struct peer *peer;
2438 afi_t afi;
2439 safi_t safi;
2440};
2441
2442static wq_item_status
2443bgp_clear_route_node (struct bgp_clear_node_queue *cq)
2444{
2445 struct bgp_adj_in *ain;
2446 struct bgp_adj_out *aout;
2447 struct bgp_info *ri;
2448
2449 assert (cq->rn && cq->peer);
2450
2451 for (ri = cq->rn->info; ri; ri = ri->next)
2452 if (ri->peer == cq->peer)
2453 {
2454 /* graceful restart STALE flag set. */
2455 if (CHECK_FLAG (cq->peer->sflags, PEER_STATUS_NSF_WAIT)
2456 && cq->peer->nsf[cq->afi][cq->safi]
2457 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
2458 && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY)
2459 && ! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
2460 {
2461 SET_FLAG (ri->flags, BGP_INFO_STALE);
2462 cq->peer->pcount[cq->afi][cq->safi]--;
2463 }
2464 else
2465 bgp_rib_remove (cq->rn, ri, cq->peer, cq->afi, cq->safi);
2466 break;
2467 }
2468 for (ain = cq->rn->adj_in; ain; ain = ain->next)
2469 if (ain->peer == cq->peer)
2470 {
2471 bgp_adj_in_remove (cq->rn, ain);
2472 bgp_unlock_node (cq->rn);
2473 break;
2474 }
2475 for (aout = cq->rn->adj_out; aout; aout = aout->next)
2476 if (aout->peer == cq->peer)
2477 {
2478 bgp_adj_out_remove (cq->rn, aout, cq->peer, cq->afi, cq->safi);
2479 bgp_unlock_node (cq->rn);
2480 break;
2481 }
2482 return WQ_SUCCESS;
2483}
2484
2485static void
2486bgp_clear_node_queue_del (struct bgp_clear_node_queue *cq)
2487{
2488 bgp_unlock_node (cq->rn);
2489 peer_unlock (cq->peer); /* bgp_clear_node_queue_del */
2490 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cq);
2491}
2492
2493static void
paul94f2b392005-06-28 12:44:16 +00002494bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002495{
2496 /* unplug the 2 processing queues */
2497 if (bm->process_main_queue)
2498 work_queue_unplug (bm->process_main_queue);
2499 if (bm->process_rsclient_queue)
2500 work_queue_unplug (bm->process_rsclient_queue);
2501}
2502
2503static void
2504bgp_clear_node_queue_init (void)
2505{
2506 if ( (bm->clear_node_queue
2507 = work_queue_new (bm->master, "clear_route_node")) == NULL)
2508 {
2509 zlog_err ("%s: Failed to allocate work queue", __func__);
2510 exit (1);
2511 }
2512 bm->clear_node_queue->spec.hold = 10;
2513 bm->clear_node_queue->spec.delay = 0; /* no gathering to be gained */
2514 bm->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2515 bm->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2516 bm->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2517 bm->clear_node_queue->spec.max_retries = 0;
2518}
2519
paul718e3742002-12-13 20:15:29 +00002520static void
2521bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002522 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002523{
paul200df112005-06-01 11:17:05 +00002524 struct bgp_clear_node_queue *cqnode;
paul718e3742002-12-13 20:15:29 +00002525 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002526
paul718e3742002-12-13 20:15:29 +00002527 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002528 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002529
hasso6cf159b2005-03-21 10:28:14 +00002530 /* If still no table => afi/safi isn't configured at all or smth. */
2531 if (! table)
2532 return;
2533
paul200df112005-06-01 11:17:05 +00002534 if (bm->clear_node_queue == NULL)
2535 bgp_clear_node_queue_init ();
2536
2537 /* plug the two bgp_process queues to avoid any chance of racing
2538 * with a session coming back up and adding routes before we've
2539 * cleared them all. We'll unplug them with completion callback.
2540 */
2541 if (bm->process_main_queue)
2542 work_queue_plug (bm->process_main_queue);
2543 if (bm->process_rsclient_queue)
2544 work_queue_plug (bm->process_rsclient_queue);
2545
paul718e3742002-12-13 20:15:29 +00002546 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2547 {
paul200df112005-06-01 11:17:05 +00002548 if (rn->info == NULL)
2549 continue;
2550
2551 if ( (cqnode = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2552 sizeof (struct bgp_clear_node_queue))) == NULL)
2553 continue;
2554
2555 cqnode->rn = bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2556 cqnode->afi = afi;
2557 cqnode->safi = safi;
2558 cqnode->peer = peer_lock (peer); /* bgp_clear_node_queue_del */
2559 work_queue_add (bm->clear_node_queue, cqnode);
paul718e3742002-12-13 20:15:29 +00002560 }
paul200df112005-06-01 11:17:05 +00002561 return;
paul718e3742002-12-13 20:15:29 +00002562}
2563
2564void
2565bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2566{
2567 struct bgp_node *rn;
2568 struct bgp_table *table;
paulfee0f4c2004-09-13 05:12:46 +00002569 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002570 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002571
paul718e3742002-12-13 20:15:29 +00002572 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002573 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002574 else
2575 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2576 rn = bgp_route_next (rn))
2577 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002578 bgp_clear_route_table (peer, afi, safi, table, NULL);
2579
paul1eb8ef22005-04-07 07:30:20 +00002580 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002581 {
2582 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2583 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2584 }
paul718e3742002-12-13 20:15:29 +00002585}
2586
2587void
2588bgp_clear_route_all (struct peer *peer)
2589{
2590 afi_t afi;
2591 safi_t safi;
2592
2593 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2594 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2595 bgp_clear_route (peer, afi, safi);
2596}
2597
2598void
2599bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2600{
2601 struct bgp_table *table;
2602 struct bgp_node *rn;
2603 struct bgp_adj_in *ain;
2604
2605 table = peer->bgp->rib[afi][safi];
2606
2607 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2608 for (ain = rn->adj_in; ain ; ain = ain->next)
2609 if (ain->peer == peer)
2610 {
2611 bgp_adj_in_remove (rn, ain);
2612 bgp_unlock_node (rn);
2613 break;
2614 }
2615}
hasso93406d82005-02-02 14:40:33 +00002616
2617void
2618bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2619{
2620 struct bgp_node *rn;
2621 struct bgp_info *ri;
2622 struct bgp_table *table;
2623
2624 table = peer->bgp->rib[afi][safi];
2625
2626 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2627 {
2628 for (ri = rn->info; ri; ri = ri->next)
2629 if (ri->peer == peer)
2630 {
2631 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2632 bgp_rib_remove (rn, ri, peer, afi, safi);
2633 break;
2634 }
2635 }
2636}
paul718e3742002-12-13 20:15:29 +00002637
2638/* Delete all kernel routes. */
2639void
paul545acaf2004-04-20 15:13:15 +00002640bgp_cleanup_routes ()
paul718e3742002-12-13 20:15:29 +00002641{
2642 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002643 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002644 struct bgp_node *rn;
2645 struct bgp_table *table;
2646 struct bgp_info *ri;
2647
paul1eb8ef22005-04-07 07:30:20 +00002648 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002649 {
2650 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2651
2652 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2653 for (ri = rn->info; ri; ri = ri->next)
2654 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2655 && ri->type == ZEBRA_ROUTE_BGP
2656 && ri->sub_type == BGP_ROUTE_NORMAL)
2657 bgp_zebra_withdraw (&rn->p, ri);
2658
2659 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2660
2661 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2662 for (ri = rn->info; ri; ri = ri->next)
2663 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2664 && ri->type == ZEBRA_ROUTE_BGP
2665 && ri->sub_type == BGP_ROUTE_NORMAL)
2666 bgp_zebra_withdraw (&rn->p, ri);
2667 }
2668}
2669
2670void
2671bgp_reset ()
2672{
2673 vty_reset ();
2674 bgp_zclient_reset ();
2675 access_list_reset ();
2676 prefix_list_reset ();
2677}
2678
2679/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2680 value. */
2681int
2682bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2683{
2684 u_char *pnt;
2685 u_char *lim;
2686 struct prefix p;
2687 int psize;
2688 int ret;
2689
2690 /* Check peer status. */
2691 if (peer->status != Established)
2692 return 0;
2693
2694 pnt = packet->nlri;
2695 lim = pnt + packet->length;
2696
2697 for (; pnt < lim; pnt += psize)
2698 {
2699 /* Clear prefix structure. */
2700 memset (&p, 0, sizeof (struct prefix));
2701
2702 /* Fetch prefix length. */
2703 p.prefixlen = *pnt++;
2704 p.family = afi2family (packet->afi);
2705
2706 /* Already checked in nlri_sanity_check(). We do double check
2707 here. */
2708 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2709 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2710 return -1;
2711
2712 /* Packet size overflow check. */
2713 psize = PSIZE (p.prefixlen);
2714
2715 /* When packet overflow occur return immediately. */
2716 if (pnt + psize > lim)
2717 return -1;
2718
2719 /* Fetch prefix from NLRI packet. */
2720 memcpy (&p.u.prefix, pnt, psize);
2721
2722 /* Check address. */
2723 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2724 {
2725 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
2726 {
paulf5ba3872004-07-09 12:11:31 +00002727 /*
2728 * From draft-ietf-idr-bgp4-22, Section 6.3:
2729 * If a BGP router receives an UPDATE message with a
2730 * semantically incorrect NLRI field, in which a prefix is
2731 * semantically incorrect (eg. an unexpected multicast IP
2732 * address), it should ignore the prefix.
2733 */
paul718e3742002-12-13 20:15:29 +00002734 zlog (peer->log, LOG_ERR,
2735 "IPv4 unicast NLRI is multicast address %s",
2736 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00002737
paul718e3742002-12-13 20:15:29 +00002738 return -1;
2739 }
2740 }
2741
2742#ifdef HAVE_IPV6
2743 /* Check address. */
2744 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
2745 {
2746 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2747 {
2748 char buf[BUFSIZ];
2749
2750 zlog (peer->log, LOG_WARNING,
2751 "IPv6 link-local NLRI received %s ignore this NLRI",
2752 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
2753
2754 continue;
2755 }
2756 }
2757#endif /* HAVE_IPV6 */
2758
2759 /* Normal process. */
2760 if (attr)
2761 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
2762 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
2763 else
2764 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
2765 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2766
2767 /* Address family configuration mismatch or maximum-prefix count
2768 overflow. */
2769 if (ret < 0)
2770 return -1;
2771 }
2772
2773 /* Packet length consistency check. */
2774 if (pnt != lim)
2775 return -1;
2776
2777 return 0;
2778}
2779
2780/* NLRI encode syntax check routine. */
2781int
2782bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
2783 bgp_size_t length)
2784{
2785 u_char *end;
2786 u_char prefixlen;
2787 int psize;
2788
2789 end = pnt + length;
2790
2791 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
2792 syntactic validity. If the field is syntactically incorrect,
2793 then the Error Subcode is set to Invalid Network Field. */
2794
2795 while (pnt < end)
2796 {
2797 prefixlen = *pnt++;
2798
2799 /* Prefix length check. */
2800 if ((afi == AFI_IP && prefixlen > 32)
2801 || (afi == AFI_IP6 && prefixlen > 128))
2802 {
2803 plog_err (peer->log,
2804 "%s [Error] Update packet error (wrong prefix length %d)",
2805 peer->host, prefixlen);
2806 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2807 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2808 return -1;
2809 }
2810
2811 /* Packet size overflow check. */
2812 psize = PSIZE (prefixlen);
2813
2814 if (pnt + psize > end)
2815 {
2816 plog_err (peer->log,
2817 "%s [Error] Update packet error"
2818 " (prefix data overflow prefix size is %d)",
2819 peer->host, psize);
2820 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2821 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2822 return -1;
2823 }
2824
2825 pnt += psize;
2826 }
2827
2828 /* Packet length consistency check. */
2829 if (pnt != end)
2830 {
2831 plog_err (peer->log,
2832 "%s [Error] Update packet error"
2833 " (prefix length mismatch with total length)",
2834 peer->host);
2835 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2836 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2837 return -1;
2838 }
2839 return 0;
2840}
2841
paul94f2b392005-06-28 12:44:16 +00002842static struct bgp_static *
paul718e3742002-12-13 20:15:29 +00002843bgp_static_new ()
2844{
2845 struct bgp_static *new;
2846 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
2847 memset (new, 0, sizeof (struct bgp_static));
2848 return new;
2849}
2850
paul94f2b392005-06-28 12:44:16 +00002851static void
paul718e3742002-12-13 20:15:29 +00002852bgp_static_free (struct bgp_static *bgp_static)
2853{
2854 if (bgp_static->rmap.name)
2855 free (bgp_static->rmap.name);
2856 XFREE (MTYPE_BGP_STATIC, bgp_static);
2857}
2858
paul94f2b392005-06-28 12:44:16 +00002859static void
paulfee0f4c2004-09-13 05:12:46 +00002860bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
2861 struct prefix *p, afi_t afi, safi_t safi)
2862{
2863 struct bgp_node *rn;
2864 struct bgp_info *ri;
2865
2866 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2867
2868 /* Check selected route and self inserted route. */
2869 for (ri = rn->info; ri; ri = ri->next)
2870 if (ri->peer == bgp->peer_self
2871 && ri->type == ZEBRA_ROUTE_BGP
2872 && ri->sub_type == BGP_ROUTE_STATIC)
2873 break;
2874
2875 /* Withdraw static BGP route from routing table. */
2876 if (ri)
2877 {
2878 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2879 bgp_process (bgp, rn, afi, safi);
2880 bgp_info_delete (rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00002881 }
2882
2883 /* Unlock bgp_node_lookup. */
2884 bgp_unlock_node (rn);
2885}
2886
paul94f2b392005-06-28 12:44:16 +00002887static void
paulfee0f4c2004-09-13 05:12:46 +00002888bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
2889 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
2890{
2891 struct bgp_node *rn;
2892 struct bgp_info *ri;
2893 struct bgp_info *new;
2894 struct bgp_info info;
2895 struct attr new_attr;
2896 struct attr *attr_new;
2897 struct attr attr;
2898 struct bgp *bgp;
2899 int ret;
2900 char buf[SU_ADDRSTRLEN];
2901
2902 bgp = rsclient->bgp;
2903
2904 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2905
2906 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2907 if (bgp_static)
2908 {
2909 attr.nexthop = bgp_static->igpnexthop;
2910 attr.med = bgp_static->igpmetric;
2911 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
2912 }
2913
2914 new_attr = attr;
2915
2916 /* Apply network route-map for export to this rsclient. */
2917 if (bgp_static->rmap.name)
2918 {
2919 info.peer = rsclient;
2920 info.attr = &new_attr;
2921
2922 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
2923 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
2924
2925 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
2926
2927 rsclient->rmap_type = 0;
2928
2929 if (ret == RMAP_DENYMATCH)
2930 {
2931 /* Free uninterned attribute. */
2932 bgp_attr_flush (&new_attr);
2933
2934 /* Unintern original. */
2935 aspath_unintern (attr.aspath);
2936 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2937
2938 return;
2939 }
2940 attr_new = bgp_attr_intern (&new_attr);
2941 }
2942 else
2943 attr_new = bgp_attr_intern (&attr);
2944
2945 new_attr = *attr_new;
2946
2947 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
2948
2949 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) == RMAP_DENY)
2950{
2951 /* This BGP update is filtered. Log the reason then update BGP entry. */
2952 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002953 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002954 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
2955 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2956 p->prefixlen, rsclient->host);
2957
2958 bgp->peer_self->rmap_type = 0;
2959
2960 bgp_attr_unintern (attr_new);
2961 aspath_unintern (attr.aspath);
2962
2963 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2964
2965 return;
2966 }
2967
2968 bgp->peer_self->rmap_type = 0;
2969
2970 bgp_attr_unintern (attr_new);
2971 attr_new = bgp_attr_intern (&new_attr);
2972
2973 for (ri = rn->info; ri; ri = ri->next)
2974 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
2975 && ri->sub_type == BGP_ROUTE_STATIC)
2976 break;
2977
2978 if (ri)
2979 {
2980 if (attrhash_cmp (ri->attr, attr_new))
2981 {
2982 bgp_unlock_node (rn);
2983 bgp_attr_unintern (attr_new);
2984 aspath_unintern (attr.aspath);
2985 return;
2986 }
2987 else
2988 {
2989 /* The attribute is changed. */
2990 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
2991
2992 /* Rewrite BGP route information. */
2993 bgp_attr_unintern (ri->attr);
2994 ri->attr = attr_new;
2995 ri->uptime = time (NULL);
2996
2997 /* Process change. */
2998 bgp_process (bgp, rn, afi, safi);
2999 bgp_unlock_node (rn);
3000 aspath_unintern (attr.aspath);
3001 return;
3002 }
3003}
3004
3005 /* Make new BGP info. */
3006 new = bgp_info_new ();
3007 new->type = ZEBRA_ROUTE_BGP;
3008 new->sub_type = BGP_ROUTE_STATIC;
3009 new->peer = bgp->peer_self;
3010 SET_FLAG (new->flags, BGP_INFO_VALID);
3011 new->attr = attr_new;
3012 new->uptime = time (NULL);
3013
3014 /* Register new BGP information. */
3015 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003016
3017 /* route_node_get lock */
3018 bgp_unlock_node (rn);
3019
paulfee0f4c2004-09-13 05:12:46 +00003020 /* Process change. */
3021 bgp_process (bgp, rn, afi, safi);
3022
3023 /* Unintern original. */
3024 aspath_unintern (attr.aspath);
3025}
3026
paul94f2b392005-06-28 12:44:16 +00003027static void
paulfee0f4c2004-09-13 05:12:46 +00003028bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003029 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3030{
3031 struct bgp_node *rn;
3032 struct bgp_info *ri;
3033 struct bgp_info *new;
3034 struct bgp_info info;
3035 struct attr attr;
paul286e1e72003-08-08 00:24:31 +00003036 struct attr attr_tmp;
paul718e3742002-12-13 20:15:29 +00003037 struct attr *attr_new;
3038 int ret;
3039
paulfee0f4c2004-09-13 05:12:46 +00003040 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003041
3042 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3043 if (bgp_static)
3044 {
3045 attr.nexthop = bgp_static->igpnexthop;
3046 attr.med = bgp_static->igpmetric;
3047 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3048 }
3049
3050 /* Apply route-map. */
3051 if (bgp_static->rmap.name)
3052 {
paul286e1e72003-08-08 00:24:31 +00003053 attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003054 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003055 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003056
paulfee0f4c2004-09-13 05:12:46 +00003057 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3058
paul718e3742002-12-13 20:15:29 +00003059 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003060
paulfee0f4c2004-09-13 05:12:46 +00003061 bgp->peer_self->rmap_type = 0;
3062
paul718e3742002-12-13 20:15:29 +00003063 if (ret == RMAP_DENYMATCH)
3064 {
3065 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003066 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003067
3068 /* Unintern original. */
3069 aspath_unintern (attr.aspath);
3070 bgp_static_withdraw (bgp, p, afi, safi);
3071 return;
3072 }
paul286e1e72003-08-08 00:24:31 +00003073 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003074 }
paul286e1e72003-08-08 00:24:31 +00003075 else
3076 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003077
3078 for (ri = rn->info; ri; ri = ri->next)
3079 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3080 && ri->sub_type == BGP_ROUTE_STATIC)
3081 break;
3082
3083 if (ri)
3084 {
3085 if (attrhash_cmp (ri->attr, attr_new))
3086 {
3087 bgp_unlock_node (rn);
3088 bgp_attr_unintern (attr_new);
3089 aspath_unintern (attr.aspath);
3090 return;
3091 }
3092 else
3093 {
3094 /* The attribute is changed. */
3095 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3096
3097 /* Rewrite BGP route information. */
3098 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3099 bgp_attr_unintern (ri->attr);
3100 ri->attr = attr_new;
3101 ri->uptime = time (NULL);
3102
3103 /* Process change. */
3104 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3105 bgp_process (bgp, rn, afi, safi);
3106 bgp_unlock_node (rn);
3107 aspath_unintern (attr.aspath);
3108 return;
3109 }
3110 }
3111
3112 /* Make new BGP info. */
3113 new = bgp_info_new ();
3114 new->type = ZEBRA_ROUTE_BGP;
3115 new->sub_type = BGP_ROUTE_STATIC;
3116 new->peer = bgp->peer_self;
3117 SET_FLAG (new->flags, BGP_INFO_VALID);
3118 new->attr = attr_new;
3119 new->uptime = time (NULL);
3120
3121 /* Aggregate address increment. */
3122 bgp_aggregate_increment (bgp, p, new, afi, safi);
3123
3124 /* Register new BGP information. */
3125 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003126
3127 /* route_node_get lock */
3128 bgp_unlock_node (rn);
3129
paul718e3742002-12-13 20:15:29 +00003130 /* Process change. */
3131 bgp_process (bgp, rn, afi, safi);
3132
3133 /* Unintern original. */
3134 aspath_unintern (attr.aspath);
3135}
3136
3137void
paulfee0f4c2004-09-13 05:12:46 +00003138bgp_static_update (struct bgp *bgp, struct prefix *p,
3139 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3140{
3141 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003142 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003143
3144 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3145
paul1eb8ef22005-04-07 07:30:20 +00003146 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003147 {
3148 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
3149 }
3150}
3151
paul94f2b392005-06-28 12:44:16 +00003152static void
paul718e3742002-12-13 20:15:29 +00003153bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3154 u_char safi, struct prefix_rd *prd, u_char *tag)
3155{
3156 struct bgp_node *rn;
3157 struct bgp_info *new;
3158
paulfee0f4c2004-09-13 05:12:46 +00003159 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003160
3161 /* Make new BGP info. */
3162 new = bgp_info_new ();
3163 new->type = ZEBRA_ROUTE_BGP;
3164 new->sub_type = BGP_ROUTE_STATIC;
3165 new->peer = bgp->peer_self;
3166 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3167 SET_FLAG (new->flags, BGP_INFO_VALID);
3168 new->uptime = time (NULL);
3169 memcpy (new->tag, tag, 3);
3170
3171 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003172 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003173
3174 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003175 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003176
paul200df112005-06-01 11:17:05 +00003177 /* route_node_get lock */
3178 bgp_unlock_node (rn);
3179
paul718e3742002-12-13 20:15:29 +00003180 /* Process change. */
3181 bgp_process (bgp, rn, afi, safi);
3182}
3183
3184void
3185bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3186 safi_t safi)
3187{
3188 struct bgp_node *rn;
3189 struct bgp_info *ri;
3190
paulfee0f4c2004-09-13 05:12:46 +00003191 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003192
3193 /* Check selected route and self inserted route. */
3194 for (ri = rn->info; ri; ri = ri->next)
3195 if (ri->peer == bgp->peer_self
3196 && ri->type == ZEBRA_ROUTE_BGP
3197 && ri->sub_type == BGP_ROUTE_STATIC)
3198 break;
3199
3200 /* Withdraw static BGP route from routing table. */
3201 if (ri)
3202 {
3203 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3204 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3205 bgp_process (bgp, rn, afi, safi);
3206 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003207 }
3208
3209 /* Unlock bgp_node_lookup. */
3210 bgp_unlock_node (rn);
3211}
3212
3213void
paulfee0f4c2004-09-13 05:12:46 +00003214bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3215{
3216 struct bgp_static *bgp_static;
3217 struct bgp *bgp;
3218 struct bgp_node *rn;
3219 struct prefix *p;
3220
3221 bgp = rsclient->bgp;
3222
3223 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3224 if ((bgp_static = rn->info) != NULL)
3225 {
3226 p = &rn->p;
3227
3228 bgp_static_update_rsclient (rsclient, p, bgp_static,
3229 afi, safi);
3230 }
3231}
3232
paul94f2b392005-06-28 12:44:16 +00003233static void
paul718e3742002-12-13 20:15:29 +00003234bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3235 u_char safi, struct prefix_rd *prd, u_char *tag)
3236{
3237 struct bgp_node *rn;
3238 struct bgp_info *ri;
3239
paulfee0f4c2004-09-13 05:12:46 +00003240 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003241
3242 /* Check selected route and self inserted route. */
3243 for (ri = rn->info; ri; ri = ri->next)
3244 if (ri->peer == bgp->peer_self
3245 && ri->type == ZEBRA_ROUTE_BGP
3246 && ri->sub_type == BGP_ROUTE_STATIC)
3247 break;
3248
3249 /* Withdraw static BGP route from routing table. */
3250 if (ri)
3251 {
3252 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3253 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3254 bgp_process (bgp, rn, afi, safi);
3255 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00003256 }
3257
3258 /* Unlock bgp_node_lookup. */
3259 bgp_unlock_node (rn);
3260}
3261
3262/* Configure static BGP network. When user don't run zebra, static
3263 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003264static int
paulfd79ac92004-10-13 05:06:08 +00003265bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3266 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003267{
3268 int ret;
3269 struct prefix p;
3270 struct bgp_static *bgp_static;
3271 struct bgp_node *rn;
3272 int need_update = 0;
3273
3274 /* Convert IP prefix string to struct prefix. */
3275 ret = str2prefix (ip_str, &p);
3276 if (! ret)
3277 {
3278 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3279 return CMD_WARNING;
3280 }
3281#ifdef HAVE_IPV6
3282 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3283 {
3284 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3285 VTY_NEWLINE);
3286 return CMD_WARNING;
3287 }
3288#endif /* HAVE_IPV6 */
3289
3290 apply_mask (&p);
3291
3292 /* Set BGP static route configuration. */
3293 rn = bgp_node_get (bgp->route[afi][safi], &p);
3294
3295 if (rn->info)
3296 {
3297 /* Configuration change. */
3298 bgp_static = rn->info;
3299
3300 /* Check previous routes are installed into BGP. */
3301 if (! bgp_static->backdoor && bgp_static->valid)
3302 need_update = 1;
3303
3304 bgp_static->backdoor = backdoor;
3305 if (rmap)
3306 {
3307 if (bgp_static->rmap.name)
3308 free (bgp_static->rmap.name);
3309 bgp_static->rmap.name = strdup (rmap);
3310 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3311 }
3312 else
3313 {
3314 if (bgp_static->rmap.name)
3315 free (bgp_static->rmap.name);
3316 bgp_static->rmap.name = NULL;
3317 bgp_static->rmap.map = NULL;
3318 bgp_static->valid = 0;
3319 }
3320 bgp_unlock_node (rn);
3321 }
3322 else
3323 {
3324 /* New configuration. */
3325 bgp_static = bgp_static_new ();
3326 bgp_static->backdoor = backdoor;
3327 bgp_static->valid = 0;
3328 bgp_static->igpmetric = 0;
3329 bgp_static->igpnexthop.s_addr = 0;
3330 if (rmap)
3331 {
3332 if (bgp_static->rmap.name)
3333 free (bgp_static->rmap.name);
3334 bgp_static->rmap.name = strdup (rmap);
3335 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3336 }
3337 rn->info = bgp_static;
3338 }
3339
3340 /* If BGP scan is not enabled, we should install this route here. */
3341 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3342 {
3343 bgp_static->valid = 1;
3344
3345 if (need_update)
3346 bgp_static_withdraw (bgp, &p, afi, safi);
3347
3348 if (! bgp_static->backdoor)
3349 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3350 }
3351
3352 return CMD_SUCCESS;
3353}
3354
3355/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003356static int
paulfd79ac92004-10-13 05:06:08 +00003357bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003358 u_int16_t afi, u_char safi)
3359{
3360 int ret;
3361 struct prefix p;
3362 struct bgp_static *bgp_static;
3363 struct bgp_node *rn;
3364
3365 /* Convert IP prefix string to struct prefix. */
3366 ret = str2prefix (ip_str, &p);
3367 if (! ret)
3368 {
3369 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3370 return CMD_WARNING;
3371 }
3372#ifdef HAVE_IPV6
3373 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3374 {
3375 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3376 VTY_NEWLINE);
3377 return CMD_WARNING;
3378 }
3379#endif /* HAVE_IPV6 */
3380
3381 apply_mask (&p);
3382
3383 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3384 if (! rn)
3385 {
3386 vty_out (vty, "%% Can't find specified static route configuration.%s",
3387 VTY_NEWLINE);
3388 return CMD_WARNING;
3389 }
3390
3391 bgp_static = rn->info;
3392
3393 /* Update BGP RIB. */
3394 if (! bgp_static->backdoor)
3395 bgp_static_withdraw (bgp, &p, afi, safi);
3396
3397 /* Clear configuration. */
3398 bgp_static_free (bgp_static);
3399 rn->info = NULL;
3400 bgp_unlock_node (rn);
3401 bgp_unlock_node (rn);
3402
3403 return CMD_SUCCESS;
3404}
3405
3406/* Called from bgp_delete(). Delete all static routes from the BGP
3407 instance. */
3408void
3409bgp_static_delete (struct bgp *bgp)
3410{
3411 afi_t afi;
3412 safi_t safi;
3413 struct bgp_node *rn;
3414 struct bgp_node *rm;
3415 struct bgp_table *table;
3416 struct bgp_static *bgp_static;
3417
3418 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3419 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3420 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3421 if (rn->info != NULL)
3422 {
3423 if (safi == SAFI_MPLS_VPN)
3424 {
3425 table = rn->info;
3426
3427 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3428 {
3429 bgp_static = rn->info;
3430 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3431 AFI_IP, SAFI_MPLS_VPN,
3432 (struct prefix_rd *)&rn->p,
3433 bgp_static->tag);
3434 bgp_static_free (bgp_static);
3435 rn->info = NULL;
3436 bgp_unlock_node (rn);
3437 }
3438 }
3439 else
3440 {
3441 bgp_static = rn->info;
3442 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3443 bgp_static_free (bgp_static);
3444 rn->info = NULL;
3445 bgp_unlock_node (rn);
3446 }
3447 }
3448}
3449
3450int
paulfd79ac92004-10-13 05:06:08 +00003451bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3452 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003453{
3454 int ret;
3455 struct prefix p;
3456 struct prefix_rd prd;
3457 struct bgp *bgp;
3458 struct bgp_node *prn;
3459 struct bgp_node *rn;
3460 struct bgp_table *table;
3461 struct bgp_static *bgp_static;
3462 u_char tag[3];
3463
3464 bgp = vty->index;
3465
3466 ret = str2prefix (ip_str, &p);
3467 if (! ret)
3468 {
3469 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3470 return CMD_WARNING;
3471 }
3472 apply_mask (&p);
3473
3474 ret = str2prefix_rd (rd_str, &prd);
3475 if (! ret)
3476 {
3477 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3478 return CMD_WARNING;
3479 }
3480
3481 ret = str2tag (tag_str, tag);
3482 if (! ret)
3483 {
3484 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3485 return CMD_WARNING;
3486 }
3487
3488 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3489 (struct prefix *)&prd);
3490 if (prn->info == NULL)
3491 prn->info = bgp_table_init ();
3492 else
3493 bgp_unlock_node (prn);
3494 table = prn->info;
3495
3496 rn = bgp_node_get (table, &p);
3497
3498 if (rn->info)
3499 {
3500 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3501 bgp_unlock_node (rn);
3502 }
3503 else
3504 {
3505 /* New configuration. */
3506 bgp_static = bgp_static_new ();
3507 bgp_static->valid = 1;
3508 memcpy (bgp_static->tag, tag, 3);
3509 rn->info = bgp_static;
3510
3511 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3512 }
3513
3514 return CMD_SUCCESS;
3515}
3516
3517/* Configure static BGP network. */
3518int
paulfd79ac92004-10-13 05:06:08 +00003519bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3520 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003521{
3522 int ret;
3523 struct bgp *bgp;
3524 struct prefix p;
3525 struct prefix_rd prd;
3526 struct bgp_node *prn;
3527 struct bgp_node *rn;
3528 struct bgp_table *table;
3529 struct bgp_static *bgp_static;
3530 u_char tag[3];
3531
3532 bgp = vty->index;
3533
3534 /* Convert IP prefix string to struct prefix. */
3535 ret = str2prefix (ip_str, &p);
3536 if (! ret)
3537 {
3538 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3539 return CMD_WARNING;
3540 }
3541 apply_mask (&p);
3542
3543 ret = str2prefix_rd (rd_str, &prd);
3544 if (! ret)
3545 {
3546 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3547 return CMD_WARNING;
3548 }
3549
3550 ret = str2tag (tag_str, tag);
3551 if (! ret)
3552 {
3553 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3554 return CMD_WARNING;
3555 }
3556
3557 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3558 (struct prefix *)&prd);
3559 if (prn->info == NULL)
3560 prn->info = bgp_table_init ();
3561 else
3562 bgp_unlock_node (prn);
3563 table = prn->info;
3564
3565 rn = bgp_node_lookup (table, &p);
3566
3567 if (rn)
3568 {
3569 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3570
3571 bgp_static = rn->info;
3572 bgp_static_free (bgp_static);
3573 rn->info = NULL;
3574 bgp_unlock_node (rn);
3575 bgp_unlock_node (rn);
3576 }
3577 else
3578 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3579
3580 return CMD_SUCCESS;
3581}
3582
3583DEFUN (bgp_network,
3584 bgp_network_cmd,
3585 "network A.B.C.D/M",
3586 "Specify a network to announce via BGP\n"
3587 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3588{
3589 return bgp_static_set (vty, vty->index, argv[0],
3590 AFI_IP, bgp_node_safi (vty), NULL, 0);
3591}
3592
3593DEFUN (bgp_network_route_map,
3594 bgp_network_route_map_cmd,
3595 "network A.B.C.D/M route-map WORD",
3596 "Specify a network to announce via BGP\n"
3597 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3598 "Route-map to modify the attributes\n"
3599 "Name of the route map\n")
3600{
3601 return bgp_static_set (vty, vty->index, argv[0],
3602 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3603}
3604
3605DEFUN (bgp_network_backdoor,
3606 bgp_network_backdoor_cmd,
3607 "network A.B.C.D/M backdoor",
3608 "Specify a network to announce via BGP\n"
3609 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3610 "Specify a BGP backdoor route\n")
3611{
3612 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
3613}
3614
3615DEFUN (bgp_network_mask,
3616 bgp_network_mask_cmd,
3617 "network A.B.C.D mask A.B.C.D",
3618 "Specify a network to announce via BGP\n"
3619 "Network number\n"
3620 "Network mask\n"
3621 "Network mask\n")
3622{
3623 int ret;
3624 char prefix_str[BUFSIZ];
3625
3626 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3627 if (! ret)
3628 {
3629 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3630 return CMD_WARNING;
3631 }
3632
3633 return bgp_static_set (vty, vty->index, prefix_str,
3634 AFI_IP, bgp_node_safi (vty), NULL, 0);
3635}
3636
3637DEFUN (bgp_network_mask_route_map,
3638 bgp_network_mask_route_map_cmd,
3639 "network A.B.C.D mask A.B.C.D route-map WORD",
3640 "Specify a network to announce via BGP\n"
3641 "Network number\n"
3642 "Network mask\n"
3643 "Network mask\n"
3644 "Route-map to modify the attributes\n"
3645 "Name of the route map\n")
3646{
3647 int ret;
3648 char prefix_str[BUFSIZ];
3649
3650 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3651 if (! ret)
3652 {
3653 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3654 return CMD_WARNING;
3655 }
3656
3657 return bgp_static_set (vty, vty->index, prefix_str,
3658 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3659}
3660
3661DEFUN (bgp_network_mask_backdoor,
3662 bgp_network_mask_backdoor_cmd,
3663 "network A.B.C.D mask A.B.C.D backdoor",
3664 "Specify a network to announce via BGP\n"
3665 "Network number\n"
3666 "Network mask\n"
3667 "Network mask\n"
3668 "Specify a BGP backdoor route\n")
3669{
3670 int ret;
3671 char prefix_str[BUFSIZ];
3672
3673 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3674 if (! ret)
3675 {
3676 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3677 return CMD_WARNING;
3678 }
3679
3680 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3681}
3682
3683DEFUN (bgp_network_mask_natural,
3684 bgp_network_mask_natural_cmd,
3685 "network A.B.C.D",
3686 "Specify a network to announce via BGP\n"
3687 "Network number\n")
3688{
3689 int ret;
3690 char prefix_str[BUFSIZ];
3691
3692 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3693 if (! ret)
3694 {
3695 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3696 return CMD_WARNING;
3697 }
3698
3699 return bgp_static_set (vty, vty->index, prefix_str,
3700 AFI_IP, bgp_node_safi (vty), NULL, 0);
3701}
3702
3703DEFUN (bgp_network_mask_natural_route_map,
3704 bgp_network_mask_natural_route_map_cmd,
3705 "network A.B.C.D route-map WORD",
3706 "Specify a network to announce via BGP\n"
3707 "Network number\n"
3708 "Route-map to modify the attributes\n"
3709 "Name of the route map\n")
3710{
3711 int ret;
3712 char prefix_str[BUFSIZ];
3713
3714 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3715 if (! ret)
3716 {
3717 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3718 return CMD_WARNING;
3719 }
3720
3721 return bgp_static_set (vty, vty->index, prefix_str,
3722 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3723}
3724
3725DEFUN (bgp_network_mask_natural_backdoor,
3726 bgp_network_mask_natural_backdoor_cmd,
3727 "network A.B.C.D backdoor",
3728 "Specify a network to announce via BGP\n"
3729 "Network number\n"
3730 "Specify a BGP backdoor route\n")
3731{
3732 int ret;
3733 char prefix_str[BUFSIZ];
3734
3735 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3736 if (! ret)
3737 {
3738 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3739 return CMD_WARNING;
3740 }
3741
3742 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3743}
3744
3745DEFUN (no_bgp_network,
3746 no_bgp_network_cmd,
3747 "no network A.B.C.D/M",
3748 NO_STR
3749 "Specify a network to announce via BGP\n"
3750 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3751{
3752 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
3753 bgp_node_safi (vty));
3754}
3755
3756ALIAS (no_bgp_network,
3757 no_bgp_network_route_map_cmd,
3758 "no network A.B.C.D/M route-map WORD",
3759 NO_STR
3760 "Specify a network to announce via BGP\n"
3761 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3762 "Route-map to modify the attributes\n"
3763 "Name of the route map\n")
3764
3765ALIAS (no_bgp_network,
3766 no_bgp_network_backdoor_cmd,
3767 "no network A.B.C.D/M backdoor",
3768 NO_STR
3769 "Specify a network to announce via BGP\n"
3770 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3771 "Specify a BGP backdoor route\n")
3772
3773DEFUN (no_bgp_network_mask,
3774 no_bgp_network_mask_cmd,
3775 "no network A.B.C.D mask A.B.C.D",
3776 NO_STR
3777 "Specify a network to announce via BGP\n"
3778 "Network number\n"
3779 "Network mask\n"
3780 "Network mask\n")
3781{
3782 int ret;
3783 char prefix_str[BUFSIZ];
3784
3785 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3786 if (! ret)
3787 {
3788 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3789 return CMD_WARNING;
3790 }
3791
3792 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3793 bgp_node_safi (vty));
3794}
3795
3796ALIAS (no_bgp_network_mask,
3797 no_bgp_network_mask_route_map_cmd,
3798 "no network A.B.C.D mask A.B.C.D route-map WORD",
3799 NO_STR
3800 "Specify a network to announce via BGP\n"
3801 "Network number\n"
3802 "Network mask\n"
3803 "Network mask\n"
3804 "Route-map to modify the attributes\n"
3805 "Name of the route map\n")
3806
3807ALIAS (no_bgp_network_mask,
3808 no_bgp_network_mask_backdoor_cmd,
3809 "no network A.B.C.D mask A.B.C.D backdoor",
3810 NO_STR
3811 "Specify a network to announce via BGP\n"
3812 "Network number\n"
3813 "Network mask\n"
3814 "Network mask\n"
3815 "Specify a BGP backdoor route\n")
3816
3817DEFUN (no_bgp_network_mask_natural,
3818 no_bgp_network_mask_natural_cmd,
3819 "no network A.B.C.D",
3820 NO_STR
3821 "Specify a network to announce via BGP\n"
3822 "Network number\n")
3823{
3824 int ret;
3825 char prefix_str[BUFSIZ];
3826
3827 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3828 if (! ret)
3829 {
3830 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3831 return CMD_WARNING;
3832 }
3833
3834 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3835 bgp_node_safi (vty));
3836}
3837
3838ALIAS (no_bgp_network_mask_natural,
3839 no_bgp_network_mask_natural_route_map_cmd,
3840 "no network A.B.C.D route-map WORD",
3841 NO_STR
3842 "Specify a network to announce via BGP\n"
3843 "Network number\n"
3844 "Route-map to modify the attributes\n"
3845 "Name of the route map\n")
3846
3847ALIAS (no_bgp_network_mask_natural,
3848 no_bgp_network_mask_natural_backdoor_cmd,
3849 "no network A.B.C.D backdoor",
3850 NO_STR
3851 "Specify a network to announce via BGP\n"
3852 "Network number\n"
3853 "Specify a BGP backdoor route\n")
3854
3855#ifdef HAVE_IPV6
3856DEFUN (ipv6_bgp_network,
3857 ipv6_bgp_network_cmd,
3858 "network X:X::X:X/M",
3859 "Specify a network to announce via BGP\n"
3860 "IPv6 prefix <network>/<length>\n")
3861{
3862 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
3863}
3864
3865DEFUN (ipv6_bgp_network_route_map,
3866 ipv6_bgp_network_route_map_cmd,
3867 "network X:X::X:X/M route-map WORD",
3868 "Specify a network to announce via BGP\n"
3869 "IPv6 prefix <network>/<length>\n"
3870 "Route-map to modify the attributes\n"
3871 "Name of the route map\n")
3872{
3873 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
3874 bgp_node_safi (vty), argv[1], 0);
3875}
3876
3877DEFUN (no_ipv6_bgp_network,
3878 no_ipv6_bgp_network_cmd,
3879 "no network X:X::X:X/M",
3880 NO_STR
3881 "Specify a network to announce via BGP\n"
3882 "IPv6 prefix <network>/<length>\n")
3883{
3884 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
3885}
3886
3887ALIAS (no_ipv6_bgp_network,
3888 no_ipv6_bgp_network_route_map_cmd,
3889 "no network X:X::X:X/M route-map WORD",
3890 NO_STR
3891 "Specify a network to announce via BGP\n"
3892 "IPv6 prefix <network>/<length>\n"
3893 "Route-map to modify the attributes\n"
3894 "Name of the route map\n")
3895
3896ALIAS (ipv6_bgp_network,
3897 old_ipv6_bgp_network_cmd,
3898 "ipv6 bgp network X:X::X:X/M",
3899 IPV6_STR
3900 BGP_STR
3901 "Specify a network to announce via BGP\n"
3902 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3903
3904ALIAS (no_ipv6_bgp_network,
3905 old_no_ipv6_bgp_network_cmd,
3906 "no ipv6 bgp network X:X::X:X/M",
3907 NO_STR
3908 IPV6_STR
3909 BGP_STR
3910 "Specify a network to announce via BGP\n"
3911 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3912#endif /* HAVE_IPV6 */
3913
3914/* Aggreagete address:
3915
3916 advertise-map Set condition to advertise attribute
3917 as-set Generate AS set path information
3918 attribute-map Set attributes of aggregate
3919 route-map Set parameters of aggregate
3920 summary-only Filter more specific routes from updates
3921 suppress-map Conditionally filter more specific routes from updates
3922 <cr>
3923 */
3924struct bgp_aggregate
3925{
3926 /* Summary-only flag. */
3927 u_char summary_only;
3928
3929 /* AS set generation. */
3930 u_char as_set;
3931
3932 /* Route-map for aggregated route. */
3933 struct route_map *map;
3934
3935 /* Suppress-count. */
3936 unsigned long count;
3937
3938 /* SAFI configuration. */
3939 safi_t safi;
3940};
3941
paul94f2b392005-06-28 12:44:16 +00003942static struct bgp_aggregate *
paul718e3742002-12-13 20:15:29 +00003943bgp_aggregate_new ()
3944{
3945 struct bgp_aggregate *new;
3946 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
3947 memset (new, 0, sizeof (struct bgp_aggregate));
3948 return new;
3949}
3950
paul94f2b392005-06-28 12:44:16 +00003951static void
paul718e3742002-12-13 20:15:29 +00003952bgp_aggregate_free (struct bgp_aggregate *aggregate)
3953{
3954 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
3955}
3956
paul94f2b392005-06-28 12:44:16 +00003957static void
paul718e3742002-12-13 20:15:29 +00003958bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
3959 afi_t afi, safi_t safi, struct bgp_info *del,
3960 struct bgp_aggregate *aggregate)
3961{
3962 struct bgp_table *table;
3963 struct bgp_node *top;
3964 struct bgp_node *rn;
3965 u_char origin;
3966 struct aspath *aspath = NULL;
3967 struct aspath *asmerge = NULL;
3968 struct community *community = NULL;
3969 struct community *commerge = NULL;
3970 struct in_addr nexthop;
3971 u_int32_t med = 0;
3972 struct bgp_info *ri;
3973 struct bgp_info *new;
3974 int first = 1;
3975 unsigned long match = 0;
3976
3977 /* Record adding route's nexthop and med. */
3978 if (rinew)
3979 {
3980 nexthop = rinew->attr->nexthop;
3981 med = rinew->attr->med;
3982 }
3983
3984 /* ORIGIN attribute: If at least one route among routes that are
3985 aggregated has ORIGIN with the value INCOMPLETE, then the
3986 aggregated route must have the ORIGIN attribute with the value
3987 INCOMPLETE. Otherwise, if at least one route among routes that
3988 are aggregated has ORIGIN with the value EGP, then the aggregated
3989 route must have the origin attribute with the value EGP. In all
3990 other case the value of the ORIGIN attribute of the aggregated
3991 route is INTERNAL. */
3992 origin = BGP_ORIGIN_IGP;
3993
3994 table = bgp->rib[afi][safi];
3995
3996 top = bgp_node_get (table, p);
3997 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
3998 if (rn->p.prefixlen > p->prefixlen)
3999 {
4000 match = 0;
4001
4002 for (ri = rn->info; ri; ri = ri->next)
4003 {
4004 if (BGP_INFO_HOLDDOWN (ri))
4005 continue;
4006
4007 if (del && ri == del)
4008 continue;
4009
4010 if (! rinew && first)
4011 {
4012 nexthop = ri->attr->nexthop;
4013 med = ri->attr->med;
4014 first = 0;
4015 }
4016
4017#ifdef AGGREGATE_NEXTHOP_CHECK
4018 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4019 || ri->attr->med != med)
4020 {
4021 if (aspath)
4022 aspath_free (aspath);
4023 if (community)
4024 community_free (community);
4025 bgp_unlock_node (rn);
4026 bgp_unlock_node (top);
4027 return;
4028 }
4029#endif /* AGGREGATE_NEXTHOP_CHECK */
4030
4031 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4032 {
4033 if (aggregate->summary_only)
4034 {
4035 ri->suppress++;
4036 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4037 match++;
4038 }
4039
4040 aggregate->count++;
4041
4042 if (aggregate->as_set)
4043 {
4044 if (origin < ri->attr->origin)
4045 origin = ri->attr->origin;
4046
4047 if (aspath)
4048 {
4049 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4050 aspath_free (aspath);
4051 aspath = asmerge;
4052 }
4053 else
4054 aspath = aspath_dup (ri->attr->aspath);
4055
4056 if (ri->attr->community)
4057 {
4058 if (community)
4059 {
4060 commerge = community_merge (community,
4061 ri->attr->community);
4062 community = community_uniq_sort (commerge);
4063 community_free (commerge);
4064 }
4065 else
4066 community = community_dup (ri->attr->community);
4067 }
4068 }
4069 }
4070 }
4071 if (match)
4072 bgp_process (bgp, rn, afi, safi);
4073 }
4074 bgp_unlock_node (top);
4075
4076 if (rinew)
4077 {
4078 aggregate->count++;
4079
4080 if (aggregate->summary_only)
4081 rinew->suppress++;
4082
4083 if (aggregate->as_set)
4084 {
4085 if (origin < rinew->attr->origin)
4086 origin = rinew->attr->origin;
4087
4088 if (aspath)
4089 {
4090 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4091 aspath_free (aspath);
4092 aspath = asmerge;
4093 }
4094 else
4095 aspath = aspath_dup (rinew->attr->aspath);
4096
4097 if (rinew->attr->community)
4098 {
4099 if (community)
4100 {
4101 commerge = community_merge (community,
4102 rinew->attr->community);
4103 community = community_uniq_sort (commerge);
4104 community_free (commerge);
4105 }
4106 else
4107 community = community_dup (rinew->attr->community);
4108 }
4109 }
4110 }
4111
4112 if (aggregate->count > 0)
4113 {
4114 rn = bgp_node_get (table, p);
4115 new = bgp_info_new ();
4116 new->type = ZEBRA_ROUTE_BGP;
4117 new->sub_type = BGP_ROUTE_AGGREGATE;
4118 new->peer = bgp->peer_self;
4119 SET_FLAG (new->flags, BGP_INFO_VALID);
4120 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4121 new->uptime = time (NULL);
4122
4123 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004124 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004125 bgp_process (bgp, rn, afi, safi);
4126 }
4127 else
4128 {
4129 if (aspath)
4130 aspath_free (aspath);
4131 if (community)
4132 community_free (community);
4133 }
4134}
4135
4136void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4137 struct bgp_aggregate *);
4138
4139void
4140bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4141 struct bgp_info *ri, afi_t afi, safi_t safi)
4142{
4143 struct bgp_node *child;
4144 struct bgp_node *rn;
4145 struct bgp_aggregate *aggregate;
4146
4147 /* MPLS-VPN aggregation is not yet supported. */
4148 if (safi == SAFI_MPLS_VPN)
4149 return;
4150
4151 if (p->prefixlen == 0)
4152 return;
4153
4154 if (BGP_INFO_HOLDDOWN (ri))
4155 return;
4156
4157 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4158
4159 /* Aggregate address configuration check. */
4160 for (rn = child; rn; rn = rn->parent)
4161 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4162 {
4163 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004164 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004165 }
4166 bgp_unlock_node (child);
4167}
4168
4169void
4170bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4171 struct bgp_info *del, afi_t afi, safi_t safi)
4172{
4173 struct bgp_node *child;
4174 struct bgp_node *rn;
4175 struct bgp_aggregate *aggregate;
4176
4177 /* MPLS-VPN aggregation is not yet supported. */
4178 if (safi == SAFI_MPLS_VPN)
4179 return;
4180
4181 if (p->prefixlen == 0)
4182 return;
4183
4184 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4185
4186 /* Aggregate address configuration check. */
4187 for (rn = child; rn; rn = rn->parent)
4188 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4189 {
4190 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004191 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004192 }
4193 bgp_unlock_node (child);
4194}
4195
paul94f2b392005-06-28 12:44:16 +00004196static void
paul718e3742002-12-13 20:15:29 +00004197bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4198 struct bgp_aggregate *aggregate)
4199{
4200 struct bgp_table *table;
4201 struct bgp_node *top;
4202 struct bgp_node *rn;
4203 struct bgp_info *new;
4204 struct bgp_info *ri;
4205 unsigned long match;
4206 u_char origin = BGP_ORIGIN_IGP;
4207 struct aspath *aspath = NULL;
4208 struct aspath *asmerge = NULL;
4209 struct community *community = NULL;
4210 struct community *commerge = NULL;
4211
4212 table = bgp->rib[afi][safi];
4213
4214 /* Sanity check. */
4215 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4216 return;
4217 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4218 return;
4219
4220 /* If routes exists below this node, generate aggregate routes. */
4221 top = bgp_node_get (table, p);
4222 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4223 if (rn->p.prefixlen > p->prefixlen)
4224 {
4225 match = 0;
4226
4227 for (ri = rn->info; ri; ri = ri->next)
4228 {
4229 if (BGP_INFO_HOLDDOWN (ri))
4230 continue;
4231
4232 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4233 {
4234 /* summary-only aggregate route suppress aggregated
4235 route announcement. */
4236 if (aggregate->summary_only)
4237 {
4238 ri->suppress++;
4239 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4240 match++;
4241 }
4242 /* as-set aggregate route generate origin, as path,
4243 community aggregation. */
4244 if (aggregate->as_set)
4245 {
4246 if (origin < ri->attr->origin)
4247 origin = ri->attr->origin;
4248
4249 if (aspath)
4250 {
4251 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4252 aspath_free (aspath);
4253 aspath = asmerge;
4254 }
4255 else
4256 aspath = aspath_dup (ri->attr->aspath);
4257
4258 if (ri->attr->community)
4259 {
4260 if (community)
4261 {
4262 commerge = community_merge (community,
4263 ri->attr->community);
4264 community = community_uniq_sort (commerge);
4265 community_free (commerge);
4266 }
4267 else
4268 community = community_dup (ri->attr->community);
4269 }
4270 }
4271 aggregate->count++;
4272 }
4273 }
4274
4275 /* If this node is suppressed, process the change. */
4276 if (match)
4277 bgp_process (bgp, rn, afi, safi);
4278 }
4279 bgp_unlock_node (top);
4280
4281 /* Add aggregate route to BGP table. */
4282 if (aggregate->count)
4283 {
4284 rn = bgp_node_get (table, p);
4285
4286 new = bgp_info_new ();
4287 new->type = ZEBRA_ROUTE_BGP;
4288 new->sub_type = BGP_ROUTE_AGGREGATE;
4289 new->peer = bgp->peer_self;
4290 SET_FLAG (new->flags, BGP_INFO_VALID);
4291 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4292 new->uptime = time (NULL);
4293
4294 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004295 bgp_unlock_node (rn);
4296
paul718e3742002-12-13 20:15:29 +00004297 /* Process change. */
4298 bgp_process (bgp, rn, afi, safi);
4299 }
4300}
4301
4302void
4303bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4304 safi_t safi, struct bgp_aggregate *aggregate)
4305{
4306 struct bgp_table *table;
4307 struct bgp_node *top;
4308 struct bgp_node *rn;
4309 struct bgp_info *ri;
4310 unsigned long match;
4311
4312 table = bgp->rib[afi][safi];
4313
4314 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4315 return;
4316 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4317 return;
4318
4319 /* If routes exists below this node, generate aggregate routes. */
4320 top = bgp_node_get (table, p);
4321 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4322 if (rn->p.prefixlen > p->prefixlen)
4323 {
4324 match = 0;
4325
4326 for (ri = rn->info; ri; ri = ri->next)
4327 {
4328 if (BGP_INFO_HOLDDOWN (ri))
4329 continue;
4330
4331 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4332 {
4333 if (aggregate->summary_only)
4334 {
4335 ri->suppress--;
4336
4337 if (ri->suppress == 0)
4338 {
4339 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
4340 match++;
4341 }
4342 }
4343 aggregate->count--;
4344 }
4345 }
4346
4347 /* If this node is suppressed, process the change. */
4348 if (match)
4349 bgp_process (bgp, rn, afi, safi);
4350 }
4351 bgp_unlock_node (top);
4352
4353 /* Delete aggregate route from BGP table. */
4354 rn = bgp_node_get (table, p);
4355
4356 for (ri = rn->info; ri; ri = ri->next)
4357 if (ri->peer == bgp->peer_self
4358 && ri->type == ZEBRA_ROUTE_BGP
4359 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4360 break;
4361
4362 /* Withdraw static BGP route from routing table. */
4363 if (ri)
4364 {
4365 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4366 bgp_process (bgp, rn, afi, safi);
4367 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004368 }
4369
4370 /* Unlock bgp_node_lookup. */
4371 bgp_unlock_node (rn);
4372}
4373
4374/* Aggregate route attribute. */
4375#define AGGREGATE_SUMMARY_ONLY 1
4376#define AGGREGATE_AS_SET 1
4377
paul94f2b392005-06-28 12:44:16 +00004378static int
paulfd79ac92004-10-13 05:06:08 +00004379bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4380 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004381 u_char summary_only, u_char as_set)
4382{
4383 int ret;
4384 struct prefix p;
4385 struct bgp_node *rn;
4386 struct bgp *bgp;
4387 struct bgp_aggregate *aggregate;
4388
4389 /* Convert string to prefix structure. */
4390 ret = str2prefix (prefix_str, &p);
4391 if (!ret)
4392 {
4393 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4394 return CMD_WARNING;
4395 }
4396 apply_mask (&p);
4397
4398 /* Get BGP structure. */
4399 bgp = vty->index;
4400
4401 /* Old configuration check. */
4402 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4403
4404 if (rn->info)
4405 {
4406 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4407 bgp_unlock_node (rn);
4408 return CMD_WARNING;
4409 }
4410
4411 /* Make aggregate address structure. */
4412 aggregate = bgp_aggregate_new ();
4413 aggregate->summary_only = summary_only;
4414 aggregate->as_set = as_set;
4415 aggregate->safi = safi;
4416 rn->info = aggregate;
4417
4418 /* Aggregate address insert into BGP routing table. */
4419 if (safi & SAFI_UNICAST)
4420 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4421 if (safi & SAFI_MULTICAST)
4422 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4423
4424 return CMD_SUCCESS;
4425}
4426
paul94f2b392005-06-28 12:44:16 +00004427static int
paulfd79ac92004-10-13 05:06:08 +00004428bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4429 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004430{
4431 int ret;
4432 struct prefix p;
4433 struct bgp_node *rn;
4434 struct bgp *bgp;
4435 struct bgp_aggregate *aggregate;
4436
4437 /* Convert string to prefix structure. */
4438 ret = str2prefix (prefix_str, &p);
4439 if (!ret)
4440 {
4441 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4442 return CMD_WARNING;
4443 }
4444 apply_mask (&p);
4445
4446 /* Get BGP structure. */
4447 bgp = vty->index;
4448
4449 /* Old configuration check. */
4450 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4451 if (! rn)
4452 {
4453 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4454 VTY_NEWLINE);
4455 return CMD_WARNING;
4456 }
4457
4458 aggregate = rn->info;
4459 if (aggregate->safi & SAFI_UNICAST)
4460 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4461 if (aggregate->safi & SAFI_MULTICAST)
4462 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4463
4464 /* Unlock aggregate address configuration. */
4465 rn->info = NULL;
4466 bgp_aggregate_free (aggregate);
4467 bgp_unlock_node (rn);
4468 bgp_unlock_node (rn);
4469
4470 return CMD_SUCCESS;
4471}
4472
4473DEFUN (aggregate_address,
4474 aggregate_address_cmd,
4475 "aggregate-address A.B.C.D/M",
4476 "Configure BGP aggregate entries\n"
4477 "Aggregate prefix\n")
4478{
4479 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4480}
4481
4482DEFUN (aggregate_address_mask,
4483 aggregate_address_mask_cmd,
4484 "aggregate-address A.B.C.D A.B.C.D",
4485 "Configure BGP aggregate entries\n"
4486 "Aggregate address\n"
4487 "Aggregate mask\n")
4488{
4489 int ret;
4490 char prefix_str[BUFSIZ];
4491
4492 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4493
4494 if (! ret)
4495 {
4496 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4497 return CMD_WARNING;
4498 }
4499
4500 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4501 0, 0);
4502}
4503
4504DEFUN (aggregate_address_summary_only,
4505 aggregate_address_summary_only_cmd,
4506 "aggregate-address A.B.C.D/M summary-only",
4507 "Configure BGP aggregate entries\n"
4508 "Aggregate prefix\n"
4509 "Filter more specific routes from updates\n")
4510{
4511 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4512 AGGREGATE_SUMMARY_ONLY, 0);
4513}
4514
4515DEFUN (aggregate_address_mask_summary_only,
4516 aggregate_address_mask_summary_only_cmd,
4517 "aggregate-address A.B.C.D A.B.C.D summary-only",
4518 "Configure BGP aggregate entries\n"
4519 "Aggregate address\n"
4520 "Aggregate mask\n"
4521 "Filter more specific routes from updates\n")
4522{
4523 int ret;
4524 char prefix_str[BUFSIZ];
4525
4526 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4527
4528 if (! ret)
4529 {
4530 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4531 return CMD_WARNING;
4532 }
4533
4534 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4535 AGGREGATE_SUMMARY_ONLY, 0);
4536}
4537
4538DEFUN (aggregate_address_as_set,
4539 aggregate_address_as_set_cmd,
4540 "aggregate-address A.B.C.D/M as-set",
4541 "Configure BGP aggregate entries\n"
4542 "Aggregate prefix\n"
4543 "Generate AS set path information\n")
4544{
4545 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4546 0, AGGREGATE_AS_SET);
4547}
4548
4549DEFUN (aggregate_address_mask_as_set,
4550 aggregate_address_mask_as_set_cmd,
4551 "aggregate-address A.B.C.D A.B.C.D as-set",
4552 "Configure BGP aggregate entries\n"
4553 "Aggregate address\n"
4554 "Aggregate mask\n"
4555 "Generate AS set path information\n")
4556{
4557 int ret;
4558 char prefix_str[BUFSIZ];
4559
4560 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4561
4562 if (! ret)
4563 {
4564 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4565 return CMD_WARNING;
4566 }
4567
4568 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4569 0, AGGREGATE_AS_SET);
4570}
4571
4572
4573DEFUN (aggregate_address_as_set_summary,
4574 aggregate_address_as_set_summary_cmd,
4575 "aggregate-address A.B.C.D/M as-set summary-only",
4576 "Configure BGP aggregate entries\n"
4577 "Aggregate prefix\n"
4578 "Generate AS set path information\n"
4579 "Filter more specific routes from updates\n")
4580{
4581 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4582 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4583}
4584
4585ALIAS (aggregate_address_as_set_summary,
4586 aggregate_address_summary_as_set_cmd,
4587 "aggregate-address A.B.C.D/M summary-only as-set",
4588 "Configure BGP aggregate entries\n"
4589 "Aggregate prefix\n"
4590 "Filter more specific routes from updates\n"
4591 "Generate AS set path information\n")
4592
4593DEFUN (aggregate_address_mask_as_set_summary,
4594 aggregate_address_mask_as_set_summary_cmd,
4595 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4596 "Configure BGP aggregate entries\n"
4597 "Aggregate address\n"
4598 "Aggregate mask\n"
4599 "Generate AS set path information\n"
4600 "Filter more specific routes from updates\n")
4601{
4602 int ret;
4603 char prefix_str[BUFSIZ];
4604
4605 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4606
4607 if (! ret)
4608 {
4609 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4610 return CMD_WARNING;
4611 }
4612
4613 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4614 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4615}
4616
4617ALIAS (aggregate_address_mask_as_set_summary,
4618 aggregate_address_mask_summary_as_set_cmd,
4619 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4620 "Configure BGP aggregate entries\n"
4621 "Aggregate address\n"
4622 "Aggregate mask\n"
4623 "Filter more specific routes from updates\n"
4624 "Generate AS set path information\n")
4625
4626DEFUN (no_aggregate_address,
4627 no_aggregate_address_cmd,
4628 "no aggregate-address A.B.C.D/M",
4629 NO_STR
4630 "Configure BGP aggregate entries\n"
4631 "Aggregate prefix\n")
4632{
4633 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4634}
4635
4636ALIAS (no_aggregate_address,
4637 no_aggregate_address_summary_only_cmd,
4638 "no aggregate-address A.B.C.D/M summary-only",
4639 NO_STR
4640 "Configure BGP aggregate entries\n"
4641 "Aggregate prefix\n"
4642 "Filter more specific routes from updates\n")
4643
4644ALIAS (no_aggregate_address,
4645 no_aggregate_address_as_set_cmd,
4646 "no aggregate-address A.B.C.D/M as-set",
4647 NO_STR
4648 "Configure BGP aggregate entries\n"
4649 "Aggregate prefix\n"
4650 "Generate AS set path information\n")
4651
4652ALIAS (no_aggregate_address,
4653 no_aggregate_address_as_set_summary_cmd,
4654 "no aggregate-address A.B.C.D/M as-set summary-only",
4655 NO_STR
4656 "Configure BGP aggregate entries\n"
4657 "Aggregate prefix\n"
4658 "Generate AS set path information\n"
4659 "Filter more specific routes from updates\n")
4660
4661ALIAS (no_aggregate_address,
4662 no_aggregate_address_summary_as_set_cmd,
4663 "no aggregate-address A.B.C.D/M summary-only as-set",
4664 NO_STR
4665 "Configure BGP aggregate entries\n"
4666 "Aggregate prefix\n"
4667 "Filter more specific routes from updates\n"
4668 "Generate AS set path information\n")
4669
4670DEFUN (no_aggregate_address_mask,
4671 no_aggregate_address_mask_cmd,
4672 "no aggregate-address A.B.C.D A.B.C.D",
4673 NO_STR
4674 "Configure BGP aggregate entries\n"
4675 "Aggregate address\n"
4676 "Aggregate mask\n")
4677{
4678 int ret;
4679 char prefix_str[BUFSIZ];
4680
4681 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4682
4683 if (! ret)
4684 {
4685 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4686 return CMD_WARNING;
4687 }
4688
4689 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4690}
4691
4692ALIAS (no_aggregate_address_mask,
4693 no_aggregate_address_mask_summary_only_cmd,
4694 "no aggregate-address A.B.C.D A.B.C.D summary-only",
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
4701ALIAS (no_aggregate_address_mask,
4702 no_aggregate_address_mask_as_set_cmd,
4703 "no aggregate-address A.B.C.D A.B.C.D as-set",
4704 NO_STR
4705 "Configure BGP aggregate entries\n"
4706 "Aggregate address\n"
4707 "Aggregate mask\n"
4708 "Generate AS set path information\n")
4709
4710ALIAS (no_aggregate_address_mask,
4711 no_aggregate_address_mask_as_set_summary_cmd,
4712 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4713 NO_STR
4714 "Configure BGP aggregate entries\n"
4715 "Aggregate address\n"
4716 "Aggregate mask\n"
4717 "Generate AS set path information\n"
4718 "Filter more specific routes from updates\n")
4719
4720ALIAS (no_aggregate_address_mask,
4721 no_aggregate_address_mask_summary_as_set_cmd,
4722 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4723 NO_STR
4724 "Configure BGP aggregate entries\n"
4725 "Aggregate address\n"
4726 "Aggregate mask\n"
4727 "Filter more specific routes from updates\n"
4728 "Generate AS set path information\n")
4729
4730#ifdef HAVE_IPV6
4731DEFUN (ipv6_aggregate_address,
4732 ipv6_aggregate_address_cmd,
4733 "aggregate-address X:X::X:X/M",
4734 "Configure BGP aggregate entries\n"
4735 "Aggregate prefix\n")
4736{
4737 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4738}
4739
4740DEFUN (ipv6_aggregate_address_summary_only,
4741 ipv6_aggregate_address_summary_only_cmd,
4742 "aggregate-address X:X::X:X/M summary-only",
4743 "Configure BGP aggregate entries\n"
4744 "Aggregate prefix\n"
4745 "Filter more specific routes from updates\n")
4746{
4747 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4748 AGGREGATE_SUMMARY_ONLY, 0);
4749}
4750
4751DEFUN (no_ipv6_aggregate_address,
4752 no_ipv6_aggregate_address_cmd,
4753 "no aggregate-address X:X::X:X/M",
4754 NO_STR
4755 "Configure BGP aggregate entries\n"
4756 "Aggregate prefix\n")
4757{
4758 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4759}
4760
4761DEFUN (no_ipv6_aggregate_address_summary_only,
4762 no_ipv6_aggregate_address_summary_only_cmd,
4763 "no aggregate-address X:X::X:X/M summary-only",
4764 NO_STR
4765 "Configure BGP aggregate entries\n"
4766 "Aggregate prefix\n"
4767 "Filter more specific routes from updates\n")
4768{
4769 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4770}
4771
4772ALIAS (ipv6_aggregate_address,
4773 old_ipv6_aggregate_address_cmd,
4774 "ipv6 bgp aggregate-address X:X::X:X/M",
4775 IPV6_STR
4776 BGP_STR
4777 "Configure BGP aggregate entries\n"
4778 "Aggregate prefix\n")
4779
4780ALIAS (ipv6_aggregate_address_summary_only,
4781 old_ipv6_aggregate_address_summary_only_cmd,
4782 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4783 IPV6_STR
4784 BGP_STR
4785 "Configure BGP aggregate entries\n"
4786 "Aggregate prefix\n"
4787 "Filter more specific routes from updates\n")
4788
4789ALIAS (no_ipv6_aggregate_address,
4790 old_no_ipv6_aggregate_address_cmd,
4791 "no ipv6 bgp aggregate-address X:X::X:X/M",
4792 NO_STR
4793 IPV6_STR
4794 BGP_STR
4795 "Configure BGP aggregate entries\n"
4796 "Aggregate prefix\n")
4797
4798ALIAS (no_ipv6_aggregate_address_summary_only,
4799 old_no_ipv6_aggregate_address_summary_only_cmd,
4800 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4801 NO_STR
4802 IPV6_STR
4803 BGP_STR
4804 "Configure BGP aggregate entries\n"
4805 "Aggregate prefix\n"
4806 "Filter more specific routes from updates\n")
4807#endif /* HAVE_IPV6 */
4808
4809/* Redistribute route treatment. */
4810void
4811bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4812 u_int32_t metric, u_char type)
4813{
4814 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004815 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004816 struct bgp_info *new;
4817 struct bgp_info *bi;
4818 struct bgp_info info;
4819 struct bgp_node *bn;
4820 struct attr attr;
4821 struct attr attr_new;
4822 struct attr *new_attr;
4823 afi_t afi;
4824 int ret;
4825
4826 /* Make default attribute. */
4827 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4828 if (nexthop)
4829 attr.nexthop = *nexthop;
4830
4831 attr.med = metric;
4832 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4833
paul1eb8ef22005-04-07 07:30:20 +00004834 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004835 {
4836 afi = family2afi (p->family);
4837
4838 if (bgp->redist[afi][type])
4839 {
4840 /* Copy attribute for modification. */
4841 attr_new = attr;
4842
4843 if (bgp->redist_metric_flag[afi][type])
4844 attr_new.med = bgp->redist_metric[afi][type];
4845
4846 /* Apply route-map. */
4847 if (bgp->rmap[afi][type].map)
4848 {
4849 info.peer = bgp->peer_self;
4850 info.attr = &attr_new;
4851
paulfee0f4c2004-09-13 05:12:46 +00004852 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
4853
paul718e3742002-12-13 20:15:29 +00004854 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
4855 &info);
paulfee0f4c2004-09-13 05:12:46 +00004856
4857 bgp->peer_self->rmap_type = 0;
4858
paul718e3742002-12-13 20:15:29 +00004859 if (ret == RMAP_DENYMATCH)
4860 {
4861 /* Free uninterned attribute. */
4862 bgp_attr_flush (&attr_new);
4863
4864 /* Unintern original. */
4865 aspath_unintern (attr.aspath);
4866 bgp_redistribute_delete (p, type);
4867 return;
4868 }
4869 }
4870
paulfee0f4c2004-09-13 05:12:46 +00004871 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004872 new_attr = bgp_attr_intern (&attr_new);
4873
4874 for (bi = bn->info; bi; bi = bi->next)
4875 if (bi->peer == bgp->peer_self
4876 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
4877 break;
4878
4879 if (bi)
4880 {
4881 if (attrhash_cmp (bi->attr, new_attr))
4882 {
4883 bgp_attr_unintern (new_attr);
4884 aspath_unintern (attr.aspath);
4885 bgp_unlock_node (bn);
4886 return;
4887 }
4888 else
4889 {
4890 /* The attribute is changed. */
4891 SET_FLAG (bi->flags, BGP_INFO_ATTR_CHANGED);
4892
4893 /* Rewrite BGP route information. */
4894 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
4895 bgp_attr_unintern (bi->attr);
4896 bi->attr = new_attr;
4897 bi->uptime = time (NULL);
4898
4899 /* Process change. */
4900 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
4901 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4902 bgp_unlock_node (bn);
4903 aspath_unintern (attr.aspath);
4904 return;
4905 }
4906 }
4907
4908 new = bgp_info_new ();
4909 new->type = type;
4910 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
4911 new->peer = bgp->peer_self;
4912 SET_FLAG (new->flags, BGP_INFO_VALID);
4913 new->attr = new_attr;
4914 new->uptime = time (NULL);
4915
4916 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
4917 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00004918 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00004919 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4920 }
4921 }
4922
4923 /* Unintern original. */
4924 aspath_unintern (attr.aspath);
4925}
4926
4927void
4928bgp_redistribute_delete (struct prefix *p, u_char type)
4929{
4930 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004931 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004932 afi_t afi;
4933 struct bgp_node *rn;
4934 struct bgp_info *ri;
4935
paul1eb8ef22005-04-07 07:30:20 +00004936 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004937 {
4938 afi = family2afi (p->family);
4939
4940 if (bgp->redist[afi][type])
4941 {
paulfee0f4c2004-09-13 05:12:46 +00004942 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004943
4944 for (ri = rn->info; ri; ri = ri->next)
4945 if (ri->peer == bgp->peer_self
4946 && ri->type == type)
4947 break;
4948
4949 if (ri)
4950 {
4951 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
4952 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4953 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4954 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004955 }
4956 bgp_unlock_node (rn);
4957 }
4958 }
4959}
4960
4961/* Withdraw specified route type's route. */
4962void
4963bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
4964{
4965 struct bgp_node *rn;
4966 struct bgp_info *ri;
4967 struct bgp_table *table;
4968
4969 table = bgp->rib[afi][SAFI_UNICAST];
4970
4971 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4972 {
4973 for (ri = rn->info; ri; ri = ri->next)
4974 if (ri->peer == bgp->peer_self
4975 && ri->type == type)
4976 break;
4977
4978 if (ri)
4979 {
4980 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
4981 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4982 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4983 bgp_info_delete (rn, ri);
paul718e3742002-12-13 20:15:29 +00004984 }
4985 }
4986}
4987
4988/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00004989static void
paul718e3742002-12-13 20:15:29 +00004990route_vty_out_route (struct prefix *p, struct vty *vty)
4991{
4992 int len;
4993 u_int32_t destination;
4994 char buf[BUFSIZ];
4995
4996 if (p->family == AF_INET)
4997 {
4998 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
4999 destination = ntohl (p->u.prefix4.s_addr);
5000
5001 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5002 || (IN_CLASSB (destination) && p->prefixlen == 16)
5003 || (IN_CLASSA (destination) && p->prefixlen == 8)
5004 || p->u.prefix4.s_addr == 0)
5005 {
5006 /* When mask is natural, mask is not displayed. */
5007 }
5008 else
5009 len += vty_out (vty, "/%d", p->prefixlen);
5010 }
5011 else
5012 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5013 p->prefixlen);
5014
5015 len = 17 - len;
5016 if (len < 1)
5017 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5018 else
5019 vty_out (vty, "%*s", len, " ");
5020}
5021
paul718e3742002-12-13 20:15:29 +00005022enum bgp_display_type
5023{
5024 normal_list,
5025};
5026
paulb40d9392005-08-22 22:34:41 +00005027/* Print the short form route status for a bgp_info */
5028static void
5029route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005030{
paulb40d9392005-08-22 22:34:41 +00005031 /* Route status display. */
5032 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5033 vty_out (vty, "R");
5034 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005035 vty_out (vty, "S");
5036 else if (binfo->suppress)
paul718e3742002-12-13 20:15:29 +00005037 vty_out (vty, "s");
5038 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5039 vty_out (vty, "*");
5040 else
5041 vty_out (vty, " ");
5042
5043 /* Selected */
5044 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5045 vty_out (vty, "h");
5046 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5047 vty_out (vty, "d");
5048 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5049 vty_out (vty, ">");
5050 else
5051 vty_out (vty, " ");
5052
5053 /* Internal route. */
5054 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5055 vty_out (vty, "i");
5056 else
paulb40d9392005-08-22 22:34:41 +00005057 vty_out (vty, " ");
5058}
5059
5060/* called from terminal list command */
5061void
5062route_vty_out (struct vty *vty, struct prefix *p,
5063 struct bgp_info *binfo, int display, safi_t safi)
5064{
5065 struct attr *attr;
5066
5067 /* short status lead text */
5068 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005069
5070 /* print prefix and mask */
5071 if (! display)
5072 route_vty_out_route (p, vty);
5073 else
5074 vty_out (vty, "%*s", 17, " ");
5075
5076 /* Print attribute */
5077 attr = binfo->attr;
5078 if (attr)
5079 {
5080 if (p->family == AF_INET)
5081 {
5082 if (safi == SAFI_MPLS_VPN)
5083 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5084 else
5085 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5086 }
5087#ifdef HAVE_IPV6
5088 else if (p->family == AF_INET6)
5089 {
5090 int len;
5091 char buf[BUFSIZ];
5092
5093 len = vty_out (vty, "%s",
5094 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5095 len = 16 - len;
5096 if (len < 1)
5097 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5098 else
5099 vty_out (vty, "%*s", len, " ");
5100 }
5101#endif /* HAVE_IPV6 */
5102
5103 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5104 vty_out (vty, "%10d", attr->med);
5105 else
5106 vty_out (vty, " ");
5107
5108 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5109 vty_out (vty, "%7d", attr->local_pref);
5110 else
5111 vty_out (vty, " ");
5112
5113 vty_out (vty, "%7u ",attr->weight);
5114
5115 /* Print aspath */
5116 if (attr->aspath)
5117 aspath_print_vty (vty, attr->aspath);
5118
5119 /* Print origin */
5120 if (strlen (attr->aspath->str) == 0)
5121 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5122 else
5123 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5124 }
5125 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005126}
5127
5128/* called from terminal list command */
5129void
5130route_vty_out_tmp (struct vty *vty, struct prefix *p,
5131 struct attr *attr, safi_t safi)
5132{
5133 /* Route status display. */
5134 vty_out (vty, "*");
5135 vty_out (vty, ">");
5136 vty_out (vty, " ");
5137
5138 /* print prefix and mask */
5139 route_vty_out_route (p, vty);
5140
5141 /* Print attribute */
5142 if (attr)
5143 {
5144 if (p->family == AF_INET)
5145 {
5146 if (safi == SAFI_MPLS_VPN)
5147 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5148 else
5149 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5150 }
5151#ifdef HAVE_IPV6
5152 else if (p->family == AF_INET6)
5153 {
5154 int len;
5155 char buf[BUFSIZ];
5156
5157 len = vty_out (vty, "%s",
5158 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5159 len = 16 - len;
5160 if (len < 1)
5161 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5162 else
5163 vty_out (vty, "%*s", len, " ");
5164 }
5165#endif /* HAVE_IPV6 */
5166
5167 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5168 vty_out (vty, "%10d", attr->med);
5169 else
5170 vty_out (vty, " ");
5171
5172 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5173 vty_out (vty, "%7d", attr->local_pref);
5174 else
5175 vty_out (vty, " ");
5176
5177 vty_out (vty, "%7d ",attr->weight);
5178
5179 /* Print aspath */
5180 if (attr->aspath)
5181 aspath_print_vty (vty, attr->aspath);
5182
5183 /* Print origin */
5184 if (strlen (attr->aspath->str) == 0)
5185 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5186 else
5187 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5188 }
5189
5190 vty_out (vty, "%s", VTY_NEWLINE);
5191}
5192
ajs5a646652004-11-05 01:25:55 +00005193void
paul718e3742002-12-13 20:15:29 +00005194route_vty_out_tag (struct vty *vty, struct prefix *p,
5195 struct bgp_info *binfo, int display, safi_t safi)
5196{
5197 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005198 u_int32_t label = 0;
5199
paulb40d9392005-08-22 22:34:41 +00005200 /* short status lead text */
5201 route_vty_short_status_out (vty, binfo);
5202
paul718e3742002-12-13 20:15:29 +00005203 /* print prefix and mask */
5204 if (! display)
5205 route_vty_out_route (p, vty);
5206 else
5207 vty_out (vty, "%*s", 17, " ");
5208
5209 /* Print attribute */
5210 attr = binfo->attr;
5211 if (attr)
5212 {
5213 if (p->family == AF_INET)
5214 {
5215 if (safi == SAFI_MPLS_VPN)
5216 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5217 else
5218 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5219 }
5220#ifdef HAVE_IPV6
5221 else if (p->family == AF_INET6)
5222 {
5223 char buf[BUFSIZ];
5224 char buf1[BUFSIZ];
5225 if (attr->mp_nexthop_len == 16)
5226 vty_out (vty, "%s",
5227 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5228 else if (attr->mp_nexthop_len == 32)
5229 vty_out (vty, "%s(%s)",
5230 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
5231 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
5232
5233 }
5234#endif /* HAVE_IPV6 */
5235 }
5236
5237 label = decode_label (binfo->tag);
5238
5239 vty_out (vty, "notag/%d", label);
5240
5241 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005242}
5243
5244/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005245static void
paul718e3742002-12-13 20:15:29 +00005246damp_route_vty_out (struct vty *vty, struct prefix *p,
5247 struct bgp_info *binfo, int display, safi_t safi)
5248{
5249 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005250 int len;
5251
paulb40d9392005-08-22 22:34:41 +00005252 /* short status lead text */
5253 route_vty_short_status_out (vty, binfo);
5254
paul718e3742002-12-13 20:15:29 +00005255 /* 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
paulb40d9392005-08-22 22:34:41 +00005301 /* short status lead text */
5302 route_vty_short_status_out (vty, binfo);
5303
paul718e3742002-12-13 20:15:29 +00005304 /* print prefix and mask */
5305 if (! display)
5306 route_vty_out_route (p, vty);
5307 else
5308 vty_out (vty, "%*s", 17, " ");
5309
5310 len = vty_out (vty, "%s", binfo->peer->host);
5311 len = 16 - len;
5312 if (len < 1)
5313 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5314 else
5315 vty_out (vty, "%*s", len, " ");
5316
5317 len = vty_out (vty, "%d", bdi->flap);
5318 len = 5 - len;
5319 if (len < 1)
5320 vty_out (vty, " ");
5321 else
5322 vty_out (vty, "%*s ", len, " ");
5323
5324 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5325 timebuf, BGP_UPTIME_LEN));
5326
5327 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5328 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5329 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5330 else
5331 vty_out (vty, "%*s ", 8, " ");
5332
5333 /* Print attribute */
5334 attr = binfo->attr;
5335 if (attr)
5336 {
5337 /* Print aspath */
5338 if (attr->aspath)
5339 aspath_print_vty (vty, attr->aspath);
5340
5341 /* Print origin */
5342 if (strlen (attr->aspath->str) == 0)
5343 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5344 else
5345 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5346 }
5347 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005348}
5349
paul94f2b392005-06-28 12:44:16 +00005350static void
paul718e3742002-12-13 20:15:29 +00005351route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5352 struct bgp_info *binfo, afi_t afi, safi_t safi)
5353{
5354 char buf[INET6_ADDRSTRLEN];
5355 char buf1[BUFSIZ];
5356 struct attr *attr;
5357 int sockunion_vty_out (struct vty *, union sockunion *);
5358
5359 attr = binfo->attr;
5360
5361 if (attr)
5362 {
5363 /* Line1 display AS-path, Aggregator */
5364 if (attr->aspath)
5365 {
5366 vty_out (vty, " ");
5367 if (attr->aspath->length == 0)
5368 vty_out (vty, "Local");
5369 else
5370 aspath_print_vty (vty, attr->aspath);
5371 }
5372
paulb40d9392005-08-22 22:34:41 +00005373 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5374 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005375 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5376 vty_out (vty, ", (stale)");
5377 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5378 vty_out (vty, ", (aggregated by %d %s)", attr->aggregator_as,
5379 inet_ntoa (attr->aggregator_addr));
5380 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5381 vty_out (vty, ", (Received from a RR-client)");
5382 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5383 vty_out (vty, ", (Received from a RS-client)");
5384 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5385 vty_out (vty, ", (history entry)");
5386 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5387 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005388 vty_out (vty, "%s", VTY_NEWLINE);
5389
5390 /* Line2 display Next-hop, Neighbor, Router-id */
5391 if (p->family == AF_INET)
5392 {
5393 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5394 inet_ntoa (attr->mp_nexthop_global_in) :
5395 inet_ntoa (attr->nexthop));
5396 }
5397#ifdef HAVE_IPV6
5398 else
5399 {
5400 vty_out (vty, " %s",
5401 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5402 buf, INET6_ADDRSTRLEN));
5403 }
5404#endif /* HAVE_IPV6 */
5405
5406 if (binfo->peer == bgp->peer_self)
5407 {
5408 vty_out (vty, " from %s ",
5409 p->family == AF_INET ? "0.0.0.0" : "::");
5410 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5411 }
5412 else
5413 {
5414 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5415 vty_out (vty, " (inaccessible)");
5416 else if (binfo->igpmetric)
5417 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005418 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005419 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5420 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5421 else
5422 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5423 }
5424 vty_out (vty, "%s", VTY_NEWLINE);
5425
5426#ifdef HAVE_IPV6
5427 /* display nexthop local */
5428 if (attr->mp_nexthop_len == 32)
5429 {
5430 vty_out (vty, " (%s)%s",
5431 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5432 buf, INET6_ADDRSTRLEN),
5433 VTY_NEWLINE);
5434 }
5435#endif /* HAVE_IPV6 */
5436
5437 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5438 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5439
5440 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5441 vty_out (vty, ", metric %d", attr->med);
5442
5443 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5444 vty_out (vty, ", localpref %d", attr->local_pref);
5445 else
5446 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5447
5448 if (attr->weight != 0)
5449 vty_out (vty, ", weight %d", attr->weight);
5450
5451 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5452 vty_out (vty, ", valid");
5453
5454 if (binfo->peer != bgp->peer_self)
5455 {
5456 if (binfo->peer->as == binfo->peer->local_as)
5457 vty_out (vty, ", internal");
5458 else
5459 vty_out (vty, ", %s",
5460 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5461 }
5462 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5463 vty_out (vty, ", aggregated, local");
5464 else if (binfo->type != ZEBRA_ROUTE_BGP)
5465 vty_out (vty, ", sourced");
5466 else
5467 vty_out (vty, ", sourced, local");
5468
5469 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5470 vty_out (vty, ", atomic-aggregate");
5471
5472 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5473 vty_out (vty, ", best");
5474
5475 vty_out (vty, "%s", VTY_NEWLINE);
5476
5477 /* Line 4 display Community */
5478 if (attr->community)
5479 vty_out (vty, " Community: %s%s", attr->community->str,
5480 VTY_NEWLINE);
5481
5482 /* Line 5 display Extended-community */
5483 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5484 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5485 VTY_NEWLINE);
5486
5487 /* Line 6 display Originator, Cluster-id */
5488 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5489 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5490 {
5491 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5492 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5493
5494 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5495 {
5496 int i;
5497 vty_out (vty, ", Cluster list: ");
5498 for (i = 0; i < attr->cluster->length / 4; i++)
5499 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5500 }
5501 vty_out (vty, "%s", VTY_NEWLINE);
5502 }
5503
5504 if (binfo->damp_info)
5505 bgp_damp_info_vty (vty, binfo);
5506
5507 /* Line 7 display Uptime */
5508 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5509 }
5510 vty_out (vty, "%s", VTY_NEWLINE);
5511}
5512
paulb40d9392005-08-22 22:34:41 +00005513#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,%s r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00005514#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005515#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5516#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5517#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5518
5519enum bgp_show_type
5520{
5521 bgp_show_type_normal,
5522 bgp_show_type_regexp,
5523 bgp_show_type_prefix_list,
5524 bgp_show_type_filter_list,
5525 bgp_show_type_route_map,
5526 bgp_show_type_neighbor,
5527 bgp_show_type_cidr_only,
5528 bgp_show_type_prefix_longer,
5529 bgp_show_type_community_all,
5530 bgp_show_type_community,
5531 bgp_show_type_community_exact,
5532 bgp_show_type_community_list,
5533 bgp_show_type_community_list_exact,
5534 bgp_show_type_flap_statistics,
5535 bgp_show_type_flap_address,
5536 bgp_show_type_flap_prefix,
5537 bgp_show_type_flap_cidr_only,
5538 bgp_show_type_flap_regexp,
5539 bgp_show_type_flap_filter_list,
5540 bgp_show_type_flap_prefix_list,
5541 bgp_show_type_flap_prefix_longer,
5542 bgp_show_type_flap_route_map,
5543 bgp_show_type_flap_neighbor,
5544 bgp_show_type_dampend_paths,
5545 bgp_show_type_damp_neighbor
5546};
5547
ajs5a646652004-11-05 01:25:55 +00005548static int
paulfee0f4c2004-09-13 05:12:46 +00005549bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00005550 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00005551{
paul718e3742002-12-13 20:15:29 +00005552 struct bgp_info *ri;
5553 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005554 int header = 1;
paul718e3742002-12-13 20:15:29 +00005555 int display;
ajs5a646652004-11-05 01:25:55 +00005556 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00005557
5558 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00005559 output_count = 0;
paul718e3742002-12-13 20:15:29 +00005560
paul718e3742002-12-13 20:15:29 +00005561 /* Start processing of routes. */
5562 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5563 if (rn->info != NULL)
5564 {
5565 display = 0;
5566
5567 for (ri = rn->info; ri; ri = ri->next)
5568 {
ajs5a646652004-11-05 01:25:55 +00005569 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00005570 || type == bgp_show_type_flap_address
5571 || type == bgp_show_type_flap_prefix
5572 || type == bgp_show_type_flap_cidr_only
5573 || type == bgp_show_type_flap_regexp
5574 || type == bgp_show_type_flap_filter_list
5575 || type == bgp_show_type_flap_prefix_list
5576 || type == bgp_show_type_flap_prefix_longer
5577 || type == bgp_show_type_flap_route_map
5578 || type == bgp_show_type_flap_neighbor
5579 || type == bgp_show_type_dampend_paths
5580 || type == bgp_show_type_damp_neighbor)
5581 {
5582 if (! ri->damp_info)
5583 continue;
5584 }
5585 if (type == bgp_show_type_regexp
5586 || type == bgp_show_type_flap_regexp)
5587 {
ajs5a646652004-11-05 01:25:55 +00005588 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00005589
5590 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5591 continue;
5592 }
5593 if (type == bgp_show_type_prefix_list
5594 || type == bgp_show_type_flap_prefix_list)
5595 {
ajs5a646652004-11-05 01:25:55 +00005596 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00005597
5598 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5599 continue;
5600 }
5601 if (type == bgp_show_type_filter_list
5602 || type == bgp_show_type_flap_filter_list)
5603 {
ajs5a646652004-11-05 01:25:55 +00005604 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00005605
5606 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5607 continue;
5608 }
5609 if (type == bgp_show_type_route_map
5610 || type == bgp_show_type_flap_route_map)
5611 {
ajs5a646652004-11-05 01:25:55 +00005612 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00005613 struct bgp_info binfo;
5614 struct attr dummy_attr;
5615 int ret;
5616
5617 dummy_attr = *ri->attr;
5618 binfo.peer = ri->peer;
5619 binfo.attr = &dummy_attr;
5620
5621 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5622
5623 if (ret == RMAP_DENYMATCH)
5624 continue;
5625 }
5626 if (type == bgp_show_type_neighbor
5627 || type == bgp_show_type_flap_neighbor
5628 || type == bgp_show_type_damp_neighbor)
5629 {
ajs5a646652004-11-05 01:25:55 +00005630 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00005631
5632 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5633 continue;
5634 }
5635 if (type == bgp_show_type_cidr_only
5636 || type == bgp_show_type_flap_cidr_only)
5637 {
5638 u_int32_t destination;
5639
5640 destination = ntohl (rn->p.u.prefix4.s_addr);
5641 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5642 continue;
5643 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5644 continue;
5645 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5646 continue;
5647 }
5648 if (type == bgp_show_type_prefix_longer
5649 || type == bgp_show_type_flap_prefix_longer)
5650 {
ajs5a646652004-11-05 01:25:55 +00005651 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005652
5653 if (! prefix_match (p, &rn->p))
5654 continue;
5655 }
5656 if (type == bgp_show_type_community_all)
5657 {
5658 if (! ri->attr->community)
5659 continue;
5660 }
5661 if (type == bgp_show_type_community)
5662 {
ajs5a646652004-11-05 01:25:55 +00005663 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005664
5665 if (! ri->attr->community ||
5666 ! community_match (ri->attr->community, com))
5667 continue;
5668 }
5669 if (type == bgp_show_type_community_exact)
5670 {
ajs5a646652004-11-05 01:25:55 +00005671 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005672
5673 if (! ri->attr->community ||
5674 ! community_cmp (ri->attr->community, com))
5675 continue;
5676 }
5677 if (type == bgp_show_type_community_list)
5678 {
ajs5a646652004-11-05 01:25:55 +00005679 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005680
5681 if (! community_list_match (ri->attr->community, list))
5682 continue;
5683 }
5684 if (type == bgp_show_type_community_list_exact)
5685 {
ajs5a646652004-11-05 01:25:55 +00005686 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005687
5688 if (! community_list_exact_match (ri->attr->community, list))
5689 continue;
5690 }
5691 if (type == bgp_show_type_flap_address
5692 || type == bgp_show_type_flap_prefix)
5693 {
ajs5a646652004-11-05 01:25:55 +00005694 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005695
5696 if (! prefix_match (&rn->p, p))
5697 continue;
5698
5699 if (type == bgp_show_type_flap_prefix)
5700 if (p->prefixlen != rn->p.prefixlen)
5701 continue;
5702 }
5703 if (type == bgp_show_type_dampend_paths
5704 || type == bgp_show_type_damp_neighbor)
5705 {
5706 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5707 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5708 continue;
5709 }
5710
5711 if (header)
5712 {
hasso93406d82005-02-02 14:40:33 +00005713 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
5714 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
5715 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005716 if (type == bgp_show_type_dampend_paths
5717 || type == bgp_show_type_damp_neighbor)
5718 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5719 else if (type == bgp_show_type_flap_statistics
5720 || type == bgp_show_type_flap_address
5721 || type == bgp_show_type_flap_prefix
5722 || type == bgp_show_type_flap_cidr_only
5723 || type == bgp_show_type_flap_regexp
5724 || type == bgp_show_type_flap_filter_list
5725 || type == bgp_show_type_flap_prefix_list
5726 || type == bgp_show_type_flap_prefix_longer
5727 || type == bgp_show_type_flap_route_map
5728 || type == bgp_show_type_flap_neighbor)
5729 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5730 else
5731 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005732 header = 0;
5733 }
5734
5735 if (type == bgp_show_type_dampend_paths
5736 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00005737 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005738 else if (type == bgp_show_type_flap_statistics
5739 || type == bgp_show_type_flap_address
5740 || type == bgp_show_type_flap_prefix
5741 || type == bgp_show_type_flap_cidr_only
5742 || type == bgp_show_type_flap_regexp
5743 || type == bgp_show_type_flap_filter_list
5744 || type == bgp_show_type_flap_prefix_list
5745 || type == bgp_show_type_flap_prefix_longer
5746 || type == bgp_show_type_flap_route_map
5747 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00005748 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005749 else
ajs5a646652004-11-05 01:25:55 +00005750 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005751 display++;
5752 }
5753 if (display)
ajs5a646652004-11-05 01:25:55 +00005754 output_count++;
paul718e3742002-12-13 20:15:29 +00005755 }
5756
5757 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00005758 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00005759 {
5760 if (type == bgp_show_type_normal)
5761 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5762 }
5763 else
5764 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00005765 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005766
5767 return CMD_SUCCESS;
5768}
5769
ajs5a646652004-11-05 01:25:55 +00005770static int
paulfee0f4c2004-09-13 05:12:46 +00005771bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00005772 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00005773{
5774 struct bgp_table *table;
5775
5776 if (bgp == NULL) {
5777 bgp = bgp_get_default ();
5778 }
5779
5780 if (bgp == NULL)
5781 {
5782 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5783 return CMD_WARNING;
5784 }
5785
5786
5787 table = bgp->rib[afi][safi];
5788
ajs5a646652004-11-05 01:25:55 +00005789 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00005790}
5791
paul718e3742002-12-13 20:15:29 +00005792/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00005793static void
paul718e3742002-12-13 20:15:29 +00005794route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5795 struct bgp_node *rn,
5796 struct prefix_rd *prd, afi_t afi, safi_t safi)
5797{
5798 struct bgp_info *ri;
5799 struct prefix *p;
5800 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00005801 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005802 char buf1[INET6_ADDRSTRLEN];
5803 char buf2[INET6_ADDRSTRLEN];
5804 int count = 0;
5805 int best = 0;
5806 int suppress = 0;
5807 int no_export = 0;
5808 int no_advertise = 0;
5809 int local_as = 0;
5810 int first = 0;
5811
5812 p = &rn->p;
5813 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5814 (safi == SAFI_MPLS_VPN ?
5815 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5816 safi == SAFI_MPLS_VPN ? ":" : "",
5817 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5818 p->prefixlen, VTY_NEWLINE);
5819
5820 for (ri = rn->info; ri; ri = ri->next)
5821 {
5822 count++;
5823 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5824 {
5825 best = count;
5826 if (ri->suppress)
5827 suppress = 1;
5828 if (ri->attr->community != NULL)
5829 {
5830 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5831 no_advertise = 1;
5832 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5833 no_export = 1;
5834 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5835 local_as = 1;
5836 }
5837 }
5838 }
5839
5840 vty_out (vty, "Paths: (%d available", count);
5841 if (best)
5842 {
5843 vty_out (vty, ", best #%d", best);
5844 if (safi == SAFI_UNICAST)
5845 vty_out (vty, ", table Default-IP-Routing-Table");
5846 }
5847 else
5848 vty_out (vty, ", no best path");
5849 if (no_advertise)
5850 vty_out (vty, ", not advertised to any peer");
5851 else if (no_export)
5852 vty_out (vty, ", not advertised to EBGP peer");
5853 else if (local_as)
5854 vty_out (vty, ", not advertised outside local AS");
5855 if (suppress)
5856 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5857 vty_out (vty, ")%s", VTY_NEWLINE);
5858
5859 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00005860 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00005861 {
5862 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5863 {
5864 if (! first)
5865 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5866 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5867 first = 1;
5868 }
5869 }
5870 if (! first)
5871 vty_out (vty, " Not advertised to any peer");
5872 vty_out (vty, "%s", VTY_NEWLINE);
5873}
5874
5875/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00005876static int
paulfee0f4c2004-09-13 05:12:46 +00005877bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00005878 struct bgp_table *rib, const char *ip_str,
5879 afi_t afi, safi_t safi, struct prefix_rd *prd,
5880 int prefix_check)
paul718e3742002-12-13 20:15:29 +00005881{
5882 int ret;
5883 int header;
5884 int display = 0;
5885 struct prefix match;
5886 struct bgp_node *rn;
5887 struct bgp_node *rm;
5888 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00005889 struct bgp_table *table;
5890
paul718e3742002-12-13 20:15:29 +00005891 /* Check IP address argument. */
5892 ret = str2prefix (ip_str, &match);
5893 if (! ret)
5894 {
5895 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5896 return CMD_WARNING;
5897 }
5898
5899 match.family = afi2family (afi);
5900
5901 if (safi == SAFI_MPLS_VPN)
5902 {
paulfee0f4c2004-09-13 05:12:46 +00005903 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00005904 {
5905 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5906 continue;
5907
5908 if ((table = rn->info) != NULL)
5909 {
5910 header = 1;
5911
5912 if ((rm = bgp_node_match (table, &match)) != NULL)
5913 {
5914 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5915 continue;
5916
5917 for (ri = rm->info; ri; ri = ri->next)
5918 {
5919 if (header)
5920 {
5921 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5922 AFI_IP, SAFI_MPLS_VPN);
5923
5924 header = 0;
5925 }
5926 display++;
5927 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5928 }
5929 }
5930 }
5931 }
5932 }
5933 else
5934 {
5935 header = 1;
5936
paulfee0f4c2004-09-13 05:12:46 +00005937 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00005938 {
5939 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5940 {
5941 for (ri = rn->info; ri; ri = ri->next)
5942 {
5943 if (header)
5944 {
5945 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
5946 header = 0;
5947 }
5948 display++;
5949 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
5950 }
5951 }
5952 }
5953 }
5954
5955 if (! display)
5956 {
5957 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5958 return CMD_WARNING;
5959 }
5960
5961 return CMD_SUCCESS;
5962}
5963
paulfee0f4c2004-09-13 05:12:46 +00005964/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00005965static int
paulfd79ac92004-10-13 05:06:08 +00005966bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00005967 afi_t afi, safi_t safi, struct prefix_rd *prd,
5968 int prefix_check)
5969{
5970 struct bgp *bgp;
5971
5972 /* BGP structure lookup. */
5973 if (view_name)
5974 {
5975 bgp = bgp_lookup_by_name (view_name);
5976 if (bgp == NULL)
5977 {
5978 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
5979 return CMD_WARNING;
5980 }
5981 }
5982 else
5983 {
5984 bgp = bgp_get_default ();
5985 if (bgp == NULL)
5986 {
5987 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5988 return CMD_WARNING;
5989 }
5990 }
5991
5992 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
5993 afi, safi, prd, prefix_check);
5994}
5995
paul718e3742002-12-13 20:15:29 +00005996/* BGP route print out function. */
5997DEFUN (show_ip_bgp,
5998 show_ip_bgp_cmd,
5999 "show ip bgp",
6000 SHOW_STR
6001 IP_STR
6002 BGP_STR)
6003{
ajs5a646652004-11-05 01:25:55 +00006004 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006005}
6006
6007DEFUN (show_ip_bgp_ipv4,
6008 show_ip_bgp_ipv4_cmd,
6009 "show ip bgp ipv4 (unicast|multicast)",
6010 SHOW_STR
6011 IP_STR
6012 BGP_STR
6013 "Address family\n"
6014 "Address Family modifier\n"
6015 "Address Family modifier\n")
6016{
6017 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006018 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6019 NULL);
paul718e3742002-12-13 20:15:29 +00006020
ajs5a646652004-11-05 01:25:55 +00006021 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006022}
6023
6024DEFUN (show_ip_bgp_route,
6025 show_ip_bgp_route_cmd,
6026 "show ip bgp A.B.C.D",
6027 SHOW_STR
6028 IP_STR
6029 BGP_STR
6030 "Network in the BGP routing table to display\n")
6031{
6032 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6033}
6034
6035DEFUN (show_ip_bgp_ipv4_route,
6036 show_ip_bgp_ipv4_route_cmd,
6037 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6038 SHOW_STR
6039 IP_STR
6040 BGP_STR
6041 "Address family\n"
6042 "Address Family modifier\n"
6043 "Address Family modifier\n"
6044 "Network in the BGP routing table to display\n")
6045{
6046 if (strncmp (argv[0], "m", 1) == 0)
6047 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6048
6049 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6050}
6051
6052DEFUN (show_ip_bgp_vpnv4_all_route,
6053 show_ip_bgp_vpnv4_all_route_cmd,
6054 "show ip bgp vpnv4 all A.B.C.D",
6055 SHOW_STR
6056 IP_STR
6057 BGP_STR
6058 "Display VPNv4 NLRI specific information\n"
6059 "Display information about all VPNv4 NLRIs\n"
6060 "Network in the BGP routing table to display\n")
6061{
6062 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6063}
6064
6065DEFUN (show_ip_bgp_vpnv4_rd_route,
6066 show_ip_bgp_vpnv4_rd_route_cmd,
6067 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6068 SHOW_STR
6069 IP_STR
6070 BGP_STR
6071 "Display VPNv4 NLRI specific information\n"
6072 "Display information for a route distinguisher\n"
6073 "VPN Route Distinguisher\n"
6074 "Network in the BGP routing table to display\n")
6075{
6076 int ret;
6077 struct prefix_rd prd;
6078
6079 ret = str2prefix_rd (argv[0], &prd);
6080 if (! ret)
6081 {
6082 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6083 return CMD_WARNING;
6084 }
6085 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6086}
6087
6088DEFUN (show_ip_bgp_prefix,
6089 show_ip_bgp_prefix_cmd,
6090 "show ip bgp A.B.C.D/M",
6091 SHOW_STR
6092 IP_STR
6093 BGP_STR
6094 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6095{
6096 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6097}
6098
6099DEFUN (show_ip_bgp_ipv4_prefix,
6100 show_ip_bgp_ipv4_prefix_cmd,
6101 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6102 SHOW_STR
6103 IP_STR
6104 BGP_STR
6105 "Address family\n"
6106 "Address Family modifier\n"
6107 "Address Family modifier\n"
6108 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6109{
6110 if (strncmp (argv[0], "m", 1) == 0)
6111 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6112
6113 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6114}
6115
6116DEFUN (show_ip_bgp_vpnv4_all_prefix,
6117 show_ip_bgp_vpnv4_all_prefix_cmd,
6118 "show ip bgp vpnv4 all A.B.C.D/M",
6119 SHOW_STR
6120 IP_STR
6121 BGP_STR
6122 "Display VPNv4 NLRI specific information\n"
6123 "Display information about all VPNv4 NLRIs\n"
6124 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6125{
6126 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6127}
6128
6129DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6130 show_ip_bgp_vpnv4_rd_prefix_cmd,
6131 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6132 SHOW_STR
6133 IP_STR
6134 BGP_STR
6135 "Display VPNv4 NLRI specific information\n"
6136 "Display information for a route distinguisher\n"
6137 "VPN Route Distinguisher\n"
6138 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6139{
6140 int ret;
6141 struct prefix_rd prd;
6142
6143 ret = str2prefix_rd (argv[0], &prd);
6144 if (! ret)
6145 {
6146 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6147 return CMD_WARNING;
6148 }
6149 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6150}
6151
6152DEFUN (show_ip_bgp_view,
6153 show_ip_bgp_view_cmd,
6154 "show ip bgp view WORD",
6155 SHOW_STR
6156 IP_STR
6157 BGP_STR
6158 "BGP view\n"
6159 "BGP view name\n")
6160{
paulbb46e942003-10-24 19:02:03 +00006161 struct bgp *bgp;
6162
6163 /* BGP structure lookup. */
6164 bgp = bgp_lookup_by_name (argv[0]);
6165 if (bgp == NULL)
6166 {
6167 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6168 return CMD_WARNING;
6169 }
6170
ajs5a646652004-11-05 01:25:55 +00006171 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006172}
6173
6174DEFUN (show_ip_bgp_view_route,
6175 show_ip_bgp_view_route_cmd,
6176 "show ip bgp view WORD A.B.C.D",
6177 SHOW_STR
6178 IP_STR
6179 BGP_STR
6180 "BGP view\n"
6181 "BGP view name\n"
6182 "Network in the BGP routing table to display\n")
6183{
6184 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6185}
6186
6187DEFUN (show_ip_bgp_view_prefix,
6188 show_ip_bgp_view_prefix_cmd,
6189 "show ip bgp view WORD A.B.C.D/M",
6190 SHOW_STR
6191 IP_STR
6192 BGP_STR
6193 "BGP view\n"
6194 "BGP view name\n"
6195 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6196{
6197 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6198}
6199
6200#ifdef HAVE_IPV6
6201DEFUN (show_bgp,
6202 show_bgp_cmd,
6203 "show bgp",
6204 SHOW_STR
6205 BGP_STR)
6206{
ajs5a646652004-11-05 01:25:55 +00006207 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6208 NULL);
paul718e3742002-12-13 20:15:29 +00006209}
6210
6211ALIAS (show_bgp,
6212 show_bgp_ipv6_cmd,
6213 "show bgp ipv6",
6214 SHOW_STR
6215 BGP_STR
6216 "Address family\n")
6217
6218/* old command */
6219DEFUN (show_ipv6_bgp,
6220 show_ipv6_bgp_cmd,
6221 "show ipv6 bgp",
6222 SHOW_STR
6223 IP_STR
6224 BGP_STR)
6225{
ajs5a646652004-11-05 01:25:55 +00006226 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6227 NULL);
paul718e3742002-12-13 20:15:29 +00006228}
6229
6230DEFUN (show_bgp_route,
6231 show_bgp_route_cmd,
6232 "show bgp X:X::X:X",
6233 SHOW_STR
6234 BGP_STR
6235 "Network in the BGP routing table to display\n")
6236{
6237 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6238}
6239
6240ALIAS (show_bgp_route,
6241 show_bgp_ipv6_route_cmd,
6242 "show bgp ipv6 X:X::X:X",
6243 SHOW_STR
6244 BGP_STR
6245 "Address family\n"
6246 "Network in the BGP routing table to display\n")
6247
6248/* old command */
6249DEFUN (show_ipv6_bgp_route,
6250 show_ipv6_bgp_route_cmd,
6251 "show ipv6 bgp X:X::X:X",
6252 SHOW_STR
6253 IP_STR
6254 BGP_STR
6255 "Network in the BGP routing table to display\n")
6256{
6257 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6258}
6259
6260DEFUN (show_bgp_prefix,
6261 show_bgp_prefix_cmd,
6262 "show bgp X:X::X:X/M",
6263 SHOW_STR
6264 BGP_STR
6265 "IPv6 prefix <network>/<length>\n")
6266{
6267 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6268}
6269
6270ALIAS (show_bgp_prefix,
6271 show_bgp_ipv6_prefix_cmd,
6272 "show bgp ipv6 X:X::X:X/M",
6273 SHOW_STR
6274 BGP_STR
6275 "Address family\n"
6276 "IPv6 prefix <network>/<length>\n")
6277
6278/* old command */
6279DEFUN (show_ipv6_bgp_prefix,
6280 show_ipv6_bgp_prefix_cmd,
6281 "show ipv6 bgp X:X::X:X/M",
6282 SHOW_STR
6283 IP_STR
6284 BGP_STR
6285 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6286{
6287 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6288}
6289
paulbb46e942003-10-24 19:02:03 +00006290DEFUN (show_bgp_view,
6291 show_bgp_view_cmd,
6292 "show bgp view WORD",
6293 SHOW_STR
6294 BGP_STR
6295 "BGP view\n"
6296 "View name\n")
6297{
6298 struct bgp *bgp;
6299
6300 /* BGP structure lookup. */
6301 bgp = bgp_lookup_by_name (argv[0]);
6302 if (bgp == NULL)
6303 {
6304 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6305 return CMD_WARNING;
6306 }
6307
ajs5a646652004-11-05 01:25:55 +00006308 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006309}
6310
6311ALIAS (show_bgp_view,
6312 show_bgp_view_ipv6_cmd,
6313 "show bgp view WORD ipv6",
6314 SHOW_STR
6315 BGP_STR
6316 "BGP view\n"
6317 "View name\n"
6318 "Address family\n")
6319
6320DEFUN (show_bgp_view_route,
6321 show_bgp_view_route_cmd,
6322 "show bgp view WORD X:X::X:X",
6323 SHOW_STR
6324 BGP_STR
6325 "BGP view\n"
6326 "View name\n"
6327 "Network in the BGP routing table to display\n")
6328{
6329 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6330}
6331
6332ALIAS (show_bgp_view_route,
6333 show_bgp_view_ipv6_route_cmd,
6334 "show bgp view WORD ipv6 X:X::X:X",
6335 SHOW_STR
6336 BGP_STR
6337 "BGP view\n"
6338 "View name\n"
6339 "Address family\n"
6340 "Network in the BGP routing table to display\n")
6341
6342DEFUN (show_bgp_view_prefix,
6343 show_bgp_view_prefix_cmd,
6344 "show bgp view WORD X:X::X:X/M",
6345 SHOW_STR
6346 BGP_STR
6347 "BGP view\n"
6348 "View name\n"
6349 "IPv6 prefix <network>/<length>\n")
6350{
6351 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6352}
6353
6354ALIAS (show_bgp_view_prefix,
6355 show_bgp_view_ipv6_prefix_cmd,
6356 "show bgp view WORD ipv6 X:X::X:X/M",
6357 SHOW_STR
6358 BGP_STR
6359 "BGP view\n"
6360 "View name\n"
6361 "Address family\n"
6362 "IPv6 prefix <network>/<length>\n")
6363
paul718e3742002-12-13 20:15:29 +00006364/* old command */
6365DEFUN (show_ipv6_mbgp,
6366 show_ipv6_mbgp_cmd,
6367 "show ipv6 mbgp",
6368 SHOW_STR
6369 IP_STR
6370 MBGP_STR)
6371{
ajs5a646652004-11-05 01:25:55 +00006372 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6373 NULL);
paul718e3742002-12-13 20:15:29 +00006374}
6375
6376/* old command */
6377DEFUN (show_ipv6_mbgp_route,
6378 show_ipv6_mbgp_route_cmd,
6379 "show ipv6 mbgp X:X::X:X",
6380 SHOW_STR
6381 IP_STR
6382 MBGP_STR
6383 "Network in the MBGP routing table to display\n")
6384{
6385 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6386}
6387
6388/* old command */
6389DEFUN (show_ipv6_mbgp_prefix,
6390 show_ipv6_mbgp_prefix_cmd,
6391 "show ipv6 mbgp X:X::X:X/M",
6392 SHOW_STR
6393 IP_STR
6394 MBGP_STR
6395 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6396{
6397 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6398}
6399#endif
6400
paul718e3742002-12-13 20:15:29 +00006401
paul94f2b392005-06-28 12:44:16 +00006402static int
paulfd79ac92004-10-13 05:06:08 +00006403bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006404 safi_t safi, enum bgp_show_type type)
6405{
6406 int i;
6407 struct buffer *b;
6408 char *regstr;
6409 int first;
6410 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006411 int rc;
paul718e3742002-12-13 20:15:29 +00006412
6413 first = 0;
6414 b = buffer_new (1024);
6415 for (i = 0; i < argc; i++)
6416 {
6417 if (first)
6418 buffer_putc (b, ' ');
6419 else
6420 {
6421 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6422 continue;
6423 first = 1;
6424 }
6425
6426 buffer_putstr (b, argv[i]);
6427 }
6428 buffer_putc (b, '\0');
6429
6430 regstr = buffer_getstr (b);
6431 buffer_free (b);
6432
6433 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006434 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006435 if (! regex)
6436 {
6437 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6438 VTY_NEWLINE);
6439 return CMD_WARNING;
6440 }
6441
ajs5a646652004-11-05 01:25:55 +00006442 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6443 bgp_regex_free (regex);
6444 return rc;
paul718e3742002-12-13 20:15:29 +00006445}
6446
6447DEFUN (show_ip_bgp_regexp,
6448 show_ip_bgp_regexp_cmd,
6449 "show ip bgp regexp .LINE",
6450 SHOW_STR
6451 IP_STR
6452 BGP_STR
6453 "Display routes matching the AS path regular expression\n"
6454 "A regular-expression to match the BGP AS paths\n")
6455{
6456 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6457 bgp_show_type_regexp);
6458}
6459
6460DEFUN (show_ip_bgp_flap_regexp,
6461 show_ip_bgp_flap_regexp_cmd,
6462 "show ip bgp flap-statistics regexp .LINE",
6463 SHOW_STR
6464 IP_STR
6465 BGP_STR
6466 "Display flap statistics of routes\n"
6467 "Display routes matching the AS path regular expression\n"
6468 "A regular-expression to match the BGP AS paths\n")
6469{
6470 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6471 bgp_show_type_flap_regexp);
6472}
6473
6474DEFUN (show_ip_bgp_ipv4_regexp,
6475 show_ip_bgp_ipv4_regexp_cmd,
6476 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6477 SHOW_STR
6478 IP_STR
6479 BGP_STR
6480 "Address family\n"
6481 "Address Family modifier\n"
6482 "Address Family modifier\n"
6483 "Display routes matching the AS path regular expression\n"
6484 "A regular-expression to match the BGP AS paths\n")
6485{
6486 if (strncmp (argv[0], "m", 1) == 0)
6487 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6488 bgp_show_type_regexp);
6489
6490 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6491 bgp_show_type_regexp);
6492}
6493
6494#ifdef HAVE_IPV6
6495DEFUN (show_bgp_regexp,
6496 show_bgp_regexp_cmd,
6497 "show bgp regexp .LINE",
6498 SHOW_STR
6499 BGP_STR
6500 "Display routes matching the AS path regular expression\n"
6501 "A regular-expression to match the BGP AS paths\n")
6502{
6503 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6504 bgp_show_type_regexp);
6505}
6506
6507ALIAS (show_bgp_regexp,
6508 show_bgp_ipv6_regexp_cmd,
6509 "show bgp ipv6 regexp .LINE",
6510 SHOW_STR
6511 BGP_STR
6512 "Address family\n"
6513 "Display routes matching the AS path regular expression\n"
6514 "A regular-expression to match the BGP AS paths\n")
6515
6516/* old command */
6517DEFUN (show_ipv6_bgp_regexp,
6518 show_ipv6_bgp_regexp_cmd,
6519 "show ipv6 bgp regexp .LINE",
6520 SHOW_STR
6521 IP_STR
6522 BGP_STR
6523 "Display routes matching the AS path regular expression\n"
6524 "A regular-expression to match the BGP AS paths\n")
6525{
6526 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6527 bgp_show_type_regexp);
6528}
6529
6530/* old command */
6531DEFUN (show_ipv6_mbgp_regexp,
6532 show_ipv6_mbgp_regexp_cmd,
6533 "show ipv6 mbgp regexp .LINE",
6534 SHOW_STR
6535 IP_STR
6536 BGP_STR
6537 "Display routes matching the AS path regular expression\n"
6538 "A regular-expression to match the MBGP AS paths\n")
6539{
6540 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6541 bgp_show_type_regexp);
6542}
6543#endif /* HAVE_IPV6 */
6544
paul94f2b392005-06-28 12:44:16 +00006545static int
paulfd79ac92004-10-13 05:06:08 +00006546bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006547 safi_t safi, enum bgp_show_type type)
6548{
6549 struct prefix_list *plist;
6550
6551 plist = prefix_list_lookup (afi, prefix_list_str);
6552 if (plist == NULL)
6553 {
6554 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6555 prefix_list_str, VTY_NEWLINE);
6556 return CMD_WARNING;
6557 }
6558
ajs5a646652004-11-05 01:25:55 +00006559 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00006560}
6561
6562DEFUN (show_ip_bgp_prefix_list,
6563 show_ip_bgp_prefix_list_cmd,
6564 "show ip bgp prefix-list WORD",
6565 SHOW_STR
6566 IP_STR
6567 BGP_STR
6568 "Display routes conforming to the prefix-list\n"
6569 "IP prefix-list name\n")
6570{
6571 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6572 bgp_show_type_prefix_list);
6573}
6574
6575DEFUN (show_ip_bgp_flap_prefix_list,
6576 show_ip_bgp_flap_prefix_list_cmd,
6577 "show ip bgp flap-statistics prefix-list WORD",
6578 SHOW_STR
6579 IP_STR
6580 BGP_STR
6581 "Display flap statistics of routes\n"
6582 "Display routes conforming to the prefix-list\n"
6583 "IP prefix-list name\n")
6584{
6585 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6586 bgp_show_type_flap_prefix_list);
6587}
6588
6589DEFUN (show_ip_bgp_ipv4_prefix_list,
6590 show_ip_bgp_ipv4_prefix_list_cmd,
6591 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6592 SHOW_STR
6593 IP_STR
6594 BGP_STR
6595 "Address family\n"
6596 "Address Family modifier\n"
6597 "Address Family modifier\n"
6598 "Display routes conforming to the prefix-list\n"
6599 "IP prefix-list name\n")
6600{
6601 if (strncmp (argv[0], "m", 1) == 0)
6602 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6603 bgp_show_type_prefix_list);
6604
6605 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6606 bgp_show_type_prefix_list);
6607}
6608
6609#ifdef HAVE_IPV6
6610DEFUN (show_bgp_prefix_list,
6611 show_bgp_prefix_list_cmd,
6612 "show bgp prefix-list WORD",
6613 SHOW_STR
6614 BGP_STR
6615 "Display routes conforming to the prefix-list\n"
6616 "IPv6 prefix-list name\n")
6617{
6618 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6619 bgp_show_type_prefix_list);
6620}
6621
6622ALIAS (show_bgp_prefix_list,
6623 show_bgp_ipv6_prefix_list_cmd,
6624 "show bgp ipv6 prefix-list WORD",
6625 SHOW_STR
6626 BGP_STR
6627 "Address family\n"
6628 "Display routes conforming to the prefix-list\n"
6629 "IPv6 prefix-list name\n")
6630
6631/* old command */
6632DEFUN (show_ipv6_bgp_prefix_list,
6633 show_ipv6_bgp_prefix_list_cmd,
6634 "show ipv6 bgp prefix-list WORD",
6635 SHOW_STR
6636 IPV6_STR
6637 BGP_STR
6638 "Display routes matching the prefix-list\n"
6639 "IPv6 prefix-list name\n")
6640{
6641 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6642 bgp_show_type_prefix_list);
6643}
6644
6645/* old command */
6646DEFUN (show_ipv6_mbgp_prefix_list,
6647 show_ipv6_mbgp_prefix_list_cmd,
6648 "show ipv6 mbgp prefix-list WORD",
6649 SHOW_STR
6650 IPV6_STR
6651 MBGP_STR
6652 "Display routes matching the prefix-list\n"
6653 "IPv6 prefix-list name\n")
6654{
6655 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6656 bgp_show_type_prefix_list);
6657}
6658#endif /* HAVE_IPV6 */
6659
paul94f2b392005-06-28 12:44:16 +00006660static int
paulfd79ac92004-10-13 05:06:08 +00006661bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006662 safi_t safi, enum bgp_show_type type)
6663{
6664 struct as_list *as_list;
6665
6666 as_list = as_list_lookup (filter);
6667 if (as_list == NULL)
6668 {
6669 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6670 return CMD_WARNING;
6671 }
6672
ajs5a646652004-11-05 01:25:55 +00006673 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00006674}
6675
6676DEFUN (show_ip_bgp_filter_list,
6677 show_ip_bgp_filter_list_cmd,
6678 "show ip bgp filter-list WORD",
6679 SHOW_STR
6680 IP_STR
6681 BGP_STR
6682 "Display routes conforming to the filter-list\n"
6683 "Regular expression access list name\n")
6684{
6685 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6686 bgp_show_type_filter_list);
6687}
6688
6689DEFUN (show_ip_bgp_flap_filter_list,
6690 show_ip_bgp_flap_filter_list_cmd,
6691 "show ip bgp flap-statistics filter-list WORD",
6692 SHOW_STR
6693 IP_STR
6694 BGP_STR
6695 "Display flap statistics of routes\n"
6696 "Display routes conforming to the filter-list\n"
6697 "Regular expression access list name\n")
6698{
6699 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6700 bgp_show_type_flap_filter_list);
6701}
6702
6703DEFUN (show_ip_bgp_ipv4_filter_list,
6704 show_ip_bgp_ipv4_filter_list_cmd,
6705 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6706 SHOW_STR
6707 IP_STR
6708 BGP_STR
6709 "Address family\n"
6710 "Address Family modifier\n"
6711 "Address Family modifier\n"
6712 "Display routes conforming to the filter-list\n"
6713 "Regular expression access list name\n")
6714{
6715 if (strncmp (argv[0], "m", 1) == 0)
6716 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6717 bgp_show_type_filter_list);
6718
6719 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6720 bgp_show_type_filter_list);
6721}
6722
6723#ifdef HAVE_IPV6
6724DEFUN (show_bgp_filter_list,
6725 show_bgp_filter_list_cmd,
6726 "show bgp filter-list WORD",
6727 SHOW_STR
6728 BGP_STR
6729 "Display routes conforming to the filter-list\n"
6730 "Regular expression access list name\n")
6731{
6732 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6733 bgp_show_type_filter_list);
6734}
6735
6736ALIAS (show_bgp_filter_list,
6737 show_bgp_ipv6_filter_list_cmd,
6738 "show bgp ipv6 filter-list WORD",
6739 SHOW_STR
6740 BGP_STR
6741 "Address family\n"
6742 "Display routes conforming to the filter-list\n"
6743 "Regular expression access list name\n")
6744
6745/* old command */
6746DEFUN (show_ipv6_bgp_filter_list,
6747 show_ipv6_bgp_filter_list_cmd,
6748 "show ipv6 bgp filter-list WORD",
6749 SHOW_STR
6750 IPV6_STR
6751 BGP_STR
6752 "Display routes conforming to the filter-list\n"
6753 "Regular expression access list name\n")
6754{
6755 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6756 bgp_show_type_filter_list);
6757}
6758
6759/* old command */
6760DEFUN (show_ipv6_mbgp_filter_list,
6761 show_ipv6_mbgp_filter_list_cmd,
6762 "show ipv6 mbgp filter-list WORD",
6763 SHOW_STR
6764 IPV6_STR
6765 MBGP_STR
6766 "Display routes conforming to the filter-list\n"
6767 "Regular expression access list name\n")
6768{
6769 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6770 bgp_show_type_filter_list);
6771}
6772#endif /* HAVE_IPV6 */
6773
paul94f2b392005-06-28 12:44:16 +00006774static int
paulfd79ac92004-10-13 05:06:08 +00006775bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006776 safi_t safi, enum bgp_show_type type)
6777{
6778 struct route_map *rmap;
6779
6780 rmap = route_map_lookup_by_name (rmap_str);
6781 if (! rmap)
6782 {
6783 vty_out (vty, "%% %s is not a valid route-map name%s",
6784 rmap_str, VTY_NEWLINE);
6785 return CMD_WARNING;
6786 }
6787
ajs5a646652004-11-05 01:25:55 +00006788 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00006789}
6790
6791DEFUN (show_ip_bgp_route_map,
6792 show_ip_bgp_route_map_cmd,
6793 "show ip bgp route-map WORD",
6794 SHOW_STR
6795 IP_STR
6796 BGP_STR
6797 "Display routes matching the route-map\n"
6798 "A route-map to match on\n")
6799{
6800 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6801 bgp_show_type_route_map);
6802}
6803
6804DEFUN (show_ip_bgp_flap_route_map,
6805 show_ip_bgp_flap_route_map_cmd,
6806 "show ip bgp flap-statistics route-map WORD",
6807 SHOW_STR
6808 IP_STR
6809 BGP_STR
6810 "Display flap statistics of routes\n"
6811 "Display routes matching the route-map\n"
6812 "A route-map to match on\n")
6813{
6814 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6815 bgp_show_type_flap_route_map);
6816}
6817
6818DEFUN (show_ip_bgp_ipv4_route_map,
6819 show_ip_bgp_ipv4_route_map_cmd,
6820 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6821 SHOW_STR
6822 IP_STR
6823 BGP_STR
6824 "Address family\n"
6825 "Address Family modifier\n"
6826 "Address Family modifier\n"
6827 "Display routes matching the route-map\n"
6828 "A route-map to match on\n")
6829{
6830 if (strncmp (argv[0], "m", 1) == 0)
6831 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6832 bgp_show_type_route_map);
6833
6834 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6835 bgp_show_type_route_map);
6836}
6837
6838DEFUN (show_bgp_route_map,
6839 show_bgp_route_map_cmd,
6840 "show bgp route-map WORD",
6841 SHOW_STR
6842 BGP_STR
6843 "Display routes matching the route-map\n"
6844 "A route-map to match on\n")
6845{
6846 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6847 bgp_show_type_route_map);
6848}
6849
6850ALIAS (show_bgp_route_map,
6851 show_bgp_ipv6_route_map_cmd,
6852 "show bgp ipv6 route-map WORD",
6853 SHOW_STR
6854 BGP_STR
6855 "Address family\n"
6856 "Display routes matching the route-map\n"
6857 "A route-map to match on\n")
6858
6859DEFUN (show_ip_bgp_cidr_only,
6860 show_ip_bgp_cidr_only_cmd,
6861 "show ip bgp cidr-only",
6862 SHOW_STR
6863 IP_STR
6864 BGP_STR
6865 "Display only routes with non-natural netmasks\n")
6866{
6867 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006868 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006869}
6870
6871DEFUN (show_ip_bgp_flap_cidr_only,
6872 show_ip_bgp_flap_cidr_only_cmd,
6873 "show ip bgp flap-statistics cidr-only",
6874 SHOW_STR
6875 IP_STR
6876 BGP_STR
6877 "Display flap statistics of routes\n"
6878 "Display only routes with non-natural netmasks\n")
6879{
6880 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006881 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006882}
6883
6884DEFUN (show_ip_bgp_ipv4_cidr_only,
6885 show_ip_bgp_ipv4_cidr_only_cmd,
6886 "show ip bgp ipv4 (unicast|multicast) cidr-only",
6887 SHOW_STR
6888 IP_STR
6889 BGP_STR
6890 "Address family\n"
6891 "Address Family modifier\n"
6892 "Address Family modifier\n"
6893 "Display only routes with non-natural netmasks\n")
6894{
6895 if (strncmp (argv[0], "m", 1) == 0)
6896 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006897 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006898
6899 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006900 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006901}
6902
6903DEFUN (show_ip_bgp_community_all,
6904 show_ip_bgp_community_all_cmd,
6905 "show ip bgp community",
6906 SHOW_STR
6907 IP_STR
6908 BGP_STR
6909 "Display routes matching the communities\n")
6910{
6911 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006912 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006913}
6914
6915DEFUN (show_ip_bgp_ipv4_community_all,
6916 show_ip_bgp_ipv4_community_all_cmd,
6917 "show ip bgp ipv4 (unicast|multicast) community",
6918 SHOW_STR
6919 IP_STR
6920 BGP_STR
6921 "Address family\n"
6922 "Address Family modifier\n"
6923 "Address Family modifier\n"
6924 "Display routes matching the communities\n")
6925{
6926 if (strncmp (argv[0], "m", 1) == 0)
6927 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006928 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006929
6930 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006931 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006932}
6933
6934#ifdef HAVE_IPV6
6935DEFUN (show_bgp_community_all,
6936 show_bgp_community_all_cmd,
6937 "show bgp community",
6938 SHOW_STR
6939 BGP_STR
6940 "Display routes matching the communities\n")
6941{
6942 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006943 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006944}
6945
6946ALIAS (show_bgp_community_all,
6947 show_bgp_ipv6_community_all_cmd,
6948 "show bgp ipv6 community",
6949 SHOW_STR
6950 BGP_STR
6951 "Address family\n"
6952 "Display routes matching the communities\n")
6953
6954/* old command */
6955DEFUN (show_ipv6_bgp_community_all,
6956 show_ipv6_bgp_community_all_cmd,
6957 "show ipv6 bgp community",
6958 SHOW_STR
6959 IPV6_STR
6960 BGP_STR
6961 "Display routes matching the communities\n")
6962{
6963 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006964 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006965}
6966
6967/* old command */
6968DEFUN (show_ipv6_mbgp_community_all,
6969 show_ipv6_mbgp_community_all_cmd,
6970 "show ipv6 mbgp community",
6971 SHOW_STR
6972 IPV6_STR
6973 MBGP_STR
6974 "Display routes matching the communities\n")
6975{
6976 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006977 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006978}
6979#endif /* HAVE_IPV6 */
6980
paul94f2b392005-06-28 12:44:16 +00006981static int
paulfd79ac92004-10-13 05:06:08 +00006982bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
6983 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00006984{
6985 struct community *com;
6986 struct buffer *b;
6987 int i;
6988 char *str;
6989 int first = 0;
6990
6991 b = buffer_new (1024);
6992 for (i = 0; i < argc; i++)
6993 {
6994 if (first)
6995 buffer_putc (b, ' ');
6996 else
6997 {
6998 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6999 continue;
7000 first = 1;
7001 }
7002
7003 buffer_putstr (b, argv[i]);
7004 }
7005 buffer_putc (b, '\0');
7006
7007 str = buffer_getstr (b);
7008 buffer_free (b);
7009
7010 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007011 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007012 if (! com)
7013 {
7014 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7015 return CMD_WARNING;
7016 }
7017
ajs5a646652004-11-05 01:25:55 +00007018 return bgp_show (vty, NULL, afi, safi,
7019 (exact ? bgp_show_type_community_exact :
7020 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007021}
7022
7023DEFUN (show_ip_bgp_community,
7024 show_ip_bgp_community_cmd,
7025 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7026 SHOW_STR
7027 IP_STR
7028 BGP_STR
7029 "Display routes matching the communities\n"
7030 "community number\n"
7031 "Do not send outside local AS (well-known community)\n"
7032 "Do not advertise to any peer (well-known community)\n"
7033 "Do not export to next AS (well-known community)\n")
7034{
7035 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7036}
7037
7038ALIAS (show_ip_bgp_community,
7039 show_ip_bgp_community2_cmd,
7040 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (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 "community number\n"
7050 "Do not send outside local AS (well-known community)\n"
7051 "Do not advertise to any peer (well-known community)\n"
7052 "Do not export to next AS (well-known community)\n")
7053
7054ALIAS (show_ip_bgp_community,
7055 show_ip_bgp_community3_cmd,
7056 "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)",
7057 SHOW_STR
7058 IP_STR
7059 BGP_STR
7060 "Display routes matching the communities\n"
7061 "community number\n"
7062 "Do not send outside local AS (well-known community)\n"
7063 "Do not advertise to any peer (well-known community)\n"
7064 "Do not export to next AS (well-known community)\n"
7065 "community number\n"
7066 "Do not send outside local AS (well-known community)\n"
7067 "Do not advertise to any peer (well-known community)\n"
7068 "Do not export to next AS (well-known community)\n"
7069 "community number\n"
7070 "Do not send outside local AS (well-known community)\n"
7071 "Do not advertise to any peer (well-known community)\n"
7072 "Do not export to next AS (well-known community)\n")
7073
7074ALIAS (show_ip_bgp_community,
7075 show_ip_bgp_community4_cmd,
7076 "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)",
7077 SHOW_STR
7078 IP_STR
7079 BGP_STR
7080 "Display routes matching the communities\n"
7081 "community number\n"
7082 "Do not send outside local AS (well-known community)\n"
7083 "Do not advertise to any peer (well-known community)\n"
7084 "Do not export to next AS (well-known community)\n"
7085 "community number\n"
7086 "Do not send outside local AS (well-known community)\n"
7087 "Do not advertise to any peer (well-known community)\n"
7088 "Do not export to next AS (well-known community)\n"
7089 "community number\n"
7090 "Do not send outside local AS (well-known community)\n"
7091 "Do not advertise to any peer (well-known community)\n"
7092 "Do not export to next AS (well-known community)\n"
7093 "community number\n"
7094 "Do not send outside local AS (well-known community)\n"
7095 "Do not advertise to any peer (well-known community)\n"
7096 "Do not export to next AS (well-known community)\n")
7097
7098DEFUN (show_ip_bgp_ipv4_community,
7099 show_ip_bgp_ipv4_community_cmd,
7100 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7101 SHOW_STR
7102 IP_STR
7103 BGP_STR
7104 "Address family\n"
7105 "Address Family modifier\n"
7106 "Address Family modifier\n"
7107 "Display routes matching the communities\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{
7113 if (strncmp (argv[0], "m", 1) == 0)
7114 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7115
7116 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7117}
7118
7119ALIAS (show_ip_bgp_ipv4_community,
7120 show_ip_bgp_ipv4_community2_cmd,
7121 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7122 SHOW_STR
7123 IP_STR
7124 BGP_STR
7125 "Address family\n"
7126 "Address Family modifier\n"
7127 "Address Family modifier\n"
7128 "Display routes matching the communities\n"
7129 "community number\n"
7130 "Do not send outside local AS (well-known community)\n"
7131 "Do not advertise to any peer (well-known community)\n"
7132 "Do not export to next AS (well-known community)\n"
7133 "community number\n"
7134 "Do not send outside local AS (well-known community)\n"
7135 "Do not advertise to any peer (well-known community)\n"
7136 "Do not export to next AS (well-known community)\n")
7137
7138ALIAS (show_ip_bgp_ipv4_community,
7139 show_ip_bgp_ipv4_community3_cmd,
7140 "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)",
7141 SHOW_STR
7142 IP_STR
7143 BGP_STR
7144 "Address family\n"
7145 "Address Family modifier\n"
7146 "Address Family modifier\n"
7147 "Display routes matching the communities\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 "community number\n"
7153 "Do not send outside local AS (well-known community)\n"
7154 "Do not advertise to any peer (well-known community)\n"
7155 "Do not export to next AS (well-known community)\n"
7156 "community number\n"
7157 "Do not send outside local AS (well-known community)\n"
7158 "Do not advertise to any peer (well-known community)\n"
7159 "Do not export to next AS (well-known community)\n")
7160
7161ALIAS (show_ip_bgp_ipv4_community,
7162 show_ip_bgp_ipv4_community4_cmd,
7163 "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)",
7164 SHOW_STR
7165 IP_STR
7166 BGP_STR
7167 "Address family\n"
7168 "Address Family modifier\n"
7169 "Address Family modifier\n"
7170 "Display routes matching the communities\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 "community number\n"
7176 "Do not send outside local AS (well-known community)\n"
7177 "Do not advertise to any peer (well-known community)\n"
7178 "Do not export to next AS (well-known community)\n"
7179 "community number\n"
7180 "Do not send outside local AS (well-known community)\n"
7181 "Do not advertise to any peer (well-known community)\n"
7182 "Do not export to next AS (well-known community)\n"
7183 "community number\n"
7184 "Do not send outside local AS (well-known community)\n"
7185 "Do not advertise to any peer (well-known community)\n"
7186 "Do not export to next AS (well-known community)\n")
7187
7188DEFUN (show_ip_bgp_community_exact,
7189 show_ip_bgp_community_exact_cmd,
7190 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7191 SHOW_STR
7192 IP_STR
7193 BGP_STR
7194 "Display routes matching the communities\n"
7195 "community number\n"
7196 "Do not send outside local AS (well-known community)\n"
7197 "Do not advertise to any peer (well-known community)\n"
7198 "Do not export to next AS (well-known community)\n"
7199 "Exact match of the communities")
7200{
7201 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7202}
7203
7204ALIAS (show_ip_bgp_community_exact,
7205 show_ip_bgp_community2_exact_cmd,
7206 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7207 SHOW_STR
7208 IP_STR
7209 BGP_STR
7210 "Display routes matching the communities\n"
7211 "community number\n"
7212 "Do not send outside local AS (well-known community)\n"
7213 "Do not advertise to any peer (well-known community)\n"
7214 "Do not export to next AS (well-known community)\n"
7215 "community number\n"
7216 "Do not send outside local AS (well-known community)\n"
7217 "Do not advertise to any peer (well-known community)\n"
7218 "Do not export to next AS (well-known community)\n"
7219 "Exact match of the communities")
7220
7221ALIAS (show_ip_bgp_community_exact,
7222 show_ip_bgp_community3_exact_cmd,
7223 "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",
7224 SHOW_STR
7225 IP_STR
7226 BGP_STR
7227 "Display routes matching the communities\n"
7228 "community number\n"
7229 "Do not send outside local AS (well-known community)\n"
7230 "Do not advertise to any peer (well-known community)\n"
7231 "Do not export to next AS (well-known community)\n"
7232 "community number\n"
7233 "Do not send outside local AS (well-known community)\n"
7234 "Do not advertise to any peer (well-known community)\n"
7235 "Do not export to next AS (well-known community)\n"
7236 "community number\n"
7237 "Do not send outside local AS (well-known community)\n"
7238 "Do not advertise to any peer (well-known community)\n"
7239 "Do not export to next AS (well-known community)\n"
7240 "Exact match of the communities")
7241
7242ALIAS (show_ip_bgp_community_exact,
7243 show_ip_bgp_community4_exact_cmd,
7244 "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",
7245 SHOW_STR
7246 IP_STR
7247 BGP_STR
7248 "Display routes matching the communities\n"
7249 "community number\n"
7250 "Do not send outside local AS (well-known community)\n"
7251 "Do not advertise to any peer (well-known community)\n"
7252 "Do not export to next AS (well-known community)\n"
7253 "community number\n"
7254 "Do not send outside local AS (well-known community)\n"
7255 "Do not advertise to any peer (well-known community)\n"
7256 "Do not export to next AS (well-known community)\n"
7257 "community number\n"
7258 "Do not send outside local AS (well-known community)\n"
7259 "Do not advertise to any peer (well-known community)\n"
7260 "Do not export to next AS (well-known community)\n"
7261 "community number\n"
7262 "Do not send outside local AS (well-known community)\n"
7263 "Do not advertise to any peer (well-known community)\n"
7264 "Do not export to next AS (well-known community)\n"
7265 "Exact match of the communities")
7266
7267DEFUN (show_ip_bgp_ipv4_community_exact,
7268 show_ip_bgp_ipv4_community_exact_cmd,
7269 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7270 SHOW_STR
7271 IP_STR
7272 BGP_STR
7273 "Address family\n"
7274 "Address Family modifier\n"
7275 "Address Family modifier\n"
7276 "Display routes matching the communities\n"
7277 "community number\n"
7278 "Do not send outside local AS (well-known community)\n"
7279 "Do not advertise to any peer (well-known community)\n"
7280 "Do not export to next AS (well-known community)\n"
7281 "Exact match of the communities")
7282{
7283 if (strncmp (argv[0], "m", 1) == 0)
7284 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7285
7286 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7287}
7288
7289ALIAS (show_ip_bgp_ipv4_community_exact,
7290 show_ip_bgp_ipv4_community2_exact_cmd,
7291 "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",
7292 SHOW_STR
7293 IP_STR
7294 BGP_STR
7295 "Address family\n"
7296 "Address Family modifier\n"
7297 "Address Family modifier\n"
7298 "Display routes matching the communities\n"
7299 "community number\n"
7300 "Do not send outside local AS (well-known community)\n"
7301 "Do not advertise to any peer (well-known community)\n"
7302 "Do not export to next AS (well-known community)\n"
7303 "community number\n"
7304 "Do not send outside local AS (well-known community)\n"
7305 "Do not advertise to any peer (well-known community)\n"
7306 "Do not export to next AS (well-known community)\n"
7307 "Exact match of the communities")
7308
7309ALIAS (show_ip_bgp_ipv4_community_exact,
7310 show_ip_bgp_ipv4_community3_exact_cmd,
7311 "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",
7312 SHOW_STR
7313 IP_STR
7314 BGP_STR
7315 "Address family\n"
7316 "Address Family modifier\n"
7317 "Address Family modifier\n"
7318 "Display routes matching the communities\n"
7319 "community number\n"
7320 "Do not send outside local AS (well-known community)\n"
7321 "Do not advertise to any peer (well-known community)\n"
7322 "Do not export to next AS (well-known community)\n"
7323 "community number\n"
7324 "Do not send outside local AS (well-known community)\n"
7325 "Do not advertise to any peer (well-known community)\n"
7326 "Do not export to next AS (well-known community)\n"
7327 "community number\n"
7328 "Do not send outside local AS (well-known community)\n"
7329 "Do not advertise to any peer (well-known community)\n"
7330 "Do not export to next AS (well-known community)\n"
7331 "Exact match of the communities")
7332
7333ALIAS (show_ip_bgp_ipv4_community_exact,
7334 show_ip_bgp_ipv4_community4_exact_cmd,
7335 "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",
7336 SHOW_STR
7337 IP_STR
7338 BGP_STR
7339 "Address family\n"
7340 "Address Family modifier\n"
7341 "Address Family modifier\n"
7342 "Display routes matching the communities\n"
7343 "community number\n"
7344 "Do not send outside local AS (well-known community)\n"
7345 "Do not advertise to any peer (well-known community)\n"
7346 "Do not export to next AS (well-known community)\n"
7347 "community number\n"
7348 "Do not send outside local AS (well-known community)\n"
7349 "Do not advertise to any peer (well-known community)\n"
7350 "Do not export to next AS (well-known community)\n"
7351 "community number\n"
7352 "Do not send outside local AS (well-known community)\n"
7353 "Do not advertise to any peer (well-known community)\n"
7354 "Do not export to next AS (well-known community)\n"
7355 "community number\n"
7356 "Do not send outside local AS (well-known community)\n"
7357 "Do not advertise to any peer (well-known community)\n"
7358 "Do not export to next AS (well-known community)\n"
7359 "Exact match of the communities")
7360
7361#ifdef HAVE_IPV6
7362DEFUN (show_bgp_community,
7363 show_bgp_community_cmd,
7364 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7365 SHOW_STR
7366 BGP_STR
7367 "Display routes matching the communities\n"
7368 "community number\n"
7369 "Do not send outside local AS (well-known community)\n"
7370 "Do not advertise to any peer (well-known community)\n"
7371 "Do not export to next AS (well-known community)\n")
7372{
7373 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7374}
7375
7376ALIAS (show_bgp_community,
7377 show_bgp_ipv6_community_cmd,
7378 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7379 SHOW_STR
7380 BGP_STR
7381 "Address family\n"
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
7388ALIAS (show_bgp_community,
7389 show_bgp_community2_cmd,
7390 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7391 SHOW_STR
7392 BGP_STR
7393 "Display routes matching the communities\n"
7394 "community number\n"
7395 "Do not send outside local AS (well-known community)\n"
7396 "Do not advertise to any peer (well-known community)\n"
7397 "Do not export to next AS (well-known community)\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_ipv6_community2_cmd,
7405 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7406 SHOW_STR
7407 BGP_STR
7408 "Address family\n"
7409 "Display routes matching the communities\n"
7410 "community number\n"
7411 "Do not send outside local AS (well-known community)\n"
7412 "Do not advertise to any peer (well-known community)\n"
7413 "Do not export to next AS (well-known community)\n"
7414 "community number\n"
7415 "Do not send outside local AS (well-known community)\n"
7416 "Do not advertise to any peer (well-known community)\n"
7417 "Do not export to next AS (well-known community)\n")
7418
7419ALIAS (show_bgp_community,
7420 show_bgp_community3_cmd,
7421 "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)",
7422 SHOW_STR
7423 BGP_STR
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 "community number\n"
7434 "Do not send outside local AS (well-known community)\n"
7435 "Do not advertise to any peer (well-known community)\n"
7436 "Do not export to next AS (well-known community)\n")
7437
7438ALIAS (show_bgp_community,
7439 show_bgp_ipv6_community3_cmd,
7440 "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)",
7441 SHOW_STR
7442 BGP_STR
7443 "Address family\n"
7444 "Display routes matching the communities\n"
7445 "community number\n"
7446 "Do not send outside local AS (well-known community)\n"
7447 "Do not advertise to any peer (well-known community)\n"
7448 "Do not export to next AS (well-known community)\n"
7449 "community number\n"
7450 "Do not send outside local AS (well-known community)\n"
7451 "Do not advertise to any peer (well-known community)\n"
7452 "Do not export to next AS (well-known community)\n"
7453 "community number\n"
7454 "Do not send outside local AS (well-known community)\n"
7455 "Do not advertise to any peer (well-known community)\n"
7456 "Do not export to next AS (well-known community)\n")
7457
7458ALIAS (show_bgp_community,
7459 show_bgp_community4_cmd,
7460 "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)",
7461 SHOW_STR
7462 BGP_STR
7463 "Display routes matching the communities\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 "community number\n"
7473 "Do not send outside local AS (well-known community)\n"
7474 "Do not advertise to any peer (well-known community)\n"
7475 "Do not export to next AS (well-known community)\n"
7476 "community number\n"
7477 "Do not send outside local AS (well-known community)\n"
7478 "Do not advertise to any peer (well-known community)\n"
7479 "Do not export to next AS (well-known community)\n")
7480
7481ALIAS (show_bgp_community,
7482 show_bgp_ipv6_community4_cmd,
7483 "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)",
7484 SHOW_STR
7485 BGP_STR
7486 "Address family\n"
7487 "Display routes matching the communities\n"
7488 "community number\n"
7489 "Do not send outside local AS (well-known community)\n"
7490 "Do not advertise to any peer (well-known community)\n"
7491 "Do not export to next AS (well-known community)\n"
7492 "community number\n"
7493 "Do not send outside local AS (well-known community)\n"
7494 "Do not advertise to any peer (well-known community)\n"
7495 "Do not export to next AS (well-known community)\n"
7496 "community number\n"
7497 "Do not send outside local AS (well-known community)\n"
7498 "Do not advertise to any peer (well-known community)\n"
7499 "Do not export to next AS (well-known community)\n"
7500 "community number\n"
7501 "Do not send outside local AS (well-known community)\n"
7502 "Do not advertise to any peer (well-known community)\n"
7503 "Do not export to next AS (well-known community)\n")
7504
7505/* old command */
7506DEFUN (show_ipv6_bgp_community,
7507 show_ipv6_bgp_community_cmd,
7508 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7509 SHOW_STR
7510 IPV6_STR
7511 BGP_STR
7512 "Display routes matching the communities\n"
7513 "community number\n"
7514 "Do not send outside local AS (well-known community)\n"
7515 "Do not advertise to any peer (well-known community)\n"
7516 "Do not export to next AS (well-known community)\n")
7517{
7518 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7519}
7520
7521/* old command */
7522ALIAS (show_ipv6_bgp_community,
7523 show_ipv6_bgp_community2_cmd,
7524 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7525 SHOW_STR
7526 IPV6_STR
7527 BGP_STR
7528 "Display routes matching the communities\n"
7529 "community number\n"
7530 "Do not send outside local AS (well-known community)\n"
7531 "Do not advertise to any peer (well-known community)\n"
7532 "Do not export to next AS (well-known community)\n"
7533 "community number\n"
7534 "Do not send outside local AS (well-known community)\n"
7535 "Do not advertise to any peer (well-known community)\n"
7536 "Do not export to next AS (well-known community)\n")
7537
7538/* old command */
7539ALIAS (show_ipv6_bgp_community,
7540 show_ipv6_bgp_community3_cmd,
7541 "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)",
7542 SHOW_STR
7543 IPV6_STR
7544 BGP_STR
7545 "Display routes matching the communities\n"
7546 "community number\n"
7547 "Do not send outside local AS (well-known community)\n"
7548 "Do not advertise to any peer (well-known community)\n"
7549 "Do not export to next AS (well-known community)\n"
7550 "community number\n"
7551 "Do not send outside local AS (well-known community)\n"
7552 "Do not advertise to any peer (well-known community)\n"
7553 "Do not export to next AS (well-known community)\n"
7554 "community number\n"
7555 "Do not send outside local AS (well-known community)\n"
7556 "Do not advertise to any peer (well-known community)\n"
7557 "Do not export to next AS (well-known community)\n")
7558
7559/* old command */
7560ALIAS (show_ipv6_bgp_community,
7561 show_ipv6_bgp_community4_cmd,
7562 "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)",
7563 SHOW_STR
7564 IPV6_STR
7565 BGP_STR
7566 "Display routes matching the communities\n"
7567 "community number\n"
7568 "Do not send outside local AS (well-known community)\n"
7569 "Do not advertise to any peer (well-known community)\n"
7570 "Do not export to next AS (well-known community)\n"
7571 "community number\n"
7572 "Do not send outside local AS (well-known community)\n"
7573 "Do not advertise to any peer (well-known community)\n"
7574 "Do not export to next AS (well-known community)\n"
7575 "community number\n"
7576 "Do not send outside local AS (well-known community)\n"
7577 "Do not advertise to any peer (well-known community)\n"
7578 "Do not export to next AS (well-known community)\n"
7579 "community number\n"
7580 "Do not send outside local AS (well-known community)\n"
7581 "Do not advertise to any peer (well-known community)\n"
7582 "Do not export to next AS (well-known community)\n")
7583
7584DEFUN (show_bgp_community_exact,
7585 show_bgp_community_exact_cmd,
7586 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7587 SHOW_STR
7588 BGP_STR
7589 "Display routes matching the communities\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 "Exact match of the communities")
7595{
7596 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7597}
7598
7599ALIAS (show_bgp_community_exact,
7600 show_bgp_ipv6_community_exact_cmd,
7601 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7602 SHOW_STR
7603 BGP_STR
7604 "Address family\n"
7605 "Display routes matching the communities\n"
7606 "community number\n"
7607 "Do not send outside local AS (well-known community)\n"
7608 "Do not advertise to any peer (well-known community)\n"
7609 "Do not export to next AS (well-known community)\n"
7610 "Exact match of the communities")
7611
7612ALIAS (show_bgp_community_exact,
7613 show_bgp_community2_exact_cmd,
7614 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7615 SHOW_STR
7616 BGP_STR
7617 "Display routes matching the communities\n"
7618 "community number\n"
7619 "Do not send outside local AS (well-known community)\n"
7620 "Do not advertise to any peer (well-known community)\n"
7621 "Do not export to next AS (well-known community)\n"
7622 "community number\n"
7623 "Do not send outside local AS (well-known community)\n"
7624 "Do not advertise to any peer (well-known community)\n"
7625 "Do not export to next AS (well-known community)\n"
7626 "Exact match of the communities")
7627
7628ALIAS (show_bgp_community_exact,
7629 show_bgp_ipv6_community2_exact_cmd,
7630 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7631 SHOW_STR
7632 BGP_STR
7633 "Address family\n"
7634 "Display routes matching the communities\n"
7635 "community number\n"
7636 "Do not send outside local AS (well-known community)\n"
7637 "Do not advertise to any peer (well-known community)\n"
7638 "Do not export to next AS (well-known community)\n"
7639 "community number\n"
7640 "Do not send outside local AS (well-known community)\n"
7641 "Do not advertise to any peer (well-known community)\n"
7642 "Do not export to next AS (well-known community)\n"
7643 "Exact match of the communities")
7644
7645ALIAS (show_bgp_community_exact,
7646 show_bgp_community3_exact_cmd,
7647 "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",
7648 SHOW_STR
7649 BGP_STR
7650 "Display routes matching the communities\n"
7651 "community number\n"
7652 "Do not send outside local AS (well-known community)\n"
7653 "Do not advertise to any peer (well-known community)\n"
7654 "Do not export to next AS (well-known community)\n"
7655 "community number\n"
7656 "Do not send outside local AS (well-known community)\n"
7657 "Do not advertise to any peer (well-known community)\n"
7658 "Do not export to next AS (well-known community)\n"
7659 "community number\n"
7660 "Do not send outside local AS (well-known community)\n"
7661 "Do not advertise to any peer (well-known community)\n"
7662 "Do not export to next AS (well-known community)\n"
7663 "Exact match of the communities")
7664
7665ALIAS (show_bgp_community_exact,
7666 show_bgp_ipv6_community3_exact_cmd,
7667 "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",
7668 SHOW_STR
7669 BGP_STR
7670 "Address family\n"
7671 "Display routes matching the communities\n"
7672 "community number\n"
7673 "Do not send outside local AS (well-known community)\n"
7674 "Do not advertise to any peer (well-known community)\n"
7675 "Do not export to next AS (well-known community)\n"
7676 "community number\n"
7677 "Do not send outside local AS (well-known community)\n"
7678 "Do not advertise to any peer (well-known community)\n"
7679 "Do not export to next AS (well-known community)\n"
7680 "community number\n"
7681 "Do not send outside local AS (well-known community)\n"
7682 "Do not advertise to any peer (well-known community)\n"
7683 "Do not export to next AS (well-known community)\n"
7684 "Exact match of the communities")
7685
7686ALIAS (show_bgp_community_exact,
7687 show_bgp_community4_exact_cmd,
7688 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7689 SHOW_STR
7690 BGP_STR
7691 "Display routes matching the communities\n"
7692 "community number\n"
7693 "Do not send outside local AS (well-known community)\n"
7694 "Do not advertise to any peer (well-known community)\n"
7695 "Do not export to next AS (well-known community)\n"
7696 "community number\n"
7697 "Do not send outside local AS (well-known community)\n"
7698 "Do not advertise to any peer (well-known community)\n"
7699 "Do not export to next AS (well-known community)\n"
7700 "community number\n"
7701 "Do not send outside local AS (well-known community)\n"
7702 "Do not advertise to any peer (well-known community)\n"
7703 "Do not export to next AS (well-known community)\n"
7704 "community number\n"
7705 "Do not send outside local AS (well-known community)\n"
7706 "Do not advertise to any peer (well-known community)\n"
7707 "Do not export to next AS (well-known community)\n"
7708 "Exact match of the communities")
7709
7710ALIAS (show_bgp_community_exact,
7711 show_bgp_ipv6_community4_exact_cmd,
7712 "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",
7713 SHOW_STR
7714 BGP_STR
7715 "Address family\n"
7716 "Display routes matching the communities\n"
7717 "community number\n"
7718 "Do not send outside local AS (well-known community)\n"
7719 "Do not advertise to any peer (well-known community)\n"
7720 "Do not export to next AS (well-known community)\n"
7721 "community number\n"
7722 "Do not send outside local AS (well-known community)\n"
7723 "Do not advertise to any peer (well-known community)\n"
7724 "Do not export to next AS (well-known community)\n"
7725 "community number\n"
7726 "Do not send outside local AS (well-known community)\n"
7727 "Do not advertise to any peer (well-known community)\n"
7728 "Do not export to next AS (well-known community)\n"
7729 "community number\n"
7730 "Do not send outside local AS (well-known community)\n"
7731 "Do not advertise to any peer (well-known community)\n"
7732 "Do not export to next AS (well-known community)\n"
7733 "Exact match of the communities")
7734
7735/* old command */
7736DEFUN (show_ipv6_bgp_community_exact,
7737 show_ipv6_bgp_community_exact_cmd,
7738 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7739 SHOW_STR
7740 IPV6_STR
7741 BGP_STR
7742 "Display routes matching the communities\n"
7743 "community number\n"
7744 "Do not send outside local AS (well-known community)\n"
7745 "Do not advertise to any peer (well-known community)\n"
7746 "Do not export to next AS (well-known community)\n"
7747 "Exact match of the communities")
7748{
7749 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7750}
7751
7752/* old command */
7753ALIAS (show_ipv6_bgp_community_exact,
7754 show_ipv6_bgp_community2_exact_cmd,
7755 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7756 SHOW_STR
7757 IPV6_STR
7758 BGP_STR
7759 "Display routes matching the communities\n"
7760 "community number\n"
7761 "Do not send outside local AS (well-known community)\n"
7762 "Do not advertise to any peer (well-known community)\n"
7763 "Do not export to next AS (well-known community)\n"
7764 "community number\n"
7765 "Do not send outside local AS (well-known community)\n"
7766 "Do not advertise to any peer (well-known community)\n"
7767 "Do not export to next AS (well-known community)\n"
7768 "Exact match of the communities")
7769
7770/* old command */
7771ALIAS (show_ipv6_bgp_community_exact,
7772 show_ipv6_bgp_community3_exact_cmd,
7773 "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",
7774 SHOW_STR
7775 IPV6_STR
7776 BGP_STR
7777 "Display routes matching the communities\n"
7778 "community number\n"
7779 "Do not send outside local AS (well-known community)\n"
7780 "Do not advertise to any peer (well-known community)\n"
7781 "Do not export to next AS (well-known community)\n"
7782 "community number\n"
7783 "Do not send outside local AS (well-known community)\n"
7784 "Do not advertise to any peer (well-known community)\n"
7785 "Do not export to next AS (well-known community)\n"
7786 "community number\n"
7787 "Do not send outside local AS (well-known community)\n"
7788 "Do not advertise to any peer (well-known community)\n"
7789 "Do not export to next AS (well-known community)\n"
7790 "Exact match of the communities")
7791
7792/* old command */
7793ALIAS (show_ipv6_bgp_community_exact,
7794 show_ipv6_bgp_community4_exact_cmd,
7795 "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",
7796 SHOW_STR
7797 IPV6_STR
7798 BGP_STR
7799 "Display routes matching the communities\n"
7800 "community number\n"
7801 "Do not send outside local AS (well-known community)\n"
7802 "Do not advertise to any peer (well-known community)\n"
7803 "Do not export to next AS (well-known community)\n"
7804 "community number\n"
7805 "Do not send outside local AS (well-known community)\n"
7806 "Do not advertise to any peer (well-known community)\n"
7807 "Do not export to next AS (well-known community)\n"
7808 "community number\n"
7809 "Do not send outside local AS (well-known community)\n"
7810 "Do not advertise to any peer (well-known community)\n"
7811 "Do not export to next AS (well-known community)\n"
7812 "community number\n"
7813 "Do not send outside local AS (well-known community)\n"
7814 "Do not advertise to any peer (well-known community)\n"
7815 "Do not export to next AS (well-known community)\n"
7816 "Exact match of the communities")
7817
7818/* old command */
7819DEFUN (show_ipv6_mbgp_community,
7820 show_ipv6_mbgp_community_cmd,
7821 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7822 SHOW_STR
7823 IPV6_STR
7824 MBGP_STR
7825 "Display routes matching the communities\n"
7826 "community number\n"
7827 "Do not send outside local AS (well-known community)\n"
7828 "Do not advertise to any peer (well-known community)\n"
7829 "Do not export to next AS (well-known community)\n")
7830{
7831 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7832}
7833
7834/* old command */
7835ALIAS (show_ipv6_mbgp_community,
7836 show_ipv6_mbgp_community2_cmd,
7837 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7838 SHOW_STR
7839 IPV6_STR
7840 MBGP_STR
7841 "Display routes matching the communities\n"
7842 "community number\n"
7843 "Do not send outside local AS (well-known community)\n"
7844 "Do not advertise to any peer (well-known community)\n"
7845 "Do not export to next AS (well-known community)\n"
7846 "community number\n"
7847 "Do not send outside local AS (well-known community)\n"
7848 "Do not advertise to any peer (well-known community)\n"
7849 "Do not export to next AS (well-known community)\n")
7850
7851/* old command */
7852ALIAS (show_ipv6_mbgp_community,
7853 show_ipv6_mbgp_community3_cmd,
7854 "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)",
7855 SHOW_STR
7856 IPV6_STR
7857 MBGP_STR
7858 "Display routes matching the communities\n"
7859 "community number\n"
7860 "Do not send outside local AS (well-known community)\n"
7861 "Do not advertise to any peer (well-known community)\n"
7862 "Do not export to next AS (well-known community)\n"
7863 "community number\n"
7864 "Do not send outside local AS (well-known community)\n"
7865 "Do not advertise to any peer (well-known community)\n"
7866 "Do not export to next AS (well-known community)\n"
7867 "community number\n"
7868 "Do not send outside local AS (well-known community)\n"
7869 "Do not advertise to any peer (well-known community)\n"
7870 "Do not export to next AS (well-known community)\n")
7871
7872/* old command */
7873ALIAS (show_ipv6_mbgp_community,
7874 show_ipv6_mbgp_community4_cmd,
7875 "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)",
7876 SHOW_STR
7877 IPV6_STR
7878 MBGP_STR
7879 "Display routes matching the communities\n"
7880 "community number\n"
7881 "Do not send outside local AS (well-known community)\n"
7882 "Do not advertise to any peer (well-known community)\n"
7883 "Do not export to next AS (well-known community)\n"
7884 "community number\n"
7885 "Do not send outside local AS (well-known community)\n"
7886 "Do not advertise to any peer (well-known community)\n"
7887 "Do not export to next AS (well-known community)\n"
7888 "community number\n"
7889 "Do not send outside local AS (well-known community)\n"
7890 "Do not advertise to any peer (well-known community)\n"
7891 "Do not export to next AS (well-known community)\n"
7892 "community number\n"
7893 "Do not send outside local AS (well-known community)\n"
7894 "Do not advertise to any peer (well-known community)\n"
7895 "Do not export to next AS (well-known community)\n")
7896
7897/* old command */
7898DEFUN (show_ipv6_mbgp_community_exact,
7899 show_ipv6_mbgp_community_exact_cmd,
7900 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7901 SHOW_STR
7902 IPV6_STR
7903 MBGP_STR
7904 "Display routes matching the communities\n"
7905 "community number\n"
7906 "Do not send outside local AS (well-known community)\n"
7907 "Do not advertise to any peer (well-known community)\n"
7908 "Do not export to next AS (well-known community)\n"
7909 "Exact match of the communities")
7910{
7911 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7912}
7913
7914/* old command */
7915ALIAS (show_ipv6_mbgp_community_exact,
7916 show_ipv6_mbgp_community2_exact_cmd,
7917 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7918 SHOW_STR
7919 IPV6_STR
7920 MBGP_STR
7921 "Display routes matching the communities\n"
7922 "community number\n"
7923 "Do not send outside local AS (well-known community)\n"
7924 "Do not advertise to any peer (well-known community)\n"
7925 "Do not export to next AS (well-known community)\n"
7926 "community number\n"
7927 "Do not send outside local AS (well-known community)\n"
7928 "Do not advertise to any peer (well-known community)\n"
7929 "Do not export to next AS (well-known community)\n"
7930 "Exact match of the communities")
7931
7932/* old command */
7933ALIAS (show_ipv6_mbgp_community_exact,
7934 show_ipv6_mbgp_community3_exact_cmd,
7935 "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",
7936 SHOW_STR
7937 IPV6_STR
7938 MBGP_STR
7939 "Display routes matching the communities\n"
7940 "community number\n"
7941 "Do not send outside local AS (well-known community)\n"
7942 "Do not advertise to any peer (well-known community)\n"
7943 "Do not export to next AS (well-known community)\n"
7944 "community number\n"
7945 "Do not send outside local AS (well-known community)\n"
7946 "Do not advertise to any peer (well-known community)\n"
7947 "Do not export to next AS (well-known community)\n"
7948 "community number\n"
7949 "Do not send outside local AS (well-known community)\n"
7950 "Do not advertise to any peer (well-known community)\n"
7951 "Do not export to next AS (well-known community)\n"
7952 "Exact match of the communities")
7953
7954/* old command */
7955ALIAS (show_ipv6_mbgp_community_exact,
7956 show_ipv6_mbgp_community4_exact_cmd,
7957 "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",
7958 SHOW_STR
7959 IPV6_STR
7960 MBGP_STR
7961 "Display routes matching the communities\n"
7962 "community number\n"
7963 "Do not send outside local AS (well-known community)\n"
7964 "Do not advertise to any peer (well-known community)\n"
7965 "Do not export to next AS (well-known community)\n"
7966 "community number\n"
7967 "Do not send outside local AS (well-known community)\n"
7968 "Do not advertise to any peer (well-known community)\n"
7969 "Do not export to next AS (well-known community)\n"
7970 "community number\n"
7971 "Do not send outside local AS (well-known community)\n"
7972 "Do not advertise to any peer (well-known community)\n"
7973 "Do not export to next AS (well-known community)\n"
7974 "community number\n"
7975 "Do not send outside local AS (well-known community)\n"
7976 "Do not advertise to any peer (well-known community)\n"
7977 "Do not export to next AS (well-known community)\n"
7978 "Exact match of the communities")
7979#endif /* HAVE_IPV6 */
7980
paul94f2b392005-06-28 12:44:16 +00007981static int
paulfd79ac92004-10-13 05:06:08 +00007982bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00007983 u_int16_t afi, u_char safi)
7984{
7985 struct community_list *list;
7986
hassofee6e4e2005-02-02 16:29:31 +00007987 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00007988 if (list == NULL)
7989 {
7990 vty_out (vty, "%% %s is not a valid community-list name%s", com,
7991 VTY_NEWLINE);
7992 return CMD_WARNING;
7993 }
7994
ajs5a646652004-11-05 01:25:55 +00007995 return bgp_show (vty, NULL, afi, safi,
7996 (exact ? bgp_show_type_community_list_exact :
7997 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00007998}
7999
8000DEFUN (show_ip_bgp_community_list,
8001 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008002 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008003 SHOW_STR
8004 IP_STR
8005 BGP_STR
8006 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008007 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008008 "community-list name\n")
8009{
8010 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8011}
8012
8013DEFUN (show_ip_bgp_ipv4_community_list,
8014 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008015 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008016 SHOW_STR
8017 IP_STR
8018 BGP_STR
8019 "Address family\n"
8020 "Address Family modifier\n"
8021 "Address Family modifier\n"
8022 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008023 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008024 "community-list name\n")
8025{
8026 if (strncmp (argv[0], "m", 1) == 0)
8027 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8028
8029 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8030}
8031
8032DEFUN (show_ip_bgp_community_list_exact,
8033 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008034 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008035 SHOW_STR
8036 IP_STR
8037 BGP_STR
8038 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008039 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008040 "community-list name\n"
8041 "Exact match of the communities\n")
8042{
8043 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8044}
8045
8046DEFUN (show_ip_bgp_ipv4_community_list_exact,
8047 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008048 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008049 SHOW_STR
8050 IP_STR
8051 BGP_STR
8052 "Address family\n"
8053 "Address Family modifier\n"
8054 "Address Family modifier\n"
8055 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008056 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008057 "community-list name\n"
8058 "Exact match of the communities\n")
8059{
8060 if (strncmp (argv[0], "m", 1) == 0)
8061 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8062
8063 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8064}
8065
8066#ifdef HAVE_IPV6
8067DEFUN (show_bgp_community_list,
8068 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008069 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008070 SHOW_STR
8071 BGP_STR
8072 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008073 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008074 "community-list name\n")
8075{
8076 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8077}
8078
8079ALIAS (show_bgp_community_list,
8080 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008081 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008082 SHOW_STR
8083 BGP_STR
8084 "Address family\n"
8085 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008086 "community-list number\n"
8087 "community-list name\n");
paul718e3742002-12-13 20:15:29 +00008088
8089/* old command */
8090DEFUN (show_ipv6_bgp_community_list,
8091 show_ipv6_bgp_community_list_cmd,
8092 "show ipv6 bgp community-list WORD",
8093 SHOW_STR
8094 IPV6_STR
8095 BGP_STR
8096 "Display routes matching the community-list\n"
8097 "community-list name\n")
8098{
8099 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8100}
8101
8102/* old command */
8103DEFUN (show_ipv6_mbgp_community_list,
8104 show_ipv6_mbgp_community_list_cmd,
8105 "show ipv6 mbgp community-list WORD",
8106 SHOW_STR
8107 IPV6_STR
8108 MBGP_STR
8109 "Display routes matching the community-list\n"
8110 "community-list name\n")
8111{
8112 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8113}
8114
8115DEFUN (show_bgp_community_list_exact,
8116 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008117 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008118 SHOW_STR
8119 BGP_STR
8120 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008121 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008122 "community-list name\n"
8123 "Exact match of the communities\n")
8124{
8125 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8126}
8127
8128ALIAS (show_bgp_community_list_exact,
8129 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008130 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008131 SHOW_STR
8132 BGP_STR
8133 "Address family\n"
8134 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008135 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008136 "community-list name\n"
8137 "Exact match of the communities\n")
8138
8139/* old command */
8140DEFUN (show_ipv6_bgp_community_list_exact,
8141 show_ipv6_bgp_community_list_exact_cmd,
8142 "show ipv6 bgp community-list WORD exact-match",
8143 SHOW_STR
8144 IPV6_STR
8145 BGP_STR
8146 "Display routes matching the community-list\n"
8147 "community-list name\n"
8148 "Exact match of the communities\n")
8149{
8150 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8151}
8152
8153/* old command */
8154DEFUN (show_ipv6_mbgp_community_list_exact,
8155 show_ipv6_mbgp_community_list_exact_cmd,
8156 "show ipv6 mbgp community-list WORD exact-match",
8157 SHOW_STR
8158 IPV6_STR
8159 MBGP_STR
8160 "Display routes matching the community-list\n"
8161 "community-list name\n"
8162 "Exact match of the communities\n")
8163{
8164 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8165}
8166#endif /* HAVE_IPV6 */
8167
paul94f2b392005-06-28 12:44:16 +00008168static int
paulfd79ac92004-10-13 05:06:08 +00008169bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008170 safi_t safi, enum bgp_show_type type)
8171{
8172 int ret;
8173 struct prefix *p;
8174
8175 p = prefix_new();
8176
8177 ret = str2prefix (prefix, p);
8178 if (! ret)
8179 {
8180 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8181 return CMD_WARNING;
8182 }
8183
ajs5a646652004-11-05 01:25:55 +00008184 ret = bgp_show (vty, NULL, afi, safi, type, p);
8185 prefix_free(p);
8186 return ret;
paul718e3742002-12-13 20:15:29 +00008187}
8188
8189DEFUN (show_ip_bgp_prefix_longer,
8190 show_ip_bgp_prefix_longer_cmd,
8191 "show ip bgp A.B.C.D/M longer-prefixes",
8192 SHOW_STR
8193 IP_STR
8194 BGP_STR
8195 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8196 "Display route and more specific routes\n")
8197{
8198 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8199 bgp_show_type_prefix_longer);
8200}
8201
8202DEFUN (show_ip_bgp_flap_prefix_longer,
8203 show_ip_bgp_flap_prefix_longer_cmd,
8204 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8205 SHOW_STR
8206 IP_STR
8207 BGP_STR
8208 "Display flap statistics of routes\n"
8209 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8210 "Display route and more specific routes\n")
8211{
8212 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8213 bgp_show_type_flap_prefix_longer);
8214}
8215
8216DEFUN (show_ip_bgp_ipv4_prefix_longer,
8217 show_ip_bgp_ipv4_prefix_longer_cmd,
8218 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8219 SHOW_STR
8220 IP_STR
8221 BGP_STR
8222 "Address family\n"
8223 "Address Family modifier\n"
8224 "Address Family modifier\n"
8225 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8226 "Display route and more specific routes\n")
8227{
8228 if (strncmp (argv[0], "m", 1) == 0)
8229 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8230 bgp_show_type_prefix_longer);
8231
8232 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8233 bgp_show_type_prefix_longer);
8234}
8235
8236DEFUN (show_ip_bgp_flap_address,
8237 show_ip_bgp_flap_address_cmd,
8238 "show ip bgp flap-statistics A.B.C.D",
8239 SHOW_STR
8240 IP_STR
8241 BGP_STR
8242 "Display flap statistics of routes\n"
8243 "Network in the BGP routing table to display\n")
8244{
8245 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8246 bgp_show_type_flap_address);
8247}
8248
8249DEFUN (show_ip_bgp_flap_prefix,
8250 show_ip_bgp_flap_prefix_cmd,
8251 "show ip bgp flap-statistics A.B.C.D/M",
8252 SHOW_STR
8253 IP_STR
8254 BGP_STR
8255 "Display flap statistics of routes\n"
8256 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8257{
8258 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8259 bgp_show_type_flap_prefix);
8260}
8261#ifdef HAVE_IPV6
8262DEFUN (show_bgp_prefix_longer,
8263 show_bgp_prefix_longer_cmd,
8264 "show bgp X:X::X:X/M longer-prefixes",
8265 SHOW_STR
8266 BGP_STR
8267 "IPv6 prefix <network>/<length>\n"
8268 "Display route and more specific routes\n")
8269{
8270 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8271 bgp_show_type_prefix_longer);
8272}
8273
8274ALIAS (show_bgp_prefix_longer,
8275 show_bgp_ipv6_prefix_longer_cmd,
8276 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8277 SHOW_STR
8278 BGP_STR
8279 "Address family\n"
8280 "IPv6 prefix <network>/<length>\n"
8281 "Display route and more specific routes\n")
8282
8283/* old command */
8284DEFUN (show_ipv6_bgp_prefix_longer,
8285 show_ipv6_bgp_prefix_longer_cmd,
8286 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8287 SHOW_STR
8288 IPV6_STR
8289 BGP_STR
8290 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8291 "Display route and more specific routes\n")
8292{
8293 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8294 bgp_show_type_prefix_longer);
8295}
8296
8297/* old command */
8298DEFUN (show_ipv6_mbgp_prefix_longer,
8299 show_ipv6_mbgp_prefix_longer_cmd,
8300 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8301 SHOW_STR
8302 IPV6_STR
8303 MBGP_STR
8304 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8305 "Display route and more specific routes\n")
8306{
8307 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8308 bgp_show_type_prefix_longer);
8309}
8310#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008311
paul94f2b392005-06-28 12:44:16 +00008312static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008313peer_lookup_in_view (struct vty *vty, const char *view_name,
8314 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008315{
8316 int ret;
8317 struct bgp *bgp;
8318 struct peer *peer;
8319 union sockunion su;
8320
8321 /* BGP structure lookup. */
8322 if (view_name)
8323 {
8324 bgp = bgp_lookup_by_name (view_name);
8325 if (! bgp)
8326 {
8327 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8328 return NULL;
8329 }
8330 }
paul5228ad22004-06-04 17:58:18 +00008331 else
paulbb46e942003-10-24 19:02:03 +00008332 {
8333 bgp = bgp_get_default ();
8334 if (! bgp)
8335 {
8336 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8337 return NULL;
8338 }
8339 }
8340
8341 /* Get peer sockunion. */
8342 ret = str2sockunion (ip_str, &su);
8343 if (ret < 0)
8344 {
8345 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8346 return NULL;
8347 }
8348
8349 /* Peer structure lookup. */
8350 peer = peer_lookup (bgp, &su);
8351 if (! peer)
8352 {
8353 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8354 return NULL;
8355 }
8356
8357 return peer;
8358}
8359
paul94f2b392005-06-28 12:44:16 +00008360static void
paul718e3742002-12-13 20:15:29 +00008361show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
8362 int in)
8363{
8364 struct bgp_table *table;
8365 struct bgp_adj_in *ain;
8366 struct bgp_adj_out *adj;
8367 unsigned long output_count;
8368 struct bgp_node *rn;
8369 int header1 = 1;
8370 struct bgp *bgp;
8371 int header2 = 1;
8372
paulbb46e942003-10-24 19:02:03 +00008373 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00008374
8375 if (! bgp)
8376 return;
8377
8378 table = bgp->rib[afi][safi];
8379
8380 output_count = 0;
8381
8382 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
8383 PEER_STATUS_DEFAULT_ORIGINATE))
8384 {
8385 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 +00008386 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8387 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008388
8389 vty_out (vty, "Originating default network 0.0.0.0%s%s",
8390 VTY_NEWLINE, VTY_NEWLINE);
8391 header1 = 0;
8392 }
8393
8394 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8395 if (in)
8396 {
8397 for (ain = rn->adj_in; ain; ain = ain->next)
8398 if (ain->peer == peer)
8399 {
8400 if (header1)
8401 {
8402 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 +00008403 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8404 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008405 header1 = 0;
8406 }
8407 if (header2)
8408 {
8409 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8410 header2 = 0;
8411 }
8412 if (ain->attr)
8413 {
8414 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
8415 output_count++;
8416 }
8417 }
8418 }
8419 else
8420 {
8421 for (adj = rn->adj_out; adj; adj = adj->next)
8422 if (adj->peer == peer)
8423 {
8424 if (header1)
8425 {
8426 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
hasso93406d82005-02-02 14:40:33 +00008427 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
8428 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008429 header1 = 0;
8430 }
8431 if (header2)
8432 {
8433 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8434 header2 = 0;
8435 }
8436 if (adj->attr)
8437 {
8438 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
8439 output_count++;
8440 }
8441 }
8442 }
8443
8444 if (output_count != 0)
8445 vty_out (vty, "%sTotal number of prefixes %ld%s",
8446 VTY_NEWLINE, output_count, VTY_NEWLINE);
8447}
8448
paul94f2b392005-06-28 12:44:16 +00008449static int
paulbb46e942003-10-24 19:02:03 +00008450peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
8451{
paul718e3742002-12-13 20:15:29 +00008452 if (! peer || ! peer->afc[afi][safi])
8453 {
8454 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8455 return CMD_WARNING;
8456 }
8457
8458 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8459 {
8460 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
8461 VTY_NEWLINE);
8462 return CMD_WARNING;
8463 }
8464
8465 show_adj_route (vty, peer, afi, safi, in);
8466
8467 return CMD_SUCCESS;
8468}
8469
8470DEFUN (show_ip_bgp_neighbor_advertised_route,
8471 show_ip_bgp_neighbor_advertised_route_cmd,
8472 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8473 SHOW_STR
8474 IP_STR
8475 BGP_STR
8476 "Detailed information on TCP and BGP neighbor connections\n"
8477 "Neighbor to display information about\n"
8478 "Neighbor to display information about\n"
8479 "Display the routes advertised to a BGP neighbor\n")
8480{
paulbb46e942003-10-24 19:02:03 +00008481 struct peer *peer;
8482
8483 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8484 if (! peer)
8485 return CMD_WARNING;
8486
8487 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008488}
8489
8490DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
8491 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
8492 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8493 SHOW_STR
8494 IP_STR
8495 BGP_STR
8496 "Address family\n"
8497 "Address Family modifier\n"
8498 "Address Family modifier\n"
8499 "Detailed information on TCP and BGP neighbor connections\n"
8500 "Neighbor to display information about\n"
8501 "Neighbor to display information about\n"
8502 "Display the routes advertised to a BGP neighbor\n")
8503{
paulbb46e942003-10-24 19:02:03 +00008504 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008505
paulbb46e942003-10-24 19:02:03 +00008506 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8507 if (! peer)
8508 return CMD_WARNING;
8509
8510 if (strncmp (argv[0], "m", 1) == 0)
8511 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
8512
8513 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008514}
8515
8516#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008517DEFUN (show_bgp_view_neighbor_advertised_route,
8518 show_bgp_view_neighbor_advertised_route_cmd,
8519 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8520 SHOW_STR
8521 BGP_STR
8522 "BGP view\n"
8523 "View name\n"
8524 "Detailed information on TCP and BGP neighbor connections\n"
8525 "Neighbor to display information about\n"
8526 "Neighbor to display information about\n"
8527 "Display the routes advertised to a BGP neighbor\n")
8528{
8529 struct peer *peer;
8530
8531 if (argc == 2)
8532 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8533 else
8534 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8535
8536 if (! peer)
8537 return CMD_WARNING;
8538
8539 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
8540}
8541
8542ALIAS (show_bgp_view_neighbor_advertised_route,
8543 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
8544 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8545 SHOW_STR
8546 BGP_STR
8547 "BGP view\n"
8548 "View name\n"
8549 "Address family\n"
8550 "Detailed information on TCP and BGP neighbor connections\n"
8551 "Neighbor to display information about\n"
8552 "Neighbor to display information about\n"
8553 "Display the routes advertised to a BGP neighbor\n")
8554
8555DEFUN (show_bgp_view_neighbor_received_routes,
8556 show_bgp_view_neighbor_received_routes_cmd,
8557 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
8558 SHOW_STR
8559 BGP_STR
8560 "BGP view\n"
8561 "View name\n"
8562 "Detailed information on TCP and BGP neighbor connections\n"
8563 "Neighbor to display information about\n"
8564 "Neighbor to display information about\n"
8565 "Display the received routes from neighbor\n")
8566{
8567 struct peer *peer;
8568
8569 if (argc == 2)
8570 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8571 else
8572 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8573
8574 if (! peer)
8575 return CMD_WARNING;
8576
8577 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
8578}
8579
8580ALIAS (show_bgp_view_neighbor_received_routes,
8581 show_bgp_view_ipv6_neighbor_received_routes_cmd,
8582 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8583 SHOW_STR
8584 BGP_STR
8585 "BGP view\n"
8586 "View name\n"
8587 "Address family\n"
8588 "Detailed information on TCP and BGP neighbor connections\n"
8589 "Neighbor to display information about\n"
8590 "Neighbor to display information about\n"
8591 "Display the received routes from neighbor\n")
8592
8593ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008594 show_bgp_neighbor_advertised_route_cmd,
8595 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8596 SHOW_STR
8597 BGP_STR
8598 "Detailed information on TCP and BGP neighbor connections\n"
8599 "Neighbor to display information about\n"
8600 "Neighbor to display information about\n"
8601 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008602
8603ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008604 show_bgp_ipv6_neighbor_advertised_route_cmd,
8605 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8606 SHOW_STR
8607 BGP_STR
8608 "Address family\n"
8609 "Detailed information on TCP and BGP neighbor connections\n"
8610 "Neighbor to display information about\n"
8611 "Neighbor to display information about\n"
8612 "Display the routes advertised to a BGP neighbor\n")
8613
8614/* old command */
paulbb46e942003-10-24 19:02:03 +00008615ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008616 ipv6_bgp_neighbor_advertised_route_cmd,
8617 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8618 SHOW_STR
8619 IPV6_STR
8620 BGP_STR
8621 "Detailed information on TCP and BGP neighbor connections\n"
8622 "Neighbor to display information about\n"
8623 "Neighbor to display information about\n"
8624 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008625
paul718e3742002-12-13 20:15:29 +00008626/* old command */
8627DEFUN (ipv6_mbgp_neighbor_advertised_route,
8628 ipv6_mbgp_neighbor_advertised_route_cmd,
8629 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8630 SHOW_STR
8631 IPV6_STR
8632 MBGP_STR
8633 "Detailed information on TCP and BGP neighbor connections\n"
8634 "Neighbor to display information about\n"
8635 "Neighbor to display information about\n"
8636 "Display the routes advertised to a BGP neighbor\n")
8637{
paulbb46e942003-10-24 19:02:03 +00008638 struct peer *peer;
8639
8640 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8641 if (! peer)
8642 return CMD_WARNING;
8643
8644 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00008645}
8646#endif /* HAVE_IPV6 */
8647
8648DEFUN (show_ip_bgp_neighbor_received_routes,
8649 show_ip_bgp_neighbor_received_routes_cmd,
8650 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8651 SHOW_STR
8652 IP_STR
8653 BGP_STR
8654 "Detailed information on TCP and BGP neighbor connections\n"
8655 "Neighbor to display information about\n"
8656 "Neighbor to display information about\n"
8657 "Display the received routes from neighbor\n")
8658{
paulbb46e942003-10-24 19:02:03 +00008659 struct peer *peer;
8660
8661 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8662 if (! peer)
8663 return CMD_WARNING;
8664
8665 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008666}
8667
8668DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
8669 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
8670 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
8671 SHOW_STR
8672 IP_STR
8673 BGP_STR
8674 "Address family\n"
8675 "Address Family modifier\n"
8676 "Address Family modifier\n"
8677 "Detailed information on TCP and BGP neighbor connections\n"
8678 "Neighbor to display information about\n"
8679 "Neighbor to display information about\n"
8680 "Display the received routes from neighbor\n")
8681{
paulbb46e942003-10-24 19:02:03 +00008682 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008683
paulbb46e942003-10-24 19:02:03 +00008684 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8685 if (! peer)
8686 return CMD_WARNING;
8687
8688 if (strncmp (argv[0], "m", 1) == 0)
8689 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
8690
8691 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008692}
8693
8694DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
8695 show_ip_bgp_neighbor_received_prefix_filter_cmd,
8696 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8697 SHOW_STR
8698 IP_STR
8699 BGP_STR
8700 "Detailed information on TCP and BGP neighbor connections\n"
8701 "Neighbor to display information about\n"
8702 "Neighbor to display information about\n"
8703 "Display information received from a BGP neighbor\n"
8704 "Display the prefixlist filter\n")
8705{
8706 char name[BUFSIZ];
8707 union sockunion *su;
8708 struct peer *peer;
8709 int count;
8710
8711 su = sockunion_str2su (argv[0]);
8712 if (su == NULL)
8713 return CMD_WARNING;
8714
8715 peer = peer_lookup (NULL, su);
8716 if (! peer)
8717 return CMD_WARNING;
8718
8719 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8720 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8721 if (count)
8722 {
8723 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8724 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8725 }
8726
8727 return CMD_SUCCESS;
8728}
8729
8730DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
8731 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
8732 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8733 SHOW_STR
8734 IP_STR
8735 BGP_STR
8736 "Address family\n"
8737 "Address Family modifier\n"
8738 "Address Family modifier\n"
8739 "Detailed information on TCP and BGP neighbor connections\n"
8740 "Neighbor to display information about\n"
8741 "Neighbor to display information about\n"
8742 "Display information received from a BGP neighbor\n"
8743 "Display the prefixlist filter\n")
8744{
8745 char name[BUFSIZ];
8746 union sockunion *su;
8747 struct peer *peer;
8748 int count;
8749
8750 su = sockunion_str2su (argv[1]);
8751 if (su == NULL)
8752 return CMD_WARNING;
8753
8754 peer = peer_lookup (NULL, su);
8755 if (! peer)
8756 return CMD_WARNING;
8757
8758 if (strncmp (argv[0], "m", 1) == 0)
8759 {
8760 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
8761 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8762 if (count)
8763 {
8764 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
8765 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8766 }
8767 }
8768 else
8769 {
8770 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8771 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8772 if (count)
8773 {
8774 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8775 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8776 }
8777 }
8778
8779 return CMD_SUCCESS;
8780}
8781
8782
8783#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008784ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008785 show_bgp_neighbor_received_routes_cmd,
8786 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8787 SHOW_STR
8788 BGP_STR
8789 "Detailed information on TCP and BGP neighbor connections\n"
8790 "Neighbor to display information about\n"
8791 "Neighbor to display information about\n"
8792 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008793
paulbb46e942003-10-24 19:02:03 +00008794ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008795 show_bgp_ipv6_neighbor_received_routes_cmd,
8796 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8797 SHOW_STR
8798 BGP_STR
8799 "Address family\n"
8800 "Detailed information on TCP and BGP neighbor connections\n"
8801 "Neighbor to display information about\n"
8802 "Neighbor to display information about\n"
8803 "Display the received routes from neighbor\n")
8804
8805DEFUN (show_bgp_neighbor_received_prefix_filter,
8806 show_bgp_neighbor_received_prefix_filter_cmd,
8807 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8808 SHOW_STR
8809 BGP_STR
8810 "Detailed information on TCP and BGP neighbor connections\n"
8811 "Neighbor to display information about\n"
8812 "Neighbor to display information about\n"
8813 "Display information received from a BGP neighbor\n"
8814 "Display the prefixlist filter\n")
8815{
8816 char name[BUFSIZ];
8817 union sockunion *su;
8818 struct peer *peer;
8819 int count;
8820
8821 su = sockunion_str2su (argv[0]);
8822 if (su == NULL)
8823 return CMD_WARNING;
8824
8825 peer = peer_lookup (NULL, su);
8826 if (! peer)
8827 return CMD_WARNING;
8828
8829 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8830 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8831 if (count)
8832 {
8833 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8834 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8835 }
8836
8837 return CMD_SUCCESS;
8838}
8839
8840ALIAS (show_bgp_neighbor_received_prefix_filter,
8841 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
8842 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8843 SHOW_STR
8844 BGP_STR
8845 "Address family\n"
8846 "Detailed information on TCP and BGP neighbor connections\n"
8847 "Neighbor to display information about\n"
8848 "Neighbor to display information about\n"
8849 "Display information received from a BGP neighbor\n"
8850 "Display the prefixlist filter\n")
8851
8852/* old command */
paulbb46e942003-10-24 19:02:03 +00008853ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008854 ipv6_bgp_neighbor_received_routes_cmd,
8855 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8856 SHOW_STR
8857 IPV6_STR
8858 BGP_STR
8859 "Detailed information on TCP and BGP neighbor connections\n"
8860 "Neighbor to display information about\n"
8861 "Neighbor to display information about\n"
8862 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008863
8864/* old command */
8865DEFUN (ipv6_mbgp_neighbor_received_routes,
8866 ipv6_mbgp_neighbor_received_routes_cmd,
8867 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8868 SHOW_STR
8869 IPV6_STR
8870 MBGP_STR
8871 "Detailed information on TCP and BGP neighbor connections\n"
8872 "Neighbor to display information about\n"
8873 "Neighbor to display information about\n"
8874 "Display the received routes from neighbor\n")
8875{
paulbb46e942003-10-24 19:02:03 +00008876 struct peer *peer;
8877
8878 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8879 if (! peer)
8880 return CMD_WARNING;
8881
8882 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00008883}
paulbb46e942003-10-24 19:02:03 +00008884
8885DEFUN (show_bgp_view_neighbor_received_prefix_filter,
8886 show_bgp_view_neighbor_received_prefix_filter_cmd,
8887 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8888 SHOW_STR
8889 BGP_STR
8890 "BGP view\n"
8891 "View name\n"
8892 "Detailed information on TCP and BGP neighbor connections\n"
8893 "Neighbor to display information about\n"
8894 "Neighbor to display information about\n"
8895 "Display information received from a BGP neighbor\n"
8896 "Display the prefixlist filter\n")
8897{
8898 char name[BUFSIZ];
8899 union sockunion *su;
8900 struct peer *peer;
8901 struct bgp *bgp;
8902 int count;
8903
8904 /* BGP structure lookup. */
8905 bgp = bgp_lookup_by_name (argv[0]);
8906 if (bgp == NULL)
8907 {
8908 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8909 return CMD_WARNING;
8910 }
8911
8912 su = sockunion_str2su (argv[1]);
8913 if (su == NULL)
8914 return CMD_WARNING;
8915
8916 peer = peer_lookup (bgp, su);
8917 if (! peer)
8918 return CMD_WARNING;
8919
8920 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8921 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8922 if (count)
8923 {
8924 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8925 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8926 }
8927
8928 return CMD_SUCCESS;
8929}
8930
8931ALIAS (show_bgp_view_neighbor_received_prefix_filter,
8932 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
8933 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8934 SHOW_STR
8935 BGP_STR
8936 "BGP view\n"
8937 "View name\n"
8938 "Address family\n"
8939 "Detailed information on TCP and BGP neighbor connections\n"
8940 "Neighbor to display information about\n"
8941 "Neighbor to display information about\n"
8942 "Display information received from a BGP neighbor\n"
8943 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00008944#endif /* HAVE_IPV6 */
8945
paul94f2b392005-06-28 12:44:16 +00008946static int
paulbb46e942003-10-24 19:02:03 +00008947bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008948 safi_t safi, enum bgp_show_type type)
8949{
paul718e3742002-12-13 20:15:29 +00008950 if (! peer || ! peer->afc[afi][safi])
8951 {
8952 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008953 return CMD_WARNING;
8954 }
8955
ajs5a646652004-11-05 01:25:55 +00008956 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +00008957}
8958
8959DEFUN (show_ip_bgp_neighbor_routes,
8960 show_ip_bgp_neighbor_routes_cmd,
8961 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
8962 SHOW_STR
8963 IP_STR
8964 BGP_STR
8965 "Detailed information on TCP and BGP neighbor connections\n"
8966 "Neighbor to display information about\n"
8967 "Neighbor to display information about\n"
8968 "Display routes learned from neighbor\n")
8969{
paulbb46e942003-10-24 19:02:03 +00008970 struct peer *peer;
8971
8972 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8973 if (! peer)
8974 return CMD_WARNING;
8975
8976 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008977 bgp_show_type_neighbor);
8978}
8979
8980DEFUN (show_ip_bgp_neighbor_flap,
8981 show_ip_bgp_neighbor_flap_cmd,
8982 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
8983 SHOW_STR
8984 IP_STR
8985 BGP_STR
8986 "Detailed information on TCP and BGP neighbor connections\n"
8987 "Neighbor to display information about\n"
8988 "Neighbor to display information about\n"
8989 "Display flap statistics of the routes learned from neighbor\n")
8990{
paulbb46e942003-10-24 19:02:03 +00008991 struct peer *peer;
8992
8993 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8994 if (! peer)
8995 return CMD_WARNING;
8996
8997 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008998 bgp_show_type_flap_neighbor);
8999}
9000
9001DEFUN (show_ip_bgp_neighbor_damp,
9002 show_ip_bgp_neighbor_damp_cmd,
9003 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9004 SHOW_STR
9005 IP_STR
9006 BGP_STR
9007 "Detailed information on TCP and BGP neighbor connections\n"
9008 "Neighbor to display information about\n"
9009 "Neighbor to display information about\n"
9010 "Display the dampened routes received from neighbor\n")
9011{
paulbb46e942003-10-24 19:02:03 +00009012 struct peer *peer;
9013
9014 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9015 if (! peer)
9016 return CMD_WARNING;
9017
9018 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009019 bgp_show_type_damp_neighbor);
9020}
9021
9022DEFUN (show_ip_bgp_ipv4_neighbor_routes,
9023 show_ip_bgp_ipv4_neighbor_routes_cmd,
9024 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
9025 SHOW_STR
9026 IP_STR
9027 BGP_STR
9028 "Address family\n"
9029 "Address Family modifier\n"
9030 "Address Family modifier\n"
9031 "Detailed information on TCP and BGP neighbor connections\n"
9032 "Neighbor to display information about\n"
9033 "Neighbor to display information about\n"
9034 "Display routes learned from neighbor\n")
9035{
paulbb46e942003-10-24 19:02:03 +00009036 struct peer *peer;
9037
9038 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9039 if (! peer)
9040 return CMD_WARNING;
9041
paul718e3742002-12-13 20:15:29 +00009042 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00009043 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009044 bgp_show_type_neighbor);
9045
paulbb46e942003-10-24 19:02:03 +00009046 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009047 bgp_show_type_neighbor);
9048}
paulbb46e942003-10-24 19:02:03 +00009049
paulfee0f4c2004-09-13 05:12:46 +00009050DEFUN (show_ip_bgp_view_rsclient,
9051 show_ip_bgp_view_rsclient_cmd,
9052 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9053 SHOW_STR
9054 IP_STR
9055 BGP_STR
9056 "BGP view\n"
9057 "BGP view name\n"
9058 "Information about Route Server Client\n"
9059 NEIGHBOR_ADDR_STR)
9060{
9061 struct bgp_table *table;
9062 struct peer *peer;
9063
9064 if (argc == 2)
9065 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9066 else
9067 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9068
9069 if (! peer)
9070 return CMD_WARNING;
9071
9072 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9073 {
9074 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9075 VTY_NEWLINE);
9076 return CMD_WARNING;
9077 }
9078
9079 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9080 PEER_FLAG_RSERVER_CLIENT))
9081 {
9082 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9083 VTY_NEWLINE);
9084 return CMD_WARNING;
9085 }
9086
9087 table = peer->rib[AFI_IP][SAFI_UNICAST];
9088
ajs5a646652004-11-05 01:25:55 +00009089 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009090}
9091
9092ALIAS (show_ip_bgp_view_rsclient,
9093 show_ip_bgp_rsclient_cmd,
9094 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
9095 SHOW_STR
9096 IP_STR
9097 BGP_STR
9098 "Information about Route Server Client\n"
9099 NEIGHBOR_ADDR_STR)
9100
9101DEFUN (show_ip_bgp_view_rsclient_route,
9102 show_ip_bgp_view_rsclient_route_cmd,
9103 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9104 SHOW_STR
9105 IP_STR
9106 BGP_STR
9107 "BGP view\n"
9108 "BGP view name\n"
9109 "Information about Route Server Client\n"
9110 NEIGHBOR_ADDR_STR
9111 "Network in the BGP routing table to display\n")
9112{
9113 struct bgp *bgp;
9114 struct peer *peer;
9115
9116 /* BGP structure lookup. */
9117 if (argc == 3)
9118 {
9119 bgp = bgp_lookup_by_name (argv[0]);
9120 if (bgp == NULL)
9121 {
9122 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9123 return CMD_WARNING;
9124 }
9125 }
9126 else
9127 {
9128 bgp = bgp_get_default ();
9129 if (bgp == NULL)
9130 {
9131 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9132 return CMD_WARNING;
9133 }
9134 }
9135
9136 if (argc == 3)
9137 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9138 else
9139 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9140
9141 if (! peer)
9142 return CMD_WARNING;
9143
9144 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9145 {
9146 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9147 VTY_NEWLINE);
9148 return CMD_WARNING;
9149}
9150
9151 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9152 PEER_FLAG_RSERVER_CLIENT))
9153 {
9154 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9155 VTY_NEWLINE);
9156 return CMD_WARNING;
9157 }
9158
9159 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9160 (argc == 3) ? argv[2] : argv[1],
9161 AFI_IP, SAFI_UNICAST, NULL, 0);
9162}
9163
9164ALIAS (show_ip_bgp_view_rsclient_route,
9165 show_ip_bgp_rsclient_route_cmd,
9166 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9167 SHOW_STR
9168 IP_STR
9169 BGP_STR
9170 "Information about Route Server Client\n"
9171 NEIGHBOR_ADDR_STR
9172 "Network in the BGP routing table to display\n")
9173
9174DEFUN (show_ip_bgp_view_rsclient_prefix,
9175 show_ip_bgp_view_rsclient_prefix_cmd,
9176 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9177 SHOW_STR
9178 IP_STR
9179 BGP_STR
9180 "BGP view\n"
9181 "BGP view name\n"
9182 "Information about Route Server Client\n"
9183 NEIGHBOR_ADDR_STR
9184 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9185{
9186 struct bgp *bgp;
9187 struct peer *peer;
9188
9189 /* BGP structure lookup. */
9190 if (argc == 3)
9191 {
9192 bgp = bgp_lookup_by_name (argv[0]);
9193 if (bgp == NULL)
9194 {
9195 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9196 return CMD_WARNING;
9197 }
9198 }
9199 else
9200 {
9201 bgp = bgp_get_default ();
9202 if (bgp == NULL)
9203 {
9204 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9205 return CMD_WARNING;
9206 }
9207 }
9208
9209 if (argc == 3)
9210 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9211 else
9212 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9213
9214 if (! peer)
9215 return CMD_WARNING;
9216
9217 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9218 {
9219 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9220 VTY_NEWLINE);
9221 return CMD_WARNING;
9222}
9223
9224 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9225 PEER_FLAG_RSERVER_CLIENT))
9226{
9227 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9228 VTY_NEWLINE);
9229 return CMD_WARNING;
9230 }
9231
9232 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9233 (argc == 3) ? argv[2] : argv[1],
9234 AFI_IP, SAFI_UNICAST, NULL, 1);
9235}
9236
9237ALIAS (show_ip_bgp_view_rsclient_prefix,
9238 show_ip_bgp_rsclient_prefix_cmd,
9239 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9240 SHOW_STR
9241 IP_STR
9242 BGP_STR
9243 "Information about Route Server Client\n"
9244 NEIGHBOR_ADDR_STR
9245 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9246
9247
paul718e3742002-12-13 20:15:29 +00009248#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009249DEFUN (show_bgp_view_neighbor_routes,
9250 show_bgp_view_neighbor_routes_cmd,
9251 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
9252 SHOW_STR
9253 BGP_STR
9254 "BGP view\n"
9255 "BGP view name\n"
9256 "Detailed information on TCP and BGP neighbor connections\n"
9257 "Neighbor to display information about\n"
9258 "Neighbor to display information about\n"
9259 "Display routes learned from neighbor\n")
9260{
9261 struct peer *peer;
9262
9263 if (argc == 2)
9264 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9265 else
9266 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9267
9268 if (! peer)
9269 return CMD_WARNING;
9270
9271 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9272 bgp_show_type_neighbor);
9273}
9274
9275ALIAS (show_bgp_view_neighbor_routes,
9276 show_bgp_view_ipv6_neighbor_routes_cmd,
9277 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9278 SHOW_STR
9279 BGP_STR
9280 "BGP view\n"
9281 "BGP view name\n"
9282 "Address family\n"
9283 "Detailed information on TCP and BGP neighbor connections\n"
9284 "Neighbor to display information about\n"
9285 "Neighbor to display information about\n"
9286 "Display routes learned from neighbor\n")
9287
9288DEFUN (show_bgp_view_neighbor_damp,
9289 show_bgp_view_neighbor_damp_cmd,
9290 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9291 SHOW_STR
9292 BGP_STR
9293 "BGP view\n"
9294 "BGP view name\n"
9295 "Detailed information on TCP and BGP neighbor connections\n"
9296 "Neighbor to display information about\n"
9297 "Neighbor to display information about\n"
9298 "Display the dampened routes received from neighbor\n")
9299{
9300 struct peer *peer;
9301
9302 if (argc == 2)
9303 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9304 else
9305 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9306
9307 if (! peer)
9308 return CMD_WARNING;
9309
9310 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9311 bgp_show_type_damp_neighbor);
9312}
9313
9314ALIAS (show_bgp_view_neighbor_damp,
9315 show_bgp_view_ipv6_neighbor_damp_cmd,
9316 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9317 SHOW_STR
9318 BGP_STR
9319 "BGP view\n"
9320 "BGP view name\n"
9321 "Address family\n"
9322 "Detailed information on TCP and BGP neighbor connections\n"
9323 "Neighbor to display information about\n"
9324 "Neighbor to display information about\n"
9325 "Display the dampened routes received from neighbor\n")
9326
9327DEFUN (show_bgp_view_neighbor_flap,
9328 show_bgp_view_neighbor_flap_cmd,
9329 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9330 SHOW_STR
9331 BGP_STR
9332 "BGP view\n"
9333 "BGP view name\n"
9334 "Detailed information on TCP and BGP neighbor connections\n"
9335 "Neighbor to display information about\n"
9336 "Neighbor to display information about\n"
9337 "Display flap statistics of the routes learned from neighbor\n")
9338{
9339 struct peer *peer;
9340
9341 if (argc == 2)
9342 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9343 else
9344 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9345
9346 if (! peer)
9347 return CMD_WARNING;
9348
9349 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9350 bgp_show_type_flap_neighbor);
9351}
9352
9353ALIAS (show_bgp_view_neighbor_flap,
9354 show_bgp_view_ipv6_neighbor_flap_cmd,
9355 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9356 SHOW_STR
9357 BGP_STR
9358 "BGP view\n"
9359 "BGP view name\n"
9360 "Address family\n"
9361 "Detailed information on TCP and BGP neighbor connections\n"
9362 "Neighbor to display information about\n"
9363 "Neighbor to display information about\n"
9364 "Display flap statistics of the routes learned from neighbor\n")
9365
9366ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009367 show_bgp_neighbor_routes_cmd,
9368 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
9369 SHOW_STR
9370 BGP_STR
9371 "Detailed information on TCP and BGP neighbor connections\n"
9372 "Neighbor to display information about\n"
9373 "Neighbor to display information about\n"
9374 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009375
paulbb46e942003-10-24 19:02:03 +00009376
9377ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009378 show_bgp_ipv6_neighbor_routes_cmd,
9379 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9380 SHOW_STR
9381 BGP_STR
9382 "Address family\n"
9383 "Detailed information on TCP and BGP neighbor connections\n"
9384 "Neighbor to display information about\n"
9385 "Neighbor to display information about\n"
9386 "Display routes learned from neighbor\n")
9387
9388/* old command */
paulbb46e942003-10-24 19:02:03 +00009389ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009390 ipv6_bgp_neighbor_routes_cmd,
9391 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
9392 SHOW_STR
9393 IPV6_STR
9394 BGP_STR
9395 "Detailed information on TCP and BGP neighbor connections\n"
9396 "Neighbor to display information about\n"
9397 "Neighbor to display information about\n"
9398 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009399
9400/* old command */
9401DEFUN (ipv6_mbgp_neighbor_routes,
9402 ipv6_mbgp_neighbor_routes_cmd,
9403 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
9404 SHOW_STR
9405 IPV6_STR
9406 MBGP_STR
9407 "Detailed information on TCP and BGP neighbor connections\n"
9408 "Neighbor to display information about\n"
9409 "Neighbor to display information about\n"
9410 "Display routes learned from neighbor\n")
9411{
paulbb46e942003-10-24 19:02:03 +00009412 struct peer *peer;
9413
9414 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9415 if (! peer)
9416 return CMD_WARNING;
9417
9418 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009419 bgp_show_type_neighbor);
9420}
paulbb46e942003-10-24 19:02:03 +00009421
9422ALIAS (show_bgp_view_neighbor_flap,
9423 show_bgp_neighbor_flap_cmd,
9424 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9425 SHOW_STR
9426 BGP_STR
9427 "Detailed information on TCP and BGP neighbor connections\n"
9428 "Neighbor to display information about\n"
9429 "Neighbor to display information about\n"
9430 "Display flap statistics of the routes learned from neighbor\n")
9431
9432ALIAS (show_bgp_view_neighbor_flap,
9433 show_bgp_ipv6_neighbor_flap_cmd,
9434 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9435 SHOW_STR
9436 BGP_STR
9437 "Address family\n"
9438 "Detailed information on TCP and BGP neighbor connections\n"
9439 "Neighbor to display information about\n"
9440 "Neighbor to display information about\n"
9441 "Display flap statistics of the routes learned from neighbor\n")
9442
9443ALIAS (show_bgp_view_neighbor_damp,
9444 show_bgp_neighbor_damp_cmd,
9445 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9446 SHOW_STR
9447 BGP_STR
9448 "Detailed information on TCP and BGP neighbor connections\n"
9449 "Neighbor to display information about\n"
9450 "Neighbor to display information about\n"
9451 "Display the dampened routes received from neighbor\n")
9452
9453ALIAS (show_bgp_view_neighbor_damp,
9454 show_bgp_ipv6_neighbor_damp_cmd,
9455 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9456 SHOW_STR
9457 BGP_STR
9458 "Address family\n"
9459 "Detailed information on TCP and BGP neighbor connections\n"
9460 "Neighbor to display information about\n"
9461 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +00009462 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +00009463
9464DEFUN (show_bgp_view_rsclient,
9465 show_bgp_view_rsclient_cmd,
9466 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9467 SHOW_STR
9468 BGP_STR
9469 "BGP view\n"
9470 "BGP view name\n"
9471 "Information about Route Server Client\n"
9472 NEIGHBOR_ADDR_STR)
9473{
9474 struct bgp_table *table;
9475 struct peer *peer;
9476
9477 if (argc == 2)
9478 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9479 else
9480 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9481
9482 if (! peer)
9483 return CMD_WARNING;
9484
9485 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9486 {
9487 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9488 VTY_NEWLINE);
9489 return CMD_WARNING;
9490 }
9491
9492 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9493 PEER_FLAG_RSERVER_CLIENT))
9494 {
9495 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9496 VTY_NEWLINE);
9497 return CMD_WARNING;
9498 }
9499
9500 table = peer->rib[AFI_IP6][SAFI_UNICAST];
9501
ajs5a646652004-11-05 01:25:55 +00009502 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009503}
9504
9505ALIAS (show_bgp_view_rsclient,
9506 show_bgp_rsclient_cmd,
9507 "show bgp rsclient (A.B.C.D|X:X::X:X)",
9508 SHOW_STR
9509 BGP_STR
9510 "Information about Route Server Client\n"
9511 NEIGHBOR_ADDR_STR)
9512
9513DEFUN (show_bgp_view_rsclient_route,
9514 show_bgp_view_rsclient_route_cmd,
9515 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9516 SHOW_STR
9517 BGP_STR
9518 "BGP view\n"
9519 "BGP view name\n"
9520 "Information about Route Server Client\n"
9521 NEIGHBOR_ADDR_STR
9522 "Network in the BGP routing table to display\n")
9523{
9524 struct bgp *bgp;
9525 struct peer *peer;
9526
9527 /* BGP structure lookup. */
9528 if (argc == 3)
9529 {
9530 bgp = bgp_lookup_by_name (argv[0]);
9531 if (bgp == NULL)
9532 {
9533 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9534 return CMD_WARNING;
9535 }
9536 }
9537 else
9538 {
9539 bgp = bgp_get_default ();
9540 if (bgp == NULL)
9541 {
9542 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9543 return CMD_WARNING;
9544 }
9545 }
9546
9547 if (argc == 3)
9548 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9549 else
9550 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9551
9552 if (! peer)
9553 return CMD_WARNING;
9554
9555 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9556 {
9557 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9558 VTY_NEWLINE);
9559 return CMD_WARNING;
9560 }
9561
9562 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9563 PEER_FLAG_RSERVER_CLIENT))
9564 {
9565 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9566 VTY_NEWLINE);
9567 return CMD_WARNING;
9568 }
9569
9570 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9571 (argc == 3) ? argv[2] : argv[1],
9572 AFI_IP6, SAFI_UNICAST, NULL, 0);
9573}
9574
9575ALIAS (show_bgp_view_rsclient_route,
9576 show_bgp_rsclient_route_cmd,
9577 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9578 SHOW_STR
9579 BGP_STR
9580 "Information about Route Server Client\n"
9581 NEIGHBOR_ADDR_STR
9582 "Network in the BGP routing table to display\n")
9583
9584DEFUN (show_bgp_view_rsclient_prefix,
9585 show_bgp_view_rsclient_prefix_cmd,
9586 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9587 SHOW_STR
9588 BGP_STR
9589 "BGP view\n"
9590 "BGP view name\n"
9591 "Information about Route Server Client\n"
9592 NEIGHBOR_ADDR_STR
9593 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9594{
9595 struct bgp *bgp;
9596 struct peer *peer;
9597
9598 /* BGP structure lookup. */
9599 if (argc == 3)
9600 {
9601 bgp = bgp_lookup_by_name (argv[0]);
9602 if (bgp == NULL)
9603 {
9604 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9605 return CMD_WARNING;
9606 }
9607 }
9608 else
9609 {
9610 bgp = bgp_get_default ();
9611 if (bgp == NULL)
9612 {
9613 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9614 return CMD_WARNING;
9615 }
9616 }
9617
9618 if (argc == 3)
9619 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9620 else
9621 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9622
9623 if (! peer)
9624 return CMD_WARNING;
9625
9626 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9627 {
9628 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9629 VTY_NEWLINE);
9630 return CMD_WARNING;
9631 }
9632
9633 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9634 PEER_FLAG_RSERVER_CLIENT))
9635 {
9636 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9637 VTY_NEWLINE);
9638 return CMD_WARNING;
9639 }
9640
9641 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9642 (argc == 3) ? argv[2] : argv[1],
9643 AFI_IP6, SAFI_UNICAST, NULL, 1);
9644}
9645
9646ALIAS (show_bgp_view_rsclient_prefix,
9647 show_bgp_rsclient_prefix_cmd,
9648 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9649 SHOW_STR
9650 BGP_STR
9651 "Information about Route Server Client\n"
9652 NEIGHBOR_ADDR_STR
9653 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9654
paul718e3742002-12-13 20:15:29 +00009655#endif /* HAVE_IPV6 */
9656
9657struct bgp_table *bgp_distance_table;
9658
9659struct bgp_distance
9660{
9661 /* Distance value for the IP source prefix. */
9662 u_char distance;
9663
9664 /* Name of the access-list to be matched. */
9665 char *access_list;
9666};
9667
paul94f2b392005-06-28 12:44:16 +00009668static struct bgp_distance *
paul718e3742002-12-13 20:15:29 +00009669bgp_distance_new ()
9670{
9671 struct bgp_distance *new;
9672 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
9673 memset (new, 0, sizeof (struct bgp_distance));
9674 return new;
9675}
9676
paul94f2b392005-06-28 12:44:16 +00009677static void
paul718e3742002-12-13 20:15:29 +00009678bgp_distance_free (struct bgp_distance *bdistance)
9679{
9680 XFREE (MTYPE_BGP_DISTANCE, bdistance);
9681}
9682
paul94f2b392005-06-28 12:44:16 +00009683static int
paulfd79ac92004-10-13 05:06:08 +00009684bgp_distance_set (struct vty *vty, const char *distance_str,
9685 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009686{
9687 int ret;
9688 struct prefix_ipv4 p;
9689 u_char distance;
9690 struct bgp_node *rn;
9691 struct bgp_distance *bdistance;
9692
9693 ret = str2prefix_ipv4 (ip_str, &p);
9694 if (ret == 0)
9695 {
9696 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9697 return CMD_WARNING;
9698 }
9699
9700 distance = atoi (distance_str);
9701
9702 /* Get BGP distance node. */
9703 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
9704 if (rn->info)
9705 {
9706 bdistance = rn->info;
9707 bgp_unlock_node (rn);
9708 }
9709 else
9710 {
9711 bdistance = bgp_distance_new ();
9712 rn->info = bdistance;
9713 }
9714
9715 /* Set distance value. */
9716 bdistance->distance = distance;
9717
9718 /* Reset access-list configuration. */
9719 if (bdistance->access_list)
9720 {
9721 free (bdistance->access_list);
9722 bdistance->access_list = NULL;
9723 }
9724 if (access_list_str)
9725 bdistance->access_list = strdup (access_list_str);
9726
9727 return CMD_SUCCESS;
9728}
9729
paul94f2b392005-06-28 12:44:16 +00009730static int
paulfd79ac92004-10-13 05:06:08 +00009731bgp_distance_unset (struct vty *vty, const char *distance_str,
9732 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009733{
9734 int ret;
9735 struct prefix_ipv4 p;
9736 u_char distance;
9737 struct bgp_node *rn;
9738 struct bgp_distance *bdistance;
9739
9740 ret = str2prefix_ipv4 (ip_str, &p);
9741 if (ret == 0)
9742 {
9743 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9744 return CMD_WARNING;
9745 }
9746
9747 distance = atoi (distance_str);
9748
9749 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
9750 if (! rn)
9751 {
9752 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
9753 return CMD_WARNING;
9754 }
9755
9756 bdistance = rn->info;
9757
9758 if (bdistance->access_list)
9759 free (bdistance->access_list);
9760 bgp_distance_free (bdistance);
9761
9762 rn->info = NULL;
9763 bgp_unlock_node (rn);
9764 bgp_unlock_node (rn);
9765
9766 return CMD_SUCCESS;
9767}
9768
paul94f2b392005-06-28 12:44:16 +00009769static void
paul718e3742002-12-13 20:15:29 +00009770bgp_distance_reset ()
9771{
9772 struct bgp_node *rn;
9773 struct bgp_distance *bdistance;
9774
9775 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
9776 if ((bdistance = rn->info) != NULL)
9777 {
9778 if (bdistance->access_list)
9779 free (bdistance->access_list);
9780 bgp_distance_free (bdistance);
9781 rn->info = NULL;
9782 bgp_unlock_node (rn);
9783 }
9784}
9785
9786/* Apply BGP information to distance method. */
9787u_char
9788bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
9789{
9790 struct bgp_node *rn;
9791 struct prefix_ipv4 q;
9792 struct peer *peer;
9793 struct bgp_distance *bdistance;
9794 struct access_list *alist;
9795 struct bgp_static *bgp_static;
9796
9797 if (! bgp)
9798 return 0;
9799
9800 if (p->family != AF_INET)
9801 return 0;
9802
9803 peer = rinfo->peer;
9804
9805 if (peer->su.sa.sa_family != AF_INET)
9806 return 0;
9807
9808 memset (&q, 0, sizeof (struct prefix_ipv4));
9809 q.family = AF_INET;
9810 q.prefix = peer->su.sin.sin_addr;
9811 q.prefixlen = IPV4_MAX_BITLEN;
9812
9813 /* Check source address. */
9814 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
9815 if (rn)
9816 {
9817 bdistance = rn->info;
9818 bgp_unlock_node (rn);
9819
9820 if (bdistance->access_list)
9821 {
9822 alist = access_list_lookup (AFI_IP, bdistance->access_list);
9823 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
9824 return bdistance->distance;
9825 }
9826 else
9827 return bdistance->distance;
9828 }
9829
9830 /* Backdoor check. */
9831 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
9832 if (rn)
9833 {
9834 bgp_static = rn->info;
9835 bgp_unlock_node (rn);
9836
9837 if (bgp_static->backdoor)
9838 {
9839 if (bgp->distance_local)
9840 return bgp->distance_local;
9841 else
9842 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9843 }
9844 }
9845
9846 if (peer_sort (peer) == BGP_PEER_EBGP)
9847 {
9848 if (bgp->distance_ebgp)
9849 return bgp->distance_ebgp;
9850 return ZEBRA_EBGP_DISTANCE_DEFAULT;
9851 }
9852 else
9853 {
9854 if (bgp->distance_ibgp)
9855 return bgp->distance_ibgp;
9856 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9857 }
9858}
9859
9860DEFUN (bgp_distance,
9861 bgp_distance_cmd,
9862 "distance bgp <1-255> <1-255> <1-255>",
9863 "Define an administrative distance\n"
9864 "BGP distance\n"
9865 "Distance for routes external to the AS\n"
9866 "Distance for routes internal to the AS\n"
9867 "Distance for local routes\n")
9868{
9869 struct bgp *bgp;
9870
9871 bgp = vty->index;
9872
9873 bgp->distance_ebgp = atoi (argv[0]);
9874 bgp->distance_ibgp = atoi (argv[1]);
9875 bgp->distance_local = atoi (argv[2]);
9876 return CMD_SUCCESS;
9877}
9878
9879DEFUN (no_bgp_distance,
9880 no_bgp_distance_cmd,
9881 "no distance bgp <1-255> <1-255> <1-255>",
9882 NO_STR
9883 "Define an administrative distance\n"
9884 "BGP distance\n"
9885 "Distance for routes external to the AS\n"
9886 "Distance for routes internal to the AS\n"
9887 "Distance for local routes\n")
9888{
9889 struct bgp *bgp;
9890
9891 bgp = vty->index;
9892
9893 bgp->distance_ebgp= 0;
9894 bgp->distance_ibgp = 0;
9895 bgp->distance_local = 0;
9896 return CMD_SUCCESS;
9897}
9898
9899ALIAS (no_bgp_distance,
9900 no_bgp_distance2_cmd,
9901 "no distance bgp",
9902 NO_STR
9903 "Define an administrative distance\n"
9904 "BGP distance\n")
9905
9906DEFUN (bgp_distance_source,
9907 bgp_distance_source_cmd,
9908 "distance <1-255> A.B.C.D/M",
9909 "Define an administrative distance\n"
9910 "Administrative distance\n"
9911 "IP source prefix\n")
9912{
9913 bgp_distance_set (vty, argv[0], argv[1], NULL);
9914 return CMD_SUCCESS;
9915}
9916
9917DEFUN (no_bgp_distance_source,
9918 no_bgp_distance_source_cmd,
9919 "no distance <1-255> A.B.C.D/M",
9920 NO_STR
9921 "Define an administrative distance\n"
9922 "Administrative distance\n"
9923 "IP source prefix\n")
9924{
9925 bgp_distance_unset (vty, argv[0], argv[1], NULL);
9926 return CMD_SUCCESS;
9927}
9928
9929DEFUN (bgp_distance_source_access_list,
9930 bgp_distance_source_access_list_cmd,
9931 "distance <1-255> A.B.C.D/M WORD",
9932 "Define an administrative distance\n"
9933 "Administrative distance\n"
9934 "IP source prefix\n"
9935 "Access list name\n")
9936{
9937 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
9938 return CMD_SUCCESS;
9939}
9940
9941DEFUN (no_bgp_distance_source_access_list,
9942 no_bgp_distance_source_access_list_cmd,
9943 "no distance <1-255> A.B.C.D/M WORD",
9944 NO_STR
9945 "Define an administrative distance\n"
9946 "Administrative distance\n"
9947 "IP source prefix\n"
9948 "Access list name\n")
9949{
9950 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
9951 return CMD_SUCCESS;
9952}
9953
9954DEFUN (bgp_damp_set,
9955 bgp_damp_set_cmd,
9956 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
9957 "BGP Specific commands\n"
9958 "Enable route-flap dampening\n"
9959 "Half-life time for the penalty\n"
9960 "Value to start reusing a route\n"
9961 "Value to start suppressing a route\n"
9962 "Maximum duration to suppress a stable route\n")
9963{
9964 struct bgp *bgp;
9965 int half = DEFAULT_HALF_LIFE * 60;
9966 int reuse = DEFAULT_REUSE;
9967 int suppress = DEFAULT_SUPPRESS;
9968 int max = 4 * half;
9969
9970 if (argc == 4)
9971 {
9972 half = atoi (argv[0]) * 60;
9973 reuse = atoi (argv[1]);
9974 suppress = atoi (argv[2]);
9975 max = atoi (argv[3]) * 60;
9976 }
9977 else if (argc == 1)
9978 {
9979 half = atoi (argv[0]) * 60;
9980 max = 4 * half;
9981 }
9982
9983 bgp = vty->index;
9984 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
9985 half, reuse, suppress, max);
9986}
9987
9988ALIAS (bgp_damp_set,
9989 bgp_damp_set2_cmd,
9990 "bgp dampening <1-45>",
9991 "BGP Specific commands\n"
9992 "Enable route-flap dampening\n"
9993 "Half-life time for the penalty\n")
9994
9995ALIAS (bgp_damp_set,
9996 bgp_damp_set3_cmd,
9997 "bgp dampening",
9998 "BGP Specific commands\n"
9999 "Enable route-flap dampening\n")
10000
10001DEFUN (bgp_damp_unset,
10002 bgp_damp_unset_cmd,
10003 "no bgp dampening",
10004 NO_STR
10005 "BGP Specific commands\n"
10006 "Enable route-flap dampening\n")
10007{
10008 struct bgp *bgp;
10009
10010 bgp = vty->index;
10011 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
10012}
10013
10014ALIAS (bgp_damp_unset,
10015 bgp_damp_unset2_cmd,
10016 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10017 NO_STR
10018 "BGP Specific commands\n"
10019 "Enable route-flap dampening\n"
10020 "Half-life time for the penalty\n"
10021 "Value to start reusing a route\n"
10022 "Value to start suppressing a route\n"
10023 "Maximum duration to suppress a stable route\n")
10024
10025DEFUN (show_ip_bgp_dampened_paths,
10026 show_ip_bgp_dampened_paths_cmd,
10027 "show ip bgp dampened-paths",
10028 SHOW_STR
10029 IP_STR
10030 BGP_STR
10031 "Display paths suppressed due to dampening\n")
10032{
ajs5a646652004-11-05 01:25:55 +000010033 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
10034 NULL);
paul718e3742002-12-13 20:15:29 +000010035}
10036
10037DEFUN (show_ip_bgp_flap_statistics,
10038 show_ip_bgp_flap_statistics_cmd,
10039 "show ip bgp flap-statistics",
10040 SHOW_STR
10041 IP_STR
10042 BGP_STR
10043 "Display flap statistics of routes\n")
10044{
ajs5a646652004-11-05 01:25:55 +000010045 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10046 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000010047}
10048
10049/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000010050static int
paulfd79ac92004-10-13 05:06:08 +000010051bgp_clear_damp_route (struct vty *vty, const char *view_name,
10052 const char *ip_str, afi_t afi, safi_t safi,
10053 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000010054{
10055 int ret;
10056 struct prefix match;
10057 struct bgp_node *rn;
10058 struct bgp_node *rm;
10059 struct bgp_info *ri;
10060 struct bgp_info *ri_temp;
10061 struct bgp *bgp;
10062 struct bgp_table *table;
10063
10064 /* BGP structure lookup. */
10065 if (view_name)
10066 {
10067 bgp = bgp_lookup_by_name (view_name);
10068 if (bgp == NULL)
10069 {
10070 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10071 return CMD_WARNING;
10072 }
10073 }
10074 else
10075 {
10076 bgp = bgp_get_default ();
10077 if (bgp == NULL)
10078 {
10079 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
10080 return CMD_WARNING;
10081 }
10082 }
10083
10084 /* Check IP address argument. */
10085 ret = str2prefix (ip_str, &match);
10086 if (! ret)
10087 {
10088 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
10089 return CMD_WARNING;
10090 }
10091
10092 match.family = afi2family (afi);
10093
10094 if (safi == SAFI_MPLS_VPN)
10095 {
10096 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
10097 {
10098 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
10099 continue;
10100
10101 if ((table = rn->info) != NULL)
10102 if ((rm = bgp_node_match (table, &match)) != NULL)
10103 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
10104 {
10105 ri = rm->info;
10106 while (ri)
10107 {
10108 if (ri->damp_info)
10109 {
10110 ri_temp = ri->next;
10111 bgp_damp_info_free (ri->damp_info, 1);
10112 ri = ri_temp;
10113 }
10114 else
10115 ri = ri->next;
10116 }
10117 }
10118 }
10119 }
10120 else
10121 {
10122 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
10123 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
10124 {
10125 ri = rn->info;
10126 while (ri)
10127 {
10128 if (ri->damp_info)
10129 {
10130 ri_temp = ri->next;
10131 bgp_damp_info_free (ri->damp_info, 1);
10132 ri = ri_temp;
10133 }
10134 else
10135 ri = ri->next;
10136 }
10137 }
10138 }
10139
10140 return CMD_SUCCESS;
10141}
10142
10143DEFUN (clear_ip_bgp_dampening,
10144 clear_ip_bgp_dampening_cmd,
10145 "clear ip bgp dampening",
10146 CLEAR_STR
10147 IP_STR
10148 BGP_STR
10149 "Clear route flap dampening information\n")
10150{
10151 bgp_damp_info_clean ();
10152 return CMD_SUCCESS;
10153}
10154
10155DEFUN (clear_ip_bgp_dampening_prefix,
10156 clear_ip_bgp_dampening_prefix_cmd,
10157 "clear ip bgp dampening A.B.C.D/M",
10158 CLEAR_STR
10159 IP_STR
10160 BGP_STR
10161 "Clear route flap dampening information\n"
10162 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10163{
10164 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10165 SAFI_UNICAST, NULL, 1);
10166}
10167
10168DEFUN (clear_ip_bgp_dampening_address,
10169 clear_ip_bgp_dampening_address_cmd,
10170 "clear ip bgp dampening A.B.C.D",
10171 CLEAR_STR
10172 IP_STR
10173 BGP_STR
10174 "Clear route flap dampening information\n"
10175 "Network to clear damping information\n")
10176{
10177 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10178 SAFI_UNICAST, NULL, 0);
10179}
10180
10181DEFUN (clear_ip_bgp_dampening_address_mask,
10182 clear_ip_bgp_dampening_address_mask_cmd,
10183 "clear ip bgp dampening A.B.C.D A.B.C.D",
10184 CLEAR_STR
10185 IP_STR
10186 BGP_STR
10187 "Clear route flap dampening information\n"
10188 "Network to clear damping information\n"
10189 "Network mask\n")
10190{
10191 int ret;
10192 char prefix_str[BUFSIZ];
10193
10194 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
10195 if (! ret)
10196 {
10197 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
10198 return CMD_WARNING;
10199 }
10200
10201 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
10202 SAFI_UNICAST, NULL, 0);
10203}
10204
paul94f2b392005-06-28 12:44:16 +000010205static int
paul718e3742002-12-13 20:15:29 +000010206bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
10207 afi_t afi, safi_t safi, int *write)
10208{
10209 struct bgp_node *prn;
10210 struct bgp_node *rn;
10211 struct bgp_table *table;
10212 struct prefix *p;
10213 struct prefix_rd *prd;
10214 struct bgp_static *bgp_static;
10215 u_int32_t label;
10216 char buf[SU_ADDRSTRLEN];
10217 char rdbuf[RD_ADDRSTRLEN];
10218
10219 /* Network configuration. */
10220 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
10221 if ((table = prn->info) != NULL)
10222 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10223 if ((bgp_static = rn->info) != NULL)
10224 {
10225 p = &rn->p;
10226 prd = (struct prefix_rd *) &prn->p;
10227
10228 /* "address-family" display. */
10229 bgp_config_write_family_header (vty, afi, safi, write);
10230
10231 /* "network" configuration display. */
10232 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
10233 label = decode_label (bgp_static->tag);
10234
10235 vty_out (vty, " network %s/%d rd %s tag %d",
10236 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10237 p->prefixlen,
10238 rdbuf, label);
10239 vty_out (vty, "%s", VTY_NEWLINE);
10240 }
10241 return 0;
10242}
10243
10244/* Configuration of static route announcement and aggregate
10245 information. */
10246int
10247bgp_config_write_network (struct vty *vty, struct bgp *bgp,
10248 afi_t afi, safi_t safi, int *write)
10249{
10250 struct bgp_node *rn;
10251 struct prefix *p;
10252 struct bgp_static *bgp_static;
10253 struct bgp_aggregate *bgp_aggregate;
10254 char buf[SU_ADDRSTRLEN];
10255
10256 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
10257 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
10258
10259 /* Network configuration. */
10260 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
10261 if ((bgp_static = rn->info) != NULL)
10262 {
10263 p = &rn->p;
10264
10265 /* "address-family" display. */
10266 bgp_config_write_family_header (vty, afi, safi, write);
10267
10268 /* "network" configuration display. */
10269 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10270 {
10271 u_int32_t destination;
10272 struct in_addr netmask;
10273
10274 destination = ntohl (p->u.prefix4.s_addr);
10275 masklen2ip (p->prefixlen, &netmask);
10276 vty_out (vty, " network %s",
10277 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
10278
10279 if ((IN_CLASSC (destination) && p->prefixlen == 24)
10280 || (IN_CLASSB (destination) && p->prefixlen == 16)
10281 || (IN_CLASSA (destination) && p->prefixlen == 8)
10282 || p->u.prefix4.s_addr == 0)
10283 {
10284 /* Natural mask is not display. */
10285 }
10286 else
10287 vty_out (vty, " mask %s", inet_ntoa (netmask));
10288 }
10289 else
10290 {
10291 vty_out (vty, " network %s/%d",
10292 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10293 p->prefixlen);
10294 }
10295
10296 if (bgp_static->rmap.name)
10297 vty_out (vty, " route-map %s", bgp_static->rmap.name);
10298 else if (bgp_static->backdoor)
10299 vty_out (vty, " backdoor");
10300
10301 vty_out (vty, "%s", VTY_NEWLINE);
10302 }
10303
10304 /* Aggregate-address configuration. */
10305 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
10306 if ((bgp_aggregate = rn->info) != NULL)
10307 {
10308 p = &rn->p;
10309
10310 /* "address-family" display. */
10311 bgp_config_write_family_header (vty, afi, safi, write);
10312
10313 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10314 {
10315 struct in_addr netmask;
10316
10317 masklen2ip (p->prefixlen, &netmask);
10318 vty_out (vty, " aggregate-address %s %s",
10319 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10320 inet_ntoa (netmask));
10321 }
10322 else
10323 {
10324 vty_out (vty, " aggregate-address %s/%d",
10325 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10326 p->prefixlen);
10327 }
10328
10329 if (bgp_aggregate->as_set)
10330 vty_out (vty, " as-set");
10331
10332 if (bgp_aggregate->summary_only)
10333 vty_out (vty, " summary-only");
10334
10335 vty_out (vty, "%s", VTY_NEWLINE);
10336 }
10337
10338 return 0;
10339}
10340
10341int
10342bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
10343{
10344 struct bgp_node *rn;
10345 struct bgp_distance *bdistance;
10346
10347 /* Distance configuration. */
10348 if (bgp->distance_ebgp
10349 && bgp->distance_ibgp
10350 && bgp->distance_local
10351 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
10352 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
10353 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
10354 vty_out (vty, " distance bgp %d %d %d%s",
10355 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
10356 VTY_NEWLINE);
10357
10358 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10359 if ((bdistance = rn->info) != NULL)
10360 {
10361 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
10362 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
10363 bdistance->access_list ? bdistance->access_list : "",
10364 VTY_NEWLINE);
10365 }
10366
10367 return 0;
10368}
10369
10370/* Allocate routing table structure and install commands. */
10371void
10372bgp_route_init ()
10373{
10374 /* Init BGP distance table. */
10375 bgp_distance_table = bgp_table_init ();
10376
10377 /* IPv4 BGP commands. */
10378 install_element (BGP_NODE, &bgp_network_cmd);
10379 install_element (BGP_NODE, &bgp_network_mask_cmd);
10380 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
10381 install_element (BGP_NODE, &bgp_network_route_map_cmd);
10382 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
10383 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
10384 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
10385 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
10386 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
10387 install_element (BGP_NODE, &no_bgp_network_cmd);
10388 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
10389 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
10390 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
10391 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
10392 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10393 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
10394 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
10395 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
10396
10397 install_element (BGP_NODE, &aggregate_address_cmd);
10398 install_element (BGP_NODE, &aggregate_address_mask_cmd);
10399 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
10400 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
10401 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
10402 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
10403 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
10404 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
10405 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
10406 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
10407 install_element (BGP_NODE, &no_aggregate_address_cmd);
10408 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
10409 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
10410 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
10411 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
10412 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
10413 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
10414 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
10415 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10416 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10417
10418 /* IPv4 unicast configuration. */
10419 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
10420 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
10421 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
10422 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
10423 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
10424 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
10425 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
10426 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
10427 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
10428 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
10429 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
10430 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10431 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
10432 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
10433 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
10434 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
10435 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
10436 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
10437 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
10438 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
10439 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
10440 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
10441 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
10442 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
10443 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
10444 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
10445 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
10446 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
10447 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
10448 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
10449 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10450 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10451
10452 /* IPv4 multicast configuration. */
10453 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
10454 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
10455 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
10456 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
10457 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
10458 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
10459 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
10460 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
10461 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
10462 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
10463 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
10464 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10465 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
10466 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
10467 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
10468 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
10469 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
10470 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
10471 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
10472 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
10473 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
10474 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
10475 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
10476 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
10477 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
10478 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
10479 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
10480 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
10481 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
10482 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
10483 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10484 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10485
10486 install_element (VIEW_NODE, &show_ip_bgp_cmd);
10487 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
10488 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
10489 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
10490 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10491 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10492 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
10493 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10494 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10495 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10496 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
10497 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
10498 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
10499 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
10500 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10501 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
10502 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10503 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
10504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10505 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
10506 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10507 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
10508 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10509 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
10510 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10511 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
10512 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
10513 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
10514 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
10515 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
10516 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
10517 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
10518 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
10519 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
10520 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
10521 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
10522 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
10523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10524 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10526 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10527 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
10528 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10529 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
10530 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10531 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
10532 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10533 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10534 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10535 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10536 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10537 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
10538 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10539 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10540 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10541 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
10542 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
10543 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
10544 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
10545 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10546 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
10547 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
10548 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10549 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10550 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
10551 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
10552 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010553 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
10554 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
10555 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10556 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
10557 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10558 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010559
10560 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
10561 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
10562 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
10563 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
10564 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10565 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10566 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
10567 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10568 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10569 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10570 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
10571 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
10572 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
10573 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
10574 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10575 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
10576 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10577 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
10578 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10579 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
10580 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10581 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
10582 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10583 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
10584 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10585 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
10586 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
10587 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
10588 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
10589 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
10590 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
10591 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
10592 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
10593 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
10594 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
10595 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
10596 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
10597 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10598 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10599 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10600 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10601 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
10602 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10603 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
10604 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10605 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
10606 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10607 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10608 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10609 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10610 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10611 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
10612 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10613 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10614 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10615 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
10616 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
10617 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
10618 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
10619 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10620 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
10621 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
10622 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10623 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10624 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
10625 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
10626 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010627 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
10628 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
10629 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10630 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
10631 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10632 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010633
10634 /* BGP dampening clear commands */
10635 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
10636 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
10637 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
10638 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
10639
10640#ifdef HAVE_IPV6
10641 /* New config IPv6 BGP commands. */
10642 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
10643 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
10644 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
10645 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
10646
10647 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
10648 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
10649 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
10650 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
10651
10652 /* Old config IPv6 BGP commands. */
10653 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
10654 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
10655
10656 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
10657 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
10658 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
10659 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
10660
10661 install_element (VIEW_NODE, &show_bgp_cmd);
10662 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
10663 install_element (VIEW_NODE, &show_bgp_route_cmd);
10664 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
10665 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
10666 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
10667 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
10668 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
10669 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
10670 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
10671 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
10672 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
10673 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
10674 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
10675 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
10676 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
10677 install_element (VIEW_NODE, &show_bgp_community_cmd);
10678 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
10679 install_element (VIEW_NODE, &show_bgp_community2_cmd);
10680 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
10681 install_element (VIEW_NODE, &show_bgp_community3_cmd);
10682 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
10683 install_element (VIEW_NODE, &show_bgp_community4_cmd);
10684 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
10685 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
10686 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
10687 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
10688 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
10689 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
10690 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
10691 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
10692 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
10693 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
10694 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
10695 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
10696 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10697 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
10698 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10699 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
10700 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10701 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
10702 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10703 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
10704 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10705 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10706 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010707 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
10708 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10709 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
10710 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010711 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
10712 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
10713 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010714 install_element (VIEW_NODE, &show_bgp_view_cmd);
10715 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
10716 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
10717 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
10718 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
10719 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
10720 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10721 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10722 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10723 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10724 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
10725 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10726 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10727 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10728 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
10729 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10730 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
10731 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010732 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
10733 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
10734 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010735
10736 install_element (ENABLE_NODE, &show_bgp_cmd);
10737 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
10738 install_element (ENABLE_NODE, &show_bgp_route_cmd);
10739 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
10740 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
10741 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
10742 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
10743 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
10744 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
10745 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
10746 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
10747 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
10748 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
10749 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
10750 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
10751 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
10752 install_element (ENABLE_NODE, &show_bgp_community_cmd);
10753 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
10754 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
10755 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
10756 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
10757 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
10758 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
10759 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
10760 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
10761 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
10762 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
10763 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
10764 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
10765 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
10766 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
10767 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
10768 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
10769 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
10770 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
10771 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10772 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
10773 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10774 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
10775 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10776 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
10777 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10778 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
10779 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10780 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10781 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010782 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
10783 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10784 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
10785 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010786 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
10787 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
10788 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010789 install_element (ENABLE_NODE, &show_bgp_view_cmd);
10790 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
10791 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
10792 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
10793 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
10794 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
10795 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10796 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10797 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10798 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10799 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
10800 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10801 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10802 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10803 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
10804 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10805 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
10806 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010807 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
10808 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
10809 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010810
10811 /* old command */
10812 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
10813 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
10814 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
10815 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
10816 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
10817 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
10818 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
10819 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
10820 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
10821 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
10822 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
10823 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
10824 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
10825 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
10826 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
10827 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
10828 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10829 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10830 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
10831 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
10832 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
10833 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
10834 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10835 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
10836 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
10837 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
10838 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
10839 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
10840 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
10841 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
10842 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10843 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10844 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10845 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
10846 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10847 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000010848
paul718e3742002-12-13 20:15:29 +000010849 /* old command */
10850 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
10851 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
10852 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
10853 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
10854 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
10855 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
10856 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
10857 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
10858 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
10859 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
10860 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
10861 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
10862 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
10863 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
10864 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
10865 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
10866 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10867 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10868 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
10869 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
10870 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
10871 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
10872 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10873 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
10874 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
10875 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
10876 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
10877 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
10878 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
10879 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
10880 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10881 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10882 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10883 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
10884 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10885 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
10886
10887 /* old command */
10888 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10889 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10890 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10891 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10892
10893 /* old command */
10894 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10895 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10896 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10897 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10898
10899 /* old command */
10900 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
10901 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
10902 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10903 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10904#endif /* HAVE_IPV6 */
10905
10906 install_element (BGP_NODE, &bgp_distance_cmd);
10907 install_element (BGP_NODE, &no_bgp_distance_cmd);
10908 install_element (BGP_NODE, &no_bgp_distance2_cmd);
10909 install_element (BGP_NODE, &bgp_distance_source_cmd);
10910 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
10911 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
10912 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
10913
10914 install_element (BGP_NODE, &bgp_damp_set_cmd);
10915 install_element (BGP_NODE, &bgp_damp_set2_cmd);
10916 install_element (BGP_NODE, &bgp_damp_set3_cmd);
10917 install_element (BGP_NODE, &bgp_damp_unset_cmd);
10918 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
10919 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
10920 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
10921 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
10922 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
10923 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
10924}