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