blob: c464cd0488e36f7276239b6e738596540bd6e819 [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{
Paul Jakma1a392d42006-09-07 00:24:49 +0000190 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
191 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000192 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
193}
194
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000195/* undo the effects of a previous call to bgp_info_delete; typically
196 called when a route is deleted and then quickly re-added before the
197 deletion has been processed */
198static void
199bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
200{
201 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
202 /* unset of previous already took care of pcount */
203 SET_FLAG (ri->flags, BGP_INFO_VALID);
204}
205
Paul Jakma1a392d42006-09-07 00:24:49 +0000206/* Adjust pcount as required */
207static void
208bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
209{
Paul Jakma6f585442006-10-22 19:13:07 +0000210 assert (rn && rn->table);
211 assert (ri && ri->peer && ri->peer->bgp);
212
Paul Jakma1a392d42006-09-07 00:24:49 +0000213 /* Ignore 'pcount' for RS-client tables */
214 if (rn->table->type != BGP_TABLE_MAIN
215 || ri->peer == ri->peer->bgp->peer_self)
216 return;
217
218 if (BGP_INFO_HOLDDOWN (ri)
219 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
220 {
221
222 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
223
224 /* slight hack, but more robust against errors. */
225 if (ri->peer->pcount[rn->table->afi][rn->table->safi])
226 ri->peer->pcount[rn->table->afi][rn->table->safi]--;
227 else
228 {
229 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
230 __func__, ri->peer->host);
231 zlog_backtrace (LOG_WARNING);
232 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
233 }
234 }
235 else if (!BGP_INFO_HOLDDOWN (ri)
236 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
237 {
238 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
239 ri->peer->pcount[rn->table->afi][rn->table->safi]++;
240 }
241}
242
243
244/* Set/unset bgp_info flags, adjusting any other state as needed.
245 * This is here primarily to keep prefix-count in check.
246 */
247void
248bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
249{
250 SET_FLAG (ri->flags, flag);
251
252 /* early bath if we know it's not a flag that changes useability state */
253 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
254 return;
255
256 bgp_pcount_adjust (rn, ri);
257}
258
259void
260bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
261{
262 UNSET_FLAG (ri->flags, flag);
263
264 /* early bath if we know it's not a flag that changes useability state */
265 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
266 return;
267
268 bgp_pcount_adjust (rn, ri);
269}
270
paul718e3742002-12-13 20:15:29 +0000271/* Get MED value. If MED value is missing and "bgp bestpath
272 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000273static u_int32_t
paul718e3742002-12-13 20:15:29 +0000274bgp_med_value (struct attr *attr, struct bgp *bgp)
275{
276 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
277 return attr->med;
278 else
279 {
280 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000281 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000282 else
283 return 0;
284 }
285}
286
287/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000288static int
paul718e3742002-12-13 20:15:29 +0000289bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
290{
291 u_int32_t new_pref;
292 u_int32_t exist_pref;
293 u_int32_t new_med;
294 u_int32_t exist_med;
295 struct in_addr new_id;
296 struct in_addr exist_id;
297 int new_cluster;
298 int exist_cluster;
299 int internal_as_route = 0;
300 int confed_as_route = 0;
301 int ret;
302
303 /* 0. Null check. */
304 if (new == NULL)
305 return 0;
306 if (exist == NULL)
307 return 1;
308
309 /* 1. Weight check. */
310 if (new->attr->weight > exist->attr->weight)
311 return 1;
312 if (new->attr->weight < exist->attr->weight)
313 return 0;
314
315 /* 2. Local preference check. */
316 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
317 new_pref = new->attr->local_pref;
318 else
319 new_pref = bgp->default_local_pref;
320
321 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
322 exist_pref = exist->attr->local_pref;
323 else
324 exist_pref = bgp->default_local_pref;
325
326 if (new_pref > exist_pref)
327 return 1;
328 if (new_pref < exist_pref)
329 return 0;
330
331 /* 3. Local route check. */
332 if (new->sub_type == BGP_ROUTE_STATIC)
333 return 1;
334 if (exist->sub_type == BGP_ROUTE_STATIC)
335 return 0;
336
337 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
338 return 1;
339 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
340 return 0;
341
342 if (new->sub_type == BGP_ROUTE_AGGREGATE)
343 return 1;
344 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
345 return 0;
346
347 /* 4. AS path length check. */
348 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
349 {
paulfe69a502005-09-10 16:55:02 +0000350 int exist_hops = aspath_count_hops (exist->attr->aspath);
351 int exist_confeds = aspath_count_confeds (exist->attr->aspath);
352
hasso68118452005-04-08 15:40:36 +0000353 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
354 {
paulfe69a502005-09-10 16:55:02 +0000355 int aspath_hops;
356
357 aspath_hops = aspath_count_hops (new->attr->aspath);
358 aspath_hops += aspath_count_confeds (new->attr->aspath);
359
360 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000361 return 1;
paulfe69a502005-09-10 16:55:02 +0000362 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000363 return 0;
364 }
365 else
366 {
paulfe69a502005-09-10 16:55:02 +0000367 int newhops = aspath_count_hops (new->attr->aspath);
368
369 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000370 return 1;
paulfe69a502005-09-10 16:55:02 +0000371 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000372 return 0;
373 }
paul718e3742002-12-13 20:15:29 +0000374 }
375
376 /* 5. Origin check. */
377 if (new->attr->origin < exist->attr->origin)
378 return 1;
379 if (new->attr->origin > exist->attr->origin)
380 return 0;
381
382 /* 6. MED check. */
paulfe69a502005-09-10 16:55:02 +0000383 internal_as_route = (aspath_count_hops (new->attr->aspath) == 0
384 && aspath_count_hops (exist->attr->aspath) == 0);
385 confed_as_route = (aspath_count_confeds (new->attr->aspath) > 0
386 && aspath_count_confeds (exist->attr->aspath) > 0
387 && aspath_count_hops (new->attr->aspath) == 0
388 && aspath_count_hops (exist->attr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000389
390 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
391 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
392 && confed_as_route)
393 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
394 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
395 || internal_as_route)
396 {
397 new_med = bgp_med_value (new->attr, bgp);
398 exist_med = bgp_med_value (exist->attr, bgp);
399
400 if (new_med < exist_med)
401 return 1;
402 if (new_med > exist_med)
403 return 0;
404 }
405
406 /* 7. Peer type check. */
407 if (peer_sort (new->peer) == BGP_PEER_EBGP
408 && peer_sort (exist->peer) == BGP_PEER_IBGP)
409 return 1;
410 if (peer_sort (new->peer) == BGP_PEER_EBGP
411 && peer_sort (exist->peer) == BGP_PEER_CONFED)
412 return 1;
413 if (peer_sort (new->peer) == BGP_PEER_IBGP
414 && peer_sort (exist->peer) == BGP_PEER_EBGP)
415 return 0;
416 if (peer_sort (new->peer) == BGP_PEER_CONFED
417 && peer_sort (exist->peer) == BGP_PEER_EBGP)
418 return 0;
419
420 /* 8. IGP metric check. */
421 if (new->igpmetric < exist->igpmetric)
422 return 1;
423 if (new->igpmetric > exist->igpmetric)
424 return 0;
425
426 /* 9. Maximum path check. */
427
428 /* 10. If both paths are external, prefer the path that was received
429 first (the oldest one). This step minimizes route-flap, since a
430 newer path won't displace an older one, even if it was the
431 preferred route based on the additional decision criteria below. */
432 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
433 && peer_sort (new->peer) == BGP_PEER_EBGP
434 && peer_sort (exist->peer) == BGP_PEER_EBGP)
435 {
436 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
437 return 1;
438 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
439 return 0;
440 }
441
442 /* 11. Rourter-ID comparision. */
443 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
444 new_id.s_addr = new->attr->originator_id.s_addr;
445 else
446 new_id.s_addr = new->peer->remote_id.s_addr;
447 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
448 exist_id.s_addr = exist->attr->originator_id.s_addr;
449 else
450 exist_id.s_addr = exist->peer->remote_id.s_addr;
451
452 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
453 return 1;
454 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
455 return 0;
456
457 /* 12. Cluster length comparision. */
458 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
459 new_cluster = new->attr->cluster->length;
460 else
461 new_cluster = 0;
462 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
463 exist_cluster = exist->attr->cluster->length;
464 else
465 exist_cluster = 0;
466
467 if (new_cluster < exist_cluster)
468 return 1;
469 if (new_cluster > exist_cluster)
470 return 0;
471
472 /* 13. Neighbor address comparision. */
473 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
474
475 if (ret == 1)
476 return 0;
477 if (ret == -1)
478 return 1;
479
480 return 1;
481}
482
paul94f2b392005-06-28 12:44:16 +0000483static enum filter_type
paul718e3742002-12-13 20:15:29 +0000484bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
485 afi_t afi, safi_t safi)
486{
487 struct bgp_filter *filter;
488
489 filter = &peer->filter[afi][safi];
490
491 if (DISTRIBUTE_IN_NAME (filter))
492 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
493 return FILTER_DENY;
494
495 if (PREFIX_LIST_IN_NAME (filter))
496 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
497 return FILTER_DENY;
498
499 if (FILTER_LIST_IN_NAME (filter))
500 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
501 return FILTER_DENY;
502
503 return FILTER_PERMIT;
504}
505
paul94f2b392005-06-28 12:44:16 +0000506static enum filter_type
paul718e3742002-12-13 20:15:29 +0000507bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
508 afi_t afi, safi_t safi)
509{
510 struct bgp_filter *filter;
511
512 filter = &peer->filter[afi][safi];
513
514 if (DISTRIBUTE_OUT_NAME (filter))
515 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
516 return FILTER_DENY;
517
518 if (PREFIX_LIST_OUT_NAME (filter))
519 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
520 return FILTER_DENY;
521
522 if (FILTER_LIST_OUT_NAME (filter))
523 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
524 return FILTER_DENY;
525
526 return FILTER_PERMIT;
527}
528
529/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000530static int
paul718e3742002-12-13 20:15:29 +0000531bgp_community_filter (struct peer *peer, struct attr *attr)
532{
533 if (attr->community)
534 {
535 /* NO_ADVERTISE check. */
536 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
537 return 1;
538
539 /* NO_EXPORT check. */
540 if (peer_sort (peer) == BGP_PEER_EBGP &&
541 community_include (attr->community, COMMUNITY_NO_EXPORT))
542 return 1;
543
544 /* NO_EXPORT_SUBCONFED check. */
545 if (peer_sort (peer) == BGP_PEER_EBGP
546 || peer_sort (peer) == BGP_PEER_CONFED)
547 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
548 return 1;
549 }
550 return 0;
551}
552
553/* Route reflection loop check. */
554static int
555bgp_cluster_filter (struct peer *peer, struct attr *attr)
556{
557 struct in_addr cluster_id;
558
559 if (attr->cluster)
560 {
561 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
562 cluster_id = peer->bgp->cluster_id;
563 else
564 cluster_id = peer->bgp->router_id;
565
566 if (cluster_loop_check (attr->cluster, cluster_id))
567 return 1;
568 }
569 return 0;
570}
571
paul94f2b392005-06-28 12:44:16 +0000572static int
paul718e3742002-12-13 20:15:29 +0000573bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
574 afi_t afi, safi_t safi)
575{
576 struct bgp_filter *filter;
577 struct bgp_info info;
578 route_map_result_t ret;
579
580 filter = &peer->filter[afi][safi];
581
582 /* Apply default weight value. */
583 attr->weight = peer->weight;
584
585 /* Route map apply. */
586 if (ROUTE_MAP_IN_NAME (filter))
587 {
588 /* Duplicate current value to new strucutre for modification. */
589 info.peer = peer;
590 info.attr = attr;
591
paulac41b2a2003-08-12 05:32:27 +0000592 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
593
paul718e3742002-12-13 20:15:29 +0000594 /* Apply BGP route map to the attribute. */
595 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000596
597 peer->rmap_type = 0;
598
paul718e3742002-12-13 20:15:29 +0000599 if (ret == RMAP_DENYMATCH)
600 {
601 /* Free newly generated AS path and community by route-map. */
602 bgp_attr_flush (attr);
603 return RMAP_DENY;
604 }
605 }
606 return RMAP_PERMIT;
607}
608
paul94f2b392005-06-28 12:44:16 +0000609static int
paulfee0f4c2004-09-13 05:12:46 +0000610bgp_export_modifier (struct peer *rsclient, struct peer *peer,
611 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
612{
613 struct bgp_filter *filter;
614 struct bgp_info info;
615 route_map_result_t ret;
616
617 filter = &peer->filter[afi][safi];
618
619 /* Route map apply. */
620 if (ROUTE_MAP_EXPORT_NAME (filter))
621 {
622 /* Duplicate current value to new strucutre for modification. */
623 info.peer = rsclient;
624 info.attr = attr;
625
626 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
627
628 /* Apply BGP route map to the attribute. */
629 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
630
631 rsclient->rmap_type = 0;
632
633 if (ret == RMAP_DENYMATCH)
634 {
635 /* Free newly generated AS path and community by route-map. */
636 bgp_attr_flush (attr);
637 return RMAP_DENY;
638 }
639 }
640 return RMAP_PERMIT;
641}
642
paul94f2b392005-06-28 12:44:16 +0000643static int
paulfee0f4c2004-09-13 05:12:46 +0000644bgp_import_modifier (struct peer *rsclient, struct peer *peer,
645 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
646{
647 struct bgp_filter *filter;
648 struct bgp_info info;
649 route_map_result_t ret;
650
651 filter = &rsclient->filter[afi][safi];
652
653 /* Apply default weight value. */
654 attr->weight = peer->weight;
655
656 /* Route map apply. */
657 if (ROUTE_MAP_IMPORT_NAME (filter))
658 {
659 /* Duplicate current value to new strucutre for modification. */
660 info.peer = peer;
661 info.attr = attr;
662
663 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
664
665 /* Apply BGP route map to the attribute. */
666 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
667
668 peer->rmap_type = 0;
669
670 if (ret == RMAP_DENYMATCH)
671 {
672 /* Free newly generated AS path and community by route-map. */
673 bgp_attr_flush (attr);
674 return RMAP_DENY;
675 }
676 }
677 return RMAP_PERMIT;
678}
679
paul94f2b392005-06-28 12:44:16 +0000680static int
paul718e3742002-12-13 20:15:29 +0000681bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
682 struct attr *attr, afi_t afi, safi_t safi)
683{
684 int ret;
685 char buf[SU_ADDRSTRLEN];
686 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000687 struct peer *from;
688 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000689 int transparent;
690 int reflect;
691
692 from = ri->peer;
693 filter = &peer->filter[afi][safi];
694 bgp = peer->bgp;
695
696#ifdef DISABLE_BGP_ANNOUNCE
697 return 0;
698#endif
699
paulfee0f4c2004-09-13 05:12:46 +0000700 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
701 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
702 return 0;
703
paul718e3742002-12-13 20:15:29 +0000704 /* Do not send back route to sender. */
705 if (from == peer)
706 return 0;
707
paul35be31b2004-05-01 18:17:04 +0000708 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
709 if (p->family == AF_INET
710 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
711 return 0;
712#ifdef HAVE_IPV6
713 if (p->family == AF_INET6
714 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
715 return 0;
716#endif
717
paul718e3742002-12-13 20:15:29 +0000718 /* Aggregate-address suppress check. */
719 if (ri->suppress)
720 if (! UNSUPPRESS_MAP_NAME (filter))
721 return 0;
722
723 /* Default route check. */
724 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
725 {
726 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
727 return 0;
728#ifdef HAVE_IPV6
729 else if (p->family == AF_INET6 && p->prefixlen == 0)
730 return 0;
731#endif /* HAVE_IPV6 */
732 }
733
paul286e1e72003-08-08 00:24:31 +0000734 /* Transparency check. */
735 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
736 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
737 transparent = 1;
738 else
739 transparent = 0;
740
paul718e3742002-12-13 20:15:29 +0000741 /* If community is not disabled check the no-export and local. */
paul286e1e72003-08-08 00:24:31 +0000742 if (! transparent && bgp_community_filter (peer, ri->attr))
paul718e3742002-12-13 20:15:29 +0000743 return 0;
744
745 /* If the attribute has originator-id and it is same as remote
746 peer's id. */
747 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
748 {
749 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->originator_id))
750 {
751 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000752 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000753 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
754 peer->host,
755 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
756 p->prefixlen);
757 return 0;
758 }
759 }
760
761 /* ORF prefix-list filter check */
762 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
763 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
764 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
765 if (peer->orf_plist[afi][safi])
766 {
767 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
768 return 0;
769 }
770
771 /* Output filter check. */
772 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
773 {
774 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000775 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000776 "%s [Update:SEND] %s/%d is filtered",
777 peer->host,
778 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
779 p->prefixlen);
780 return 0;
781 }
782
783#ifdef BGP_SEND_ASPATH_CHECK
784 /* AS path loop check. */
785 if (aspath_loop_check (ri->attr->aspath, peer->as))
786 {
787 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000788 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000789 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
790 peer->host, peer->as);
791 return 0;
792 }
793#endif /* BGP_SEND_ASPATH_CHECK */
794
795 /* If we're a CONFED we need to loop check the CONFED ID too */
796 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
797 {
798 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
799 {
800 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000801 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000802 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
803 peer->host,
804 bgp->confed_id);
805 return 0;
806 }
807 }
808
809 /* Route-Reflect check. */
810 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
811 reflect = 1;
812 else
813 reflect = 0;
814
815 /* IBGP reflection check. */
816 if (reflect)
817 {
818 /* A route from a Client peer. */
819 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
820 {
821 /* Reflect to all the Non-Client peers and also to the
822 Client peers other than the originator. Originator check
823 is already done. So there is noting to do. */
824 /* no bgp client-to-client reflection check. */
825 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
826 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
827 return 0;
828 }
829 else
830 {
831 /* A route from a Non-client peer. Reflect to all other
832 clients. */
833 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
834 return 0;
835 }
836 }
837
838 /* For modify attribute, copy it to temporary structure. */
839 *attr = *ri->attr;
840
841 /* If local-preference is not set. */
842 if ((peer_sort (peer) == BGP_PEER_IBGP
843 || peer_sort (peer) == BGP_PEER_CONFED)
844 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
845 {
846 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
847 attr->local_pref = bgp->default_local_pref;
848 }
849
paul718e3742002-12-13 20:15:29 +0000850 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
851 if (peer_sort (peer) == BGP_PEER_EBGP
852 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
853 {
854 if (ri->peer != bgp->peer_self && ! transparent
855 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
856 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
857 }
858
859 /* next-hop-set */
860 if (transparent || reflect
861 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
862 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000863#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000864 || (p->family == AF_INET6 &&
865 ! IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000866#endif /* HAVE_IPV6 */
867 )))
paul718e3742002-12-13 20:15:29 +0000868 {
869 /* NEXT-HOP Unchanged. */
870 }
871 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
872 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
873#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000874 || (p->family == AF_INET6 &&
875 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000876#endif /* HAVE_IPV6 */
877 || (peer_sort (peer) == BGP_PEER_EBGP
878 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
879 {
880 /* Set IPv4 nexthop. */
881 if (p->family == AF_INET)
882 {
883 if (safi == SAFI_MPLS_VPN)
884 memcpy (&attr->mp_nexthop_global_in, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
885 else
886 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
887 }
888#ifdef HAVE_IPV6
889 /* Set IPv6 nexthop. */
890 if (p->family == AF_INET6)
891 {
892 /* IPv6 global nexthop must be included. */
893 memcpy (&attr->mp_nexthop_global, &peer->nexthop.v6_global,
894 IPV6_MAX_BYTELEN);
895 attr->mp_nexthop_len = 16;
896 }
897#endif /* HAVE_IPV6 */
898 }
899
900#ifdef HAVE_IPV6
901 if (p->family == AF_INET6)
902 {
paulfee0f4c2004-09-13 05:12:46 +0000903 /* Left nexthop_local unchanged if so configured. */
904 if ( CHECK_FLAG (peer->af_flags[afi][safi],
905 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
906 {
907 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
908 attr->mp_nexthop_len=32;
909 else
910 attr->mp_nexthop_len=16;
911 }
912
913 /* Default nexthop_local treatment for non-RS-Clients */
914 else
915 {
paul718e3742002-12-13 20:15:29 +0000916 /* Link-local address should not be transit to different peer. */
917 attr->mp_nexthop_len = 16;
918
919 /* Set link-local address for shared network peer. */
920 if (peer->shared_network
921 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
922 {
923 memcpy (&attr->mp_nexthop_local, &peer->nexthop.v6_local,
924 IPV6_MAX_BYTELEN);
925 attr->mp_nexthop_len = 32;
926 }
927
928 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
929 address.*/
930 if (reflect)
931 attr->mp_nexthop_len = 16;
932
933 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
934 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
935 attr->mp_nexthop_len = 16;
936 }
paulfee0f4c2004-09-13 05:12:46 +0000937
938 }
paul718e3742002-12-13 20:15:29 +0000939#endif /* HAVE_IPV6 */
940
941 /* If this is EBGP peer and remove-private-AS is set. */
942 if (peer_sort (peer) == BGP_PEER_EBGP
943 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
944 && aspath_private_as_check (attr->aspath))
945 attr->aspath = aspath_empty_get ();
946
947 /* Route map & unsuppress-map apply. */
948 if (ROUTE_MAP_OUT_NAME (filter)
949 || ri->suppress)
950 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +0000951 struct bgp_info info;
952 struct attr dummy_attr;
953
paul718e3742002-12-13 20:15:29 +0000954 info.peer = peer;
955 info.attr = attr;
956
957 /* The route reflector is not allowed to modify the attributes
958 of the reflected IBGP routes. */
959 if (peer_sort (from) == BGP_PEER_IBGP
960 && peer_sort (peer) == BGP_PEER_IBGP)
961 {
962 dummy_attr = *attr;
963 info.attr = &dummy_attr;
964 }
paulac41b2a2003-08-12 05:32:27 +0000965
966 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
967
paul718e3742002-12-13 20:15:29 +0000968 if (ri->suppress)
969 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
970 else
971 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
972
paulac41b2a2003-08-12 05:32:27 +0000973 peer->rmap_type = 0;
974
paul718e3742002-12-13 20:15:29 +0000975 if (ret == RMAP_DENYMATCH)
976 {
977 bgp_attr_flush (attr);
978 return 0;
979 }
980 }
981 return 1;
982}
983
paul94f2b392005-06-28 12:44:16 +0000984static int
paulfee0f4c2004-09-13 05:12:46 +0000985bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
986 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000987{
paulfee0f4c2004-09-13 05:12:46 +0000988 int ret;
989 char buf[SU_ADDRSTRLEN];
990 struct bgp_filter *filter;
991 struct bgp_info info;
992 struct peer *from;
993 struct bgp *bgp;
994
995 from = ri->peer;
996 filter = &rsclient->filter[afi][safi];
997 bgp = rsclient->bgp;
998
999#ifdef DISABLE_BGP_ANNOUNCE
1000 return 0;
1001#endif
1002
1003 /* Do not send back route to sender. */
1004 if (from == rsclient)
1005 return 0;
1006
1007 /* Aggregate-address suppress check. */
1008 if (ri->suppress)
1009 if (! UNSUPPRESS_MAP_NAME (filter))
1010 return 0;
1011
1012 /* Default route check. */
1013 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1014 PEER_STATUS_DEFAULT_ORIGINATE))
1015 {
1016 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1017 return 0;
1018#ifdef HAVE_IPV6
1019 else if (p->family == AF_INET6 && p->prefixlen == 0)
1020 return 0;
1021#endif /* HAVE_IPV6 */
1022 }
1023
1024 /* If the attribute has originator-id and it is same as remote
1025 peer's id. */
1026 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1027 {
1028 if (IPV4_ADDR_SAME (&rsclient->remote_id, &ri->attr->originator_id))
1029 {
1030 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001031 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001032 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1033 rsclient->host,
1034 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1035 p->prefixlen);
1036 return 0;
1037 }
1038 }
1039
1040 /* ORF prefix-list filter check */
1041 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1042 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1043 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1044 if (rsclient->orf_plist[afi][safi])
1045 {
1046 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1047 return 0;
1048 }
1049
1050 /* Output filter check. */
1051 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1052 {
1053 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001054 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001055 "%s [Update:SEND] %s/%d is filtered",
1056 rsclient->host,
1057 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1058 p->prefixlen);
1059 return 0;
1060 }
1061
1062#ifdef BGP_SEND_ASPATH_CHECK
1063 /* AS path loop check. */
1064 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1065 {
1066 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001067 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001068 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
1069 rsclient->host, rsclient->as);
1070 return 0;
1071 }
1072#endif /* BGP_SEND_ASPATH_CHECK */
1073
1074 /* For modify attribute, copy it to temporary structure. */
1075 *attr = *ri->attr;
1076
1077 /* next-hop-set */
1078 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1079#ifdef HAVE_IPV6
1080 || (p->family == AF_INET6 &&
1081 IN6_IS_ADDR_UNSPECIFIED(&attr->mp_nexthop_global))
1082#endif /* HAVE_IPV6 */
1083 )
1084 {
1085 /* Set IPv4 nexthop. */
1086 if (p->family == AF_INET)
1087 {
1088 if (safi == SAFI_MPLS_VPN)
1089 memcpy (&attr->mp_nexthop_global_in, &rsclient->nexthop.v4,
1090 IPV4_MAX_BYTELEN);
1091 else
1092 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1093 }
1094#ifdef HAVE_IPV6
1095 /* Set IPv6 nexthop. */
1096 if (p->family == AF_INET6)
1097 {
1098 /* IPv6 global nexthop must be included. */
1099 memcpy (&attr->mp_nexthop_global, &rsclient->nexthop.v6_global,
1100
1101 IPV6_MAX_BYTELEN);
1102 attr->mp_nexthop_len = 16;
1103 }
1104#endif /* HAVE_IPV6 */
1105 }
1106
1107#ifdef HAVE_IPV6
1108 if (p->family == AF_INET6)
1109 {
1110 /* Left nexthop_local unchanged if so configured. */
1111 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1112 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1113 {
1114 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1115 attr->mp_nexthop_len=32;
1116 else
1117 attr->mp_nexthop_len=16;
1118 }
1119
1120 /* Default nexthop_local treatment for RS-Clients */
1121 else
1122 {
1123 /* Announcer and RS-Client are both in the same network */
1124 if (rsclient->shared_network && from->shared_network &&
1125 (rsclient->ifindex == from->ifindex))
1126 {
1127 if ( IN6_IS_ADDR_LINKLOCAL (&attr->mp_nexthop_local) )
1128 attr->mp_nexthop_len=32;
1129 else
1130 attr->mp_nexthop_len=16;
1131 }
1132
1133 /* Set link-local address for shared network peer. */
1134 else if (rsclient->shared_network
1135 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1136 {
1137 memcpy (&attr->mp_nexthop_local, &rsclient->nexthop.v6_local,
1138 IPV6_MAX_BYTELEN);
1139 attr->mp_nexthop_len = 32;
1140 }
1141
1142 else
1143 attr->mp_nexthop_len = 16;
1144 }
1145
1146 }
1147#endif /* HAVE_IPV6 */
1148
1149
1150 /* If this is EBGP peer and remove-private-AS is set. */
1151 if (peer_sort (rsclient) == BGP_PEER_EBGP
1152 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1153 && aspath_private_as_check (attr->aspath))
1154 attr->aspath = aspath_empty_get ();
1155
1156 /* Route map & unsuppress-map apply. */
1157 if (ROUTE_MAP_OUT_NAME (filter) || ri->suppress)
1158 {
1159 info.peer = rsclient;
1160 info.attr = attr;
1161
1162 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1163
1164 if (ri->suppress)
1165 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1166 else
1167 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1168
1169 rsclient->rmap_type = 0;
1170
1171 if (ret == RMAP_DENYMATCH)
1172 {
1173 bgp_attr_flush (attr);
1174 return 0;
1175 }
1176 }
1177
1178 return 1;
1179}
1180
1181struct bgp_info_pair
1182{
1183 struct bgp_info *old;
1184 struct bgp_info *new;
1185};
1186
paul94f2b392005-06-28 12:44:16 +00001187static void
paulfee0f4c2004-09-13 05:12:46 +00001188bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1189{
paul718e3742002-12-13 20:15:29 +00001190 struct bgp_info *new_select;
1191 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001192 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001193 struct bgp_info *ri1;
1194 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001195 struct bgp_info *nextri = NULL;
1196
paul718e3742002-12-13 20:15:29 +00001197 /* bgp deterministic-med */
1198 new_select = NULL;
1199 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1200 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1201 {
1202 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1203 continue;
1204 if (BGP_INFO_HOLDDOWN (ri1))
1205 continue;
1206
1207 new_select = ri1;
1208 if (ri1->next)
1209 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1210 {
1211 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1212 continue;
1213 if (BGP_INFO_HOLDDOWN (ri2))
1214 continue;
1215
1216 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1217 || aspath_cmp_left_confed (ri1->attr->aspath,
1218 ri2->attr->aspath))
1219 {
1220 if (bgp_info_cmp (bgp, ri2, new_select))
1221 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001222 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001223 new_select = ri2;
1224 }
1225
Paul Jakma1a392d42006-09-07 00:24:49 +00001226 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001227 }
1228 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001229 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1230 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001231 }
1232
1233 /* Check old selected route and new selected route. */
1234 old_select = NULL;
1235 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001236 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001237 {
1238 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1239 old_select = ri;
1240
1241 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001242 {
1243 /* reap REMOVED routes, if needs be
1244 * selected route must stay for a while longer though
1245 */
1246 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1247 && (ri != old_select))
1248 bgp_info_reap (rn, ri);
1249
1250 continue;
1251 }
paul718e3742002-12-13 20:15:29 +00001252
1253 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1254 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1255 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001256 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001257 continue;
1258 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001259 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1260 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001261
1262 if (bgp_info_cmp (bgp, ri, new_select))
1263 new_select = ri;
1264 }
paulb40d9392005-08-22 22:34:41 +00001265
paulfee0f4c2004-09-13 05:12:46 +00001266 result->old = old_select;
1267 result->new = new_select;
1268
1269 return;
1270}
1271
paul94f2b392005-06-28 12:44:16 +00001272static int
paulfee0f4c2004-09-13 05:12:46 +00001273bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1274 struct bgp_node *rn, struct attr *attr, afi_t afi, safi_t safi)
1275 {
1276 struct prefix *p;
1277
1278 p = &rn->p;
1279
1280 /* Announce route to Established peer. */
1281 if (peer->status != Established)
1282 return 0;
1283
1284 /* Address family configuration check. */
1285 if (! peer->afc_nego[afi][safi])
1286 return 0;
1287
1288 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1289 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1290 PEER_STATUS_ORF_WAIT_REFRESH))
1291 return 0;
1292
1293 switch (rn->table->type)
1294 {
1295 case BGP_TABLE_MAIN:
1296 /* Announcement to peer->conf. If the route is filtered,
1297 withdraw it. */
1298 if (selected && bgp_announce_check (selected, peer, p, attr, afi, safi))
1299 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1300 else
1301 bgp_adj_out_unset (rn, peer, p, afi, safi);
1302 break;
1303 case BGP_TABLE_RSCLIENT:
1304 /* Announcement to peer->conf. If the route is filtered,
1305 withdraw it. */
1306 if (selected && bgp_announce_check_rsclient
1307 (selected, peer, p, attr, afi, safi))
1308 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1309 else
1310 bgp_adj_out_unset (rn, peer, p, afi, safi);
1311 break;
1312 }
1313 return 0;
paul200df112005-06-01 11:17:05 +00001314}
paulfee0f4c2004-09-13 05:12:46 +00001315
paul200df112005-06-01 11:17:05 +00001316struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001317{
paul200df112005-06-01 11:17:05 +00001318 struct bgp *bgp;
1319 struct bgp_node *rn;
1320 afi_t afi;
1321 safi_t safi;
1322};
1323
1324static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001325bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001326{
paul0fb58d52005-11-14 14:31:49 +00001327 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001328 struct bgp *bgp = pq->bgp;
1329 struct bgp_node *rn = pq->rn;
1330 afi_t afi = pq->afi;
1331 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001332 struct bgp_info *new_select;
1333 struct bgp_info *old_select;
1334 struct bgp_info_pair old_and_new;
1335 struct attr attr;
paul1eb8ef22005-04-07 07:30:20 +00001336 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001337 struct peer *rsclient = rn->table->owner;
1338
paulfee0f4c2004-09-13 05:12:46 +00001339 /* Best path selection. */
1340 bgp_best_selection (bgp, rn, &old_and_new);
1341 new_select = old_and_new.new;
1342 old_select = old_and_new.old;
1343
paul200df112005-06-01 11:17:05 +00001344 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1345 {
1346 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1347 {
1348 /* Nothing to do. */
1349 if (old_select && old_select == new_select)
1350 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1351 continue;
paulfee0f4c2004-09-13 05:12:46 +00001352
paul200df112005-06-01 11:17:05 +00001353 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001354 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
paul200df112005-06-01 11:17:05 +00001355 if (new_select)
1356 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001357 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1358 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
paul200df112005-06-01 11:17:05 +00001359 }
paulfee0f4c2004-09-13 05:12:46 +00001360
paul200df112005-06-01 11:17:05 +00001361 bgp_process_announce_selected (rsclient, new_select, rn, &attr,
1362 afi, safi);
1363 }
1364 }
1365 else
1366 {
hassob7395792005-08-26 12:58:38 +00001367 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001368 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001369 if (new_select)
1370 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001371 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1372 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hassob7395792005-08-26 12:58:38 +00001373 }
paul200df112005-06-01 11:17:05 +00001374 bgp_process_announce_selected (rsclient, new_select, rn,
1375 &attr, afi, safi);
1376 }
paulfee0f4c2004-09-13 05:12:46 +00001377
paulb40d9392005-08-22 22:34:41 +00001378 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;
paulfee0f4c2004-09-13 05:12:46 +00001383}
1384
paul200df112005-06-01 11:17:05 +00001385static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001386bgp_process_main (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;
paul200df112005-06-01 11:17:05 +00001389 struct bgp *bgp = pq->bgp;
1390 struct bgp_node *rn = pq->rn;
1391 afi_t afi = pq->afi;
1392 safi_t safi = pq->safi;
1393 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001394 struct bgp_info *new_select;
1395 struct bgp_info *old_select;
1396 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001397 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001398 struct peer *peer;
1399 struct attr attr;
paul200df112005-06-01 11:17:05 +00001400
paulfee0f4c2004-09-13 05:12:46 +00001401 /* Best path selection. */
1402 bgp_best_selection (bgp, rn, &old_and_new);
1403 old_select = old_and_new.old;
1404 new_select = old_and_new.new;
1405
1406 /* Nothing to do. */
1407 if (old_select && old_select == new_select)
1408 {
1409 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001410 {
1411 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1412 bgp_zebra_announce (p, old_select, bgp);
1413
1414 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1415 return WQ_SUCCESS;
1416 }
paulfee0f4c2004-09-13 05:12:46 +00001417 }
paul718e3742002-12-13 20:15:29 +00001418
hasso338b3422005-02-23 14:27:24 +00001419 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001420 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001421 if (new_select)
1422 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001423 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1424 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hasso338b3422005-02-23 14:27:24 +00001425 }
1426
1427
paul718e3742002-12-13 20:15:29 +00001428 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001429 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001430 {
paulfee0f4c2004-09-13 05:12:46 +00001431 bgp_process_announce_selected (peer, new_select, rn, &attr, afi, safi);
paul718e3742002-12-13 20:15:29 +00001432 }
1433
1434 /* FIB update. */
1435 if (safi == SAFI_UNICAST && ! bgp->name &&
1436 ! bgp_option_check (BGP_OPT_NO_FIB))
1437 {
1438 if (new_select
1439 && new_select->type == ZEBRA_ROUTE_BGP
1440 && new_select->sub_type == BGP_ROUTE_NORMAL)
1441 bgp_zebra_announce (p, new_select, bgp);
1442 else
1443 {
1444 /* Withdraw the route from the kernel. */
1445 if (old_select
1446 && old_select->type == ZEBRA_ROUTE_BGP
1447 && old_select->sub_type == BGP_ROUTE_NORMAL)
1448 bgp_zebra_withdraw (p, old_select);
1449 }
1450 }
paulb40d9392005-08-22 22:34:41 +00001451
1452 /* Reap old select bgp_info, it it has been removed */
1453 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1454 bgp_info_reap (rn, old_select);
1455
paul200df112005-06-01 11:17:05 +00001456 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1457 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001458}
1459
paul200df112005-06-01 11:17:05 +00001460static void
paul0fb58d52005-11-14 14:31:49 +00001461bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001462{
paul0fb58d52005-11-14 14:31:49 +00001463 struct bgp_process_queue *pq = data;
1464
paul200df112005-06-01 11:17:05 +00001465 bgp_unlock_node (pq->rn);
1466 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1467}
1468
1469static void
1470bgp_process_queue_init (void)
1471{
1472 bm->process_main_queue
1473 = work_queue_new (bm->master, "process_main_queue");
1474 bm->process_rsclient_queue
1475 = work_queue_new (bm->master, "process_rsclient_queue");
1476
1477 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1478 {
1479 zlog_err ("%s: Failed to allocate work queue", __func__);
1480 exit (1);
1481 }
1482
1483 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1484 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1485 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1486 bm->process_rsclient_queue->spec.del_item_data
1487 = bm->process_main_queue->spec.del_item_data;
1488 bm->process_main_queue->spec.max_retries
1489 = bm->process_main_queue->spec.max_retries = 0;
1490 bm->process_rsclient_queue->spec.hold
Paul Jakma09dd5612006-09-14 03:38:16 +00001491 = bm->process_main_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001492}
1493
1494void
paulfee0f4c2004-09-13 05:12:46 +00001495bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1496{
paul200df112005-06-01 11:17:05 +00001497 struct bgp_process_queue *pqnode;
1498
1499 /* already scheduled for processing? */
1500 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1501 return;
1502
1503 if ( (bm->process_main_queue == NULL) ||
1504 (bm->process_rsclient_queue == NULL) )
1505 bgp_process_queue_init ();
1506
1507 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1508 sizeof (struct bgp_process_queue));
1509 if (!pqnode)
1510 return;
1511
1512 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1513 pqnode->bgp = bgp;
1514 pqnode->afi = afi;
1515 pqnode->safi = safi;
1516
paulfee0f4c2004-09-13 05:12:46 +00001517 switch (rn->table->type)
1518 {
paul200df112005-06-01 11:17:05 +00001519 case BGP_TABLE_MAIN:
1520 work_queue_add (bm->process_main_queue, pqnode);
1521 break;
1522 case BGP_TABLE_RSCLIENT:
1523 work_queue_add (bm->process_rsclient_queue, pqnode);
1524 break;
paulfee0f4c2004-09-13 05:12:46 +00001525 }
paul200df112005-06-01 11:17:05 +00001526
1527 return;
paulfee0f4c2004-09-13 05:12:46 +00001528}
hasso0a486e52005-02-01 20:57:17 +00001529
paul94f2b392005-06-28 12:44:16 +00001530static int
hasso0a486e52005-02-01 20:57:17 +00001531bgp_maximum_prefix_restart_timer (struct thread *thread)
1532{
1533 struct peer *peer;
1534
1535 peer = THREAD_ARG (thread);
1536 peer->t_pmax_restart = NULL;
1537
1538 if (BGP_DEBUG (events, EVENTS))
1539 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1540 peer->host);
1541
1542 peer_clear (peer);
1543
1544 return 0;
1545}
1546
paulfee0f4c2004-09-13 05:12:46 +00001547int
paul5228ad22004-06-04 17:58:18 +00001548bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1549 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001550{
hassoe0701b72004-05-20 09:19:34 +00001551 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1552 return 0;
1553
1554 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001555 {
hassoe0701b72004-05-20 09:19:34 +00001556 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1557 && ! always)
1558 return 0;
paul718e3742002-12-13 20:15:29 +00001559
hassoe0701b72004-05-20 09:19:34 +00001560 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001561 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1562 "limit %ld", afi_safi_print (afi, safi), peer->host,
1563 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001564 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001565
hassoe0701b72004-05-20 09:19:34 +00001566 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1567 return 0;
paul718e3742002-12-13 20:15:29 +00001568
hassoe0701b72004-05-20 09:19:34 +00001569 {
paul5228ad22004-06-04 17:58:18 +00001570 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001571
1572 if (safi == SAFI_MPLS_VPN)
1573 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001574
1575 ndata[0] = (afi >> 8);
1576 ndata[1] = afi;
1577 ndata[2] = safi;
1578 ndata[3] = (peer->pmax[afi][safi] >> 24);
1579 ndata[4] = (peer->pmax[afi][safi] >> 16);
1580 ndata[5] = (peer->pmax[afi][safi] >> 8);
1581 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001582
1583 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1584 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1585 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1586 }
hasso0a486e52005-02-01 20:57:17 +00001587
1588 /* restart timer start */
1589 if (peer->pmax_restart[afi][safi])
1590 {
1591 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1592
1593 if (BGP_DEBUG (events, EVENTS))
1594 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1595 peer->host, peer->v_pmax_restart);
1596
1597 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1598 peer->v_pmax_restart);
1599 }
1600
hassoe0701b72004-05-20 09:19:34 +00001601 return 1;
paul718e3742002-12-13 20:15:29 +00001602 }
hassoe0701b72004-05-20 09:19:34 +00001603 else
1604 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1605
1606 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1607 {
1608 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1609 && ! always)
1610 return 0;
1611
1612 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001613 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1614 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1615 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001616 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1617 }
1618 else
1619 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001620 return 0;
1621}
1622
paulb40d9392005-08-22 22:34:41 +00001623/* Unconditionally remove the route from the RIB, without taking
1624 * damping into consideration (eg, because the session went down)
1625 */
paul94f2b392005-06-28 12:44:16 +00001626static void
paul718e3742002-12-13 20:15:29 +00001627bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1628 afi_t afi, safi_t safi)
1629{
paul902212c2006-02-05 17:51:19 +00001630 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1631
1632 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1633 bgp_info_delete (rn, ri); /* keep historical info */
1634
paulb40d9392005-08-22 22:34:41 +00001635 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001636}
1637
paul94f2b392005-06-28 12:44:16 +00001638static void
paul718e3742002-12-13 20:15:29 +00001639bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001640 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001641{
paul718e3742002-12-13 20:15:29 +00001642 int status = BGP_DAMP_NONE;
1643
paulb40d9392005-08-22 22:34:41 +00001644 /* apply dampening, if result is suppressed, we'll be retaining
1645 * the bgp_info in the RIB for historical reference.
1646 */
1647 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1648 && peer_sort (peer) == BGP_PEER_EBGP)
1649 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1650 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001651 {
paul902212c2006-02-05 17:51:19 +00001652 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1653 return;
1654 }
1655
1656 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001657}
1658
paul94f2b392005-06-28 12:44:16 +00001659static void
paulfee0f4c2004-09-13 05:12:46 +00001660bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1661 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1662 int sub_type, struct prefix_rd *prd, u_char *tag)
1663{
1664 struct bgp_node *rn;
1665 struct bgp *bgp;
1666 struct attr new_attr;
1667 struct attr *attr_new;
1668 struct attr *attr_new2;
1669 struct bgp_info *ri;
1670 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001671 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001672 char buf[SU_ADDRSTRLEN];
1673
1674 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1675 if (peer == rsclient)
1676 return;
1677
1678 bgp = peer->bgp;
1679 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1680
1681 /* Check previously received route. */
1682 for (ri = rn->info; ri; ri = ri->next)
1683 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1684 break;
1685
1686 /* AS path loop check. */
1687 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1688 {
1689 reason = "as-path contains our own AS;";
1690 goto filtered;
1691 }
1692
1693 /* Route reflector originator ID check. */
1694 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1695 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->originator_id))
1696 {
1697 reason = "originator is us;";
1698 goto filtered;
1699 }
1700
1701 new_attr = *attr;
1702
1703 /* Apply export policy. */
1704 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1705 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1706 {
1707 reason = "export-policy;";
1708 goto filtered;
1709 }
1710
1711 attr_new2 = bgp_attr_intern (&new_attr);
1712
1713 /* Apply import policy. */
1714 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1715 {
1716 bgp_attr_unintern (attr_new2);
1717
1718 reason = "import-policy;";
1719 goto filtered;
1720 }
1721
1722 attr_new = bgp_attr_intern (&new_attr);
1723 bgp_attr_unintern (attr_new2);
1724
1725 /* IPv4 unicast next hop check. */
1726 if (afi == AFI_IP && safi == SAFI_UNICAST)
1727 {
1728 /* Next hop must not be 0.0.0.0 nor Class E address. */
1729 if (new_attr.nexthop.s_addr == 0
1730 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1731 {
1732 bgp_attr_unintern (attr_new);
1733
1734 reason = "martian next-hop;";
1735 goto filtered;
1736 }
1737 }
1738
1739 /* If the update is implicit withdraw. */
1740 if (ri)
1741 {
1742 ri->uptime = time (NULL);
1743
1744 /* Same attribute comes in. */
1745 if (attrhash_cmp (ri->attr, attr_new))
1746 {
1747
Paul Jakma1a392d42006-09-07 00:24:49 +00001748 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001749
1750 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001751 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001752 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1753 peer->host,
1754 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1755 p->prefixlen, rsclient->host);
1756
1757 bgp_unlock_node (rn);
1758 bgp_attr_unintern (attr_new);
1759
1760 return;
1761 }
1762
1763 /* Received Logging. */
1764 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001765 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001766 peer->host,
1767 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1768 p->prefixlen, rsclient->host);
1769
1770 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001771 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001772
1773 /* Update to new attribute. */
1774 bgp_attr_unintern (ri->attr);
1775 ri->attr = attr_new;
1776
1777 /* Update MPLS tag. */
1778 if (safi == SAFI_MPLS_VPN)
1779 memcpy (ri->tag, tag, 3);
1780
Paul Jakma1a392d42006-09-07 00:24:49 +00001781 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001782
1783 /* Process change. */
1784 bgp_process (bgp, rn, afi, safi);
1785 bgp_unlock_node (rn);
1786
1787 return;
1788 }
1789
1790 /* Received Logging. */
1791 if (BGP_DEBUG (update, UPDATE_IN))
1792 {
ajsd2c1f162004-12-08 21:10:20 +00001793 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001794 peer->host,
1795 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1796 p->prefixlen, rsclient->host);
1797 }
1798
1799 /* Make new BGP info. */
1800 new = bgp_info_new ();
1801 new->type = type;
1802 new->sub_type = sub_type;
1803 new->peer = peer;
1804 new->attr = attr_new;
1805 new->uptime = time (NULL);
1806
1807 /* Update MPLS tag. */
1808 if (safi == SAFI_MPLS_VPN)
1809 memcpy (new->tag, tag, 3);
1810
Paul Jakma1a392d42006-09-07 00:24:49 +00001811 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001812
1813 /* Register new BGP information. */
1814 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001815
1816 /* route_node_get lock */
1817 bgp_unlock_node (rn);
1818
paulfee0f4c2004-09-13 05:12:46 +00001819 /* Process change. */
1820 bgp_process (bgp, rn, afi, safi);
1821
1822 return;
1823
1824 filtered:
1825
1826 /* This BGP update is filtered. Log the reason then update BGP entry. */
1827 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001828 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001829 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1830 peer->host,
1831 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1832 p->prefixlen, rsclient->host, reason);
1833
1834 if (ri)
paulb40d9392005-08-22 22:34:41 +00001835 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001836
1837 bgp_unlock_node (rn);
1838
1839 return;
1840}
1841
paul94f2b392005-06-28 12:44:16 +00001842static void
paulfee0f4c2004-09-13 05:12:46 +00001843bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1844 struct peer *peer, struct prefix *p, int type, int sub_type,
1845 struct prefix_rd *prd, u_char *tag)
1846 {
1847 struct bgp_node *rn;
1848 struct bgp_info *ri;
1849 char buf[SU_ADDRSTRLEN];
1850
1851 if (rsclient == peer)
1852 return;
1853
1854 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1855
1856 /* Lookup withdrawn route. */
1857 for (ri = rn->info; ri; ri = ri->next)
1858 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1859 break;
1860
1861 /* Withdraw specified route from routing table. */
1862 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001863 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001864 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001865 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001866 "%s Can't find the route %s/%d", peer->host,
1867 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1868 p->prefixlen);
1869
1870 /* Unlock bgp_node_get() lock. */
1871 bgp_unlock_node (rn);
1872 }
1873
paul94f2b392005-06-28 12:44:16 +00001874static int
paulfee0f4c2004-09-13 05:12:46 +00001875bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001876 afi_t afi, safi_t safi, int type, int sub_type,
1877 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1878{
1879 int ret;
1880 int aspath_loop_count = 0;
1881 struct bgp_node *rn;
1882 struct bgp *bgp;
1883 struct attr new_attr;
1884 struct attr *attr_new;
1885 struct bgp_info *ri;
1886 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001887 const char *reason;
paul718e3742002-12-13 20:15:29 +00001888 char buf[SU_ADDRSTRLEN];
1889
1890 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00001891 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00001892
1893 /* When peer's soft reconfiguration enabled. Record input packet in
1894 Adj-RIBs-In. */
1895 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1896 && peer != bgp->peer_self && ! soft_reconfig)
1897 bgp_adj_in_set (rn, peer, attr);
1898
1899 /* Check previously received route. */
1900 for (ri = rn->info; ri; ri = ri->next)
1901 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1902 break;
1903
1904 /* AS path local-as loop check. */
1905 if (peer->change_local_as)
1906 {
1907 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
1908 aspath_loop_count = 1;
1909
1910 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
1911 {
1912 reason = "as-path contains our own AS;";
1913 goto filtered;
1914 }
1915 }
1916
1917 /* AS path loop check. */
1918 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
1919 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
1920 && aspath_loop_check(attr->aspath, bgp->confed_id)
1921 > peer->allowas_in[afi][safi]))
1922 {
1923 reason = "as-path contains our own AS;";
1924 goto filtered;
1925 }
1926
1927 /* Route reflector originator ID check. */
1928 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1929 && IPV4_ADDR_SAME (&bgp->router_id, &attr->originator_id))
1930 {
1931 reason = "originator is us;";
1932 goto filtered;
1933 }
1934
1935 /* Route reflector cluster ID check. */
1936 if (bgp_cluster_filter (peer, attr))
1937 {
1938 reason = "reflected from the same cluster;";
1939 goto filtered;
1940 }
1941
1942 /* Apply incoming filter. */
1943 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
1944 {
1945 reason = "filter;";
1946 goto filtered;
1947 }
1948
1949 /* Apply incoming route-map. */
1950 new_attr = *attr;
1951
1952 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
1953 {
1954 reason = "route-map;";
1955 goto filtered;
1956 }
1957
1958 /* IPv4 unicast next hop check. */
1959 if (afi == AFI_IP && safi == SAFI_UNICAST)
1960 {
1961 /* If the peer is EBGP and nexthop is not on connected route,
1962 discard it. */
1963 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
1964 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00001965 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00001966 {
1967 reason = "non-connected next-hop;";
1968 goto filtered;
1969 }
1970
1971 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
1972 must not be my own address. */
1973 if (bgp_nexthop_self (afi, &new_attr)
1974 || new_attr.nexthop.s_addr == 0
1975 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1976 {
1977 reason = "martian next-hop;";
1978 goto filtered;
1979 }
1980 }
1981
1982 attr_new = bgp_attr_intern (&new_attr);
1983
1984 /* If the update is implicit withdraw. */
1985 if (ri)
1986 {
1987 ri->uptime = time (NULL);
1988
1989 /* Same attribute comes in. */
1990 if (attrhash_cmp (ri->attr, attr_new))
1991 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001992 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00001993
1994 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1995 && peer_sort (peer) == BGP_PEER_EBGP
1996 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1997 {
1998 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001999 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002000 peer->host,
2001 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2002 p->prefixlen);
2003
paul902212c2006-02-05 17:51:19 +00002004 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2005 {
2006 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2007 bgp_process (bgp, rn, afi, safi);
2008 }
paul718e3742002-12-13 20:15:29 +00002009 }
2010 else
2011 {
2012 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002013 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002014 "%s rcvd %s/%d...duplicate ignored",
2015 peer->host,
2016 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2017 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002018
2019 /* graceful restart STALE flag unset. */
2020 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2021 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002022 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002023 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002024 }
paul718e3742002-12-13 20:15:29 +00002025 }
2026
2027 bgp_unlock_node (rn);
2028 bgp_attr_unintern (attr_new);
2029 return 0;
2030 }
2031
2032 /* Received Logging. */
2033 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002034 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002035 peer->host,
2036 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2037 p->prefixlen);
2038
hasso93406d82005-02-02 14:40:33 +00002039 /* graceful restart STALE flag unset. */
2040 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002041 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002042
paul718e3742002-12-13 20:15:29 +00002043 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002044 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002045
2046 /* implicit withdraw, decrement aggregate and pcount here.
2047 * only if update is accepted, they'll increment below.
2048 */
paul902212c2006-02-05 17:51:19 +00002049 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2050
paul718e3742002-12-13 20:15:29 +00002051 /* Update bgp route dampening information. */
2052 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2053 && peer_sort (peer) == BGP_PEER_EBGP)
2054 {
2055 /* This is implicit withdraw so we should update dampening
2056 information. */
2057 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2058 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002059 }
2060
paul718e3742002-12-13 20:15:29 +00002061 /* Update to new attribute. */
2062 bgp_attr_unintern (ri->attr);
2063 ri->attr = attr_new;
2064
2065 /* Update MPLS tag. */
2066 if (safi == SAFI_MPLS_VPN)
2067 memcpy (ri->tag, tag, 3);
2068
2069 /* Update bgp route dampening information. */
2070 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2071 && peer_sort (peer) == BGP_PEER_EBGP)
2072 {
2073 /* Now we do normal update dampening. */
2074 ret = bgp_damp_update (ri, rn, afi, safi);
2075 if (ret == BGP_DAMP_SUPPRESSED)
2076 {
2077 bgp_unlock_node (rn);
2078 return 0;
2079 }
2080 }
2081
2082 /* Nexthop reachability check. */
2083 if ((afi == AFI_IP || afi == AFI_IP6)
2084 && safi == SAFI_UNICAST
2085 && (peer_sort (peer) == BGP_PEER_IBGP
2086 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002087 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002088 {
2089 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002090 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002091 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002092 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002093 }
2094 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002095 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002096
2097 /* Process change. */
2098 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2099
2100 bgp_process (bgp, rn, afi, safi);
2101 bgp_unlock_node (rn);
2102 return 0;
2103 }
2104
2105 /* Received Logging. */
2106 if (BGP_DEBUG (update, UPDATE_IN))
2107 {
ajsd2c1f162004-12-08 21:10:20 +00002108 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002109 peer->host,
2110 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2111 p->prefixlen);
2112 }
2113
paul718e3742002-12-13 20:15:29 +00002114 /* Make new BGP info. */
2115 new = bgp_info_new ();
2116 new->type = type;
2117 new->sub_type = sub_type;
2118 new->peer = peer;
2119 new->attr = attr_new;
2120 new->uptime = time (NULL);
2121
2122 /* Update MPLS tag. */
2123 if (safi == SAFI_MPLS_VPN)
2124 memcpy (new->tag, tag, 3);
2125
2126 /* Nexthop reachability check. */
2127 if ((afi == AFI_IP || afi == AFI_IP6)
2128 && safi == SAFI_UNICAST
2129 && (peer_sort (peer) == BGP_PEER_IBGP
2130 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002131 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002132 {
2133 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002134 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002135 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002136 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002137 }
2138 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002139 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002140
paul902212c2006-02-05 17:51:19 +00002141 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002142 bgp_aggregate_increment (bgp, p, new, afi, safi);
2143
2144 /* Register new BGP information. */
2145 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002146
2147 /* route_node_get lock */
2148 bgp_unlock_node (rn);
2149
paul718e3742002-12-13 20:15:29 +00002150 /* If maximum prefix count is configured and current prefix
2151 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002152 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2153 return -1;
paul718e3742002-12-13 20:15:29 +00002154
2155 /* Process change. */
2156 bgp_process (bgp, rn, afi, safi);
2157
2158 return 0;
2159
2160 /* This BGP update is filtered. Log the reason then update BGP
2161 entry. */
2162 filtered:
2163 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002164 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002165 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2166 peer->host,
2167 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2168 p->prefixlen, reason);
2169
2170 if (ri)
paulb40d9392005-08-22 22:34:41 +00002171 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002172
2173 bgp_unlock_node (rn);
2174
2175 return 0;
2176}
2177
2178int
paulfee0f4c2004-09-13 05:12:46 +00002179bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2180 afi_t afi, safi_t safi, int type, int sub_type,
2181 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2182{
2183 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002184 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002185 struct bgp *bgp;
2186 int ret;
2187
2188 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2189 soft_reconfig);
2190
2191 bgp = peer->bgp;
2192
2193 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002194 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002195 {
2196 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2197 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2198 sub_type, prd, tag);
2199 }
2200
2201 return ret;
2202}
2203
2204int
paul718e3742002-12-13 20:15:29 +00002205bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002206 afi_t afi, safi_t safi, int type, int sub_type,
2207 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002208{
2209 struct bgp *bgp;
2210 char buf[SU_ADDRSTRLEN];
2211 struct bgp_node *rn;
2212 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002213 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002214 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002215
2216 bgp = peer->bgp;
2217
paulfee0f4c2004-09-13 05:12:46 +00002218 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002219 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002220 {
2221 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2222 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2223 }
2224
paul718e3742002-12-13 20:15:29 +00002225 /* Logging. */
2226 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002227 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002228 peer->host,
2229 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2230 p->prefixlen);
2231
2232 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002233 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002234
2235 /* If peer is soft reconfiguration enabled. Record input packet for
2236 further calculation. */
2237 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2238 && peer != bgp->peer_self)
2239 bgp_adj_in_unset (rn, peer);
2240
2241 /* Lookup withdrawn route. */
2242 for (ri = rn->info; ri; ri = ri->next)
2243 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2244 break;
2245
2246 /* Withdraw specified route from routing table. */
2247 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002248 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002249 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002250 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002251 "%s Can't find the route %s/%d", peer->host,
2252 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2253 p->prefixlen);
2254
2255 /* Unlock bgp_node_get() lock. */
2256 bgp_unlock_node (rn);
2257
2258 return 0;
2259}
2260
2261void
2262bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2263{
2264 struct bgp *bgp;
2265 struct attr attr;
2266 struct aspath *aspath;
2267 struct prefix p;
2268 struct bgp_info binfo;
2269 struct peer *from;
2270 int ret = RMAP_DENYMATCH;
2271
2272 bgp = peer->bgp;
2273 from = bgp->peer_self;
2274
2275 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2276 aspath = attr.aspath;
2277 attr.local_pref = bgp->default_local_pref;
2278 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2279
2280 if (afi == AFI_IP)
2281 str2prefix ("0.0.0.0/0", &p);
2282#ifdef HAVE_IPV6
2283 else if (afi == AFI_IP6)
2284 {
2285 str2prefix ("::/0", &p);
2286
2287 /* IPv6 global nexthop must be included. */
2288 memcpy (&attr.mp_nexthop_global, &peer->nexthop.v6_global,
2289 IPV6_MAX_BYTELEN);
2290 attr.mp_nexthop_len = 16;
2291
2292 /* If the peer is on shared nextwork and we have link-local
2293 nexthop set it. */
2294 if (peer->shared_network
2295 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2296 {
2297 memcpy (&attr.mp_nexthop_local, &peer->nexthop.v6_local,
2298 IPV6_MAX_BYTELEN);
2299 attr.mp_nexthop_len = 32;
2300 }
2301 }
2302#endif /* HAVE_IPV6 */
2303 else
2304 return;
2305
2306 if (peer->default_rmap[afi][safi].name)
2307 {
2308 binfo.peer = bgp->peer_self;
2309 binfo.attr = &attr;
2310
paulfee0f4c2004-09-13 05:12:46 +00002311 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2312
paul718e3742002-12-13 20:15:29 +00002313 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2314 RMAP_BGP, &binfo);
2315
paulfee0f4c2004-09-13 05:12:46 +00002316 bgp->peer_self->rmap_type = 0;
2317
paul718e3742002-12-13 20:15:29 +00002318 if (ret == RMAP_DENYMATCH)
2319 {
2320 bgp_attr_flush (&attr);
2321 withdraw = 1;
2322 }
2323 }
2324
2325 if (withdraw)
2326 {
2327 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2328 bgp_default_withdraw_send (peer, afi, safi);
2329 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2330 }
2331 else
2332 {
2333 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2334 bgp_default_update_send (peer, &attr, afi, safi, from);
2335 }
2336
2337 aspath_unintern (aspath);
2338}
2339
2340static void
2341bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002342 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002343{
2344 struct bgp_node *rn;
2345 struct bgp_info *ri;
2346 struct attr attr;
2347
2348 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002349 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002350
2351 if (safi != SAFI_MPLS_VPN
2352 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2353 bgp_default_originate (peer, afi, safi, 0);
2354
2355 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2356 for (ri = rn->info; ri; ri = ri->next)
2357 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2358 {
paulfee0f4c2004-09-13 05:12:46 +00002359 if ( (rsclient) ?
2360 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2361 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002362 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2363 else
2364 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2365 }
2366}
2367
2368void
2369bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2370{
2371 struct bgp_node *rn;
2372 struct bgp_table *table;
2373
2374 if (peer->status != Established)
2375 return;
2376
2377 if (! peer->afc_nego[afi][safi])
2378 return;
2379
2380 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2381 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2382 return;
2383
2384 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002385 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002386 else
2387 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2388 rn = bgp_route_next(rn))
2389 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002390 bgp_announce_table (peer, afi, safi, table, 0);
2391
2392 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2393 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002394}
2395
2396void
2397bgp_announce_route_all (struct peer *peer)
2398{
2399 afi_t afi;
2400 safi_t safi;
2401
2402 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2403 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2404 bgp_announce_route (peer, afi, safi);
2405}
2406
2407static void
paulfee0f4c2004-09-13 05:12:46 +00002408bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2409 safi_t safi, struct bgp_table *table)
2410{
2411 struct bgp_node *rn;
2412 struct bgp_adj_in *ain;
2413
2414 if (! table)
2415 table = rsclient->bgp->rib[afi][safi];
2416
2417 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2418 for (ain = rn->adj_in; ain; ain = ain->next)
2419 {
2420 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2421 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2422 }
2423}
2424
2425void
2426bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2427{
2428 struct bgp_table *table;
2429 struct bgp_node *rn;
2430
2431 if (safi != SAFI_MPLS_VPN)
2432 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2433
2434 else
2435 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2436 rn = bgp_route_next (rn))
2437 if ((table = rn->info) != NULL)
2438 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2439}
2440
2441static void
paul718e3742002-12-13 20:15:29 +00002442bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2443 struct bgp_table *table)
2444{
2445 int ret;
2446 struct bgp_node *rn;
2447 struct bgp_adj_in *ain;
2448
2449 if (! table)
2450 table = peer->bgp->rib[afi][safi];
2451
2452 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2453 for (ain = rn->adj_in; ain; ain = ain->next)
2454 {
2455 if (ain->peer == peer)
2456 {
2457 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2458 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2459 NULL, NULL, 1);
2460 if (ret < 0)
2461 {
2462 bgp_unlock_node (rn);
2463 return;
2464 }
2465 continue;
2466 }
2467 }
2468}
2469
2470void
2471bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2472{
2473 struct bgp_node *rn;
2474 struct bgp_table *table;
2475
2476 if (peer->status != Established)
2477 return;
2478
2479 if (safi != SAFI_MPLS_VPN)
2480 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2481 else
2482 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2483 rn = bgp_route_next (rn))
2484 if ((table = rn->info) != NULL)
2485 bgp_soft_reconfig_table (peer, afi, safi, table);
2486}
2487
paul200df112005-06-01 11:17:05 +00002488static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002489bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002490{
Paul Jakma64e580a2006-02-21 01:09:01 +00002491 struct bgp_node *rn = data;
2492 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002493 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002494 afi_t afi = rn->table->afi;
2495 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002496
Paul Jakma64e580a2006-02-21 01:09:01 +00002497 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002498
Paul Jakma64e580a2006-02-21 01:09:01 +00002499 for (ri = rn->info; ri; ri = ri->next)
2500 if (ri->peer == peer)
paul200df112005-06-01 11:17:05 +00002501 {
2502 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002503 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2504 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002505 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002506 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2507 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002508 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002509 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002510 break;
2511 }
paul200df112005-06-01 11:17:05 +00002512 return WQ_SUCCESS;
2513}
2514
2515static void
paul0fb58d52005-11-14 14:31:49 +00002516bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002517{
Paul Jakma64e580a2006-02-21 01:09:01 +00002518 struct bgp_node *rn = data;
2519
2520 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002521}
2522
2523static void
paul94f2b392005-06-28 12:44:16 +00002524bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002525{
Paul Jakma64e580a2006-02-21 01:09:01 +00002526 struct peer *peer = wq->spec.data;
2527
Paul Jakma64e580a2006-02-21 01:09:01 +00002528 peer_unlock (peer); /* bgp_clear_node_complete */
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002529
2530 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002531 BGP_EVENT_ADD (peer, Clearing_Completed);
paul200df112005-06-01 11:17:05 +00002532}
2533
2534static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002535bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002536{
Paul Jakma64e580a2006-02-21 01:09:01 +00002537#define CLEAR_QUEUE_NAME_LEN 26 /* "clear 2001:123:123:123::1" */
2538 char wname[CLEAR_QUEUE_NAME_LEN];
2539
2540 snprintf (wname, CLEAR_QUEUE_NAME_LEN, "clear %s", peer->host);
2541#undef CLEAR_QUEUE_NAME_LEN
2542
2543 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002544 {
2545 zlog_err ("%s: Failed to allocate work queue", __func__);
2546 exit (1);
2547 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002548 peer->clear_node_queue->spec.hold = 10;
2549 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2550 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2551 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2552 peer->clear_node_queue->spec.max_retries = 0;
2553
2554 /* we only 'lock' this peer reference when the queue is actually active */
2555 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002556}
2557
paul718e3742002-12-13 20:15:29 +00002558static void
2559bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002560 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002561{
2562 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002563
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002564
paul718e3742002-12-13 20:15:29 +00002565 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002566 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002567
hasso6cf159b2005-03-21 10:28:14 +00002568 /* If still no table => afi/safi isn't configured at all or smth. */
2569 if (! table)
2570 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002571
2572 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2573 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002574 struct bgp_info *ri;
2575 struct bgp_adj_in *ain;
2576 struct bgp_adj_out *aout;
2577
Paul Jakma65ca75e2006-05-04 08:08:15 +00002578 if (rn->info == NULL)
2579 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002580
2581 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2582 * queued for every clearing peer, regardless of whether it is
2583 * relevant to the peer at hand.
2584 *
2585 * Overview: There are 3 different indices which need to be
2586 * scrubbed, potentially, when a peer is removed:
2587 *
2588 * 1 peer's routes visible via the RIB (ie accepted routes)
2589 * 2 peer's routes visible by the (optional) peer's adj-in index
2590 * 3 other routes visible by the peer's adj-out index
2591 *
2592 * 3 there is no hurry in scrubbing, once the struct peer is
2593 * removed from bgp->peer, we could just GC such deleted peer's
2594 * adj-outs at our leisure.
2595 *
2596 * 1 and 2 must be 'scrubbed' in some way, at least made
2597 * invisible via RIB index before peer session is allowed to be
2598 * brought back up. So one needs to know when such a 'search' is
2599 * complete.
2600 *
2601 * Ideally:
2602 *
2603 * - there'd be a single global queue or a single RIB walker
2604 * - rather than tracking which route_nodes still need to be
2605 * examined on a peer basis, we'd track which peers still
2606 * aren't cleared
2607 *
2608 * Given that our per-peer prefix-counts now should be reliable,
2609 * this may actually be achievable. It doesn't seem to be a huge
2610 * problem at this time,
2611 */
2612 for (ri = rn->info; ri; ri = ri->next)
2613 if (ri->peer == peer)
2614 {
2615 bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2616 work_queue_add (peer->clear_node_queue, rn);
2617 }
2618
2619 for (ain = rn->adj_in; ain; ain = ain->next)
2620 if (ain->peer == peer)
2621 {
2622 bgp_adj_in_remove (rn, ain);
2623 bgp_unlock_node (rn);
2624 break;
2625 }
2626 for (aout = rn->adj_out; aout; aout = aout->next)
2627 if (aout->peer == peer)
2628 {
2629 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2630 bgp_unlock_node (rn);
2631 break;
2632 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002633 }
2634 return;
2635}
2636
2637void
2638bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2639{
2640 struct bgp_node *rn;
2641 struct bgp_table *table;
2642 struct peer *rsclient;
2643 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002644
Paul Jakma64e580a2006-02-21 01:09:01 +00002645 if (peer->clear_node_queue == NULL)
2646 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002647
Paul Jakmaca058a32006-09-14 02:58:49 +00002648 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2649 * Idle until it receives a Clearing_Completed event. This protects
2650 * against peers which flap faster than we can we clear, which could
2651 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002652 *
2653 * a) race with routes from the new session being installed before
2654 * clear_route_node visits the node (to delete the route of that
2655 * peer)
2656 * b) resource exhaustion, clear_route_node likely leads to an entry
2657 * on the process_main queue. Fast-flapping could cause that queue
2658 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002659 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002660 if (!peer->clear_node_queue->thread)
2661 peer_lock (peer); /* bgp_clear_node_complete */
paul200df112005-06-01 11:17:05 +00002662
paul718e3742002-12-13 20:15:29 +00002663 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002664 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002665 else
2666 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2667 rn = bgp_route_next (rn))
2668 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002669 bgp_clear_route_table (peer, afi, safi, table, NULL);
2670
paul1eb8ef22005-04-07 07:30:20 +00002671 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002672 {
2673 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2674 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2675 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002676
Paul Jakmaca058a32006-09-14 02:58:49 +00002677 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002678 * completion function won't be run by workqueue code - call it here.
2679 * XXX: Actually, this assumption doesn't hold, see
2680 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002681 *
2682 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002683 * really needed if peer state is Established - peers in
2684 * pre-Established states shouldn't have any route-update state
2685 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002686 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002687 * We still can get here in pre-Established though, through
2688 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2689 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002690 *
2691 * At some future point, this check could be move to the top of the
2692 * function, and do a quick early-return when state is
2693 * pre-Established, avoiding above list and table scans. Once we're
2694 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002695 */
2696 if (!peer->clear_node_queue->thread)
2697 bgp_clear_node_complete (peer->clear_node_queue);
Paul Jakmaca058a32006-09-14 02:58:49 +00002698 else
2699 {
2700 /* clearing queue scheduled. Normal if in Established state
2701 * (and about to transition out of it), but otherwise...
2702 */
2703 if (peer->status != Established)
2704 {
2705 plog_err (peer->log, "%s [Error] State %s is not Established,"
2706 " but routes were cleared - bug!",
2707 peer->host, LOOKUP (bgp_status_msg, peer->status));
2708 assert (peer->status == Established);
2709 }
2710 }
paul718e3742002-12-13 20:15:29 +00002711}
2712
2713void
2714bgp_clear_route_all (struct peer *peer)
2715{
2716 afi_t afi;
2717 safi_t safi;
2718
2719 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2720 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2721 bgp_clear_route (peer, afi, safi);
2722}
2723
2724void
2725bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2726{
2727 struct bgp_table *table;
2728 struct bgp_node *rn;
2729 struct bgp_adj_in *ain;
2730
2731 table = peer->bgp->rib[afi][safi];
2732
2733 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2734 for (ain = rn->adj_in; ain ; ain = ain->next)
2735 if (ain->peer == peer)
2736 {
2737 bgp_adj_in_remove (rn, ain);
2738 bgp_unlock_node (rn);
2739 break;
2740 }
2741}
hasso93406d82005-02-02 14:40:33 +00002742
2743void
2744bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2745{
2746 struct bgp_node *rn;
2747 struct bgp_info *ri;
2748 struct bgp_table *table;
2749
2750 table = peer->bgp->rib[afi][safi];
2751
2752 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2753 {
2754 for (ri = rn->info; ri; ri = ri->next)
2755 if (ri->peer == peer)
2756 {
2757 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2758 bgp_rib_remove (rn, ri, peer, afi, safi);
2759 break;
2760 }
2761 }
2762}
paul718e3742002-12-13 20:15:29 +00002763
2764/* Delete all kernel routes. */
2765void
paul545acaf2004-04-20 15:13:15 +00002766bgp_cleanup_routes ()
paul718e3742002-12-13 20:15:29 +00002767{
2768 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002769 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002770 struct bgp_node *rn;
2771 struct bgp_table *table;
2772 struct bgp_info *ri;
2773
paul1eb8ef22005-04-07 07:30:20 +00002774 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002775 {
2776 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2777
2778 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2779 for (ri = rn->info; ri; ri = ri->next)
2780 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2781 && ri->type == ZEBRA_ROUTE_BGP
2782 && ri->sub_type == BGP_ROUTE_NORMAL)
2783 bgp_zebra_withdraw (&rn->p, ri);
2784
2785 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2786
2787 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2788 for (ri = rn->info; ri; ri = ri->next)
2789 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2790 && ri->type == ZEBRA_ROUTE_BGP
2791 && ri->sub_type == BGP_ROUTE_NORMAL)
2792 bgp_zebra_withdraw (&rn->p, ri);
2793 }
2794}
2795
2796void
2797bgp_reset ()
2798{
2799 vty_reset ();
2800 bgp_zclient_reset ();
2801 access_list_reset ();
2802 prefix_list_reset ();
2803}
2804
2805/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2806 value. */
2807int
2808bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2809{
2810 u_char *pnt;
2811 u_char *lim;
2812 struct prefix p;
2813 int psize;
2814 int ret;
2815
2816 /* Check peer status. */
2817 if (peer->status != Established)
2818 return 0;
2819
2820 pnt = packet->nlri;
2821 lim = pnt + packet->length;
2822
2823 for (; pnt < lim; pnt += psize)
2824 {
2825 /* Clear prefix structure. */
2826 memset (&p, 0, sizeof (struct prefix));
2827
2828 /* Fetch prefix length. */
2829 p.prefixlen = *pnt++;
2830 p.family = afi2family (packet->afi);
2831
2832 /* Already checked in nlri_sanity_check(). We do double check
2833 here. */
2834 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2835 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2836 return -1;
2837
2838 /* Packet size overflow check. */
2839 psize = PSIZE (p.prefixlen);
2840
2841 /* When packet overflow occur return immediately. */
2842 if (pnt + psize > lim)
2843 return -1;
2844
2845 /* Fetch prefix from NLRI packet. */
2846 memcpy (&p.u.prefix, pnt, psize);
2847
2848 /* Check address. */
2849 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2850 {
2851 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
2852 {
paulf5ba3872004-07-09 12:11:31 +00002853 /*
2854 * From draft-ietf-idr-bgp4-22, Section 6.3:
2855 * If a BGP router receives an UPDATE message with a
2856 * semantically incorrect NLRI field, in which a prefix is
2857 * semantically incorrect (eg. an unexpected multicast IP
2858 * address), it should ignore the prefix.
2859 */
paul718e3742002-12-13 20:15:29 +00002860 zlog (peer->log, LOG_ERR,
2861 "IPv4 unicast NLRI is multicast address %s",
2862 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00002863
paul718e3742002-12-13 20:15:29 +00002864 return -1;
2865 }
2866 }
2867
2868#ifdef HAVE_IPV6
2869 /* Check address. */
2870 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
2871 {
2872 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2873 {
2874 char buf[BUFSIZ];
2875
2876 zlog (peer->log, LOG_WARNING,
2877 "IPv6 link-local NLRI received %s ignore this NLRI",
2878 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
2879
2880 continue;
2881 }
2882 }
2883#endif /* HAVE_IPV6 */
2884
2885 /* Normal process. */
2886 if (attr)
2887 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
2888 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
2889 else
2890 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
2891 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2892
2893 /* Address family configuration mismatch or maximum-prefix count
2894 overflow. */
2895 if (ret < 0)
2896 return -1;
2897 }
2898
2899 /* Packet length consistency check. */
2900 if (pnt != lim)
2901 return -1;
2902
2903 return 0;
2904}
2905
2906/* NLRI encode syntax check routine. */
2907int
2908bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
2909 bgp_size_t length)
2910{
2911 u_char *end;
2912 u_char prefixlen;
2913 int psize;
2914
2915 end = pnt + length;
2916
2917 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
2918 syntactic validity. If the field is syntactically incorrect,
2919 then the Error Subcode is set to Invalid Network Field. */
2920
2921 while (pnt < end)
2922 {
2923 prefixlen = *pnt++;
2924
2925 /* Prefix length check. */
2926 if ((afi == AFI_IP && prefixlen > 32)
2927 || (afi == AFI_IP6 && prefixlen > 128))
2928 {
2929 plog_err (peer->log,
2930 "%s [Error] Update packet error (wrong prefix length %d)",
2931 peer->host, prefixlen);
2932 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2933 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2934 return -1;
2935 }
2936
2937 /* Packet size overflow check. */
2938 psize = PSIZE (prefixlen);
2939
2940 if (pnt + psize > end)
2941 {
2942 plog_err (peer->log,
2943 "%s [Error] Update packet error"
2944 " (prefix data overflow prefix size is %d)",
2945 peer->host, psize);
2946 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2947 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2948 return -1;
2949 }
2950
2951 pnt += psize;
2952 }
2953
2954 /* Packet length consistency check. */
2955 if (pnt != end)
2956 {
2957 plog_err (peer->log,
2958 "%s [Error] Update packet error"
2959 " (prefix length mismatch with total length)",
2960 peer->host);
2961 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2962 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2963 return -1;
2964 }
2965 return 0;
2966}
2967
paul94f2b392005-06-28 12:44:16 +00002968static struct bgp_static *
paul718e3742002-12-13 20:15:29 +00002969bgp_static_new ()
2970{
2971 struct bgp_static *new;
2972 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
2973 memset (new, 0, sizeof (struct bgp_static));
2974 return new;
2975}
2976
paul94f2b392005-06-28 12:44:16 +00002977static void
paul718e3742002-12-13 20:15:29 +00002978bgp_static_free (struct bgp_static *bgp_static)
2979{
2980 if (bgp_static->rmap.name)
2981 free (bgp_static->rmap.name);
2982 XFREE (MTYPE_BGP_STATIC, bgp_static);
2983}
2984
paul94f2b392005-06-28 12:44:16 +00002985static void
paulfee0f4c2004-09-13 05:12:46 +00002986bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
2987 struct prefix *p, afi_t afi, safi_t safi)
2988{
2989 struct bgp_node *rn;
2990 struct bgp_info *ri;
2991
2992 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2993
2994 /* Check selected route and self inserted route. */
2995 for (ri = rn->info; ri; ri = ri->next)
2996 if (ri->peer == bgp->peer_self
2997 && ri->type == ZEBRA_ROUTE_BGP
2998 && ri->sub_type == BGP_ROUTE_STATIC)
2999 break;
3000
3001 /* Withdraw static BGP route from routing table. */
3002 if (ri)
3003 {
paulfee0f4c2004-09-13 05:12:46 +00003004 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003005 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003006 }
3007
3008 /* Unlock bgp_node_lookup. */
3009 bgp_unlock_node (rn);
3010}
3011
paul94f2b392005-06-28 12:44:16 +00003012static void
paulfee0f4c2004-09-13 05:12:46 +00003013bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
3014 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3015{
3016 struct bgp_node *rn;
3017 struct bgp_info *ri;
3018 struct bgp_info *new;
3019 struct bgp_info info;
3020 struct attr new_attr;
3021 struct attr *attr_new;
3022 struct attr attr;
3023 struct bgp *bgp;
3024 int ret;
3025 char buf[SU_ADDRSTRLEN];
3026
3027 bgp = rsclient->bgp;
3028
Paul Jakma06e110f2006-05-12 23:29:22 +00003029 assert (bgp_static);
3030 if (!bgp_static)
3031 return;
3032
paulfee0f4c2004-09-13 05:12:46 +00003033 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3034
3035 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003036
3037 attr.nexthop = bgp_static->igpnexthop;
3038 attr.med = bgp_static->igpmetric;
3039 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paulfee0f4c2004-09-13 05:12:46 +00003040
3041 new_attr = attr;
3042
3043 /* Apply network route-map for export to this rsclient. */
3044 if (bgp_static->rmap.name)
3045 {
3046 info.peer = rsclient;
3047 info.attr = &new_attr;
3048
3049 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3050 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3051
3052 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3053
3054 rsclient->rmap_type = 0;
3055
3056 if (ret == RMAP_DENYMATCH)
3057 {
3058 /* Free uninterned attribute. */
3059 bgp_attr_flush (&new_attr);
3060
3061 /* Unintern original. */
3062 aspath_unintern (attr.aspath);
3063 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3064
3065 return;
3066 }
3067 attr_new = bgp_attr_intern (&new_attr);
3068 }
3069 else
3070 attr_new = bgp_attr_intern (&attr);
3071
3072 new_attr = *attr_new;
3073
3074 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3075
3076 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) == RMAP_DENY)
3077{
3078 /* This BGP update is filtered. Log the reason then update BGP entry. */
3079 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003080 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003081 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3082 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3083 p->prefixlen, rsclient->host);
3084
3085 bgp->peer_self->rmap_type = 0;
3086
3087 bgp_attr_unintern (attr_new);
3088 aspath_unintern (attr.aspath);
3089
3090 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3091
3092 return;
3093 }
3094
3095 bgp->peer_self->rmap_type = 0;
3096
3097 bgp_attr_unintern (attr_new);
3098 attr_new = bgp_attr_intern (&new_attr);
3099
3100 for (ri = rn->info; ri; ri = ri->next)
3101 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3102 && ri->sub_type == BGP_ROUTE_STATIC)
3103 break;
3104
3105 if (ri)
3106 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003107 if (attrhash_cmp (ri->attr, attr_new) &&
3108 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003109 {
3110 bgp_unlock_node (rn);
3111 bgp_attr_unintern (attr_new);
3112 aspath_unintern (attr.aspath);
3113 return;
3114 }
3115 else
3116 {
3117 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003118 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003119
3120 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003121 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3122 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003123 bgp_attr_unintern (ri->attr);
3124 ri->attr = attr_new;
3125 ri->uptime = time (NULL);
3126
3127 /* Process change. */
3128 bgp_process (bgp, rn, afi, safi);
3129 bgp_unlock_node (rn);
3130 aspath_unintern (attr.aspath);
3131 return;
3132 }
3133}
3134
3135 /* Make new BGP info. */
3136 new = bgp_info_new ();
3137 new->type = ZEBRA_ROUTE_BGP;
3138 new->sub_type = BGP_ROUTE_STATIC;
3139 new->peer = bgp->peer_self;
3140 SET_FLAG (new->flags, BGP_INFO_VALID);
3141 new->attr = attr_new;
3142 new->uptime = time (NULL);
3143
3144 /* Register new BGP information. */
3145 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003146
3147 /* route_node_get lock */
3148 bgp_unlock_node (rn);
3149
paulfee0f4c2004-09-13 05:12:46 +00003150 /* Process change. */
3151 bgp_process (bgp, rn, afi, safi);
3152
3153 /* Unintern original. */
3154 aspath_unintern (attr.aspath);
3155}
3156
paul94f2b392005-06-28 12:44:16 +00003157static void
paulfee0f4c2004-09-13 05:12:46 +00003158bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003159 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3160{
3161 struct bgp_node *rn;
3162 struct bgp_info *ri;
3163 struct bgp_info *new;
3164 struct bgp_info info;
3165 struct attr attr;
paul286e1e72003-08-08 00:24:31 +00003166 struct attr attr_tmp;
paul718e3742002-12-13 20:15:29 +00003167 struct attr *attr_new;
3168 int ret;
3169
Paul Jakmadd8103a2006-05-12 23:27:30 +00003170 assert (bgp_static);
3171 if (!bgp_static)
3172 return;
3173
paulfee0f4c2004-09-13 05:12:46 +00003174 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003175
3176 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003177
3178 attr.nexthop = bgp_static->igpnexthop;
3179 attr.med = bgp_static->igpmetric;
3180 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003181
3182 /* Apply route-map. */
3183 if (bgp_static->rmap.name)
3184 {
paul286e1e72003-08-08 00:24:31 +00003185 attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003186 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003187 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003188
paulfee0f4c2004-09-13 05:12:46 +00003189 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3190
paul718e3742002-12-13 20:15:29 +00003191 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003192
paulfee0f4c2004-09-13 05:12:46 +00003193 bgp->peer_self->rmap_type = 0;
3194
paul718e3742002-12-13 20:15:29 +00003195 if (ret == RMAP_DENYMATCH)
3196 {
3197 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003198 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003199
3200 /* Unintern original. */
3201 aspath_unintern (attr.aspath);
3202 bgp_static_withdraw (bgp, p, afi, safi);
3203 return;
3204 }
paul286e1e72003-08-08 00:24:31 +00003205 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003206 }
paul286e1e72003-08-08 00:24:31 +00003207 else
3208 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003209
3210 for (ri = rn->info; ri; ri = ri->next)
3211 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3212 && ri->sub_type == BGP_ROUTE_STATIC)
3213 break;
3214
3215 if (ri)
3216 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003217 if (attrhash_cmp (ri->attr, attr_new) &&
3218 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003219 {
3220 bgp_unlock_node (rn);
3221 bgp_attr_unintern (attr_new);
3222 aspath_unintern (attr.aspath);
3223 return;
3224 }
3225 else
3226 {
3227 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003228 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003229
3230 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003231 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3232 bgp_info_restore(rn, ri);
3233 else
3234 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003235 bgp_attr_unintern (ri->attr);
3236 ri->attr = attr_new;
3237 ri->uptime = time (NULL);
3238
3239 /* Process change. */
3240 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3241 bgp_process (bgp, rn, afi, safi);
3242 bgp_unlock_node (rn);
3243 aspath_unintern (attr.aspath);
3244 return;
3245 }
3246 }
3247
3248 /* Make new BGP info. */
3249 new = bgp_info_new ();
3250 new->type = ZEBRA_ROUTE_BGP;
3251 new->sub_type = BGP_ROUTE_STATIC;
3252 new->peer = bgp->peer_self;
3253 SET_FLAG (new->flags, BGP_INFO_VALID);
3254 new->attr = attr_new;
3255 new->uptime = time (NULL);
3256
3257 /* Aggregate address increment. */
3258 bgp_aggregate_increment (bgp, p, new, afi, safi);
3259
3260 /* Register new BGP information. */
3261 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003262
3263 /* route_node_get lock */
3264 bgp_unlock_node (rn);
3265
paul718e3742002-12-13 20:15:29 +00003266 /* Process change. */
3267 bgp_process (bgp, rn, afi, safi);
3268
3269 /* Unintern original. */
3270 aspath_unintern (attr.aspath);
3271}
3272
3273void
paulfee0f4c2004-09-13 05:12:46 +00003274bgp_static_update (struct bgp *bgp, struct prefix *p,
3275 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3276{
3277 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003278 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003279
3280 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3281
paul1eb8ef22005-04-07 07:30:20 +00003282 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003283 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003284 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3285 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003286 }
3287}
3288
paul94f2b392005-06-28 12:44:16 +00003289static void
paul718e3742002-12-13 20:15:29 +00003290bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3291 u_char safi, struct prefix_rd *prd, u_char *tag)
3292{
3293 struct bgp_node *rn;
3294 struct bgp_info *new;
3295
paulfee0f4c2004-09-13 05:12:46 +00003296 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003297
3298 /* Make new BGP info. */
3299 new = bgp_info_new ();
3300 new->type = ZEBRA_ROUTE_BGP;
3301 new->sub_type = BGP_ROUTE_STATIC;
3302 new->peer = bgp->peer_self;
3303 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3304 SET_FLAG (new->flags, BGP_INFO_VALID);
3305 new->uptime = time (NULL);
3306 memcpy (new->tag, tag, 3);
3307
3308 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003309 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003310
3311 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003312 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003313
paul200df112005-06-01 11:17:05 +00003314 /* route_node_get lock */
3315 bgp_unlock_node (rn);
3316
paul718e3742002-12-13 20:15:29 +00003317 /* Process change. */
3318 bgp_process (bgp, rn, afi, safi);
3319}
3320
3321void
3322bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3323 safi_t safi)
3324{
3325 struct bgp_node *rn;
3326 struct bgp_info *ri;
3327
paulfee0f4c2004-09-13 05:12:46 +00003328 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003329
3330 /* Check selected route and self inserted route. */
3331 for (ri = rn->info; ri; ri = ri->next)
3332 if (ri->peer == bgp->peer_self
3333 && ri->type == ZEBRA_ROUTE_BGP
3334 && ri->sub_type == BGP_ROUTE_STATIC)
3335 break;
3336
3337 /* Withdraw static BGP route from routing table. */
3338 if (ri)
3339 {
3340 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003341 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003342 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003343 }
3344
3345 /* Unlock bgp_node_lookup. */
3346 bgp_unlock_node (rn);
3347}
3348
3349void
paulfee0f4c2004-09-13 05:12:46 +00003350bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3351{
3352 struct bgp_static *bgp_static;
3353 struct bgp *bgp;
3354 struct bgp_node *rn;
3355 struct prefix *p;
3356
3357 bgp = rsclient->bgp;
3358
3359 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3360 if ((bgp_static = rn->info) != NULL)
3361 {
3362 p = &rn->p;
3363
3364 bgp_static_update_rsclient (rsclient, p, bgp_static,
3365 afi, safi);
3366 }
3367}
3368
paul94f2b392005-06-28 12:44:16 +00003369static void
paul718e3742002-12-13 20:15:29 +00003370bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3371 u_char safi, struct prefix_rd *prd, u_char *tag)
3372{
3373 struct bgp_node *rn;
3374 struct bgp_info *ri;
3375
paulfee0f4c2004-09-13 05:12:46 +00003376 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003377
3378 /* Check selected route and self inserted route. */
3379 for (ri = rn->info; ri; ri = ri->next)
3380 if (ri->peer == bgp->peer_self
3381 && ri->type == ZEBRA_ROUTE_BGP
3382 && ri->sub_type == BGP_ROUTE_STATIC)
3383 break;
3384
3385 /* Withdraw static BGP route from routing table. */
3386 if (ri)
3387 {
3388 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003389 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003390 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003391 }
3392
3393 /* Unlock bgp_node_lookup. */
3394 bgp_unlock_node (rn);
3395}
3396
3397/* Configure static BGP network. When user don't run zebra, static
3398 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003399static int
paulfd79ac92004-10-13 05:06:08 +00003400bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3401 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003402{
3403 int ret;
3404 struct prefix p;
3405 struct bgp_static *bgp_static;
3406 struct bgp_node *rn;
3407 int need_update = 0;
3408
3409 /* Convert IP prefix string to struct prefix. */
3410 ret = str2prefix (ip_str, &p);
3411 if (! ret)
3412 {
3413 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3414 return CMD_WARNING;
3415 }
3416#ifdef HAVE_IPV6
3417 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3418 {
3419 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3420 VTY_NEWLINE);
3421 return CMD_WARNING;
3422 }
3423#endif /* HAVE_IPV6 */
3424
3425 apply_mask (&p);
3426
3427 /* Set BGP static route configuration. */
3428 rn = bgp_node_get (bgp->route[afi][safi], &p);
3429
3430 if (rn->info)
3431 {
3432 /* Configuration change. */
3433 bgp_static = rn->info;
3434
3435 /* Check previous routes are installed into BGP. */
3436 if (! bgp_static->backdoor && bgp_static->valid)
3437 need_update = 1;
3438
3439 bgp_static->backdoor = backdoor;
3440 if (rmap)
3441 {
3442 if (bgp_static->rmap.name)
3443 free (bgp_static->rmap.name);
3444 bgp_static->rmap.name = strdup (rmap);
3445 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3446 }
3447 else
3448 {
3449 if (bgp_static->rmap.name)
3450 free (bgp_static->rmap.name);
3451 bgp_static->rmap.name = NULL;
3452 bgp_static->rmap.map = NULL;
3453 bgp_static->valid = 0;
3454 }
3455 bgp_unlock_node (rn);
3456 }
3457 else
3458 {
3459 /* New configuration. */
3460 bgp_static = bgp_static_new ();
3461 bgp_static->backdoor = backdoor;
3462 bgp_static->valid = 0;
3463 bgp_static->igpmetric = 0;
3464 bgp_static->igpnexthop.s_addr = 0;
3465 if (rmap)
3466 {
3467 if (bgp_static->rmap.name)
3468 free (bgp_static->rmap.name);
3469 bgp_static->rmap.name = strdup (rmap);
3470 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3471 }
3472 rn->info = bgp_static;
3473 }
3474
3475 /* If BGP scan is not enabled, we should install this route here. */
3476 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3477 {
3478 bgp_static->valid = 1;
3479
3480 if (need_update)
3481 bgp_static_withdraw (bgp, &p, afi, safi);
3482
3483 if (! bgp_static->backdoor)
3484 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3485 }
3486
3487 return CMD_SUCCESS;
3488}
3489
3490/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003491static int
paulfd79ac92004-10-13 05:06:08 +00003492bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003493 u_int16_t afi, u_char safi)
3494{
3495 int ret;
3496 struct prefix p;
3497 struct bgp_static *bgp_static;
3498 struct bgp_node *rn;
3499
3500 /* Convert IP prefix string to struct prefix. */
3501 ret = str2prefix (ip_str, &p);
3502 if (! ret)
3503 {
3504 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3505 return CMD_WARNING;
3506 }
3507#ifdef HAVE_IPV6
3508 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3509 {
3510 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3511 VTY_NEWLINE);
3512 return CMD_WARNING;
3513 }
3514#endif /* HAVE_IPV6 */
3515
3516 apply_mask (&p);
3517
3518 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3519 if (! rn)
3520 {
3521 vty_out (vty, "%% Can't find specified static route configuration.%s",
3522 VTY_NEWLINE);
3523 return CMD_WARNING;
3524 }
3525
3526 bgp_static = rn->info;
3527
3528 /* Update BGP RIB. */
3529 if (! bgp_static->backdoor)
3530 bgp_static_withdraw (bgp, &p, afi, safi);
3531
3532 /* Clear configuration. */
3533 bgp_static_free (bgp_static);
3534 rn->info = NULL;
3535 bgp_unlock_node (rn);
3536 bgp_unlock_node (rn);
3537
3538 return CMD_SUCCESS;
3539}
3540
3541/* Called from bgp_delete(). Delete all static routes from the BGP
3542 instance. */
3543void
3544bgp_static_delete (struct bgp *bgp)
3545{
3546 afi_t afi;
3547 safi_t safi;
3548 struct bgp_node *rn;
3549 struct bgp_node *rm;
3550 struct bgp_table *table;
3551 struct bgp_static *bgp_static;
3552
3553 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3554 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3555 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3556 if (rn->info != NULL)
3557 {
3558 if (safi == SAFI_MPLS_VPN)
3559 {
3560 table = rn->info;
3561
3562 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3563 {
3564 bgp_static = rn->info;
3565 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3566 AFI_IP, SAFI_MPLS_VPN,
3567 (struct prefix_rd *)&rn->p,
3568 bgp_static->tag);
3569 bgp_static_free (bgp_static);
3570 rn->info = NULL;
3571 bgp_unlock_node (rn);
3572 }
3573 }
3574 else
3575 {
3576 bgp_static = rn->info;
3577 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3578 bgp_static_free (bgp_static);
3579 rn->info = NULL;
3580 bgp_unlock_node (rn);
3581 }
3582 }
3583}
3584
3585int
paulfd79ac92004-10-13 05:06:08 +00003586bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3587 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003588{
3589 int ret;
3590 struct prefix p;
3591 struct prefix_rd prd;
3592 struct bgp *bgp;
3593 struct bgp_node *prn;
3594 struct bgp_node *rn;
3595 struct bgp_table *table;
3596 struct bgp_static *bgp_static;
3597 u_char tag[3];
3598
3599 bgp = vty->index;
3600
3601 ret = str2prefix (ip_str, &p);
3602 if (! ret)
3603 {
3604 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3605 return CMD_WARNING;
3606 }
3607 apply_mask (&p);
3608
3609 ret = str2prefix_rd (rd_str, &prd);
3610 if (! ret)
3611 {
3612 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3613 return CMD_WARNING;
3614 }
3615
3616 ret = str2tag (tag_str, tag);
3617 if (! ret)
3618 {
3619 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3620 return CMD_WARNING;
3621 }
3622
3623 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3624 (struct prefix *)&prd);
3625 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003626 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003627 else
3628 bgp_unlock_node (prn);
3629 table = prn->info;
3630
3631 rn = bgp_node_get (table, &p);
3632
3633 if (rn->info)
3634 {
3635 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3636 bgp_unlock_node (rn);
3637 }
3638 else
3639 {
3640 /* New configuration. */
3641 bgp_static = bgp_static_new ();
3642 bgp_static->valid = 1;
3643 memcpy (bgp_static->tag, tag, 3);
3644 rn->info = bgp_static;
3645
3646 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3647 }
3648
3649 return CMD_SUCCESS;
3650}
3651
3652/* Configure static BGP network. */
3653int
paulfd79ac92004-10-13 05:06:08 +00003654bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3655 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003656{
3657 int ret;
3658 struct bgp *bgp;
3659 struct prefix p;
3660 struct prefix_rd prd;
3661 struct bgp_node *prn;
3662 struct bgp_node *rn;
3663 struct bgp_table *table;
3664 struct bgp_static *bgp_static;
3665 u_char tag[3];
3666
3667 bgp = vty->index;
3668
3669 /* Convert IP prefix string to struct prefix. */
3670 ret = str2prefix (ip_str, &p);
3671 if (! ret)
3672 {
3673 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3674 return CMD_WARNING;
3675 }
3676 apply_mask (&p);
3677
3678 ret = str2prefix_rd (rd_str, &prd);
3679 if (! ret)
3680 {
3681 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3682 return CMD_WARNING;
3683 }
3684
3685 ret = str2tag (tag_str, tag);
3686 if (! ret)
3687 {
3688 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3689 return CMD_WARNING;
3690 }
3691
3692 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3693 (struct prefix *)&prd);
3694 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003695 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003696 else
3697 bgp_unlock_node (prn);
3698 table = prn->info;
3699
3700 rn = bgp_node_lookup (table, &p);
3701
3702 if (rn)
3703 {
3704 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3705
3706 bgp_static = rn->info;
3707 bgp_static_free (bgp_static);
3708 rn->info = NULL;
3709 bgp_unlock_node (rn);
3710 bgp_unlock_node (rn);
3711 }
3712 else
3713 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3714
3715 return CMD_SUCCESS;
3716}
3717
3718DEFUN (bgp_network,
3719 bgp_network_cmd,
3720 "network A.B.C.D/M",
3721 "Specify a network to announce via BGP\n"
3722 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3723{
3724 return bgp_static_set (vty, vty->index, argv[0],
3725 AFI_IP, bgp_node_safi (vty), NULL, 0);
3726}
3727
3728DEFUN (bgp_network_route_map,
3729 bgp_network_route_map_cmd,
3730 "network A.B.C.D/M route-map WORD",
3731 "Specify a network to announce via BGP\n"
3732 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3733 "Route-map to modify the attributes\n"
3734 "Name of the route map\n")
3735{
3736 return bgp_static_set (vty, vty->index, argv[0],
3737 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3738}
3739
3740DEFUN (bgp_network_backdoor,
3741 bgp_network_backdoor_cmd,
3742 "network A.B.C.D/M backdoor",
3743 "Specify a network to announce via BGP\n"
3744 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3745 "Specify a BGP backdoor route\n")
3746{
3747 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
3748}
3749
3750DEFUN (bgp_network_mask,
3751 bgp_network_mask_cmd,
3752 "network A.B.C.D mask A.B.C.D",
3753 "Specify a network to announce via BGP\n"
3754 "Network number\n"
3755 "Network mask\n"
3756 "Network mask\n")
3757{
3758 int ret;
3759 char prefix_str[BUFSIZ];
3760
3761 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3762 if (! ret)
3763 {
3764 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3765 return CMD_WARNING;
3766 }
3767
3768 return bgp_static_set (vty, vty->index, prefix_str,
3769 AFI_IP, bgp_node_safi (vty), NULL, 0);
3770}
3771
3772DEFUN (bgp_network_mask_route_map,
3773 bgp_network_mask_route_map_cmd,
3774 "network A.B.C.D mask A.B.C.D route-map WORD",
3775 "Specify a network to announce via BGP\n"
3776 "Network number\n"
3777 "Network mask\n"
3778 "Network mask\n"
3779 "Route-map to modify the attributes\n"
3780 "Name of the route map\n")
3781{
3782 int ret;
3783 char prefix_str[BUFSIZ];
3784
3785 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3786 if (! ret)
3787 {
3788 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3789 return CMD_WARNING;
3790 }
3791
3792 return bgp_static_set (vty, vty->index, prefix_str,
3793 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3794}
3795
3796DEFUN (bgp_network_mask_backdoor,
3797 bgp_network_mask_backdoor_cmd,
3798 "network A.B.C.D mask A.B.C.D backdoor",
3799 "Specify a network to announce via BGP\n"
3800 "Network number\n"
3801 "Network mask\n"
3802 "Network mask\n"
3803 "Specify a BGP backdoor route\n")
3804{
3805 int ret;
3806 char prefix_str[BUFSIZ];
3807
3808 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3809 if (! ret)
3810 {
3811 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3812 return CMD_WARNING;
3813 }
3814
3815 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3816}
3817
3818DEFUN (bgp_network_mask_natural,
3819 bgp_network_mask_natural_cmd,
3820 "network A.B.C.D",
3821 "Specify a network to announce via BGP\n"
3822 "Network number\n")
3823{
3824 int ret;
3825 char prefix_str[BUFSIZ];
3826
3827 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3828 if (! ret)
3829 {
3830 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3831 return CMD_WARNING;
3832 }
3833
3834 return bgp_static_set (vty, vty->index, prefix_str,
3835 AFI_IP, bgp_node_safi (vty), NULL, 0);
3836}
3837
3838DEFUN (bgp_network_mask_natural_route_map,
3839 bgp_network_mask_natural_route_map_cmd,
3840 "network A.B.C.D route-map WORD",
3841 "Specify a network to announce via BGP\n"
3842 "Network number\n"
3843 "Route-map to modify the attributes\n"
3844 "Name of the route map\n")
3845{
3846 int ret;
3847 char prefix_str[BUFSIZ];
3848
3849 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3850 if (! ret)
3851 {
3852 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3853 return CMD_WARNING;
3854 }
3855
3856 return bgp_static_set (vty, vty->index, prefix_str,
3857 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3858}
3859
3860DEFUN (bgp_network_mask_natural_backdoor,
3861 bgp_network_mask_natural_backdoor_cmd,
3862 "network A.B.C.D backdoor",
3863 "Specify a network to announce via BGP\n"
3864 "Network number\n"
3865 "Specify a BGP backdoor route\n")
3866{
3867 int ret;
3868 char prefix_str[BUFSIZ];
3869
3870 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3871 if (! ret)
3872 {
3873 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3874 return CMD_WARNING;
3875 }
3876
3877 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3878}
3879
3880DEFUN (no_bgp_network,
3881 no_bgp_network_cmd,
3882 "no network A.B.C.D/M",
3883 NO_STR
3884 "Specify a network to announce via BGP\n"
3885 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3886{
3887 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
3888 bgp_node_safi (vty));
3889}
3890
3891ALIAS (no_bgp_network,
3892 no_bgp_network_route_map_cmd,
3893 "no network A.B.C.D/M route-map WORD",
3894 NO_STR
3895 "Specify a network to announce via BGP\n"
3896 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3897 "Route-map to modify the attributes\n"
3898 "Name of the route map\n")
3899
3900ALIAS (no_bgp_network,
3901 no_bgp_network_backdoor_cmd,
3902 "no network A.B.C.D/M backdoor",
3903 NO_STR
3904 "Specify a network to announce via BGP\n"
3905 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3906 "Specify a BGP backdoor route\n")
3907
3908DEFUN (no_bgp_network_mask,
3909 no_bgp_network_mask_cmd,
3910 "no network A.B.C.D mask A.B.C.D",
3911 NO_STR
3912 "Specify a network to announce via BGP\n"
3913 "Network number\n"
3914 "Network mask\n"
3915 "Network mask\n")
3916{
3917 int ret;
3918 char prefix_str[BUFSIZ];
3919
3920 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3921 if (! ret)
3922 {
3923 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3924 return CMD_WARNING;
3925 }
3926
3927 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3928 bgp_node_safi (vty));
3929}
3930
3931ALIAS (no_bgp_network_mask,
3932 no_bgp_network_mask_route_map_cmd,
3933 "no network A.B.C.D mask A.B.C.D route-map WORD",
3934 NO_STR
3935 "Specify a network to announce via BGP\n"
3936 "Network number\n"
3937 "Network mask\n"
3938 "Network mask\n"
3939 "Route-map to modify the attributes\n"
3940 "Name of the route map\n")
3941
3942ALIAS (no_bgp_network_mask,
3943 no_bgp_network_mask_backdoor_cmd,
3944 "no network A.B.C.D mask A.B.C.D backdoor",
3945 NO_STR
3946 "Specify a network to announce via BGP\n"
3947 "Network number\n"
3948 "Network mask\n"
3949 "Network mask\n"
3950 "Specify a BGP backdoor route\n")
3951
3952DEFUN (no_bgp_network_mask_natural,
3953 no_bgp_network_mask_natural_cmd,
3954 "no network A.B.C.D",
3955 NO_STR
3956 "Specify a network to announce via BGP\n"
3957 "Network number\n")
3958{
3959 int ret;
3960 char prefix_str[BUFSIZ];
3961
3962 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3963 if (! ret)
3964 {
3965 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3966 return CMD_WARNING;
3967 }
3968
3969 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3970 bgp_node_safi (vty));
3971}
3972
3973ALIAS (no_bgp_network_mask_natural,
3974 no_bgp_network_mask_natural_route_map_cmd,
3975 "no network A.B.C.D route-map WORD",
3976 NO_STR
3977 "Specify a network to announce via BGP\n"
3978 "Network number\n"
3979 "Route-map to modify the attributes\n"
3980 "Name of the route map\n")
3981
3982ALIAS (no_bgp_network_mask_natural,
3983 no_bgp_network_mask_natural_backdoor_cmd,
3984 "no network A.B.C.D backdoor",
3985 NO_STR
3986 "Specify a network to announce via BGP\n"
3987 "Network number\n"
3988 "Specify a BGP backdoor route\n")
3989
3990#ifdef HAVE_IPV6
3991DEFUN (ipv6_bgp_network,
3992 ipv6_bgp_network_cmd,
3993 "network X:X::X:X/M",
3994 "Specify a network to announce via BGP\n"
3995 "IPv6 prefix <network>/<length>\n")
3996{
3997 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
3998}
3999
4000DEFUN (ipv6_bgp_network_route_map,
4001 ipv6_bgp_network_route_map_cmd,
4002 "network X:X::X:X/M route-map WORD",
4003 "Specify a network to announce via BGP\n"
4004 "IPv6 prefix <network>/<length>\n"
4005 "Route-map to modify the attributes\n"
4006 "Name of the route map\n")
4007{
4008 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4009 bgp_node_safi (vty), argv[1], 0);
4010}
4011
4012DEFUN (no_ipv6_bgp_network,
4013 no_ipv6_bgp_network_cmd,
4014 "no network X:X::X:X/M",
4015 NO_STR
4016 "Specify a network to announce via BGP\n"
4017 "IPv6 prefix <network>/<length>\n")
4018{
4019 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4020}
4021
4022ALIAS (no_ipv6_bgp_network,
4023 no_ipv6_bgp_network_route_map_cmd,
4024 "no network X:X::X:X/M route-map WORD",
4025 NO_STR
4026 "Specify a network to announce via BGP\n"
4027 "IPv6 prefix <network>/<length>\n"
4028 "Route-map to modify the attributes\n"
4029 "Name of the route map\n")
4030
4031ALIAS (ipv6_bgp_network,
4032 old_ipv6_bgp_network_cmd,
4033 "ipv6 bgp network X:X::X:X/M",
4034 IPV6_STR
4035 BGP_STR
4036 "Specify a network to announce via BGP\n"
4037 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4038
4039ALIAS (no_ipv6_bgp_network,
4040 old_no_ipv6_bgp_network_cmd,
4041 "no ipv6 bgp network X:X::X:X/M",
4042 NO_STR
4043 IPV6_STR
4044 BGP_STR
4045 "Specify a network to announce via BGP\n"
4046 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4047#endif /* HAVE_IPV6 */
4048
4049/* Aggreagete address:
4050
4051 advertise-map Set condition to advertise attribute
4052 as-set Generate AS set path information
4053 attribute-map Set attributes of aggregate
4054 route-map Set parameters of aggregate
4055 summary-only Filter more specific routes from updates
4056 suppress-map Conditionally filter more specific routes from updates
4057 <cr>
4058 */
4059struct bgp_aggregate
4060{
4061 /* Summary-only flag. */
4062 u_char summary_only;
4063
4064 /* AS set generation. */
4065 u_char as_set;
4066
4067 /* Route-map for aggregated route. */
4068 struct route_map *map;
4069
4070 /* Suppress-count. */
4071 unsigned long count;
4072
4073 /* SAFI configuration. */
4074 safi_t safi;
4075};
4076
paul94f2b392005-06-28 12:44:16 +00004077static struct bgp_aggregate *
paul718e3742002-12-13 20:15:29 +00004078bgp_aggregate_new ()
4079{
4080 struct bgp_aggregate *new;
4081 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4082 memset (new, 0, sizeof (struct bgp_aggregate));
4083 return new;
4084}
4085
paul94f2b392005-06-28 12:44:16 +00004086static void
paul718e3742002-12-13 20:15:29 +00004087bgp_aggregate_free (struct bgp_aggregate *aggregate)
4088{
4089 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4090}
4091
paul94f2b392005-06-28 12:44:16 +00004092static void
paul718e3742002-12-13 20:15:29 +00004093bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4094 afi_t afi, safi_t safi, struct bgp_info *del,
4095 struct bgp_aggregate *aggregate)
4096{
4097 struct bgp_table *table;
4098 struct bgp_node *top;
4099 struct bgp_node *rn;
4100 u_char origin;
4101 struct aspath *aspath = NULL;
4102 struct aspath *asmerge = NULL;
4103 struct community *community = NULL;
4104 struct community *commerge = NULL;
4105 struct in_addr nexthop;
4106 u_int32_t med = 0;
4107 struct bgp_info *ri;
4108 struct bgp_info *new;
4109 int first = 1;
4110 unsigned long match = 0;
4111
4112 /* Record adding route's nexthop and med. */
4113 if (rinew)
4114 {
4115 nexthop = rinew->attr->nexthop;
4116 med = rinew->attr->med;
4117 }
4118
4119 /* ORIGIN attribute: If at least one route among routes that are
4120 aggregated has ORIGIN with the value INCOMPLETE, then the
4121 aggregated route must have the ORIGIN attribute with the value
4122 INCOMPLETE. Otherwise, if at least one route among routes that
4123 are aggregated has ORIGIN with the value EGP, then the aggregated
4124 route must have the origin attribute with the value EGP. In all
4125 other case the value of the ORIGIN attribute of the aggregated
4126 route is INTERNAL. */
4127 origin = BGP_ORIGIN_IGP;
4128
4129 table = bgp->rib[afi][safi];
4130
4131 top = bgp_node_get (table, p);
4132 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4133 if (rn->p.prefixlen > p->prefixlen)
4134 {
4135 match = 0;
4136
4137 for (ri = rn->info; ri; ri = ri->next)
4138 {
4139 if (BGP_INFO_HOLDDOWN (ri))
4140 continue;
4141
4142 if (del && ri == del)
4143 continue;
4144
4145 if (! rinew && first)
4146 {
4147 nexthop = ri->attr->nexthop;
4148 med = ri->attr->med;
4149 first = 0;
4150 }
4151
4152#ifdef AGGREGATE_NEXTHOP_CHECK
4153 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4154 || ri->attr->med != med)
4155 {
4156 if (aspath)
4157 aspath_free (aspath);
4158 if (community)
4159 community_free (community);
4160 bgp_unlock_node (rn);
4161 bgp_unlock_node (top);
4162 return;
4163 }
4164#endif /* AGGREGATE_NEXTHOP_CHECK */
4165
4166 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4167 {
4168 if (aggregate->summary_only)
4169 {
4170 ri->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004171 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004172 match++;
4173 }
4174
4175 aggregate->count++;
4176
4177 if (aggregate->as_set)
4178 {
4179 if (origin < ri->attr->origin)
4180 origin = ri->attr->origin;
4181
4182 if (aspath)
4183 {
4184 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4185 aspath_free (aspath);
4186 aspath = asmerge;
4187 }
4188 else
4189 aspath = aspath_dup (ri->attr->aspath);
4190
4191 if (ri->attr->community)
4192 {
4193 if (community)
4194 {
4195 commerge = community_merge (community,
4196 ri->attr->community);
4197 community = community_uniq_sort (commerge);
4198 community_free (commerge);
4199 }
4200 else
4201 community = community_dup (ri->attr->community);
4202 }
4203 }
4204 }
4205 }
4206 if (match)
4207 bgp_process (bgp, rn, afi, safi);
4208 }
4209 bgp_unlock_node (top);
4210
4211 if (rinew)
4212 {
4213 aggregate->count++;
4214
4215 if (aggregate->summary_only)
4216 rinew->suppress++;
4217
4218 if (aggregate->as_set)
4219 {
4220 if (origin < rinew->attr->origin)
4221 origin = rinew->attr->origin;
4222
4223 if (aspath)
4224 {
4225 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4226 aspath_free (aspath);
4227 aspath = asmerge;
4228 }
4229 else
4230 aspath = aspath_dup (rinew->attr->aspath);
4231
4232 if (rinew->attr->community)
4233 {
4234 if (community)
4235 {
4236 commerge = community_merge (community,
4237 rinew->attr->community);
4238 community = community_uniq_sort (commerge);
4239 community_free (commerge);
4240 }
4241 else
4242 community = community_dup (rinew->attr->community);
4243 }
4244 }
4245 }
4246
4247 if (aggregate->count > 0)
4248 {
4249 rn = bgp_node_get (table, p);
4250 new = bgp_info_new ();
4251 new->type = ZEBRA_ROUTE_BGP;
4252 new->sub_type = BGP_ROUTE_AGGREGATE;
4253 new->peer = bgp->peer_self;
4254 SET_FLAG (new->flags, BGP_INFO_VALID);
4255 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4256 new->uptime = time (NULL);
4257
4258 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004259 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004260 bgp_process (bgp, rn, afi, safi);
4261 }
4262 else
4263 {
4264 if (aspath)
4265 aspath_free (aspath);
4266 if (community)
4267 community_free (community);
4268 }
4269}
4270
4271void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4272 struct bgp_aggregate *);
4273
4274void
4275bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4276 struct bgp_info *ri, afi_t afi, safi_t safi)
4277{
4278 struct bgp_node *child;
4279 struct bgp_node *rn;
4280 struct bgp_aggregate *aggregate;
4281
4282 /* MPLS-VPN aggregation is not yet supported. */
4283 if (safi == SAFI_MPLS_VPN)
4284 return;
4285
4286 if (p->prefixlen == 0)
4287 return;
4288
4289 if (BGP_INFO_HOLDDOWN (ri))
4290 return;
4291
4292 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4293
4294 /* Aggregate address configuration check. */
4295 for (rn = child; rn; rn = rn->parent)
4296 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4297 {
4298 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004299 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004300 }
4301 bgp_unlock_node (child);
4302}
4303
4304void
4305bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4306 struct bgp_info *del, afi_t afi, safi_t safi)
4307{
4308 struct bgp_node *child;
4309 struct bgp_node *rn;
4310 struct bgp_aggregate *aggregate;
4311
4312 /* MPLS-VPN aggregation is not yet supported. */
4313 if (safi == SAFI_MPLS_VPN)
4314 return;
4315
4316 if (p->prefixlen == 0)
4317 return;
4318
4319 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4320
4321 /* Aggregate address configuration check. */
4322 for (rn = child; rn; rn = rn->parent)
4323 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4324 {
4325 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004326 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004327 }
4328 bgp_unlock_node (child);
4329}
4330
paul94f2b392005-06-28 12:44:16 +00004331static void
paul718e3742002-12-13 20:15:29 +00004332bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4333 struct bgp_aggregate *aggregate)
4334{
4335 struct bgp_table *table;
4336 struct bgp_node *top;
4337 struct bgp_node *rn;
4338 struct bgp_info *new;
4339 struct bgp_info *ri;
4340 unsigned long match;
4341 u_char origin = BGP_ORIGIN_IGP;
4342 struct aspath *aspath = NULL;
4343 struct aspath *asmerge = NULL;
4344 struct community *community = NULL;
4345 struct community *commerge = NULL;
4346
4347 table = bgp->rib[afi][safi];
4348
4349 /* Sanity check. */
4350 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4351 return;
4352 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4353 return;
4354
4355 /* If routes exists below this node, generate aggregate routes. */
4356 top = bgp_node_get (table, p);
4357 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4358 if (rn->p.prefixlen > p->prefixlen)
4359 {
4360 match = 0;
4361
4362 for (ri = rn->info; ri; ri = ri->next)
4363 {
4364 if (BGP_INFO_HOLDDOWN (ri))
4365 continue;
4366
4367 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4368 {
4369 /* summary-only aggregate route suppress aggregated
4370 route announcement. */
4371 if (aggregate->summary_only)
4372 {
4373 ri->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004374 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004375 match++;
4376 }
4377 /* as-set aggregate route generate origin, as path,
4378 community aggregation. */
4379 if (aggregate->as_set)
4380 {
4381 if (origin < ri->attr->origin)
4382 origin = ri->attr->origin;
4383
4384 if (aspath)
4385 {
4386 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4387 aspath_free (aspath);
4388 aspath = asmerge;
4389 }
4390 else
4391 aspath = aspath_dup (ri->attr->aspath);
4392
4393 if (ri->attr->community)
4394 {
4395 if (community)
4396 {
4397 commerge = community_merge (community,
4398 ri->attr->community);
4399 community = community_uniq_sort (commerge);
4400 community_free (commerge);
4401 }
4402 else
4403 community = community_dup (ri->attr->community);
4404 }
4405 }
4406 aggregate->count++;
4407 }
4408 }
4409
4410 /* If this node is suppressed, process the change. */
4411 if (match)
4412 bgp_process (bgp, rn, afi, safi);
4413 }
4414 bgp_unlock_node (top);
4415
4416 /* Add aggregate route to BGP table. */
4417 if (aggregate->count)
4418 {
4419 rn = bgp_node_get (table, p);
4420
4421 new = bgp_info_new ();
4422 new->type = ZEBRA_ROUTE_BGP;
4423 new->sub_type = BGP_ROUTE_AGGREGATE;
4424 new->peer = bgp->peer_self;
4425 SET_FLAG (new->flags, BGP_INFO_VALID);
4426 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4427 new->uptime = time (NULL);
4428
4429 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004430 bgp_unlock_node (rn);
4431
paul718e3742002-12-13 20:15:29 +00004432 /* Process change. */
4433 bgp_process (bgp, rn, afi, safi);
4434 }
4435}
4436
4437void
4438bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4439 safi_t safi, struct bgp_aggregate *aggregate)
4440{
4441 struct bgp_table *table;
4442 struct bgp_node *top;
4443 struct bgp_node *rn;
4444 struct bgp_info *ri;
4445 unsigned long match;
4446
4447 table = bgp->rib[afi][safi];
4448
4449 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4450 return;
4451 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4452 return;
4453
4454 /* If routes exists below this node, generate aggregate routes. */
4455 top = bgp_node_get (table, p);
4456 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4457 if (rn->p.prefixlen > p->prefixlen)
4458 {
4459 match = 0;
4460
4461 for (ri = rn->info; ri; ri = ri->next)
4462 {
4463 if (BGP_INFO_HOLDDOWN (ri))
4464 continue;
4465
4466 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4467 {
4468 if (aggregate->summary_only)
4469 {
4470 ri->suppress--;
4471
4472 if (ri->suppress == 0)
4473 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004474 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004475 match++;
4476 }
4477 }
4478 aggregate->count--;
4479 }
4480 }
4481
4482 /* If this node is suppressed, process the change. */
4483 if (match)
4484 bgp_process (bgp, rn, afi, safi);
4485 }
4486 bgp_unlock_node (top);
4487
4488 /* Delete aggregate route from BGP table. */
4489 rn = bgp_node_get (table, p);
4490
4491 for (ri = rn->info; ri; ri = ri->next)
4492 if (ri->peer == bgp->peer_self
4493 && ri->type == ZEBRA_ROUTE_BGP
4494 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4495 break;
4496
4497 /* Withdraw static BGP route from routing table. */
4498 if (ri)
4499 {
paul718e3742002-12-13 20:15:29 +00004500 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004501 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004502 }
4503
4504 /* Unlock bgp_node_lookup. */
4505 bgp_unlock_node (rn);
4506}
4507
4508/* Aggregate route attribute. */
4509#define AGGREGATE_SUMMARY_ONLY 1
4510#define AGGREGATE_AS_SET 1
4511
paul94f2b392005-06-28 12:44:16 +00004512static int
paulfd79ac92004-10-13 05:06:08 +00004513bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4514 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004515 u_char summary_only, u_char as_set)
4516{
4517 int ret;
4518 struct prefix p;
4519 struct bgp_node *rn;
4520 struct bgp *bgp;
4521 struct bgp_aggregate *aggregate;
4522
4523 /* Convert string to prefix structure. */
4524 ret = str2prefix (prefix_str, &p);
4525 if (!ret)
4526 {
4527 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4528 return CMD_WARNING;
4529 }
4530 apply_mask (&p);
4531
4532 /* Get BGP structure. */
4533 bgp = vty->index;
4534
4535 /* Old configuration check. */
4536 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4537
4538 if (rn->info)
4539 {
4540 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4541 bgp_unlock_node (rn);
4542 return CMD_WARNING;
4543 }
4544
4545 /* Make aggregate address structure. */
4546 aggregate = bgp_aggregate_new ();
4547 aggregate->summary_only = summary_only;
4548 aggregate->as_set = as_set;
4549 aggregate->safi = safi;
4550 rn->info = aggregate;
4551
4552 /* Aggregate address insert into BGP routing table. */
4553 if (safi & SAFI_UNICAST)
4554 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4555 if (safi & SAFI_MULTICAST)
4556 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4557
4558 return CMD_SUCCESS;
4559}
4560
paul94f2b392005-06-28 12:44:16 +00004561static int
paulfd79ac92004-10-13 05:06:08 +00004562bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4563 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004564{
4565 int ret;
4566 struct prefix p;
4567 struct bgp_node *rn;
4568 struct bgp *bgp;
4569 struct bgp_aggregate *aggregate;
4570
4571 /* Convert string to prefix structure. */
4572 ret = str2prefix (prefix_str, &p);
4573 if (!ret)
4574 {
4575 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4576 return CMD_WARNING;
4577 }
4578 apply_mask (&p);
4579
4580 /* Get BGP structure. */
4581 bgp = vty->index;
4582
4583 /* Old configuration check. */
4584 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4585 if (! rn)
4586 {
4587 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4588 VTY_NEWLINE);
4589 return CMD_WARNING;
4590 }
4591
4592 aggregate = rn->info;
4593 if (aggregate->safi & SAFI_UNICAST)
4594 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4595 if (aggregate->safi & SAFI_MULTICAST)
4596 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4597
4598 /* Unlock aggregate address configuration. */
4599 rn->info = NULL;
4600 bgp_aggregate_free (aggregate);
4601 bgp_unlock_node (rn);
4602 bgp_unlock_node (rn);
4603
4604 return CMD_SUCCESS;
4605}
4606
4607DEFUN (aggregate_address,
4608 aggregate_address_cmd,
4609 "aggregate-address A.B.C.D/M",
4610 "Configure BGP aggregate entries\n"
4611 "Aggregate prefix\n")
4612{
4613 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4614}
4615
4616DEFUN (aggregate_address_mask,
4617 aggregate_address_mask_cmd,
4618 "aggregate-address A.B.C.D A.B.C.D",
4619 "Configure BGP aggregate entries\n"
4620 "Aggregate address\n"
4621 "Aggregate mask\n")
4622{
4623 int ret;
4624 char prefix_str[BUFSIZ];
4625
4626 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4627
4628 if (! ret)
4629 {
4630 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4631 return CMD_WARNING;
4632 }
4633
4634 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4635 0, 0);
4636}
4637
4638DEFUN (aggregate_address_summary_only,
4639 aggregate_address_summary_only_cmd,
4640 "aggregate-address A.B.C.D/M summary-only",
4641 "Configure BGP aggregate entries\n"
4642 "Aggregate prefix\n"
4643 "Filter more specific routes from updates\n")
4644{
4645 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4646 AGGREGATE_SUMMARY_ONLY, 0);
4647}
4648
4649DEFUN (aggregate_address_mask_summary_only,
4650 aggregate_address_mask_summary_only_cmd,
4651 "aggregate-address A.B.C.D A.B.C.D summary-only",
4652 "Configure BGP aggregate entries\n"
4653 "Aggregate address\n"
4654 "Aggregate mask\n"
4655 "Filter more specific routes from updates\n")
4656{
4657 int ret;
4658 char prefix_str[BUFSIZ];
4659
4660 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4661
4662 if (! ret)
4663 {
4664 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4665 return CMD_WARNING;
4666 }
4667
4668 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4669 AGGREGATE_SUMMARY_ONLY, 0);
4670}
4671
4672DEFUN (aggregate_address_as_set,
4673 aggregate_address_as_set_cmd,
4674 "aggregate-address A.B.C.D/M as-set",
4675 "Configure BGP aggregate entries\n"
4676 "Aggregate prefix\n"
4677 "Generate AS set path information\n")
4678{
4679 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4680 0, AGGREGATE_AS_SET);
4681}
4682
4683DEFUN (aggregate_address_mask_as_set,
4684 aggregate_address_mask_as_set_cmd,
4685 "aggregate-address A.B.C.D A.B.C.D as-set",
4686 "Configure BGP aggregate entries\n"
4687 "Aggregate address\n"
4688 "Aggregate mask\n"
4689 "Generate AS set path information\n")
4690{
4691 int ret;
4692 char prefix_str[BUFSIZ];
4693
4694 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4695
4696 if (! ret)
4697 {
4698 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4699 return CMD_WARNING;
4700 }
4701
4702 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4703 0, AGGREGATE_AS_SET);
4704}
4705
4706
4707DEFUN (aggregate_address_as_set_summary,
4708 aggregate_address_as_set_summary_cmd,
4709 "aggregate-address A.B.C.D/M as-set summary-only",
4710 "Configure BGP aggregate entries\n"
4711 "Aggregate prefix\n"
4712 "Generate AS set path information\n"
4713 "Filter more specific routes from updates\n")
4714{
4715 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4716 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4717}
4718
4719ALIAS (aggregate_address_as_set_summary,
4720 aggregate_address_summary_as_set_cmd,
4721 "aggregate-address A.B.C.D/M summary-only as-set",
4722 "Configure BGP aggregate entries\n"
4723 "Aggregate prefix\n"
4724 "Filter more specific routes from updates\n"
4725 "Generate AS set path information\n")
4726
4727DEFUN (aggregate_address_mask_as_set_summary,
4728 aggregate_address_mask_as_set_summary_cmd,
4729 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4730 "Configure BGP aggregate entries\n"
4731 "Aggregate address\n"
4732 "Aggregate mask\n"
4733 "Generate AS set path information\n"
4734 "Filter more specific routes from updates\n")
4735{
4736 int ret;
4737 char prefix_str[BUFSIZ];
4738
4739 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4740
4741 if (! ret)
4742 {
4743 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4744 return CMD_WARNING;
4745 }
4746
4747 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4748 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4749}
4750
4751ALIAS (aggregate_address_mask_as_set_summary,
4752 aggregate_address_mask_summary_as_set_cmd,
4753 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4754 "Configure BGP aggregate entries\n"
4755 "Aggregate address\n"
4756 "Aggregate mask\n"
4757 "Filter more specific routes from updates\n"
4758 "Generate AS set path information\n")
4759
4760DEFUN (no_aggregate_address,
4761 no_aggregate_address_cmd,
4762 "no aggregate-address A.B.C.D/M",
4763 NO_STR
4764 "Configure BGP aggregate entries\n"
4765 "Aggregate prefix\n")
4766{
4767 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4768}
4769
4770ALIAS (no_aggregate_address,
4771 no_aggregate_address_summary_only_cmd,
4772 "no aggregate-address A.B.C.D/M summary-only",
4773 NO_STR
4774 "Configure BGP aggregate entries\n"
4775 "Aggregate prefix\n"
4776 "Filter more specific routes from updates\n")
4777
4778ALIAS (no_aggregate_address,
4779 no_aggregate_address_as_set_cmd,
4780 "no aggregate-address A.B.C.D/M as-set",
4781 NO_STR
4782 "Configure BGP aggregate entries\n"
4783 "Aggregate prefix\n"
4784 "Generate AS set path information\n")
4785
4786ALIAS (no_aggregate_address,
4787 no_aggregate_address_as_set_summary_cmd,
4788 "no aggregate-address A.B.C.D/M as-set summary-only",
4789 NO_STR
4790 "Configure BGP aggregate entries\n"
4791 "Aggregate prefix\n"
4792 "Generate AS set path information\n"
4793 "Filter more specific routes from updates\n")
4794
4795ALIAS (no_aggregate_address,
4796 no_aggregate_address_summary_as_set_cmd,
4797 "no aggregate-address A.B.C.D/M summary-only as-set",
4798 NO_STR
4799 "Configure BGP aggregate entries\n"
4800 "Aggregate prefix\n"
4801 "Filter more specific routes from updates\n"
4802 "Generate AS set path information\n")
4803
4804DEFUN (no_aggregate_address_mask,
4805 no_aggregate_address_mask_cmd,
4806 "no aggregate-address A.B.C.D A.B.C.D",
4807 NO_STR
4808 "Configure BGP aggregate entries\n"
4809 "Aggregate address\n"
4810 "Aggregate mask\n")
4811{
4812 int ret;
4813 char prefix_str[BUFSIZ];
4814
4815 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4816
4817 if (! ret)
4818 {
4819 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4820 return CMD_WARNING;
4821 }
4822
4823 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4824}
4825
4826ALIAS (no_aggregate_address_mask,
4827 no_aggregate_address_mask_summary_only_cmd,
4828 "no aggregate-address A.B.C.D A.B.C.D summary-only",
4829 NO_STR
4830 "Configure BGP aggregate entries\n"
4831 "Aggregate address\n"
4832 "Aggregate mask\n"
4833 "Filter more specific routes from updates\n")
4834
4835ALIAS (no_aggregate_address_mask,
4836 no_aggregate_address_mask_as_set_cmd,
4837 "no aggregate-address A.B.C.D A.B.C.D as-set",
4838 NO_STR
4839 "Configure BGP aggregate entries\n"
4840 "Aggregate address\n"
4841 "Aggregate mask\n"
4842 "Generate AS set path information\n")
4843
4844ALIAS (no_aggregate_address_mask,
4845 no_aggregate_address_mask_as_set_summary_cmd,
4846 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4847 NO_STR
4848 "Configure BGP aggregate entries\n"
4849 "Aggregate address\n"
4850 "Aggregate mask\n"
4851 "Generate AS set path information\n"
4852 "Filter more specific routes from updates\n")
4853
4854ALIAS (no_aggregate_address_mask,
4855 no_aggregate_address_mask_summary_as_set_cmd,
4856 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4857 NO_STR
4858 "Configure BGP aggregate entries\n"
4859 "Aggregate address\n"
4860 "Aggregate mask\n"
4861 "Filter more specific routes from updates\n"
4862 "Generate AS set path information\n")
4863
4864#ifdef HAVE_IPV6
4865DEFUN (ipv6_aggregate_address,
4866 ipv6_aggregate_address_cmd,
4867 "aggregate-address X:X::X:X/M",
4868 "Configure BGP aggregate entries\n"
4869 "Aggregate prefix\n")
4870{
4871 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4872}
4873
4874DEFUN (ipv6_aggregate_address_summary_only,
4875 ipv6_aggregate_address_summary_only_cmd,
4876 "aggregate-address X:X::X:X/M summary-only",
4877 "Configure BGP aggregate entries\n"
4878 "Aggregate prefix\n"
4879 "Filter more specific routes from updates\n")
4880{
4881 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4882 AGGREGATE_SUMMARY_ONLY, 0);
4883}
4884
4885DEFUN (no_ipv6_aggregate_address,
4886 no_ipv6_aggregate_address_cmd,
4887 "no aggregate-address X:X::X:X/M",
4888 NO_STR
4889 "Configure BGP aggregate entries\n"
4890 "Aggregate prefix\n")
4891{
4892 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4893}
4894
4895DEFUN (no_ipv6_aggregate_address_summary_only,
4896 no_ipv6_aggregate_address_summary_only_cmd,
4897 "no aggregate-address X:X::X:X/M summary-only",
4898 NO_STR
4899 "Configure BGP aggregate entries\n"
4900 "Aggregate prefix\n"
4901 "Filter more specific routes from updates\n")
4902{
4903 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4904}
4905
4906ALIAS (ipv6_aggregate_address,
4907 old_ipv6_aggregate_address_cmd,
4908 "ipv6 bgp aggregate-address X:X::X:X/M",
4909 IPV6_STR
4910 BGP_STR
4911 "Configure BGP aggregate entries\n"
4912 "Aggregate prefix\n")
4913
4914ALIAS (ipv6_aggregate_address_summary_only,
4915 old_ipv6_aggregate_address_summary_only_cmd,
4916 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4917 IPV6_STR
4918 BGP_STR
4919 "Configure BGP aggregate entries\n"
4920 "Aggregate prefix\n"
4921 "Filter more specific routes from updates\n")
4922
4923ALIAS (no_ipv6_aggregate_address,
4924 old_no_ipv6_aggregate_address_cmd,
4925 "no ipv6 bgp aggregate-address X:X::X:X/M",
4926 NO_STR
4927 IPV6_STR
4928 BGP_STR
4929 "Configure BGP aggregate entries\n"
4930 "Aggregate prefix\n")
4931
4932ALIAS (no_ipv6_aggregate_address_summary_only,
4933 old_no_ipv6_aggregate_address_summary_only_cmd,
4934 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4935 NO_STR
4936 IPV6_STR
4937 BGP_STR
4938 "Configure BGP aggregate entries\n"
4939 "Aggregate prefix\n"
4940 "Filter more specific routes from updates\n")
4941#endif /* HAVE_IPV6 */
4942
4943/* Redistribute route treatment. */
4944void
4945bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4946 u_int32_t metric, u_char type)
4947{
4948 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004949 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004950 struct bgp_info *new;
4951 struct bgp_info *bi;
4952 struct bgp_info info;
4953 struct bgp_node *bn;
4954 struct attr attr;
4955 struct attr attr_new;
4956 struct attr *new_attr;
4957 afi_t afi;
4958 int ret;
4959
4960 /* Make default attribute. */
4961 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4962 if (nexthop)
4963 attr.nexthop = *nexthop;
4964
4965 attr.med = metric;
4966 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4967
paul1eb8ef22005-04-07 07:30:20 +00004968 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004969 {
4970 afi = family2afi (p->family);
4971
4972 if (bgp->redist[afi][type])
4973 {
4974 /* Copy attribute for modification. */
4975 attr_new = attr;
4976
4977 if (bgp->redist_metric_flag[afi][type])
4978 attr_new.med = bgp->redist_metric[afi][type];
4979
4980 /* Apply route-map. */
4981 if (bgp->rmap[afi][type].map)
4982 {
4983 info.peer = bgp->peer_self;
4984 info.attr = &attr_new;
4985
paulfee0f4c2004-09-13 05:12:46 +00004986 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
4987
paul718e3742002-12-13 20:15:29 +00004988 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
4989 &info);
paulfee0f4c2004-09-13 05:12:46 +00004990
4991 bgp->peer_self->rmap_type = 0;
4992
paul718e3742002-12-13 20:15:29 +00004993 if (ret == RMAP_DENYMATCH)
4994 {
4995 /* Free uninterned attribute. */
4996 bgp_attr_flush (&attr_new);
4997
4998 /* Unintern original. */
4999 aspath_unintern (attr.aspath);
5000 bgp_redistribute_delete (p, type);
5001 return;
5002 }
5003 }
5004
paulfee0f4c2004-09-13 05:12:46 +00005005 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005006 new_attr = bgp_attr_intern (&attr_new);
5007
5008 for (bi = bn->info; bi; bi = bi->next)
5009 if (bi->peer == bgp->peer_self
5010 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5011 break;
5012
5013 if (bi)
5014 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005015 if (attrhash_cmp (bi->attr, new_attr) &&
5016 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005017 {
5018 bgp_attr_unintern (new_attr);
5019 aspath_unintern (attr.aspath);
5020 bgp_unlock_node (bn);
5021 return;
5022 }
5023 else
5024 {
5025 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005026 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005027
5028 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005029 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5030 bgp_info_restore(bn, bi);
5031 else
5032 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005033 bgp_attr_unintern (bi->attr);
5034 bi->attr = new_attr;
5035 bi->uptime = time (NULL);
5036
5037 /* Process change. */
5038 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5039 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5040 bgp_unlock_node (bn);
5041 aspath_unintern (attr.aspath);
5042 return;
5043 }
5044 }
5045
5046 new = bgp_info_new ();
5047 new->type = type;
5048 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5049 new->peer = bgp->peer_self;
5050 SET_FLAG (new->flags, BGP_INFO_VALID);
5051 new->attr = new_attr;
5052 new->uptime = time (NULL);
5053
5054 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5055 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005056 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005057 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5058 }
5059 }
5060
5061 /* Unintern original. */
5062 aspath_unintern (attr.aspath);
5063}
5064
5065void
5066bgp_redistribute_delete (struct prefix *p, u_char type)
5067{
5068 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005069 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005070 afi_t afi;
5071 struct bgp_node *rn;
5072 struct bgp_info *ri;
5073
paul1eb8ef22005-04-07 07:30:20 +00005074 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005075 {
5076 afi = family2afi (p->family);
5077
5078 if (bgp->redist[afi][type])
5079 {
paulfee0f4c2004-09-13 05:12:46 +00005080 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005081
5082 for (ri = rn->info; ri; ri = ri->next)
5083 if (ri->peer == bgp->peer_self
5084 && ri->type == type)
5085 break;
5086
5087 if (ri)
5088 {
5089 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005090 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005091 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005092 }
5093 bgp_unlock_node (rn);
5094 }
5095 }
5096}
5097
5098/* Withdraw specified route type's route. */
5099void
5100bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5101{
5102 struct bgp_node *rn;
5103 struct bgp_info *ri;
5104 struct bgp_table *table;
5105
5106 table = bgp->rib[afi][SAFI_UNICAST];
5107
5108 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5109 {
5110 for (ri = rn->info; ri; ri = ri->next)
5111 if (ri->peer == bgp->peer_self
5112 && ri->type == type)
5113 break;
5114
5115 if (ri)
5116 {
5117 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005118 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005119 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005120 }
5121 }
5122}
5123
5124/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005125static void
paul718e3742002-12-13 20:15:29 +00005126route_vty_out_route (struct prefix *p, struct vty *vty)
5127{
5128 int len;
5129 u_int32_t destination;
5130 char buf[BUFSIZ];
5131
5132 if (p->family == AF_INET)
5133 {
5134 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5135 destination = ntohl (p->u.prefix4.s_addr);
5136
5137 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5138 || (IN_CLASSB (destination) && p->prefixlen == 16)
5139 || (IN_CLASSA (destination) && p->prefixlen == 8)
5140 || p->u.prefix4.s_addr == 0)
5141 {
5142 /* When mask is natural, mask is not displayed. */
5143 }
5144 else
5145 len += vty_out (vty, "/%d", p->prefixlen);
5146 }
5147 else
5148 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5149 p->prefixlen);
5150
5151 len = 17 - len;
5152 if (len < 1)
5153 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5154 else
5155 vty_out (vty, "%*s", len, " ");
5156}
5157
paul718e3742002-12-13 20:15:29 +00005158enum bgp_display_type
5159{
5160 normal_list,
5161};
5162
paulb40d9392005-08-22 22:34:41 +00005163/* Print the short form route status for a bgp_info */
5164static void
5165route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005166{
paulb40d9392005-08-22 22:34:41 +00005167 /* Route status display. */
5168 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5169 vty_out (vty, "R");
5170 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005171 vty_out (vty, "S");
5172 else if (binfo->suppress)
paul718e3742002-12-13 20:15:29 +00005173 vty_out (vty, "s");
5174 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5175 vty_out (vty, "*");
5176 else
5177 vty_out (vty, " ");
5178
5179 /* Selected */
5180 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5181 vty_out (vty, "h");
5182 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5183 vty_out (vty, "d");
5184 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5185 vty_out (vty, ">");
5186 else
5187 vty_out (vty, " ");
5188
5189 /* Internal route. */
5190 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5191 vty_out (vty, "i");
5192 else
paulb40d9392005-08-22 22:34:41 +00005193 vty_out (vty, " ");
5194}
5195
5196/* called from terminal list command */
5197void
5198route_vty_out (struct vty *vty, struct prefix *p,
5199 struct bgp_info *binfo, int display, safi_t safi)
5200{
5201 struct attr *attr;
5202
5203 /* short status lead text */
5204 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005205
5206 /* print prefix and mask */
5207 if (! display)
5208 route_vty_out_route (p, vty);
5209 else
5210 vty_out (vty, "%*s", 17, " ");
5211
5212 /* Print attribute */
5213 attr = binfo->attr;
5214 if (attr)
5215 {
5216 if (p->family == AF_INET)
5217 {
5218 if (safi == SAFI_MPLS_VPN)
5219 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5220 else
5221 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5222 }
5223#ifdef HAVE_IPV6
5224 else if (p->family == AF_INET6)
5225 {
5226 int len;
5227 char buf[BUFSIZ];
5228
5229 len = vty_out (vty, "%s",
5230 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5231 len = 16 - len;
5232 if (len < 1)
5233 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5234 else
5235 vty_out (vty, "%*s", len, " ");
5236 }
5237#endif /* HAVE_IPV6 */
5238
5239 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5240 vty_out (vty, "%10d", attr->med);
5241 else
5242 vty_out (vty, " ");
5243
5244 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5245 vty_out (vty, "%7d", attr->local_pref);
5246 else
5247 vty_out (vty, " ");
5248
5249 vty_out (vty, "%7u ",attr->weight);
5250
Paul Jakmab2518c12006-05-12 23:48:40 +00005251 /* Print aspath */
5252 if (attr->aspath)
5253 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005254
Paul Jakmab2518c12006-05-12 23:48:40 +00005255 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005256 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005257 }
paul718e3742002-12-13 20:15:29 +00005258 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005259}
5260
5261/* called from terminal list command */
5262void
5263route_vty_out_tmp (struct vty *vty, struct prefix *p,
5264 struct attr *attr, safi_t safi)
5265{
5266 /* Route status display. */
5267 vty_out (vty, "*");
5268 vty_out (vty, ">");
5269 vty_out (vty, " ");
5270
5271 /* print prefix and mask */
5272 route_vty_out_route (p, vty);
5273
5274 /* Print attribute */
5275 if (attr)
5276 {
5277 if (p->family == AF_INET)
5278 {
5279 if (safi == SAFI_MPLS_VPN)
5280 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5281 else
5282 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5283 }
5284#ifdef HAVE_IPV6
5285 else if (p->family == AF_INET6)
5286 {
5287 int len;
5288 char buf[BUFSIZ];
5289
5290 len = vty_out (vty, "%s",
5291 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5292 len = 16 - len;
5293 if (len < 1)
5294 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5295 else
5296 vty_out (vty, "%*s", len, " ");
5297 }
5298#endif /* HAVE_IPV6 */
5299
5300 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5301 vty_out (vty, "%10d", attr->med);
5302 else
5303 vty_out (vty, " ");
5304
5305 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5306 vty_out (vty, "%7d", attr->local_pref);
5307 else
5308 vty_out (vty, " ");
5309
5310 vty_out (vty, "%7d ",attr->weight);
5311
Paul Jakmab2518c12006-05-12 23:48:40 +00005312 /* Print aspath */
5313 if (attr->aspath)
5314 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005315
Paul Jakmab2518c12006-05-12 23:48:40 +00005316 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005317 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005318 }
paul718e3742002-12-13 20:15:29 +00005319
5320 vty_out (vty, "%s", VTY_NEWLINE);
5321}
5322
ajs5a646652004-11-05 01:25:55 +00005323void
paul718e3742002-12-13 20:15:29 +00005324route_vty_out_tag (struct vty *vty, struct prefix *p,
5325 struct bgp_info *binfo, int display, safi_t safi)
5326{
5327 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005328 u_int32_t label = 0;
5329
paulb40d9392005-08-22 22:34:41 +00005330 /* short status lead text */
5331 route_vty_short_status_out (vty, binfo);
5332
paul718e3742002-12-13 20:15:29 +00005333 /* print prefix and mask */
5334 if (! display)
5335 route_vty_out_route (p, vty);
5336 else
5337 vty_out (vty, "%*s", 17, " ");
5338
5339 /* Print attribute */
5340 attr = binfo->attr;
5341 if (attr)
5342 {
5343 if (p->family == AF_INET)
5344 {
5345 if (safi == SAFI_MPLS_VPN)
5346 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5347 else
5348 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5349 }
5350#ifdef HAVE_IPV6
5351 else if (p->family == AF_INET6)
5352 {
5353 char buf[BUFSIZ];
5354 char buf1[BUFSIZ];
5355 if (attr->mp_nexthop_len == 16)
5356 vty_out (vty, "%s",
5357 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5358 else if (attr->mp_nexthop_len == 32)
5359 vty_out (vty, "%s(%s)",
5360 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
5361 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
5362
5363 }
5364#endif /* HAVE_IPV6 */
5365 }
5366
5367 label = decode_label (binfo->tag);
5368
5369 vty_out (vty, "notag/%d", label);
5370
5371 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005372}
5373
5374/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005375static void
paul718e3742002-12-13 20:15:29 +00005376damp_route_vty_out (struct vty *vty, struct prefix *p,
5377 struct bgp_info *binfo, int display, safi_t safi)
5378{
5379 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005380 int len;
5381
paulb40d9392005-08-22 22:34:41 +00005382 /* short status lead text */
5383 route_vty_short_status_out (vty, binfo);
5384
paul718e3742002-12-13 20:15:29 +00005385 /* print prefix and mask */
5386 if (! display)
5387 route_vty_out_route (p, vty);
5388 else
5389 vty_out (vty, "%*s", 17, " ");
5390
5391 len = vty_out (vty, "%s", binfo->peer->host);
5392 len = 17 - len;
5393 if (len < 1)
5394 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5395 else
5396 vty_out (vty, "%*s", len, " ");
5397
5398 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5399
5400 /* Print attribute */
5401 attr = binfo->attr;
5402 if (attr)
5403 {
5404 /* Print aspath */
5405 if (attr->aspath)
Paul Jakmab2518c12006-05-12 23:48:40 +00005406 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005407
5408 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005409 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005410 }
5411 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005412}
5413
5414#define BGP_UPTIME_LEN 25
5415
5416/* flap route */
ajs5a646652004-11-05 01:25:55 +00005417static void
paul718e3742002-12-13 20:15:29 +00005418flap_route_vty_out (struct vty *vty, struct prefix *p,
5419 struct bgp_info *binfo, int display, safi_t safi)
5420{
5421 struct attr *attr;
5422 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005423 char timebuf[BGP_UPTIME_LEN];
5424 int len;
5425
paul718e3742002-12-13 20:15:29 +00005426 bdi = binfo->damp_info;
5427
paulb40d9392005-08-22 22:34:41 +00005428 /* short status lead text */
5429 route_vty_short_status_out (vty, binfo);
5430
paul718e3742002-12-13 20:15:29 +00005431 /* print prefix and mask */
5432 if (! display)
5433 route_vty_out_route (p, vty);
5434 else
5435 vty_out (vty, "%*s", 17, " ");
5436
5437 len = vty_out (vty, "%s", binfo->peer->host);
5438 len = 16 - len;
5439 if (len < 1)
5440 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5441 else
5442 vty_out (vty, "%*s", len, " ");
5443
5444 len = vty_out (vty, "%d", bdi->flap);
5445 len = 5 - len;
5446 if (len < 1)
5447 vty_out (vty, " ");
5448 else
5449 vty_out (vty, "%*s ", len, " ");
5450
5451 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5452 timebuf, BGP_UPTIME_LEN));
5453
5454 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5455 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5456 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5457 else
5458 vty_out (vty, "%*s ", 8, " ");
5459
5460 /* Print attribute */
5461 attr = binfo->attr;
5462 if (attr)
5463 {
5464 /* Print aspath */
5465 if (attr->aspath)
Paul Jakmab2518c12006-05-12 23:48:40 +00005466 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005467
5468 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005469 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005470 }
5471 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005472}
5473
paul94f2b392005-06-28 12:44:16 +00005474static void
paul718e3742002-12-13 20:15:29 +00005475route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5476 struct bgp_info *binfo, afi_t afi, safi_t safi)
5477{
5478 char buf[INET6_ADDRSTRLEN];
5479 char buf1[BUFSIZ];
5480 struct attr *attr;
5481 int sockunion_vty_out (struct vty *, union sockunion *);
5482
5483 attr = binfo->attr;
5484
5485 if (attr)
5486 {
5487 /* Line1 display AS-path, Aggregator */
5488 if (attr->aspath)
5489 {
5490 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005491 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005492 vty_out (vty, "Local");
5493 else
Paul Jakmab2518c12006-05-12 23:48:40 +00005494 aspath_print_vty (vty, "%s", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005495 }
5496
paulb40d9392005-08-22 22:34:41 +00005497 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5498 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005499 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5500 vty_out (vty, ", (stale)");
5501 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5502 vty_out (vty, ", (aggregated by %d %s)", attr->aggregator_as,
5503 inet_ntoa (attr->aggregator_addr));
5504 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5505 vty_out (vty, ", (Received from a RR-client)");
5506 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5507 vty_out (vty, ", (Received from a RS-client)");
5508 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5509 vty_out (vty, ", (history entry)");
5510 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5511 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005512 vty_out (vty, "%s", VTY_NEWLINE);
5513
5514 /* Line2 display Next-hop, Neighbor, Router-id */
5515 if (p->family == AF_INET)
5516 {
5517 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5518 inet_ntoa (attr->mp_nexthop_global_in) :
5519 inet_ntoa (attr->nexthop));
5520 }
5521#ifdef HAVE_IPV6
5522 else
5523 {
5524 vty_out (vty, " %s",
5525 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5526 buf, INET6_ADDRSTRLEN));
5527 }
5528#endif /* HAVE_IPV6 */
5529
5530 if (binfo->peer == bgp->peer_self)
5531 {
5532 vty_out (vty, " from %s ",
5533 p->family == AF_INET ? "0.0.0.0" : "::");
5534 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5535 }
5536 else
5537 {
5538 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5539 vty_out (vty, " (inaccessible)");
5540 else if (binfo->igpmetric)
5541 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005542 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005543 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5544 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5545 else
5546 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5547 }
5548 vty_out (vty, "%s", VTY_NEWLINE);
5549
5550#ifdef HAVE_IPV6
5551 /* display nexthop local */
5552 if (attr->mp_nexthop_len == 32)
5553 {
5554 vty_out (vty, " (%s)%s",
5555 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5556 buf, INET6_ADDRSTRLEN),
5557 VTY_NEWLINE);
5558 }
5559#endif /* HAVE_IPV6 */
5560
5561 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5562 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5563
5564 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5565 vty_out (vty, ", metric %d", attr->med);
5566
5567 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5568 vty_out (vty, ", localpref %d", attr->local_pref);
5569 else
5570 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5571
5572 if (attr->weight != 0)
5573 vty_out (vty, ", weight %d", attr->weight);
5574
5575 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5576 vty_out (vty, ", valid");
5577
5578 if (binfo->peer != bgp->peer_self)
5579 {
5580 if (binfo->peer->as == binfo->peer->local_as)
5581 vty_out (vty, ", internal");
5582 else
5583 vty_out (vty, ", %s",
5584 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5585 }
5586 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5587 vty_out (vty, ", aggregated, local");
5588 else if (binfo->type != ZEBRA_ROUTE_BGP)
5589 vty_out (vty, ", sourced");
5590 else
5591 vty_out (vty, ", sourced, local");
5592
5593 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5594 vty_out (vty, ", atomic-aggregate");
5595
5596 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5597 vty_out (vty, ", best");
5598
5599 vty_out (vty, "%s", VTY_NEWLINE);
5600
5601 /* Line 4 display Community */
5602 if (attr->community)
5603 vty_out (vty, " Community: %s%s", attr->community->str,
5604 VTY_NEWLINE);
5605
5606 /* Line 5 display Extended-community */
5607 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5608 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5609 VTY_NEWLINE);
5610
5611 /* Line 6 display Originator, Cluster-id */
5612 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5613 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5614 {
5615 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5616 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5617
5618 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5619 {
5620 int i;
5621 vty_out (vty, ", Cluster list: ");
5622 for (i = 0; i < attr->cluster->length / 4; i++)
5623 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5624 }
5625 vty_out (vty, "%s", VTY_NEWLINE);
5626 }
5627
5628 if (binfo->damp_info)
5629 bgp_damp_info_vty (vty, binfo);
5630
5631 /* Line 7 display Uptime */
5632 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5633 }
5634 vty_out (vty, "%s", VTY_NEWLINE);
5635}
5636
paulb40d9392005-08-22 22:34:41 +00005637#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 +00005638#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005639#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5640#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5641#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5642
5643enum bgp_show_type
5644{
5645 bgp_show_type_normal,
5646 bgp_show_type_regexp,
5647 bgp_show_type_prefix_list,
5648 bgp_show_type_filter_list,
5649 bgp_show_type_route_map,
5650 bgp_show_type_neighbor,
5651 bgp_show_type_cidr_only,
5652 bgp_show_type_prefix_longer,
5653 bgp_show_type_community_all,
5654 bgp_show_type_community,
5655 bgp_show_type_community_exact,
5656 bgp_show_type_community_list,
5657 bgp_show_type_community_list_exact,
5658 bgp_show_type_flap_statistics,
5659 bgp_show_type_flap_address,
5660 bgp_show_type_flap_prefix,
5661 bgp_show_type_flap_cidr_only,
5662 bgp_show_type_flap_regexp,
5663 bgp_show_type_flap_filter_list,
5664 bgp_show_type_flap_prefix_list,
5665 bgp_show_type_flap_prefix_longer,
5666 bgp_show_type_flap_route_map,
5667 bgp_show_type_flap_neighbor,
5668 bgp_show_type_dampend_paths,
5669 bgp_show_type_damp_neighbor
5670};
5671
ajs5a646652004-11-05 01:25:55 +00005672static int
paulfee0f4c2004-09-13 05:12:46 +00005673bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00005674 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00005675{
paul718e3742002-12-13 20:15:29 +00005676 struct bgp_info *ri;
5677 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005678 int header = 1;
paul718e3742002-12-13 20:15:29 +00005679 int display;
ajs5a646652004-11-05 01:25:55 +00005680 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00005681
5682 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00005683 output_count = 0;
paul718e3742002-12-13 20:15:29 +00005684
paul718e3742002-12-13 20:15:29 +00005685 /* Start processing of routes. */
5686 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5687 if (rn->info != NULL)
5688 {
5689 display = 0;
5690
5691 for (ri = rn->info; ri; ri = ri->next)
5692 {
ajs5a646652004-11-05 01:25:55 +00005693 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00005694 || type == bgp_show_type_flap_address
5695 || type == bgp_show_type_flap_prefix
5696 || type == bgp_show_type_flap_cidr_only
5697 || type == bgp_show_type_flap_regexp
5698 || type == bgp_show_type_flap_filter_list
5699 || type == bgp_show_type_flap_prefix_list
5700 || type == bgp_show_type_flap_prefix_longer
5701 || type == bgp_show_type_flap_route_map
5702 || type == bgp_show_type_flap_neighbor
5703 || type == bgp_show_type_dampend_paths
5704 || type == bgp_show_type_damp_neighbor)
5705 {
5706 if (! ri->damp_info)
5707 continue;
5708 }
5709 if (type == bgp_show_type_regexp
5710 || type == bgp_show_type_flap_regexp)
5711 {
ajs5a646652004-11-05 01:25:55 +00005712 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00005713
5714 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5715 continue;
5716 }
5717 if (type == bgp_show_type_prefix_list
5718 || type == bgp_show_type_flap_prefix_list)
5719 {
ajs5a646652004-11-05 01:25:55 +00005720 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00005721
5722 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5723 continue;
5724 }
5725 if (type == bgp_show_type_filter_list
5726 || type == bgp_show_type_flap_filter_list)
5727 {
ajs5a646652004-11-05 01:25:55 +00005728 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00005729
5730 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5731 continue;
5732 }
5733 if (type == bgp_show_type_route_map
5734 || type == bgp_show_type_flap_route_map)
5735 {
ajs5a646652004-11-05 01:25:55 +00005736 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00005737 struct bgp_info binfo;
5738 struct attr dummy_attr;
5739 int ret;
5740
5741 dummy_attr = *ri->attr;
5742 binfo.peer = ri->peer;
5743 binfo.attr = &dummy_attr;
5744
5745 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5746
5747 if (ret == RMAP_DENYMATCH)
5748 continue;
5749 }
5750 if (type == bgp_show_type_neighbor
5751 || type == bgp_show_type_flap_neighbor
5752 || type == bgp_show_type_damp_neighbor)
5753 {
ajs5a646652004-11-05 01:25:55 +00005754 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00005755
5756 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5757 continue;
5758 }
5759 if (type == bgp_show_type_cidr_only
5760 || type == bgp_show_type_flap_cidr_only)
5761 {
5762 u_int32_t destination;
5763
5764 destination = ntohl (rn->p.u.prefix4.s_addr);
5765 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5766 continue;
5767 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5768 continue;
5769 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5770 continue;
5771 }
5772 if (type == bgp_show_type_prefix_longer
5773 || type == bgp_show_type_flap_prefix_longer)
5774 {
ajs5a646652004-11-05 01:25:55 +00005775 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005776
5777 if (! prefix_match (p, &rn->p))
5778 continue;
5779 }
5780 if (type == bgp_show_type_community_all)
5781 {
5782 if (! ri->attr->community)
5783 continue;
5784 }
5785 if (type == bgp_show_type_community)
5786 {
ajs5a646652004-11-05 01:25:55 +00005787 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005788
5789 if (! ri->attr->community ||
5790 ! community_match (ri->attr->community, com))
5791 continue;
5792 }
5793 if (type == bgp_show_type_community_exact)
5794 {
ajs5a646652004-11-05 01:25:55 +00005795 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005796
5797 if (! ri->attr->community ||
5798 ! community_cmp (ri->attr->community, com))
5799 continue;
5800 }
5801 if (type == bgp_show_type_community_list)
5802 {
ajs5a646652004-11-05 01:25:55 +00005803 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005804
5805 if (! community_list_match (ri->attr->community, list))
5806 continue;
5807 }
5808 if (type == bgp_show_type_community_list_exact)
5809 {
ajs5a646652004-11-05 01:25:55 +00005810 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005811
5812 if (! community_list_exact_match (ri->attr->community, list))
5813 continue;
5814 }
5815 if (type == bgp_show_type_flap_address
5816 || type == bgp_show_type_flap_prefix)
5817 {
ajs5a646652004-11-05 01:25:55 +00005818 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005819
5820 if (! prefix_match (&rn->p, p))
5821 continue;
5822
5823 if (type == bgp_show_type_flap_prefix)
5824 if (p->prefixlen != rn->p.prefixlen)
5825 continue;
5826 }
5827 if (type == bgp_show_type_dampend_paths
5828 || type == bgp_show_type_damp_neighbor)
5829 {
5830 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5831 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5832 continue;
5833 }
5834
5835 if (header)
5836 {
hasso93406d82005-02-02 14:40:33 +00005837 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
5838 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
5839 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005840 if (type == bgp_show_type_dampend_paths
5841 || type == bgp_show_type_damp_neighbor)
5842 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5843 else if (type == bgp_show_type_flap_statistics
5844 || type == bgp_show_type_flap_address
5845 || type == bgp_show_type_flap_prefix
5846 || type == bgp_show_type_flap_cidr_only
5847 || type == bgp_show_type_flap_regexp
5848 || type == bgp_show_type_flap_filter_list
5849 || type == bgp_show_type_flap_prefix_list
5850 || type == bgp_show_type_flap_prefix_longer
5851 || type == bgp_show_type_flap_route_map
5852 || type == bgp_show_type_flap_neighbor)
5853 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5854 else
5855 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005856 header = 0;
5857 }
5858
5859 if (type == bgp_show_type_dampend_paths
5860 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00005861 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005862 else if (type == bgp_show_type_flap_statistics
5863 || type == bgp_show_type_flap_address
5864 || type == bgp_show_type_flap_prefix
5865 || type == bgp_show_type_flap_cidr_only
5866 || type == bgp_show_type_flap_regexp
5867 || type == bgp_show_type_flap_filter_list
5868 || type == bgp_show_type_flap_prefix_list
5869 || type == bgp_show_type_flap_prefix_longer
5870 || type == bgp_show_type_flap_route_map
5871 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00005872 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005873 else
ajs5a646652004-11-05 01:25:55 +00005874 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005875 display++;
5876 }
5877 if (display)
ajs5a646652004-11-05 01:25:55 +00005878 output_count++;
paul718e3742002-12-13 20:15:29 +00005879 }
5880
5881 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00005882 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00005883 {
5884 if (type == bgp_show_type_normal)
5885 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5886 }
5887 else
5888 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00005889 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005890
5891 return CMD_SUCCESS;
5892}
5893
ajs5a646652004-11-05 01:25:55 +00005894static int
paulfee0f4c2004-09-13 05:12:46 +00005895bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00005896 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00005897{
5898 struct bgp_table *table;
5899
5900 if (bgp == NULL) {
5901 bgp = bgp_get_default ();
5902 }
5903
5904 if (bgp == NULL)
5905 {
5906 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5907 return CMD_WARNING;
5908 }
5909
5910
5911 table = bgp->rib[afi][safi];
5912
ajs5a646652004-11-05 01:25:55 +00005913 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00005914}
5915
paul718e3742002-12-13 20:15:29 +00005916/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00005917static void
paul718e3742002-12-13 20:15:29 +00005918route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5919 struct bgp_node *rn,
5920 struct prefix_rd *prd, afi_t afi, safi_t safi)
5921{
5922 struct bgp_info *ri;
5923 struct prefix *p;
5924 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00005925 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005926 char buf1[INET6_ADDRSTRLEN];
5927 char buf2[INET6_ADDRSTRLEN];
5928 int count = 0;
5929 int best = 0;
5930 int suppress = 0;
5931 int no_export = 0;
5932 int no_advertise = 0;
5933 int local_as = 0;
5934 int first = 0;
5935
5936 p = &rn->p;
5937 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5938 (safi == SAFI_MPLS_VPN ?
5939 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5940 safi == SAFI_MPLS_VPN ? ":" : "",
5941 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5942 p->prefixlen, VTY_NEWLINE);
5943
5944 for (ri = rn->info; ri; ri = ri->next)
5945 {
5946 count++;
5947 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5948 {
5949 best = count;
5950 if (ri->suppress)
5951 suppress = 1;
5952 if (ri->attr->community != NULL)
5953 {
5954 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5955 no_advertise = 1;
5956 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5957 no_export = 1;
5958 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5959 local_as = 1;
5960 }
5961 }
5962 }
5963
5964 vty_out (vty, "Paths: (%d available", count);
5965 if (best)
5966 {
5967 vty_out (vty, ", best #%d", best);
5968 if (safi == SAFI_UNICAST)
5969 vty_out (vty, ", table Default-IP-Routing-Table");
5970 }
5971 else
5972 vty_out (vty, ", no best path");
5973 if (no_advertise)
5974 vty_out (vty, ", not advertised to any peer");
5975 else if (no_export)
5976 vty_out (vty, ", not advertised to EBGP peer");
5977 else if (local_as)
5978 vty_out (vty, ", not advertised outside local AS");
5979 if (suppress)
5980 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5981 vty_out (vty, ")%s", VTY_NEWLINE);
5982
5983 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00005984 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00005985 {
5986 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5987 {
5988 if (! first)
5989 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5990 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5991 first = 1;
5992 }
5993 }
5994 if (! first)
5995 vty_out (vty, " Not advertised to any peer");
5996 vty_out (vty, "%s", VTY_NEWLINE);
5997}
5998
5999/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006000static int
paulfee0f4c2004-09-13 05:12:46 +00006001bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006002 struct bgp_table *rib, const char *ip_str,
6003 afi_t afi, safi_t safi, struct prefix_rd *prd,
6004 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006005{
6006 int ret;
6007 int header;
6008 int display = 0;
6009 struct prefix match;
6010 struct bgp_node *rn;
6011 struct bgp_node *rm;
6012 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006013 struct bgp_table *table;
6014
paul718e3742002-12-13 20:15:29 +00006015 /* Check IP address argument. */
6016 ret = str2prefix (ip_str, &match);
6017 if (! ret)
6018 {
6019 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6020 return CMD_WARNING;
6021 }
6022
6023 match.family = afi2family (afi);
6024
6025 if (safi == SAFI_MPLS_VPN)
6026 {
paulfee0f4c2004-09-13 05:12:46 +00006027 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006028 {
6029 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6030 continue;
6031
6032 if ((table = rn->info) != NULL)
6033 {
6034 header = 1;
6035
6036 if ((rm = bgp_node_match (table, &match)) != NULL)
6037 {
6038 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6039 continue;
6040
6041 for (ri = rm->info; ri; ri = ri->next)
6042 {
6043 if (header)
6044 {
6045 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6046 AFI_IP, SAFI_MPLS_VPN);
6047
6048 header = 0;
6049 }
6050 display++;
6051 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6052 }
6053 }
6054 }
6055 }
6056 }
6057 else
6058 {
6059 header = 1;
6060
paulfee0f4c2004-09-13 05:12:46 +00006061 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006062 {
6063 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6064 {
6065 for (ri = rn->info; ri; ri = ri->next)
6066 {
6067 if (header)
6068 {
6069 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6070 header = 0;
6071 }
6072 display++;
6073 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6074 }
6075 }
6076 }
6077 }
6078
6079 if (! display)
6080 {
6081 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6082 return CMD_WARNING;
6083 }
6084
6085 return CMD_SUCCESS;
6086}
6087
paulfee0f4c2004-09-13 05:12:46 +00006088/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006089static int
paulfd79ac92004-10-13 05:06:08 +00006090bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006091 afi_t afi, safi_t safi, struct prefix_rd *prd,
6092 int prefix_check)
6093{
6094 struct bgp *bgp;
6095
6096 /* BGP structure lookup. */
6097 if (view_name)
6098 {
6099 bgp = bgp_lookup_by_name (view_name);
6100 if (bgp == NULL)
6101 {
6102 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6103 return CMD_WARNING;
6104 }
6105 }
6106 else
6107 {
6108 bgp = bgp_get_default ();
6109 if (bgp == NULL)
6110 {
6111 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6112 return CMD_WARNING;
6113 }
6114 }
6115
6116 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6117 afi, safi, prd, prefix_check);
6118}
6119
paul718e3742002-12-13 20:15:29 +00006120/* BGP route print out function. */
6121DEFUN (show_ip_bgp,
6122 show_ip_bgp_cmd,
6123 "show ip bgp",
6124 SHOW_STR
6125 IP_STR
6126 BGP_STR)
6127{
ajs5a646652004-11-05 01:25:55 +00006128 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006129}
6130
6131DEFUN (show_ip_bgp_ipv4,
6132 show_ip_bgp_ipv4_cmd,
6133 "show ip bgp ipv4 (unicast|multicast)",
6134 SHOW_STR
6135 IP_STR
6136 BGP_STR
6137 "Address family\n"
6138 "Address Family modifier\n"
6139 "Address Family modifier\n")
6140{
6141 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006142 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6143 NULL);
paul718e3742002-12-13 20:15:29 +00006144
ajs5a646652004-11-05 01:25:55 +00006145 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006146}
6147
6148DEFUN (show_ip_bgp_route,
6149 show_ip_bgp_route_cmd,
6150 "show ip bgp A.B.C.D",
6151 SHOW_STR
6152 IP_STR
6153 BGP_STR
6154 "Network in the BGP routing table to display\n")
6155{
6156 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6157}
6158
6159DEFUN (show_ip_bgp_ipv4_route,
6160 show_ip_bgp_ipv4_route_cmd,
6161 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6162 SHOW_STR
6163 IP_STR
6164 BGP_STR
6165 "Address family\n"
6166 "Address Family modifier\n"
6167 "Address Family modifier\n"
6168 "Network in the BGP routing table to display\n")
6169{
6170 if (strncmp (argv[0], "m", 1) == 0)
6171 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6172
6173 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6174}
6175
6176DEFUN (show_ip_bgp_vpnv4_all_route,
6177 show_ip_bgp_vpnv4_all_route_cmd,
6178 "show ip bgp vpnv4 all A.B.C.D",
6179 SHOW_STR
6180 IP_STR
6181 BGP_STR
6182 "Display VPNv4 NLRI specific information\n"
6183 "Display information about all VPNv4 NLRIs\n"
6184 "Network in the BGP routing table to display\n")
6185{
6186 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6187}
6188
6189DEFUN (show_ip_bgp_vpnv4_rd_route,
6190 show_ip_bgp_vpnv4_rd_route_cmd,
6191 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6192 SHOW_STR
6193 IP_STR
6194 BGP_STR
6195 "Display VPNv4 NLRI specific information\n"
6196 "Display information for a route distinguisher\n"
6197 "VPN Route Distinguisher\n"
6198 "Network in the BGP routing table to display\n")
6199{
6200 int ret;
6201 struct prefix_rd prd;
6202
6203 ret = str2prefix_rd (argv[0], &prd);
6204 if (! ret)
6205 {
6206 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6207 return CMD_WARNING;
6208 }
6209 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6210}
6211
6212DEFUN (show_ip_bgp_prefix,
6213 show_ip_bgp_prefix_cmd,
6214 "show ip bgp A.B.C.D/M",
6215 SHOW_STR
6216 IP_STR
6217 BGP_STR
6218 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6219{
6220 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6221}
6222
6223DEFUN (show_ip_bgp_ipv4_prefix,
6224 show_ip_bgp_ipv4_prefix_cmd,
6225 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6226 SHOW_STR
6227 IP_STR
6228 BGP_STR
6229 "Address family\n"
6230 "Address Family modifier\n"
6231 "Address Family modifier\n"
6232 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6233{
6234 if (strncmp (argv[0], "m", 1) == 0)
6235 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6236
6237 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6238}
6239
6240DEFUN (show_ip_bgp_vpnv4_all_prefix,
6241 show_ip_bgp_vpnv4_all_prefix_cmd,
6242 "show ip bgp vpnv4 all A.B.C.D/M",
6243 SHOW_STR
6244 IP_STR
6245 BGP_STR
6246 "Display VPNv4 NLRI specific information\n"
6247 "Display information about all VPNv4 NLRIs\n"
6248 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6249{
6250 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6251}
6252
6253DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6254 show_ip_bgp_vpnv4_rd_prefix_cmd,
6255 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6256 SHOW_STR
6257 IP_STR
6258 BGP_STR
6259 "Display VPNv4 NLRI specific information\n"
6260 "Display information for a route distinguisher\n"
6261 "VPN Route Distinguisher\n"
6262 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6263{
6264 int ret;
6265 struct prefix_rd prd;
6266
6267 ret = str2prefix_rd (argv[0], &prd);
6268 if (! ret)
6269 {
6270 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6271 return CMD_WARNING;
6272 }
6273 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6274}
6275
6276DEFUN (show_ip_bgp_view,
6277 show_ip_bgp_view_cmd,
6278 "show ip bgp view WORD",
6279 SHOW_STR
6280 IP_STR
6281 BGP_STR
6282 "BGP view\n"
6283 "BGP view name\n")
6284{
paulbb46e942003-10-24 19:02:03 +00006285 struct bgp *bgp;
6286
6287 /* BGP structure lookup. */
6288 bgp = bgp_lookup_by_name (argv[0]);
6289 if (bgp == NULL)
6290 {
6291 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6292 return CMD_WARNING;
6293 }
6294
ajs5a646652004-11-05 01:25:55 +00006295 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006296}
6297
6298DEFUN (show_ip_bgp_view_route,
6299 show_ip_bgp_view_route_cmd,
6300 "show ip bgp view WORD A.B.C.D",
6301 SHOW_STR
6302 IP_STR
6303 BGP_STR
6304 "BGP view\n"
6305 "BGP view name\n"
6306 "Network in the BGP routing table to display\n")
6307{
6308 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6309}
6310
6311DEFUN (show_ip_bgp_view_prefix,
6312 show_ip_bgp_view_prefix_cmd,
6313 "show ip bgp view WORD A.B.C.D/M",
6314 SHOW_STR
6315 IP_STR
6316 BGP_STR
6317 "BGP view\n"
6318 "BGP view name\n"
6319 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6320{
6321 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6322}
6323
6324#ifdef HAVE_IPV6
6325DEFUN (show_bgp,
6326 show_bgp_cmd,
6327 "show bgp",
6328 SHOW_STR
6329 BGP_STR)
6330{
ajs5a646652004-11-05 01:25:55 +00006331 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6332 NULL);
paul718e3742002-12-13 20:15:29 +00006333}
6334
6335ALIAS (show_bgp,
6336 show_bgp_ipv6_cmd,
6337 "show bgp ipv6",
6338 SHOW_STR
6339 BGP_STR
6340 "Address family\n")
6341
6342/* old command */
6343DEFUN (show_ipv6_bgp,
6344 show_ipv6_bgp_cmd,
6345 "show ipv6 bgp",
6346 SHOW_STR
6347 IP_STR
6348 BGP_STR)
6349{
ajs5a646652004-11-05 01:25:55 +00006350 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6351 NULL);
paul718e3742002-12-13 20:15:29 +00006352}
6353
6354DEFUN (show_bgp_route,
6355 show_bgp_route_cmd,
6356 "show bgp X:X::X:X",
6357 SHOW_STR
6358 BGP_STR
6359 "Network in the BGP routing table to display\n")
6360{
6361 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6362}
6363
6364ALIAS (show_bgp_route,
6365 show_bgp_ipv6_route_cmd,
6366 "show bgp ipv6 X:X::X:X",
6367 SHOW_STR
6368 BGP_STR
6369 "Address family\n"
6370 "Network in the BGP routing table to display\n")
6371
6372/* old command */
6373DEFUN (show_ipv6_bgp_route,
6374 show_ipv6_bgp_route_cmd,
6375 "show ipv6 bgp X:X::X:X",
6376 SHOW_STR
6377 IP_STR
6378 BGP_STR
6379 "Network in the BGP routing table to display\n")
6380{
6381 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6382}
6383
6384DEFUN (show_bgp_prefix,
6385 show_bgp_prefix_cmd,
6386 "show bgp X:X::X:X/M",
6387 SHOW_STR
6388 BGP_STR
6389 "IPv6 prefix <network>/<length>\n")
6390{
6391 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6392}
6393
6394ALIAS (show_bgp_prefix,
6395 show_bgp_ipv6_prefix_cmd,
6396 "show bgp ipv6 X:X::X:X/M",
6397 SHOW_STR
6398 BGP_STR
6399 "Address family\n"
6400 "IPv6 prefix <network>/<length>\n")
6401
6402/* old command */
6403DEFUN (show_ipv6_bgp_prefix,
6404 show_ipv6_bgp_prefix_cmd,
6405 "show ipv6 bgp X:X::X:X/M",
6406 SHOW_STR
6407 IP_STR
6408 BGP_STR
6409 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6410{
6411 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6412}
6413
paulbb46e942003-10-24 19:02:03 +00006414DEFUN (show_bgp_view,
6415 show_bgp_view_cmd,
6416 "show bgp view WORD",
6417 SHOW_STR
6418 BGP_STR
6419 "BGP view\n"
6420 "View name\n")
6421{
6422 struct bgp *bgp;
6423
6424 /* BGP structure lookup. */
6425 bgp = bgp_lookup_by_name (argv[0]);
6426 if (bgp == NULL)
6427 {
6428 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6429 return CMD_WARNING;
6430 }
6431
ajs5a646652004-11-05 01:25:55 +00006432 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006433}
6434
6435ALIAS (show_bgp_view,
6436 show_bgp_view_ipv6_cmd,
6437 "show bgp view WORD ipv6",
6438 SHOW_STR
6439 BGP_STR
6440 "BGP view\n"
6441 "View name\n"
6442 "Address family\n")
6443
6444DEFUN (show_bgp_view_route,
6445 show_bgp_view_route_cmd,
6446 "show bgp view WORD X:X::X:X",
6447 SHOW_STR
6448 BGP_STR
6449 "BGP view\n"
6450 "View name\n"
6451 "Network in the BGP routing table to display\n")
6452{
6453 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6454}
6455
6456ALIAS (show_bgp_view_route,
6457 show_bgp_view_ipv6_route_cmd,
6458 "show bgp view WORD ipv6 X:X::X:X",
6459 SHOW_STR
6460 BGP_STR
6461 "BGP view\n"
6462 "View name\n"
6463 "Address family\n"
6464 "Network in the BGP routing table to display\n")
6465
6466DEFUN (show_bgp_view_prefix,
6467 show_bgp_view_prefix_cmd,
6468 "show bgp view WORD X:X::X:X/M",
6469 SHOW_STR
6470 BGP_STR
6471 "BGP view\n"
6472 "View name\n"
6473 "IPv6 prefix <network>/<length>\n")
6474{
6475 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6476}
6477
6478ALIAS (show_bgp_view_prefix,
6479 show_bgp_view_ipv6_prefix_cmd,
6480 "show bgp view WORD ipv6 X:X::X:X/M",
6481 SHOW_STR
6482 BGP_STR
6483 "BGP view\n"
6484 "View name\n"
6485 "Address family\n"
6486 "IPv6 prefix <network>/<length>\n")
6487
paul718e3742002-12-13 20:15:29 +00006488/* old command */
6489DEFUN (show_ipv6_mbgp,
6490 show_ipv6_mbgp_cmd,
6491 "show ipv6 mbgp",
6492 SHOW_STR
6493 IP_STR
6494 MBGP_STR)
6495{
ajs5a646652004-11-05 01:25:55 +00006496 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6497 NULL);
paul718e3742002-12-13 20:15:29 +00006498}
6499
6500/* old command */
6501DEFUN (show_ipv6_mbgp_route,
6502 show_ipv6_mbgp_route_cmd,
6503 "show ipv6 mbgp X:X::X:X",
6504 SHOW_STR
6505 IP_STR
6506 MBGP_STR
6507 "Network in the MBGP routing table to display\n")
6508{
6509 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6510}
6511
6512/* old command */
6513DEFUN (show_ipv6_mbgp_prefix,
6514 show_ipv6_mbgp_prefix_cmd,
6515 "show ipv6 mbgp X:X::X:X/M",
6516 SHOW_STR
6517 IP_STR
6518 MBGP_STR
6519 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6520{
6521 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6522}
6523#endif
6524
paul718e3742002-12-13 20:15:29 +00006525
paul94f2b392005-06-28 12:44:16 +00006526static int
paulfd79ac92004-10-13 05:06:08 +00006527bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006528 safi_t safi, enum bgp_show_type type)
6529{
6530 int i;
6531 struct buffer *b;
6532 char *regstr;
6533 int first;
6534 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006535 int rc;
paul718e3742002-12-13 20:15:29 +00006536
6537 first = 0;
6538 b = buffer_new (1024);
6539 for (i = 0; i < argc; i++)
6540 {
6541 if (first)
6542 buffer_putc (b, ' ');
6543 else
6544 {
6545 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6546 continue;
6547 first = 1;
6548 }
6549
6550 buffer_putstr (b, argv[i]);
6551 }
6552 buffer_putc (b, '\0');
6553
6554 regstr = buffer_getstr (b);
6555 buffer_free (b);
6556
6557 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006558 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006559 if (! regex)
6560 {
6561 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6562 VTY_NEWLINE);
6563 return CMD_WARNING;
6564 }
6565
ajs5a646652004-11-05 01:25:55 +00006566 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6567 bgp_regex_free (regex);
6568 return rc;
paul718e3742002-12-13 20:15:29 +00006569}
6570
6571DEFUN (show_ip_bgp_regexp,
6572 show_ip_bgp_regexp_cmd,
6573 "show ip bgp regexp .LINE",
6574 SHOW_STR
6575 IP_STR
6576 BGP_STR
6577 "Display routes matching the AS path regular expression\n"
6578 "A regular-expression to match the BGP AS paths\n")
6579{
6580 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6581 bgp_show_type_regexp);
6582}
6583
6584DEFUN (show_ip_bgp_flap_regexp,
6585 show_ip_bgp_flap_regexp_cmd,
6586 "show ip bgp flap-statistics regexp .LINE",
6587 SHOW_STR
6588 IP_STR
6589 BGP_STR
6590 "Display flap statistics of routes\n"
6591 "Display routes matching the AS path regular expression\n"
6592 "A regular-expression to match the BGP AS paths\n")
6593{
6594 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6595 bgp_show_type_flap_regexp);
6596}
6597
6598DEFUN (show_ip_bgp_ipv4_regexp,
6599 show_ip_bgp_ipv4_regexp_cmd,
6600 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6601 SHOW_STR
6602 IP_STR
6603 BGP_STR
6604 "Address family\n"
6605 "Address Family modifier\n"
6606 "Address Family modifier\n"
6607 "Display routes matching the AS path regular expression\n"
6608 "A regular-expression to match the BGP AS paths\n")
6609{
6610 if (strncmp (argv[0], "m", 1) == 0)
6611 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6612 bgp_show_type_regexp);
6613
6614 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6615 bgp_show_type_regexp);
6616}
6617
6618#ifdef HAVE_IPV6
6619DEFUN (show_bgp_regexp,
6620 show_bgp_regexp_cmd,
6621 "show bgp regexp .LINE",
6622 SHOW_STR
6623 BGP_STR
6624 "Display routes matching the AS path regular expression\n"
6625 "A regular-expression to match the BGP AS paths\n")
6626{
6627 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6628 bgp_show_type_regexp);
6629}
6630
6631ALIAS (show_bgp_regexp,
6632 show_bgp_ipv6_regexp_cmd,
6633 "show bgp ipv6 regexp .LINE",
6634 SHOW_STR
6635 BGP_STR
6636 "Address family\n"
6637 "Display routes matching the AS path regular expression\n"
6638 "A regular-expression to match the BGP AS paths\n")
6639
6640/* old command */
6641DEFUN (show_ipv6_bgp_regexp,
6642 show_ipv6_bgp_regexp_cmd,
6643 "show ipv6 bgp regexp .LINE",
6644 SHOW_STR
6645 IP_STR
6646 BGP_STR
6647 "Display routes matching the AS path regular expression\n"
6648 "A regular-expression to match the BGP AS paths\n")
6649{
6650 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6651 bgp_show_type_regexp);
6652}
6653
6654/* old command */
6655DEFUN (show_ipv6_mbgp_regexp,
6656 show_ipv6_mbgp_regexp_cmd,
6657 "show ipv6 mbgp regexp .LINE",
6658 SHOW_STR
6659 IP_STR
6660 BGP_STR
6661 "Display routes matching the AS path regular expression\n"
6662 "A regular-expression to match the MBGP AS paths\n")
6663{
6664 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6665 bgp_show_type_regexp);
6666}
6667#endif /* HAVE_IPV6 */
6668
paul94f2b392005-06-28 12:44:16 +00006669static int
paulfd79ac92004-10-13 05:06:08 +00006670bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006671 safi_t safi, enum bgp_show_type type)
6672{
6673 struct prefix_list *plist;
6674
6675 plist = prefix_list_lookup (afi, prefix_list_str);
6676 if (plist == NULL)
6677 {
6678 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6679 prefix_list_str, VTY_NEWLINE);
6680 return CMD_WARNING;
6681 }
6682
ajs5a646652004-11-05 01:25:55 +00006683 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00006684}
6685
6686DEFUN (show_ip_bgp_prefix_list,
6687 show_ip_bgp_prefix_list_cmd,
6688 "show ip bgp prefix-list WORD",
6689 SHOW_STR
6690 IP_STR
6691 BGP_STR
6692 "Display routes conforming to the prefix-list\n"
6693 "IP prefix-list name\n")
6694{
6695 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6696 bgp_show_type_prefix_list);
6697}
6698
6699DEFUN (show_ip_bgp_flap_prefix_list,
6700 show_ip_bgp_flap_prefix_list_cmd,
6701 "show ip bgp flap-statistics prefix-list WORD",
6702 SHOW_STR
6703 IP_STR
6704 BGP_STR
6705 "Display flap statistics of routes\n"
6706 "Display routes conforming to the prefix-list\n"
6707 "IP prefix-list name\n")
6708{
6709 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6710 bgp_show_type_flap_prefix_list);
6711}
6712
6713DEFUN (show_ip_bgp_ipv4_prefix_list,
6714 show_ip_bgp_ipv4_prefix_list_cmd,
6715 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6716 SHOW_STR
6717 IP_STR
6718 BGP_STR
6719 "Address family\n"
6720 "Address Family modifier\n"
6721 "Address Family modifier\n"
6722 "Display routes conforming to the prefix-list\n"
6723 "IP prefix-list name\n")
6724{
6725 if (strncmp (argv[0], "m", 1) == 0)
6726 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6727 bgp_show_type_prefix_list);
6728
6729 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6730 bgp_show_type_prefix_list);
6731}
6732
6733#ifdef HAVE_IPV6
6734DEFUN (show_bgp_prefix_list,
6735 show_bgp_prefix_list_cmd,
6736 "show bgp prefix-list WORD",
6737 SHOW_STR
6738 BGP_STR
6739 "Display routes conforming to the prefix-list\n"
6740 "IPv6 prefix-list name\n")
6741{
6742 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6743 bgp_show_type_prefix_list);
6744}
6745
6746ALIAS (show_bgp_prefix_list,
6747 show_bgp_ipv6_prefix_list_cmd,
6748 "show bgp ipv6 prefix-list WORD",
6749 SHOW_STR
6750 BGP_STR
6751 "Address family\n"
6752 "Display routes conforming to the prefix-list\n"
6753 "IPv6 prefix-list name\n")
6754
6755/* old command */
6756DEFUN (show_ipv6_bgp_prefix_list,
6757 show_ipv6_bgp_prefix_list_cmd,
6758 "show ipv6 bgp prefix-list WORD",
6759 SHOW_STR
6760 IPV6_STR
6761 BGP_STR
6762 "Display routes matching the prefix-list\n"
6763 "IPv6 prefix-list name\n")
6764{
6765 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6766 bgp_show_type_prefix_list);
6767}
6768
6769/* old command */
6770DEFUN (show_ipv6_mbgp_prefix_list,
6771 show_ipv6_mbgp_prefix_list_cmd,
6772 "show ipv6 mbgp prefix-list WORD",
6773 SHOW_STR
6774 IPV6_STR
6775 MBGP_STR
6776 "Display routes matching the prefix-list\n"
6777 "IPv6 prefix-list name\n")
6778{
6779 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6780 bgp_show_type_prefix_list);
6781}
6782#endif /* HAVE_IPV6 */
6783
paul94f2b392005-06-28 12:44:16 +00006784static int
paulfd79ac92004-10-13 05:06:08 +00006785bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006786 safi_t safi, enum bgp_show_type type)
6787{
6788 struct as_list *as_list;
6789
6790 as_list = as_list_lookup (filter);
6791 if (as_list == NULL)
6792 {
6793 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6794 return CMD_WARNING;
6795 }
6796
ajs5a646652004-11-05 01:25:55 +00006797 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00006798}
6799
6800DEFUN (show_ip_bgp_filter_list,
6801 show_ip_bgp_filter_list_cmd,
6802 "show ip bgp filter-list WORD",
6803 SHOW_STR
6804 IP_STR
6805 BGP_STR
6806 "Display routes conforming to the filter-list\n"
6807 "Regular expression access list name\n")
6808{
6809 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6810 bgp_show_type_filter_list);
6811}
6812
6813DEFUN (show_ip_bgp_flap_filter_list,
6814 show_ip_bgp_flap_filter_list_cmd,
6815 "show ip bgp flap-statistics filter-list WORD",
6816 SHOW_STR
6817 IP_STR
6818 BGP_STR
6819 "Display flap statistics of routes\n"
6820 "Display routes conforming to the filter-list\n"
6821 "Regular expression access list name\n")
6822{
6823 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6824 bgp_show_type_flap_filter_list);
6825}
6826
6827DEFUN (show_ip_bgp_ipv4_filter_list,
6828 show_ip_bgp_ipv4_filter_list_cmd,
6829 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6830 SHOW_STR
6831 IP_STR
6832 BGP_STR
6833 "Address family\n"
6834 "Address Family modifier\n"
6835 "Address Family modifier\n"
6836 "Display routes conforming to the filter-list\n"
6837 "Regular expression access list name\n")
6838{
6839 if (strncmp (argv[0], "m", 1) == 0)
6840 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6841 bgp_show_type_filter_list);
6842
6843 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6844 bgp_show_type_filter_list);
6845}
6846
6847#ifdef HAVE_IPV6
6848DEFUN (show_bgp_filter_list,
6849 show_bgp_filter_list_cmd,
6850 "show bgp filter-list WORD",
6851 SHOW_STR
6852 BGP_STR
6853 "Display routes conforming to the filter-list\n"
6854 "Regular expression access list name\n")
6855{
6856 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6857 bgp_show_type_filter_list);
6858}
6859
6860ALIAS (show_bgp_filter_list,
6861 show_bgp_ipv6_filter_list_cmd,
6862 "show bgp ipv6 filter-list WORD",
6863 SHOW_STR
6864 BGP_STR
6865 "Address family\n"
6866 "Display routes conforming to the filter-list\n"
6867 "Regular expression access list name\n")
6868
6869/* old command */
6870DEFUN (show_ipv6_bgp_filter_list,
6871 show_ipv6_bgp_filter_list_cmd,
6872 "show ipv6 bgp filter-list WORD",
6873 SHOW_STR
6874 IPV6_STR
6875 BGP_STR
6876 "Display routes conforming to the filter-list\n"
6877 "Regular expression access list name\n")
6878{
6879 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6880 bgp_show_type_filter_list);
6881}
6882
6883/* old command */
6884DEFUN (show_ipv6_mbgp_filter_list,
6885 show_ipv6_mbgp_filter_list_cmd,
6886 "show ipv6 mbgp filter-list WORD",
6887 SHOW_STR
6888 IPV6_STR
6889 MBGP_STR
6890 "Display routes conforming to the filter-list\n"
6891 "Regular expression access list name\n")
6892{
6893 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6894 bgp_show_type_filter_list);
6895}
6896#endif /* HAVE_IPV6 */
6897
paul94f2b392005-06-28 12:44:16 +00006898static int
paulfd79ac92004-10-13 05:06:08 +00006899bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006900 safi_t safi, enum bgp_show_type type)
6901{
6902 struct route_map *rmap;
6903
6904 rmap = route_map_lookup_by_name (rmap_str);
6905 if (! rmap)
6906 {
6907 vty_out (vty, "%% %s is not a valid route-map name%s",
6908 rmap_str, VTY_NEWLINE);
6909 return CMD_WARNING;
6910 }
6911
ajs5a646652004-11-05 01:25:55 +00006912 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00006913}
6914
6915DEFUN (show_ip_bgp_route_map,
6916 show_ip_bgp_route_map_cmd,
6917 "show ip bgp route-map WORD",
6918 SHOW_STR
6919 IP_STR
6920 BGP_STR
6921 "Display routes matching the route-map\n"
6922 "A route-map to match on\n")
6923{
6924 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6925 bgp_show_type_route_map);
6926}
6927
6928DEFUN (show_ip_bgp_flap_route_map,
6929 show_ip_bgp_flap_route_map_cmd,
6930 "show ip bgp flap-statistics route-map WORD",
6931 SHOW_STR
6932 IP_STR
6933 BGP_STR
6934 "Display flap statistics of routes\n"
6935 "Display routes matching the route-map\n"
6936 "A route-map to match on\n")
6937{
6938 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6939 bgp_show_type_flap_route_map);
6940}
6941
6942DEFUN (show_ip_bgp_ipv4_route_map,
6943 show_ip_bgp_ipv4_route_map_cmd,
6944 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6945 SHOW_STR
6946 IP_STR
6947 BGP_STR
6948 "Address family\n"
6949 "Address Family modifier\n"
6950 "Address Family modifier\n"
6951 "Display routes matching the route-map\n"
6952 "A route-map to match on\n")
6953{
6954 if (strncmp (argv[0], "m", 1) == 0)
6955 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6956 bgp_show_type_route_map);
6957
6958 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6959 bgp_show_type_route_map);
6960}
6961
6962DEFUN (show_bgp_route_map,
6963 show_bgp_route_map_cmd,
6964 "show bgp route-map WORD",
6965 SHOW_STR
6966 BGP_STR
6967 "Display routes matching the route-map\n"
6968 "A route-map to match on\n")
6969{
6970 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6971 bgp_show_type_route_map);
6972}
6973
6974ALIAS (show_bgp_route_map,
6975 show_bgp_ipv6_route_map_cmd,
6976 "show bgp ipv6 route-map WORD",
6977 SHOW_STR
6978 BGP_STR
6979 "Address family\n"
6980 "Display routes matching the route-map\n"
6981 "A route-map to match on\n")
6982
6983DEFUN (show_ip_bgp_cidr_only,
6984 show_ip_bgp_cidr_only_cmd,
6985 "show ip bgp cidr-only",
6986 SHOW_STR
6987 IP_STR
6988 BGP_STR
6989 "Display only routes with non-natural netmasks\n")
6990{
6991 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006992 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006993}
6994
6995DEFUN (show_ip_bgp_flap_cidr_only,
6996 show_ip_bgp_flap_cidr_only_cmd,
6997 "show ip bgp flap-statistics cidr-only",
6998 SHOW_STR
6999 IP_STR
7000 BGP_STR
7001 "Display flap statistics of routes\n"
7002 "Display only routes with non-natural netmasks\n")
7003{
7004 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007005 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007006}
7007
7008DEFUN (show_ip_bgp_ipv4_cidr_only,
7009 show_ip_bgp_ipv4_cidr_only_cmd,
7010 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7011 SHOW_STR
7012 IP_STR
7013 BGP_STR
7014 "Address family\n"
7015 "Address Family modifier\n"
7016 "Address Family modifier\n"
7017 "Display only routes with non-natural netmasks\n")
7018{
7019 if (strncmp (argv[0], "m", 1) == 0)
7020 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007021 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007022
7023 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007024 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007025}
7026
7027DEFUN (show_ip_bgp_community_all,
7028 show_ip_bgp_community_all_cmd,
7029 "show ip bgp community",
7030 SHOW_STR
7031 IP_STR
7032 BGP_STR
7033 "Display routes matching the communities\n")
7034{
7035 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007036 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007037}
7038
7039DEFUN (show_ip_bgp_ipv4_community_all,
7040 show_ip_bgp_ipv4_community_all_cmd,
7041 "show ip bgp ipv4 (unicast|multicast) community",
7042 SHOW_STR
7043 IP_STR
7044 BGP_STR
7045 "Address family\n"
7046 "Address Family modifier\n"
7047 "Address Family modifier\n"
7048 "Display routes matching the communities\n")
7049{
7050 if (strncmp (argv[0], "m", 1) == 0)
7051 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007052 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007053
7054 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007055 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007056}
7057
7058#ifdef HAVE_IPV6
7059DEFUN (show_bgp_community_all,
7060 show_bgp_community_all_cmd,
7061 "show bgp community",
7062 SHOW_STR
7063 BGP_STR
7064 "Display routes matching the communities\n")
7065{
7066 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007067 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007068}
7069
7070ALIAS (show_bgp_community_all,
7071 show_bgp_ipv6_community_all_cmd,
7072 "show bgp ipv6 community",
7073 SHOW_STR
7074 BGP_STR
7075 "Address family\n"
7076 "Display routes matching the communities\n")
7077
7078/* old command */
7079DEFUN (show_ipv6_bgp_community_all,
7080 show_ipv6_bgp_community_all_cmd,
7081 "show ipv6 bgp community",
7082 SHOW_STR
7083 IPV6_STR
7084 BGP_STR
7085 "Display routes matching the communities\n")
7086{
7087 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007088 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007089}
7090
7091/* old command */
7092DEFUN (show_ipv6_mbgp_community_all,
7093 show_ipv6_mbgp_community_all_cmd,
7094 "show ipv6 mbgp community",
7095 SHOW_STR
7096 IPV6_STR
7097 MBGP_STR
7098 "Display routes matching the communities\n")
7099{
7100 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007101 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007102}
7103#endif /* HAVE_IPV6 */
7104
paul94f2b392005-06-28 12:44:16 +00007105static int
paulfd79ac92004-10-13 05:06:08 +00007106bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7107 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007108{
7109 struct community *com;
7110 struct buffer *b;
7111 int i;
7112 char *str;
7113 int first = 0;
7114
7115 b = buffer_new (1024);
7116 for (i = 0; i < argc; i++)
7117 {
7118 if (first)
7119 buffer_putc (b, ' ');
7120 else
7121 {
7122 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7123 continue;
7124 first = 1;
7125 }
7126
7127 buffer_putstr (b, argv[i]);
7128 }
7129 buffer_putc (b, '\0');
7130
7131 str = buffer_getstr (b);
7132 buffer_free (b);
7133
7134 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007135 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007136 if (! com)
7137 {
7138 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7139 return CMD_WARNING;
7140 }
7141
ajs5a646652004-11-05 01:25:55 +00007142 return bgp_show (vty, NULL, afi, safi,
7143 (exact ? bgp_show_type_community_exact :
7144 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007145}
7146
7147DEFUN (show_ip_bgp_community,
7148 show_ip_bgp_community_cmd,
7149 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7150 SHOW_STR
7151 IP_STR
7152 BGP_STR
7153 "Display routes matching the communities\n"
7154 "community number\n"
7155 "Do not send outside local AS (well-known community)\n"
7156 "Do not advertise to any peer (well-known community)\n"
7157 "Do not export to next AS (well-known community)\n")
7158{
7159 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7160}
7161
7162ALIAS (show_ip_bgp_community,
7163 show_ip_bgp_community2_cmd,
7164 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7165 SHOW_STR
7166 IP_STR
7167 BGP_STR
7168 "Display routes matching the communities\n"
7169 "community number\n"
7170 "Do not send outside local AS (well-known community)\n"
7171 "Do not advertise to any peer (well-known community)\n"
7172 "Do not export to next AS (well-known community)\n"
7173 "community number\n"
7174 "Do not send outside local AS (well-known community)\n"
7175 "Do not advertise to any peer (well-known community)\n"
7176 "Do not export to next AS (well-known community)\n")
7177
7178ALIAS (show_ip_bgp_community,
7179 show_ip_bgp_community3_cmd,
7180 "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)",
7181 SHOW_STR
7182 IP_STR
7183 BGP_STR
7184 "Display routes matching the communities\n"
7185 "community number\n"
7186 "Do not send outside local AS (well-known community)\n"
7187 "Do not advertise to any peer (well-known community)\n"
7188 "Do not export to next AS (well-known community)\n"
7189 "community number\n"
7190 "Do not send outside local AS (well-known community)\n"
7191 "Do not advertise to any peer (well-known community)\n"
7192 "Do not export to next AS (well-known community)\n"
7193 "community number\n"
7194 "Do not send outside local AS (well-known community)\n"
7195 "Do not advertise to any peer (well-known community)\n"
7196 "Do not export to next AS (well-known community)\n")
7197
7198ALIAS (show_ip_bgp_community,
7199 show_ip_bgp_community4_cmd,
7200 "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)",
7201 SHOW_STR
7202 IP_STR
7203 BGP_STR
7204 "Display routes matching the communities\n"
7205 "community number\n"
7206 "Do not send outside local AS (well-known community)\n"
7207 "Do not advertise to any peer (well-known community)\n"
7208 "Do not export to next AS (well-known community)\n"
7209 "community number\n"
7210 "Do not send outside local AS (well-known community)\n"
7211 "Do not advertise to any peer (well-known community)\n"
7212 "Do not export to next AS (well-known community)\n"
7213 "community number\n"
7214 "Do not send outside local AS (well-known community)\n"
7215 "Do not advertise to any peer (well-known community)\n"
7216 "Do not export to next AS (well-known community)\n"
7217 "community number\n"
7218 "Do not send outside local AS (well-known community)\n"
7219 "Do not advertise to any peer (well-known community)\n"
7220 "Do not export to next AS (well-known community)\n")
7221
7222DEFUN (show_ip_bgp_ipv4_community,
7223 show_ip_bgp_ipv4_community_cmd,
7224 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7225 SHOW_STR
7226 IP_STR
7227 BGP_STR
7228 "Address family\n"
7229 "Address Family modifier\n"
7230 "Address Family modifier\n"
7231 "Display routes matching the communities\n"
7232 "community number\n"
7233 "Do not send outside local AS (well-known community)\n"
7234 "Do not advertise to any peer (well-known community)\n"
7235 "Do not export to next AS (well-known community)\n")
7236{
7237 if (strncmp (argv[0], "m", 1) == 0)
7238 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7239
7240 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7241}
7242
7243ALIAS (show_ip_bgp_ipv4_community,
7244 show_ip_bgp_ipv4_community2_cmd,
7245 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7246 SHOW_STR
7247 IP_STR
7248 BGP_STR
7249 "Address family\n"
7250 "Address Family modifier\n"
7251 "Address Family modifier\n"
7252 "Display routes matching the communities\n"
7253 "community number\n"
7254 "Do not send outside local AS (well-known community)\n"
7255 "Do not advertise to any peer (well-known community)\n"
7256 "Do not export to next AS (well-known community)\n"
7257 "community number\n"
7258 "Do not send outside local AS (well-known community)\n"
7259 "Do not advertise to any peer (well-known community)\n"
7260 "Do not export to next AS (well-known community)\n")
7261
7262ALIAS (show_ip_bgp_ipv4_community,
7263 show_ip_bgp_ipv4_community3_cmd,
7264 "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)",
7265 SHOW_STR
7266 IP_STR
7267 BGP_STR
7268 "Address family\n"
7269 "Address Family modifier\n"
7270 "Address Family modifier\n"
7271 "Display routes matching the communities\n"
7272 "community number\n"
7273 "Do not send outside local AS (well-known community)\n"
7274 "Do not advertise to any peer (well-known community)\n"
7275 "Do not export to next AS (well-known community)\n"
7276 "community number\n"
7277 "Do not send outside local AS (well-known community)\n"
7278 "Do not advertise to any peer (well-known community)\n"
7279 "Do not export to next AS (well-known community)\n"
7280 "community number\n"
7281 "Do not send outside local AS (well-known community)\n"
7282 "Do not advertise to any peer (well-known community)\n"
7283 "Do not export to next AS (well-known community)\n")
7284
7285ALIAS (show_ip_bgp_ipv4_community,
7286 show_ip_bgp_ipv4_community4_cmd,
7287 "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)",
7288 SHOW_STR
7289 IP_STR
7290 BGP_STR
7291 "Address family\n"
7292 "Address Family modifier\n"
7293 "Address Family modifier\n"
7294 "Display routes matching the communities\n"
7295 "community number\n"
7296 "Do not send outside local AS (well-known community)\n"
7297 "Do not advertise to any peer (well-known community)\n"
7298 "Do not export to next AS (well-known community)\n"
7299 "community number\n"
7300 "Do not send outside local AS (well-known community)\n"
7301 "Do not advertise to any peer (well-known community)\n"
7302 "Do not export to next AS (well-known community)\n"
7303 "community number\n"
7304 "Do not send outside local AS (well-known community)\n"
7305 "Do not advertise to any peer (well-known community)\n"
7306 "Do not export to next AS (well-known community)\n"
7307 "community number\n"
7308 "Do not send outside local AS (well-known community)\n"
7309 "Do not advertise to any peer (well-known community)\n"
7310 "Do not export to next AS (well-known community)\n")
7311
7312DEFUN (show_ip_bgp_community_exact,
7313 show_ip_bgp_community_exact_cmd,
7314 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7315 SHOW_STR
7316 IP_STR
7317 BGP_STR
7318 "Display routes matching the communities\n"
7319 "community number\n"
7320 "Do not send outside local AS (well-known community)\n"
7321 "Do not advertise to any peer (well-known community)\n"
7322 "Do not export to next AS (well-known community)\n"
7323 "Exact match of the communities")
7324{
7325 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7326}
7327
7328ALIAS (show_ip_bgp_community_exact,
7329 show_ip_bgp_community2_exact_cmd,
7330 "show ip bgp 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 "Display routes matching the communities\n"
7335 "community number\n"
7336 "Do not send outside local AS (well-known community)\n"
7337 "Do not advertise to any peer (well-known community)\n"
7338 "Do not export to next AS (well-known community)\n"
7339 "community number\n"
7340 "Do not send outside local AS (well-known community)\n"
7341 "Do not advertise to any peer (well-known community)\n"
7342 "Do not export to next AS (well-known community)\n"
7343 "Exact match of the communities")
7344
7345ALIAS (show_ip_bgp_community_exact,
7346 show_ip_bgp_community3_exact_cmd,
7347 "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",
7348 SHOW_STR
7349 IP_STR
7350 BGP_STR
7351 "Display routes matching the communities\n"
7352 "community number\n"
7353 "Do not send outside local AS (well-known community)\n"
7354 "Do not advertise to any peer (well-known community)\n"
7355 "Do not export to next AS (well-known community)\n"
7356 "community number\n"
7357 "Do not send outside local AS (well-known community)\n"
7358 "Do not advertise to any peer (well-known community)\n"
7359 "Do not export to next AS (well-known community)\n"
7360 "community number\n"
7361 "Do not send outside local AS (well-known community)\n"
7362 "Do not advertise to any peer (well-known community)\n"
7363 "Do not export to next AS (well-known community)\n"
7364 "Exact match of the communities")
7365
7366ALIAS (show_ip_bgp_community_exact,
7367 show_ip_bgp_community4_exact_cmd,
7368 "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",
7369 SHOW_STR
7370 IP_STR
7371 BGP_STR
7372 "Display routes matching the communities\n"
7373 "community number\n"
7374 "Do not send outside local AS (well-known community)\n"
7375 "Do not advertise to any peer (well-known community)\n"
7376 "Do not export to next AS (well-known community)\n"
7377 "community number\n"
7378 "Do not send outside local AS (well-known community)\n"
7379 "Do not advertise to any peer (well-known community)\n"
7380 "Do not export to next AS (well-known community)\n"
7381 "community number\n"
7382 "Do not send outside local AS (well-known community)\n"
7383 "Do not advertise to any peer (well-known community)\n"
7384 "Do not export to next AS (well-known community)\n"
7385 "community number\n"
7386 "Do not send outside local AS (well-known community)\n"
7387 "Do not advertise to any peer (well-known community)\n"
7388 "Do not export to next AS (well-known community)\n"
7389 "Exact match of the communities")
7390
7391DEFUN (show_ip_bgp_ipv4_community_exact,
7392 show_ip_bgp_ipv4_community_exact_cmd,
7393 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7394 SHOW_STR
7395 IP_STR
7396 BGP_STR
7397 "Address family\n"
7398 "Address Family modifier\n"
7399 "Address Family modifier\n"
7400 "Display routes matching the communities\n"
7401 "community number\n"
7402 "Do not send outside local AS (well-known community)\n"
7403 "Do not advertise to any peer (well-known community)\n"
7404 "Do not export to next AS (well-known community)\n"
7405 "Exact match of the communities")
7406{
7407 if (strncmp (argv[0], "m", 1) == 0)
7408 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7409
7410 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7411}
7412
7413ALIAS (show_ip_bgp_ipv4_community_exact,
7414 show_ip_bgp_ipv4_community2_exact_cmd,
7415 "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",
7416 SHOW_STR
7417 IP_STR
7418 BGP_STR
7419 "Address family\n"
7420 "Address Family modifier\n"
7421 "Address Family modifier\n"
7422 "Display routes matching the communities\n"
7423 "community number\n"
7424 "Do not send outside local AS (well-known community)\n"
7425 "Do not advertise to any peer (well-known community)\n"
7426 "Do not export to next AS (well-known community)\n"
7427 "community number\n"
7428 "Do not send outside local AS (well-known community)\n"
7429 "Do not advertise to any peer (well-known community)\n"
7430 "Do not export to next AS (well-known community)\n"
7431 "Exact match of the communities")
7432
7433ALIAS (show_ip_bgp_ipv4_community_exact,
7434 show_ip_bgp_ipv4_community3_exact_cmd,
7435 "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",
7436 SHOW_STR
7437 IP_STR
7438 BGP_STR
7439 "Address family\n"
7440 "Address Family modifier\n"
7441 "Address Family modifier\n"
7442 "Display routes matching the communities\n"
7443 "community number\n"
7444 "Do not send outside local AS (well-known community)\n"
7445 "Do not advertise to any peer (well-known community)\n"
7446 "Do not export to next AS (well-known community)\n"
7447 "community number\n"
7448 "Do not send outside local AS (well-known community)\n"
7449 "Do not advertise to any peer (well-known community)\n"
7450 "Do not export to next AS (well-known community)\n"
7451 "community number\n"
7452 "Do not send outside local AS (well-known community)\n"
7453 "Do not advertise to any peer (well-known community)\n"
7454 "Do not export to next AS (well-known community)\n"
7455 "Exact match of the communities")
7456
7457ALIAS (show_ip_bgp_ipv4_community_exact,
7458 show_ip_bgp_ipv4_community4_exact_cmd,
7459 "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",
7460 SHOW_STR
7461 IP_STR
7462 BGP_STR
7463 "Address family\n"
7464 "Address Family modifier\n"
7465 "Address Family modifier\n"
7466 "Display routes matching the communities\n"
7467 "community number\n"
7468 "Do not send outside local AS (well-known community)\n"
7469 "Do not advertise to any peer (well-known community)\n"
7470 "Do not export to next AS (well-known community)\n"
7471 "community number\n"
7472 "Do not send outside local AS (well-known community)\n"
7473 "Do not advertise to any peer (well-known community)\n"
7474 "Do not export to next AS (well-known community)\n"
7475 "community number\n"
7476 "Do not send outside local AS (well-known community)\n"
7477 "Do not advertise to any peer (well-known community)\n"
7478 "Do not export to next AS (well-known community)\n"
7479 "community number\n"
7480 "Do not send outside local AS (well-known community)\n"
7481 "Do not advertise to any peer (well-known community)\n"
7482 "Do not export to next AS (well-known community)\n"
7483 "Exact match of the communities")
7484
7485#ifdef HAVE_IPV6
7486DEFUN (show_bgp_community,
7487 show_bgp_community_cmd,
7488 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7489 SHOW_STR
7490 BGP_STR
7491 "Display routes matching the communities\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{
7497 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7498}
7499
7500ALIAS (show_bgp_community,
7501 show_bgp_ipv6_community_cmd,
7502 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7503 SHOW_STR
7504 BGP_STR
7505 "Address family\n"
7506 "Display routes matching the communities\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
7512ALIAS (show_bgp_community,
7513 show_bgp_community2_cmd,
7514 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7515 SHOW_STR
7516 BGP_STR
7517 "Display routes matching the communities\n"
7518 "community number\n"
7519 "Do not send outside local AS (well-known community)\n"
7520 "Do not advertise to any peer (well-known community)\n"
7521 "Do not export to next AS (well-known community)\n"
7522 "community number\n"
7523 "Do not send outside local AS (well-known community)\n"
7524 "Do not advertise to any peer (well-known community)\n"
7525 "Do not export to next AS (well-known community)\n")
7526
7527ALIAS (show_bgp_community,
7528 show_bgp_ipv6_community2_cmd,
7529 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7530 SHOW_STR
7531 BGP_STR
7532 "Address family\n"
7533 "Display routes matching the communities\n"
7534 "community number\n"
7535 "Do not send outside local AS (well-known community)\n"
7536 "Do not advertise to any peer (well-known community)\n"
7537 "Do not export to next AS (well-known community)\n"
7538 "community number\n"
7539 "Do not send outside local AS (well-known community)\n"
7540 "Do not advertise to any peer (well-known community)\n"
7541 "Do not export to next AS (well-known community)\n")
7542
7543ALIAS (show_bgp_community,
7544 show_bgp_community3_cmd,
7545 "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)",
7546 SHOW_STR
7547 BGP_STR
7548 "Display routes matching the communities\n"
7549 "community number\n"
7550 "Do not send outside local AS (well-known community)\n"
7551 "Do not advertise to any peer (well-known community)\n"
7552 "Do not export to next AS (well-known community)\n"
7553 "community number\n"
7554 "Do not send outside local AS (well-known community)\n"
7555 "Do not advertise to any peer (well-known community)\n"
7556 "Do not export to next AS (well-known community)\n"
7557 "community number\n"
7558 "Do not send outside local AS (well-known community)\n"
7559 "Do not advertise to any peer (well-known community)\n"
7560 "Do not export to next AS (well-known community)\n")
7561
7562ALIAS (show_bgp_community,
7563 show_bgp_ipv6_community3_cmd,
7564 "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)",
7565 SHOW_STR
7566 BGP_STR
7567 "Address family\n"
7568 "Display routes matching the communities\n"
7569 "community number\n"
7570 "Do not send outside local AS (well-known community)\n"
7571 "Do not advertise to any peer (well-known community)\n"
7572 "Do not export to next AS (well-known community)\n"
7573 "community number\n"
7574 "Do not send outside local AS (well-known community)\n"
7575 "Do not advertise to any peer (well-known community)\n"
7576 "Do not export to next AS (well-known community)\n"
7577 "community number\n"
7578 "Do not send outside local AS (well-known community)\n"
7579 "Do not advertise to any peer (well-known community)\n"
7580 "Do not export to next AS (well-known community)\n")
7581
7582ALIAS (show_bgp_community,
7583 show_bgp_community4_cmd,
7584 "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)",
7585 SHOW_STR
7586 BGP_STR
7587 "Display routes matching the communities\n"
7588 "community number\n"
7589 "Do not send outside local AS (well-known community)\n"
7590 "Do not advertise to any peer (well-known community)\n"
7591 "Do not export to next AS (well-known community)\n"
7592 "community number\n"
7593 "Do not send outside local AS (well-known community)\n"
7594 "Do not advertise to any peer (well-known community)\n"
7595 "Do not export to next AS (well-known community)\n"
7596 "community number\n"
7597 "Do not send outside local AS (well-known community)\n"
7598 "Do not advertise to any peer (well-known community)\n"
7599 "Do not export to next AS (well-known community)\n"
7600 "community number\n"
7601 "Do not send outside local AS (well-known community)\n"
7602 "Do not advertise to any peer (well-known community)\n"
7603 "Do not export to next AS (well-known community)\n")
7604
7605ALIAS (show_bgp_community,
7606 show_bgp_ipv6_community4_cmd,
7607 "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)",
7608 SHOW_STR
7609 BGP_STR
7610 "Address family\n"
7611 "Display routes matching the communities\n"
7612 "community number\n"
7613 "Do not send outside local AS (well-known community)\n"
7614 "Do not advertise to any peer (well-known community)\n"
7615 "Do not export to next AS (well-known community)\n"
7616 "community number\n"
7617 "Do not send outside local AS (well-known community)\n"
7618 "Do not advertise to any peer (well-known community)\n"
7619 "Do not export to next AS (well-known community)\n"
7620 "community number\n"
7621 "Do not send outside local AS (well-known community)\n"
7622 "Do not advertise to any peer (well-known community)\n"
7623 "Do not export to next AS (well-known community)\n"
7624 "community number\n"
7625 "Do not send outside local AS (well-known community)\n"
7626 "Do not advertise to any peer (well-known community)\n"
7627 "Do not export to next AS (well-known community)\n")
7628
7629/* old command */
7630DEFUN (show_ipv6_bgp_community,
7631 show_ipv6_bgp_community_cmd,
7632 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7633 SHOW_STR
7634 IPV6_STR
7635 BGP_STR
7636 "Display routes matching the communities\n"
7637 "community number\n"
7638 "Do not send outside local AS (well-known community)\n"
7639 "Do not advertise to any peer (well-known community)\n"
7640 "Do not export to next AS (well-known community)\n")
7641{
7642 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7643}
7644
7645/* old command */
7646ALIAS (show_ipv6_bgp_community,
7647 show_ipv6_bgp_community2_cmd,
7648 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7649 SHOW_STR
7650 IPV6_STR
7651 BGP_STR
7652 "Display routes matching the communities\n"
7653 "community number\n"
7654 "Do not send outside local AS (well-known community)\n"
7655 "Do not advertise to any peer (well-known community)\n"
7656 "Do not export to next AS (well-known community)\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
7662/* old command */
7663ALIAS (show_ipv6_bgp_community,
7664 show_ipv6_bgp_community3_cmd,
7665 "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)",
7666 SHOW_STR
7667 IPV6_STR
7668 BGP_STR
7669 "Display routes matching the communities\n"
7670 "community number\n"
7671 "Do not send outside local AS (well-known community)\n"
7672 "Do not advertise to any peer (well-known community)\n"
7673 "Do not export to next AS (well-known community)\n"
7674 "community number\n"
7675 "Do not send outside local AS (well-known community)\n"
7676 "Do not advertise to any peer (well-known community)\n"
7677 "Do not export to next AS (well-known community)\n"
7678 "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
7683/* old command */
7684ALIAS (show_ipv6_bgp_community,
7685 show_ipv6_bgp_community4_cmd,
7686 "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)",
7687 SHOW_STR
7688 IPV6_STR
7689 BGP_STR
7690 "Display routes matching the communities\n"
7691 "community number\n"
7692 "Do not send outside local AS (well-known community)\n"
7693 "Do not advertise to any peer (well-known community)\n"
7694 "Do not export to next AS (well-known community)\n"
7695 "community number\n"
7696 "Do not send outside local AS (well-known community)\n"
7697 "Do not advertise to any peer (well-known community)\n"
7698 "Do not export to next AS (well-known community)\n"
7699 "community number\n"
7700 "Do not send outside local AS (well-known community)\n"
7701 "Do not advertise to any peer (well-known community)\n"
7702 "Do not export to next AS (well-known community)\n"
7703 "community number\n"
7704 "Do not send outside local AS (well-known community)\n"
7705 "Do not advertise to any peer (well-known community)\n"
7706 "Do not export to next AS (well-known community)\n")
7707
7708DEFUN (show_bgp_community_exact,
7709 show_bgp_community_exact_cmd,
7710 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7711 SHOW_STR
7712 BGP_STR
7713 "Display routes matching the communities\n"
7714 "community number\n"
7715 "Do not send outside local AS (well-known community)\n"
7716 "Do not advertise to any peer (well-known community)\n"
7717 "Do not export to next AS (well-known community)\n"
7718 "Exact match of the communities")
7719{
7720 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7721}
7722
7723ALIAS (show_bgp_community_exact,
7724 show_bgp_ipv6_community_exact_cmd,
7725 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7726 SHOW_STR
7727 BGP_STR
7728 "Address family\n"
7729 "Display routes matching the communities\n"
7730 "community number\n"
7731 "Do not send outside local AS (well-known community)\n"
7732 "Do not advertise to any peer (well-known community)\n"
7733 "Do not export to next AS (well-known community)\n"
7734 "Exact match of the communities")
7735
7736ALIAS (show_bgp_community_exact,
7737 show_bgp_community2_exact_cmd,
7738 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7739 SHOW_STR
7740 BGP_STR
7741 "Display routes matching the communities\n"
7742 "community number\n"
7743 "Do not send outside local AS (well-known community)\n"
7744 "Do not advertise to any peer (well-known community)\n"
7745 "Do not export to next AS (well-known community)\n"
7746 "community number\n"
7747 "Do not send outside local AS (well-known community)\n"
7748 "Do not advertise to any peer (well-known community)\n"
7749 "Do not export to next AS (well-known community)\n"
7750 "Exact match of the communities")
7751
7752ALIAS (show_bgp_community_exact,
7753 show_bgp_ipv6_community2_exact_cmd,
7754 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7755 SHOW_STR
7756 BGP_STR
7757 "Address family\n"
7758 "Display routes matching the communities\n"
7759 "community number\n"
7760 "Do not send outside local AS (well-known community)\n"
7761 "Do not advertise to any peer (well-known community)\n"
7762 "Do not export to next AS (well-known community)\n"
7763 "community number\n"
7764 "Do not send outside local AS (well-known community)\n"
7765 "Do not advertise to any peer (well-known community)\n"
7766 "Do not export to next AS (well-known community)\n"
7767 "Exact match of the communities")
7768
7769ALIAS (show_bgp_community_exact,
7770 show_bgp_community3_exact_cmd,
7771 "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",
7772 SHOW_STR
7773 BGP_STR
7774 "Display routes matching the communities\n"
7775 "community number\n"
7776 "Do not send outside local AS (well-known community)\n"
7777 "Do not advertise to any peer (well-known community)\n"
7778 "Do not export to next AS (well-known community)\n"
7779 "community number\n"
7780 "Do not send outside local AS (well-known community)\n"
7781 "Do not advertise to any peer (well-known community)\n"
7782 "Do not export to next AS (well-known community)\n"
7783 "community number\n"
7784 "Do not send outside local AS (well-known community)\n"
7785 "Do not advertise to any peer (well-known community)\n"
7786 "Do not export to next AS (well-known community)\n"
7787 "Exact match of the communities")
7788
7789ALIAS (show_bgp_community_exact,
7790 show_bgp_ipv6_community3_exact_cmd,
7791 "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",
7792 SHOW_STR
7793 BGP_STR
7794 "Address family\n"
7795 "Display routes matching the communities\n"
7796 "community number\n"
7797 "Do not send outside local AS (well-known community)\n"
7798 "Do not advertise to any peer (well-known community)\n"
7799 "Do not export to next AS (well-known community)\n"
7800 "community number\n"
7801 "Do not send outside local AS (well-known community)\n"
7802 "Do not advertise to any peer (well-known community)\n"
7803 "Do not export to next AS (well-known community)\n"
7804 "community number\n"
7805 "Do not send outside local AS (well-known community)\n"
7806 "Do not advertise to any peer (well-known community)\n"
7807 "Do not export to next AS (well-known community)\n"
7808 "Exact match of the communities")
7809
7810ALIAS (show_bgp_community_exact,
7811 show_bgp_community4_exact_cmd,
7812 "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",
7813 SHOW_STR
7814 BGP_STR
7815 "Display routes matching the communities\n"
7816 "community number\n"
7817 "Do not send outside local AS (well-known community)\n"
7818 "Do not advertise to any peer (well-known community)\n"
7819 "Do not export to next AS (well-known community)\n"
7820 "community number\n"
7821 "Do not send outside local AS (well-known community)\n"
7822 "Do not advertise to any peer (well-known community)\n"
7823 "Do not export to next AS (well-known community)\n"
7824 "community number\n"
7825 "Do not send outside local AS (well-known community)\n"
7826 "Do not advertise to any peer (well-known community)\n"
7827 "Do not export to next AS (well-known community)\n"
7828 "community number\n"
7829 "Do not send outside local AS (well-known community)\n"
7830 "Do not advertise to any peer (well-known community)\n"
7831 "Do not export to next AS (well-known community)\n"
7832 "Exact match of the communities")
7833
7834ALIAS (show_bgp_community_exact,
7835 show_bgp_ipv6_community4_exact_cmd,
7836 "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",
7837 SHOW_STR
7838 BGP_STR
7839 "Address family\n"
7840 "Display routes matching the communities\n"
7841 "community number\n"
7842 "Do not send outside local AS (well-known community)\n"
7843 "Do not advertise to any peer (well-known community)\n"
7844 "Do not export to next AS (well-known community)\n"
7845 "community number\n"
7846 "Do not send outside local AS (well-known community)\n"
7847 "Do not advertise to any peer (well-known community)\n"
7848 "Do not export to next AS (well-known community)\n"
7849 "community number\n"
7850 "Do not send outside local AS (well-known community)\n"
7851 "Do not advertise to any peer (well-known community)\n"
7852 "Do not export to next AS (well-known community)\n"
7853 "community number\n"
7854 "Do not send outside local AS (well-known community)\n"
7855 "Do not advertise to any peer (well-known community)\n"
7856 "Do not export to next AS (well-known community)\n"
7857 "Exact match of the communities")
7858
7859/* old command */
7860DEFUN (show_ipv6_bgp_community_exact,
7861 show_ipv6_bgp_community_exact_cmd,
7862 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7863 SHOW_STR
7864 IPV6_STR
7865 BGP_STR
7866 "Display routes matching the communities\n"
7867 "community number\n"
7868 "Do not send outside local AS (well-known community)\n"
7869 "Do not advertise to any peer (well-known community)\n"
7870 "Do not export to next AS (well-known community)\n"
7871 "Exact match of the communities")
7872{
7873 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7874}
7875
7876/* old command */
7877ALIAS (show_ipv6_bgp_community_exact,
7878 show_ipv6_bgp_community2_exact_cmd,
7879 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7880 SHOW_STR
7881 IPV6_STR
7882 BGP_STR
7883 "Display routes matching the communities\n"
7884 "community number\n"
7885 "Do not send outside local AS (well-known community)\n"
7886 "Do not advertise to any peer (well-known community)\n"
7887 "Do not export to next AS (well-known community)\n"
7888 "community number\n"
7889 "Do not send outside local AS (well-known community)\n"
7890 "Do not advertise to any peer (well-known community)\n"
7891 "Do not export to next AS (well-known community)\n"
7892 "Exact match of the communities")
7893
7894/* old command */
7895ALIAS (show_ipv6_bgp_community_exact,
7896 show_ipv6_bgp_community3_exact_cmd,
7897 "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",
7898 SHOW_STR
7899 IPV6_STR
7900 BGP_STR
7901 "Display routes matching the communities\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 "community number\n"
7911 "Do not send outside local AS (well-known community)\n"
7912 "Do not advertise to any peer (well-known community)\n"
7913 "Do not export to next AS (well-known community)\n"
7914 "Exact match of the communities")
7915
7916/* old command */
7917ALIAS (show_ipv6_bgp_community_exact,
7918 show_ipv6_bgp_community4_exact_cmd,
7919 "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",
7920 SHOW_STR
7921 IPV6_STR
7922 BGP_STR
7923 "Display routes matching the communities\n"
7924 "community number\n"
7925 "Do not send outside local AS (well-known community)\n"
7926 "Do not advertise to any peer (well-known community)\n"
7927 "Do not export to next AS (well-known community)\n"
7928 "community number\n"
7929 "Do not send outside local AS (well-known community)\n"
7930 "Do not advertise to any peer (well-known community)\n"
7931 "Do not export to next AS (well-known community)\n"
7932 "community number\n"
7933 "Do not send outside local AS (well-known community)\n"
7934 "Do not advertise to any peer (well-known community)\n"
7935 "Do not export to next AS (well-known community)\n"
7936 "community number\n"
7937 "Do not send outside local AS (well-known community)\n"
7938 "Do not advertise to any peer (well-known community)\n"
7939 "Do not export to next AS (well-known community)\n"
7940 "Exact match of the communities")
7941
7942/* old command */
7943DEFUN (show_ipv6_mbgp_community,
7944 show_ipv6_mbgp_community_cmd,
7945 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7946 SHOW_STR
7947 IPV6_STR
7948 MBGP_STR
7949 "Display routes matching the communities\n"
7950 "community number\n"
7951 "Do not send outside local AS (well-known community)\n"
7952 "Do not advertise to any peer (well-known community)\n"
7953 "Do not export to next AS (well-known community)\n")
7954{
7955 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7956}
7957
7958/* old command */
7959ALIAS (show_ipv6_mbgp_community,
7960 show_ipv6_mbgp_community2_cmd,
7961 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7962 SHOW_STR
7963 IPV6_STR
7964 MBGP_STR
7965 "Display routes matching the communities\n"
7966 "community number\n"
7967 "Do not send outside local AS (well-known community)\n"
7968 "Do not advertise to any peer (well-known community)\n"
7969 "Do not export to next AS (well-known community)\n"
7970 "community number\n"
7971 "Do not send outside local AS (well-known community)\n"
7972 "Do not advertise to any peer (well-known community)\n"
7973 "Do not export to next AS (well-known community)\n")
7974
7975/* old command */
7976ALIAS (show_ipv6_mbgp_community,
7977 show_ipv6_mbgp_community3_cmd,
7978 "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)",
7979 SHOW_STR
7980 IPV6_STR
7981 MBGP_STR
7982 "Display routes matching the communities\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 "community number\n"
7992 "Do not send outside local AS (well-known community)\n"
7993 "Do not advertise to any peer (well-known community)\n"
7994 "Do not export to next AS (well-known community)\n")
7995
7996/* old command */
7997ALIAS (show_ipv6_mbgp_community,
7998 show_ipv6_mbgp_community4_cmd,
7999 "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)",
8000 SHOW_STR
8001 IPV6_STR
8002 MBGP_STR
8003 "Display routes matching the communities\n"
8004 "community number\n"
8005 "Do not send outside local AS (well-known community)\n"
8006 "Do not advertise to any peer (well-known community)\n"
8007 "Do not export to next AS (well-known community)\n"
8008 "community number\n"
8009 "Do not send outside local AS (well-known community)\n"
8010 "Do not advertise to any peer (well-known community)\n"
8011 "Do not export to next AS (well-known community)\n"
8012 "community number\n"
8013 "Do not send outside local AS (well-known community)\n"
8014 "Do not advertise to any peer (well-known community)\n"
8015 "Do not export to next AS (well-known community)\n"
8016 "community number\n"
8017 "Do not send outside local AS (well-known community)\n"
8018 "Do not advertise to any peer (well-known community)\n"
8019 "Do not export to next AS (well-known community)\n")
8020
8021/* old command */
8022DEFUN (show_ipv6_mbgp_community_exact,
8023 show_ipv6_mbgp_community_exact_cmd,
8024 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8025 SHOW_STR
8026 IPV6_STR
8027 MBGP_STR
8028 "Display routes matching the communities\n"
8029 "community number\n"
8030 "Do not send outside local AS (well-known community)\n"
8031 "Do not advertise to any peer (well-known community)\n"
8032 "Do not export to next AS (well-known community)\n"
8033 "Exact match of the communities")
8034{
8035 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8036}
8037
8038/* old command */
8039ALIAS (show_ipv6_mbgp_community_exact,
8040 show_ipv6_mbgp_community2_exact_cmd,
8041 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8042 SHOW_STR
8043 IPV6_STR
8044 MBGP_STR
8045 "Display routes matching the communities\n"
8046 "community number\n"
8047 "Do not send outside local AS (well-known community)\n"
8048 "Do not advertise to any peer (well-known community)\n"
8049 "Do not export to next AS (well-known community)\n"
8050 "community number\n"
8051 "Do not send outside local AS (well-known community)\n"
8052 "Do not advertise to any peer (well-known community)\n"
8053 "Do not export to next AS (well-known community)\n"
8054 "Exact match of the communities")
8055
8056/* old command */
8057ALIAS (show_ipv6_mbgp_community_exact,
8058 show_ipv6_mbgp_community3_exact_cmd,
8059 "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",
8060 SHOW_STR
8061 IPV6_STR
8062 MBGP_STR
8063 "Display routes matching the communities\n"
8064 "community number\n"
8065 "Do not send outside local AS (well-known community)\n"
8066 "Do not advertise to any peer (well-known community)\n"
8067 "Do not export to next AS (well-known community)\n"
8068 "community number\n"
8069 "Do not send outside local AS (well-known community)\n"
8070 "Do not advertise to any peer (well-known community)\n"
8071 "Do not export to next AS (well-known community)\n"
8072 "community number\n"
8073 "Do not send outside local AS (well-known community)\n"
8074 "Do not advertise to any peer (well-known community)\n"
8075 "Do not export to next AS (well-known community)\n"
8076 "Exact match of the communities")
8077
8078/* old command */
8079ALIAS (show_ipv6_mbgp_community_exact,
8080 show_ipv6_mbgp_community4_exact_cmd,
8081 "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",
8082 SHOW_STR
8083 IPV6_STR
8084 MBGP_STR
8085 "Display routes matching the communities\n"
8086 "community number\n"
8087 "Do not send outside local AS (well-known community)\n"
8088 "Do not advertise to any peer (well-known community)\n"
8089 "Do not export to next AS (well-known community)\n"
8090 "community number\n"
8091 "Do not send outside local AS (well-known community)\n"
8092 "Do not advertise to any peer (well-known community)\n"
8093 "Do not export to next AS (well-known community)\n"
8094 "community number\n"
8095 "Do not send outside local AS (well-known community)\n"
8096 "Do not advertise to any peer (well-known community)\n"
8097 "Do not export to next AS (well-known community)\n"
8098 "community number\n"
8099 "Do not send outside local AS (well-known community)\n"
8100 "Do not advertise to any peer (well-known community)\n"
8101 "Do not export to next AS (well-known community)\n"
8102 "Exact match of the communities")
8103#endif /* HAVE_IPV6 */
8104
paul94f2b392005-06-28 12:44:16 +00008105static int
paulfd79ac92004-10-13 05:06:08 +00008106bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008107 u_int16_t afi, u_char safi)
8108{
8109 struct community_list *list;
8110
hassofee6e4e2005-02-02 16:29:31 +00008111 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008112 if (list == NULL)
8113 {
8114 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8115 VTY_NEWLINE);
8116 return CMD_WARNING;
8117 }
8118
ajs5a646652004-11-05 01:25:55 +00008119 return bgp_show (vty, NULL, afi, safi,
8120 (exact ? bgp_show_type_community_list_exact :
8121 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008122}
8123
8124DEFUN (show_ip_bgp_community_list,
8125 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008126 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008127 SHOW_STR
8128 IP_STR
8129 BGP_STR
8130 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008131 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008132 "community-list name\n")
8133{
8134 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8135}
8136
8137DEFUN (show_ip_bgp_ipv4_community_list,
8138 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008139 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008140 SHOW_STR
8141 IP_STR
8142 BGP_STR
8143 "Address family\n"
8144 "Address Family modifier\n"
8145 "Address Family modifier\n"
8146 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008147 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008148 "community-list name\n")
8149{
8150 if (strncmp (argv[0], "m", 1) == 0)
8151 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8152
8153 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8154}
8155
8156DEFUN (show_ip_bgp_community_list_exact,
8157 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008158 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008159 SHOW_STR
8160 IP_STR
8161 BGP_STR
8162 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008163 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008164 "community-list name\n"
8165 "Exact match of the communities\n")
8166{
8167 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8168}
8169
8170DEFUN (show_ip_bgp_ipv4_community_list_exact,
8171 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008172 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008173 SHOW_STR
8174 IP_STR
8175 BGP_STR
8176 "Address family\n"
8177 "Address Family modifier\n"
8178 "Address Family modifier\n"
8179 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008180 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008181 "community-list name\n"
8182 "Exact match of the communities\n")
8183{
8184 if (strncmp (argv[0], "m", 1) == 0)
8185 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8186
8187 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8188}
8189
8190#ifdef HAVE_IPV6
8191DEFUN (show_bgp_community_list,
8192 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008193 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008194 SHOW_STR
8195 BGP_STR
8196 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008197 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008198 "community-list name\n")
8199{
8200 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8201}
8202
8203ALIAS (show_bgp_community_list,
8204 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008205 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008206 SHOW_STR
8207 BGP_STR
8208 "Address family\n"
8209 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008210 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008211 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008212
8213/* old command */
8214DEFUN (show_ipv6_bgp_community_list,
8215 show_ipv6_bgp_community_list_cmd,
8216 "show ipv6 bgp community-list WORD",
8217 SHOW_STR
8218 IPV6_STR
8219 BGP_STR
8220 "Display routes matching the community-list\n"
8221 "community-list name\n")
8222{
8223 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8224}
8225
8226/* old command */
8227DEFUN (show_ipv6_mbgp_community_list,
8228 show_ipv6_mbgp_community_list_cmd,
8229 "show ipv6 mbgp community-list WORD",
8230 SHOW_STR
8231 IPV6_STR
8232 MBGP_STR
8233 "Display routes matching the community-list\n"
8234 "community-list name\n")
8235{
8236 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8237}
8238
8239DEFUN (show_bgp_community_list_exact,
8240 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008241 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008242 SHOW_STR
8243 BGP_STR
8244 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008245 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008246 "community-list name\n"
8247 "Exact match of the communities\n")
8248{
8249 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8250}
8251
8252ALIAS (show_bgp_community_list_exact,
8253 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008254 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008255 SHOW_STR
8256 BGP_STR
8257 "Address family\n"
8258 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008259 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008260 "community-list name\n"
8261 "Exact match of the communities\n")
8262
8263/* old command */
8264DEFUN (show_ipv6_bgp_community_list_exact,
8265 show_ipv6_bgp_community_list_exact_cmd,
8266 "show ipv6 bgp community-list WORD exact-match",
8267 SHOW_STR
8268 IPV6_STR
8269 BGP_STR
8270 "Display routes matching the community-list\n"
8271 "community-list name\n"
8272 "Exact match of the communities\n")
8273{
8274 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8275}
8276
8277/* old command */
8278DEFUN (show_ipv6_mbgp_community_list_exact,
8279 show_ipv6_mbgp_community_list_exact_cmd,
8280 "show ipv6 mbgp community-list WORD exact-match",
8281 SHOW_STR
8282 IPV6_STR
8283 MBGP_STR
8284 "Display routes matching the community-list\n"
8285 "community-list name\n"
8286 "Exact match of the communities\n")
8287{
8288 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8289}
8290#endif /* HAVE_IPV6 */
8291
paul94f2b392005-06-28 12:44:16 +00008292static int
paulfd79ac92004-10-13 05:06:08 +00008293bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008294 safi_t safi, enum bgp_show_type type)
8295{
8296 int ret;
8297 struct prefix *p;
8298
8299 p = prefix_new();
8300
8301 ret = str2prefix (prefix, p);
8302 if (! ret)
8303 {
8304 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8305 return CMD_WARNING;
8306 }
8307
ajs5a646652004-11-05 01:25:55 +00008308 ret = bgp_show (vty, NULL, afi, safi, type, p);
8309 prefix_free(p);
8310 return ret;
paul718e3742002-12-13 20:15:29 +00008311}
8312
8313DEFUN (show_ip_bgp_prefix_longer,
8314 show_ip_bgp_prefix_longer_cmd,
8315 "show ip bgp A.B.C.D/M longer-prefixes",
8316 SHOW_STR
8317 IP_STR
8318 BGP_STR
8319 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8320 "Display route and more specific routes\n")
8321{
8322 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8323 bgp_show_type_prefix_longer);
8324}
8325
8326DEFUN (show_ip_bgp_flap_prefix_longer,
8327 show_ip_bgp_flap_prefix_longer_cmd,
8328 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8329 SHOW_STR
8330 IP_STR
8331 BGP_STR
8332 "Display flap statistics of routes\n"
8333 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8334 "Display route and more specific routes\n")
8335{
8336 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8337 bgp_show_type_flap_prefix_longer);
8338}
8339
8340DEFUN (show_ip_bgp_ipv4_prefix_longer,
8341 show_ip_bgp_ipv4_prefix_longer_cmd,
8342 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8343 SHOW_STR
8344 IP_STR
8345 BGP_STR
8346 "Address family\n"
8347 "Address Family modifier\n"
8348 "Address Family modifier\n"
8349 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8350 "Display route and more specific routes\n")
8351{
8352 if (strncmp (argv[0], "m", 1) == 0)
8353 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8354 bgp_show_type_prefix_longer);
8355
8356 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8357 bgp_show_type_prefix_longer);
8358}
8359
8360DEFUN (show_ip_bgp_flap_address,
8361 show_ip_bgp_flap_address_cmd,
8362 "show ip bgp flap-statistics A.B.C.D",
8363 SHOW_STR
8364 IP_STR
8365 BGP_STR
8366 "Display flap statistics of routes\n"
8367 "Network in the BGP routing table to display\n")
8368{
8369 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8370 bgp_show_type_flap_address);
8371}
8372
8373DEFUN (show_ip_bgp_flap_prefix,
8374 show_ip_bgp_flap_prefix_cmd,
8375 "show ip bgp flap-statistics A.B.C.D/M",
8376 SHOW_STR
8377 IP_STR
8378 BGP_STR
8379 "Display flap statistics of routes\n"
8380 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8381{
8382 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8383 bgp_show_type_flap_prefix);
8384}
8385#ifdef HAVE_IPV6
8386DEFUN (show_bgp_prefix_longer,
8387 show_bgp_prefix_longer_cmd,
8388 "show bgp X:X::X:X/M longer-prefixes",
8389 SHOW_STR
8390 BGP_STR
8391 "IPv6 prefix <network>/<length>\n"
8392 "Display route and more specific routes\n")
8393{
8394 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8395 bgp_show_type_prefix_longer);
8396}
8397
8398ALIAS (show_bgp_prefix_longer,
8399 show_bgp_ipv6_prefix_longer_cmd,
8400 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8401 SHOW_STR
8402 BGP_STR
8403 "Address family\n"
8404 "IPv6 prefix <network>/<length>\n"
8405 "Display route and more specific routes\n")
8406
8407/* old command */
8408DEFUN (show_ipv6_bgp_prefix_longer,
8409 show_ipv6_bgp_prefix_longer_cmd,
8410 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8411 SHOW_STR
8412 IPV6_STR
8413 BGP_STR
8414 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8415 "Display route and more specific routes\n")
8416{
8417 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8418 bgp_show_type_prefix_longer);
8419}
8420
8421/* old command */
8422DEFUN (show_ipv6_mbgp_prefix_longer,
8423 show_ipv6_mbgp_prefix_longer_cmd,
8424 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8425 SHOW_STR
8426 IPV6_STR
8427 MBGP_STR
8428 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8429 "Display route and more specific routes\n")
8430{
8431 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8432 bgp_show_type_prefix_longer);
8433}
8434#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008435
paul94f2b392005-06-28 12:44:16 +00008436static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008437peer_lookup_in_view (struct vty *vty, const char *view_name,
8438 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008439{
8440 int ret;
8441 struct bgp *bgp;
8442 struct peer *peer;
8443 union sockunion su;
8444
8445 /* BGP structure lookup. */
8446 if (view_name)
8447 {
8448 bgp = bgp_lookup_by_name (view_name);
8449 if (! bgp)
8450 {
8451 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8452 return NULL;
8453 }
8454 }
paul5228ad22004-06-04 17:58:18 +00008455 else
paulbb46e942003-10-24 19:02:03 +00008456 {
8457 bgp = bgp_get_default ();
8458 if (! bgp)
8459 {
8460 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8461 return NULL;
8462 }
8463 }
8464
8465 /* Get peer sockunion. */
8466 ret = str2sockunion (ip_str, &su);
8467 if (ret < 0)
8468 {
8469 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8470 return NULL;
8471 }
8472
8473 /* Peer structure lookup. */
8474 peer = peer_lookup (bgp, &su);
8475 if (! peer)
8476 {
8477 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8478 return NULL;
8479 }
8480
8481 return peer;
8482}
Paul Jakma2815e612006-09-14 02:56:07 +00008483
8484enum bgp_stats
8485{
8486 BGP_STATS_MAXBITLEN = 0,
8487 BGP_STATS_RIB,
8488 BGP_STATS_PREFIXES,
8489 BGP_STATS_TOTPLEN,
8490 BGP_STATS_UNAGGREGATEABLE,
8491 BGP_STATS_MAX_AGGREGATEABLE,
8492 BGP_STATS_AGGREGATES,
8493 BGP_STATS_SPACE,
8494 BGP_STATS_ASPATH_COUNT,
8495 BGP_STATS_ASPATH_MAXHOPS,
8496 BGP_STATS_ASPATH_TOTHOPS,
8497 BGP_STATS_ASPATH_MAXSIZE,
8498 BGP_STATS_ASPATH_TOTSIZE,
8499 BGP_STATS_ASN_HIGHEST,
8500 BGP_STATS_MAX,
8501};
paulbb46e942003-10-24 19:02:03 +00008502
Paul Jakma2815e612006-09-14 02:56:07 +00008503static const char *table_stats_strs[] =
8504{
8505 [BGP_STATS_PREFIXES] = "Total Prefixes",
8506 [BGP_STATS_TOTPLEN] = "Average prefix length",
8507 [BGP_STATS_RIB] = "Total Advertisements",
8508 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8509 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8510 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8511 [BGP_STATS_SPACE] = "Address space advertised",
8512 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8513 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8514 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8515 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
8516 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
8517 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
8518 [BGP_STATS_MAX] = NULL,
8519};
8520
8521struct bgp_table_stats
8522{
8523 struct bgp_table *table;
8524 unsigned long long counts[BGP_STATS_MAX];
8525};
8526
8527#if 0
8528#define TALLY_SIGFIG 100000
8529static unsigned long
8530ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
8531{
8532 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
8533 unsigned long res = (newtot * TALLY_SIGFIG) / count;
8534 unsigned long ret = newtot / count;
8535
8536 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
8537 return ret + 1;
8538 else
8539 return ret;
8540}
8541#endif
8542
8543static int
8544bgp_table_stats_walker (struct thread *t)
8545{
8546 struct bgp_node *rn;
8547 struct bgp_node *top;
8548 struct bgp_table_stats *ts = THREAD_ARG (t);
8549 unsigned int space = 0;
8550
Paul Jakma53d9f672006-10-15 23:41:16 +00008551 if (!(top = bgp_table_top (ts->table)))
8552 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00008553
8554 switch (top->p.family)
8555 {
8556 case AF_INET:
8557 space = IPV4_MAX_BITLEN;
8558 break;
8559 case AF_INET6:
8560 space = IPV6_MAX_BITLEN;
8561 break;
8562 }
8563
8564 ts->counts[BGP_STATS_MAXBITLEN] = space;
8565
8566 for (rn = top; rn; rn = bgp_route_next (rn))
8567 {
8568 struct bgp_info *ri;
8569 struct bgp_node *prn = rn->parent;
8570 unsigned int rinum = 0;
8571
8572 if (rn == top)
8573 continue;
8574
8575 if (!rn->info)
8576 continue;
8577
8578 ts->counts[BGP_STATS_PREFIXES]++;
8579 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
8580
8581#if 0
8582 ts->counts[BGP_STATS_AVGPLEN]
8583 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
8584 ts->counts[BGP_STATS_AVGPLEN],
8585 rn->p.prefixlen);
8586#endif
8587
8588 /* check if the prefix is included by any other announcements */
8589 while (prn && !prn->info)
8590 prn = prn->parent;
8591
8592 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00008593 {
8594 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
8595 /* announced address space */
8596 if (space)
8597 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
8598 }
Paul Jakma2815e612006-09-14 02:56:07 +00008599 else if (prn->info)
8600 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
8601
Paul Jakma2815e612006-09-14 02:56:07 +00008602 for (ri = rn->info; ri; ri = ri->next)
8603 {
8604 rinum++;
8605 ts->counts[BGP_STATS_RIB]++;
8606
8607 if (ri->attr &&
8608 (CHECK_FLAG (ri->attr->flag,
8609 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
8610 ts->counts[BGP_STATS_AGGREGATES]++;
8611
8612 /* as-path stats */
8613 if (ri->attr && ri->attr->aspath)
8614 {
8615 unsigned int hops = aspath_count_hops (ri->attr->aspath);
8616 unsigned int size = aspath_size (ri->attr->aspath);
8617 as_t highest = aspath_highest (ri->attr->aspath);
8618
8619 ts->counts[BGP_STATS_ASPATH_COUNT]++;
8620
8621 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
8622 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
8623
8624 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
8625 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
8626
8627 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
8628 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
8629#if 0
8630 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
8631 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8632 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
8633 hops);
8634 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
8635 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8636 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
8637 size);
8638#endif
8639 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
8640 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
8641 }
8642 }
8643 }
8644 return 0;
8645}
8646
8647static int
8648bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
8649{
8650 struct bgp_table_stats ts;
8651 unsigned int i;
8652
8653 if (!bgp->rib[afi][safi])
8654 {
8655 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
8656 return CMD_WARNING;
8657 }
8658
8659 memset (&ts, 0, sizeof (ts));
8660 ts.table = bgp->rib[afi][safi];
8661 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
8662
8663 vty_out (vty, "BGP %s RIB statistics%s%s",
8664 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
8665
8666 for (i = 0; i < BGP_STATS_MAX; i++)
8667 {
8668 if (!table_stats_strs[i])
8669 continue;
8670
8671 switch (i)
8672 {
8673#if 0
8674 case BGP_STATS_ASPATH_AVGHOPS:
8675 case BGP_STATS_ASPATH_AVGSIZE:
8676 case BGP_STATS_AVGPLEN:
8677 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8678 vty_out (vty, "%12.2f",
8679 (float)ts.counts[i] / (float)TALLY_SIGFIG);
8680 break;
8681#endif
8682 case BGP_STATS_ASPATH_TOTHOPS:
8683 case BGP_STATS_ASPATH_TOTSIZE:
8684 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8685 vty_out (vty, "%12.2f",
8686 ts.counts[i] ?
8687 (float)ts.counts[i] /
8688 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
8689 : 0);
8690 break;
8691 case BGP_STATS_TOTPLEN:
8692 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8693 vty_out (vty, "%12.2f",
8694 ts.counts[i] ?
8695 (float)ts.counts[i] /
8696 (float)ts.counts[BGP_STATS_PREFIXES]
8697 : 0);
8698 break;
8699 case BGP_STATS_SPACE:
8700 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8701 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
8702 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
8703 break;
8704 vty_out (vty, "%30s: ", "\% announced ");
8705 vty_out (vty, "%12.2f%s",
8706 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00008707 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00008708 VTY_NEWLINE);
8709 vty_out (vty, "%30s: ", "/8 equivalent ");
8710 vty_out (vty, "%12.2f%s",
8711 (float)ts.counts[BGP_STATS_SPACE] /
8712 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
8713 VTY_NEWLINE);
8714 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
8715 break;
8716 vty_out (vty, "%30s: ", "/24 equivalent ");
8717 vty_out (vty, "%12.2f",
8718 (float)ts.counts[BGP_STATS_SPACE] /
8719 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
8720 break;
8721 default:
8722 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8723 vty_out (vty, "%12llu", ts.counts[i]);
8724 }
8725
8726 vty_out (vty, "%s", VTY_NEWLINE);
8727 }
8728 return CMD_SUCCESS;
8729}
8730
8731static int
8732bgp_table_stats_vty (struct vty *vty, const char *name,
8733 const char *afi_str, const char *safi_str)
8734{
8735 struct bgp *bgp;
8736 afi_t afi;
8737 safi_t safi;
8738
8739 if (name)
8740 bgp = bgp_lookup_by_name (name);
8741 else
8742 bgp = bgp_get_default ();
8743
8744 if (!bgp)
8745 {
8746 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
8747 return CMD_WARNING;
8748 }
8749 if (strncmp (afi_str, "ipv", 3) == 0)
8750 {
8751 if (strncmp (afi_str, "ipv4", 4) == 0)
8752 afi = AFI_IP;
8753 else if (strncmp (afi_str, "ipv6", 4) == 0)
8754 afi = AFI_IP6;
8755 else
8756 {
8757 vty_out (vty, "%% Invalid address family %s%s",
8758 afi_str, VTY_NEWLINE);
8759 return CMD_WARNING;
8760 }
8761 if (strncmp (safi_str, "m", 1) == 0)
8762 safi = SAFI_MULTICAST;
8763 else if (strncmp (safi_str, "u", 1) == 0)
8764 safi = SAFI_UNICAST;
8765 else if (strncmp (safi_str, "vpnv4", 5) == 0)
8766 safi = BGP_SAFI_VPNV4;
8767 else if (strncmp (safi_str, "vpnv6", 6) == 0)
8768 safi = BGP_SAFI_VPNV6;
8769 else
8770 {
8771 vty_out (vty, "%% Invalid subsequent address family %s%s",
8772 safi_str, VTY_NEWLINE);
8773 return CMD_WARNING;
8774 }
8775 }
8776 else
8777 {
8778 vty_out (vty, "%% Invalid address family %s%s",
8779 afi_str, VTY_NEWLINE);
8780 return CMD_WARNING;
8781 }
8782
8783 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
8784 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
8785 {
8786 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
8787 afi_str, safi_str, VTY_NEWLINE);
8788 return CMD_WARNING;
8789 }
8790 return bgp_table_stats (vty, bgp, afi, safi);
8791}
8792
8793DEFUN (show_bgp_statistics,
8794 show_bgp_statistics_cmd,
8795 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
8796 SHOW_STR
8797 BGP_STR
8798 "Address family\n"
8799 "Address family\n"
8800 "Address Family modifier\n"
8801 "Address Family modifier\n"
8802 "BGP RIB advertisement statistics\n")
8803{
8804 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
8805}
8806
8807ALIAS (show_bgp_statistics,
8808 show_bgp_statistics_vpnv4_cmd,
8809 "show bgp (ipv4) (vpnv4) statistics",
8810 SHOW_STR
8811 BGP_STR
8812 "Address family\n"
8813 "Address Family modifier\n"
8814 "BGP RIB advertisement statistics\n")
8815
8816DEFUN (show_bgp_statistics_view,
8817 show_bgp_statistics_view_cmd,
8818 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
8819 SHOW_STR
8820 BGP_STR
8821 "BGP view\n"
8822 "Address family\n"
8823 "Address family\n"
8824 "Address Family modifier\n"
8825 "Address Family modifier\n"
8826 "BGP RIB advertisement statistics\n")
8827{
8828 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
8829}
8830
8831ALIAS (show_bgp_statistics_view,
8832 show_bgp_statistics_view_vpnv4_cmd,
8833 "show bgp view WORD (ipv4) (vpnv4) statistics",
8834 SHOW_STR
8835 BGP_STR
8836 "BGP view\n"
8837 "Address family\n"
8838 "Address Family modifier\n"
8839 "BGP RIB advertisement statistics\n")
8840
Paul Jakmaff7924f2006-09-04 01:10:36 +00008841enum bgp_pcounts
8842{
8843 PCOUNT_ADJ_IN = 0,
8844 PCOUNT_DAMPED,
8845 PCOUNT_REMOVED,
8846 PCOUNT_HISTORY,
8847 PCOUNT_STALE,
8848 PCOUNT_VALID,
8849 PCOUNT_ALL,
8850 PCOUNT_COUNTED,
8851 PCOUNT_PFCNT, /* the figure we display to users */
8852 PCOUNT_MAX,
8853};
8854
8855static const char *pcount_strs[] =
8856{
8857 [PCOUNT_ADJ_IN] = "Adj-in",
8858 [PCOUNT_DAMPED] = "Damped",
8859 [PCOUNT_REMOVED] = "Removed",
8860 [PCOUNT_HISTORY] = "History",
8861 [PCOUNT_STALE] = "Stale",
8862 [PCOUNT_VALID] = "Valid",
8863 [PCOUNT_ALL] = "All RIB",
8864 [PCOUNT_COUNTED] = "PfxCt counted",
8865 [PCOUNT_PFCNT] = "Useable",
8866 [PCOUNT_MAX] = NULL,
8867};
8868
Paul Jakma2815e612006-09-14 02:56:07 +00008869struct peer_pcounts
8870{
8871 unsigned int count[PCOUNT_MAX];
8872 const struct peer *peer;
8873 const struct bgp_table *table;
8874};
8875
Paul Jakmaff7924f2006-09-04 01:10:36 +00008876static int
Paul Jakma2815e612006-09-14 02:56:07 +00008877bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00008878{
8879 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00008880 struct peer_pcounts *pc = THREAD_ARG (t);
8881 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008882
Paul Jakma2815e612006-09-14 02:56:07 +00008883 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00008884 {
8885 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00008886 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008887
8888 for (ain = rn->adj_in; ain; ain = ain->next)
8889 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00008890 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008891
Paul Jakmaff7924f2006-09-04 01:10:36 +00008892 for (ri = rn->info; ri; ri = ri->next)
8893 {
8894 char buf[SU_ADDRSTRLEN];
8895
8896 if (ri->peer != peer)
8897 continue;
8898
Paul Jakma2815e612006-09-14 02:56:07 +00008899 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008900
8901 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00008902 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008903 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00008904 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008905 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00008906 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008907 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00008908 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008909 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00008910 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00008911 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00008912 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008913
8914 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
8915 {
Paul Jakma2815e612006-09-14 02:56:07 +00008916 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00008917 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00008918 plog_warn (peer->log,
8919 "%s [pcount] %s/%d is counted but flags 0x%x",
8920 peer->host,
8921 inet_ntop(rn->p.family, &rn->p.u.prefix,
8922 buf, SU_ADDRSTRLEN),
8923 rn->p.prefixlen,
8924 ri->flags);
8925 }
8926 else
8927 {
Paul Jakma1a392d42006-09-07 00:24:49 +00008928 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00008929 plog_warn (peer->log,
8930 "%s [pcount] %s/%d not counted but flags 0x%x",
8931 peer->host,
8932 inet_ntop(rn->p.family, &rn->p.u.prefix,
8933 buf, SU_ADDRSTRLEN),
8934 rn->p.prefixlen,
8935 ri->flags);
8936 }
8937 }
8938 }
Paul Jakma2815e612006-09-14 02:56:07 +00008939 return 0;
8940}
Paul Jakmaff7924f2006-09-04 01:10:36 +00008941
Paul Jakma2815e612006-09-14 02:56:07 +00008942static int
8943bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
8944{
8945 struct peer_pcounts pcounts = { .peer = peer };
8946 unsigned int i;
8947
8948 if (!peer || !peer->bgp || !peer->afc[afi][safi]
8949 || !peer->bgp->rib[afi][safi])
8950 {
8951 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8952 return CMD_WARNING;
8953 }
8954
8955 memset (&pcounts, 0, sizeof(pcounts));
8956 pcounts.peer = peer;
8957 pcounts.table = peer->bgp->rib[afi][safi];
8958
8959 /* in-place call via thread subsystem so as to record execution time
8960 * stats for the thread-walk (i.e. ensure this can't be blamed on
8961 * on just vty_read()).
8962 */
8963 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
8964
Paul Jakmaff7924f2006-09-04 01:10:36 +00008965 vty_out (vty, "Prefix counts for %s, %s%s",
8966 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
8967 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
8968 vty_out (vty, "%sCounts from RIB table walk:%s%s",
8969 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8970
8971 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00008972 vty_out (vty, "%20s: %-10d%s",
8973 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00008974
Paul Jakma2815e612006-09-14 02:56:07 +00008975 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00008976 {
8977 vty_out (vty, "%s [pcount] PfxCt drift!%s",
8978 peer->host, VTY_NEWLINE);
8979 vty_out (vty, "Please report this bug, with the above command output%s",
8980 VTY_NEWLINE);
8981 }
8982
8983 return CMD_SUCCESS;
8984}
8985
8986DEFUN (show_ip_bgp_neighbor_prefix_counts,
8987 show_ip_bgp_neighbor_prefix_counts_cmd,
8988 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
8989 SHOW_STR
8990 IP_STR
8991 BGP_STR
8992 "Detailed information on TCP and BGP neighbor connections\n"
8993 "Neighbor to display information about\n"
8994 "Neighbor to display information about\n"
8995 "Display detailed prefix count information\n")
8996{
8997 struct peer *peer;
8998
8999 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9000 if (! peer)
9001 return CMD_WARNING;
9002
9003 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9004}
9005
9006DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9007 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9008 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9009 SHOW_STR
9010 BGP_STR
9011 "Address family\n"
9012 "Detailed information on TCP and BGP neighbor connections\n"
9013 "Neighbor to display information about\n"
9014 "Neighbor to display information about\n"
9015 "Display detailed prefix count information\n")
9016{
9017 struct peer *peer;
9018
9019 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9020 if (! peer)
9021 return CMD_WARNING;
9022
9023 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9024}
9025
9026DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9027 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9028 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9029 SHOW_STR
9030 IP_STR
9031 BGP_STR
9032 "Address family\n"
9033 "Address Family modifier\n"
9034 "Address Family modifier\n"
9035 "Detailed information on TCP and BGP neighbor connections\n"
9036 "Neighbor to display information about\n"
9037 "Neighbor to display information about\n"
9038 "Display detailed prefix count information\n")
9039{
9040 struct peer *peer;
9041
9042 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9043 if (! peer)
9044 return CMD_WARNING;
9045
9046 if (strncmp (argv[0], "m", 1) == 0)
9047 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9048
9049 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9050}
9051
9052DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9053 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9054 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9055 SHOW_STR
9056 IP_STR
9057 BGP_STR
9058 "Address family\n"
9059 "Address Family modifier\n"
9060 "Address Family modifier\n"
9061 "Detailed information on TCP and BGP neighbor connections\n"
9062 "Neighbor to display information about\n"
9063 "Neighbor to display information about\n"
9064 "Display detailed prefix count information\n")
9065{
9066 struct peer *peer;
9067
9068 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9069 if (! peer)
9070 return CMD_WARNING;
9071
9072 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9073}
9074
9075
paul94f2b392005-06-28 12:44:16 +00009076static void
paul718e3742002-12-13 20:15:29 +00009077show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9078 int in)
9079{
9080 struct bgp_table *table;
9081 struct bgp_adj_in *ain;
9082 struct bgp_adj_out *adj;
9083 unsigned long output_count;
9084 struct bgp_node *rn;
9085 int header1 = 1;
9086 struct bgp *bgp;
9087 int header2 = 1;
9088
paulbb46e942003-10-24 19:02:03 +00009089 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009090
9091 if (! bgp)
9092 return;
9093
9094 table = bgp->rib[afi][safi];
9095
9096 output_count = 0;
9097
9098 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9099 PEER_STATUS_DEFAULT_ORIGINATE))
9100 {
9101 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 +00009102 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9103 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009104
9105 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9106 VTY_NEWLINE, VTY_NEWLINE);
9107 header1 = 0;
9108 }
9109
9110 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9111 if (in)
9112 {
9113 for (ain = rn->adj_in; ain; ain = ain->next)
9114 if (ain->peer == peer)
9115 {
9116 if (header1)
9117 {
9118 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 +00009119 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9120 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009121 header1 = 0;
9122 }
9123 if (header2)
9124 {
9125 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9126 header2 = 0;
9127 }
9128 if (ain->attr)
9129 {
9130 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9131 output_count++;
9132 }
9133 }
9134 }
9135 else
9136 {
9137 for (adj = rn->adj_out; adj; adj = adj->next)
9138 if (adj->peer == peer)
9139 {
9140 if (header1)
9141 {
9142 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 +00009143 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9144 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009145 header1 = 0;
9146 }
9147 if (header2)
9148 {
9149 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9150 header2 = 0;
9151 }
9152 if (adj->attr)
9153 {
9154 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9155 output_count++;
9156 }
9157 }
9158 }
9159
9160 if (output_count != 0)
9161 vty_out (vty, "%sTotal number of prefixes %ld%s",
9162 VTY_NEWLINE, output_count, VTY_NEWLINE);
9163}
9164
paul94f2b392005-06-28 12:44:16 +00009165static int
paulbb46e942003-10-24 19:02:03 +00009166peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9167{
paul718e3742002-12-13 20:15:29 +00009168 if (! peer || ! peer->afc[afi][safi])
9169 {
9170 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9171 return CMD_WARNING;
9172 }
9173
9174 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9175 {
9176 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9177 VTY_NEWLINE);
9178 return CMD_WARNING;
9179 }
9180
9181 show_adj_route (vty, peer, afi, safi, in);
9182
9183 return CMD_SUCCESS;
9184}
9185
9186DEFUN (show_ip_bgp_neighbor_advertised_route,
9187 show_ip_bgp_neighbor_advertised_route_cmd,
9188 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9189 SHOW_STR
9190 IP_STR
9191 BGP_STR
9192 "Detailed information on TCP and BGP neighbor connections\n"
9193 "Neighbor to display information about\n"
9194 "Neighbor to display information about\n"
9195 "Display the routes advertised to a BGP neighbor\n")
9196{
paulbb46e942003-10-24 19:02:03 +00009197 struct peer *peer;
9198
9199 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9200 if (! peer)
9201 return CMD_WARNING;
9202
9203 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009204}
9205
9206DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9207 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9208 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9209 SHOW_STR
9210 IP_STR
9211 BGP_STR
9212 "Address family\n"
9213 "Address Family modifier\n"
9214 "Address Family modifier\n"
9215 "Detailed information on TCP and BGP neighbor connections\n"
9216 "Neighbor to display information about\n"
9217 "Neighbor to display information about\n"
9218 "Display the routes advertised to a BGP neighbor\n")
9219{
paulbb46e942003-10-24 19:02:03 +00009220 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009221
paulbb46e942003-10-24 19:02:03 +00009222 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9223 if (! peer)
9224 return CMD_WARNING;
9225
9226 if (strncmp (argv[0], "m", 1) == 0)
9227 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9228
9229 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009230}
9231
9232#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009233DEFUN (show_bgp_view_neighbor_advertised_route,
9234 show_bgp_view_neighbor_advertised_route_cmd,
9235 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9236 SHOW_STR
9237 BGP_STR
9238 "BGP view\n"
9239 "View name\n"
9240 "Detailed information on TCP and BGP neighbor connections\n"
9241 "Neighbor to display information about\n"
9242 "Neighbor to display information about\n"
9243 "Display the routes advertised to a BGP neighbor\n")
9244{
9245 struct peer *peer;
9246
9247 if (argc == 2)
9248 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9249 else
9250 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9251
9252 if (! peer)
9253 return CMD_WARNING;
9254
9255 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9256}
9257
9258ALIAS (show_bgp_view_neighbor_advertised_route,
9259 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9260 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9261 SHOW_STR
9262 BGP_STR
9263 "BGP view\n"
9264 "View name\n"
9265 "Address family\n"
9266 "Detailed information on TCP and BGP neighbor connections\n"
9267 "Neighbor to display information about\n"
9268 "Neighbor to display information about\n"
9269 "Display the routes advertised to a BGP neighbor\n")
9270
9271DEFUN (show_bgp_view_neighbor_received_routes,
9272 show_bgp_view_neighbor_received_routes_cmd,
9273 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9274 SHOW_STR
9275 BGP_STR
9276 "BGP view\n"
9277 "View name\n"
9278 "Detailed information on TCP and BGP neighbor connections\n"
9279 "Neighbor to display information about\n"
9280 "Neighbor to display information about\n"
9281 "Display the received routes from neighbor\n")
9282{
9283 struct peer *peer;
9284
9285 if (argc == 2)
9286 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9287 else
9288 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9289
9290 if (! peer)
9291 return CMD_WARNING;
9292
9293 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9294}
9295
9296ALIAS (show_bgp_view_neighbor_received_routes,
9297 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9298 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9299 SHOW_STR
9300 BGP_STR
9301 "BGP view\n"
9302 "View name\n"
9303 "Address family\n"
9304 "Detailed information on TCP and BGP neighbor connections\n"
9305 "Neighbor to display information about\n"
9306 "Neighbor to display information about\n"
9307 "Display the received routes from neighbor\n")
9308
9309ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009310 show_bgp_neighbor_advertised_route_cmd,
9311 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9312 SHOW_STR
9313 BGP_STR
9314 "Detailed information on TCP and BGP neighbor connections\n"
9315 "Neighbor to display information about\n"
9316 "Neighbor to display information about\n"
9317 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009318
9319ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009320 show_bgp_ipv6_neighbor_advertised_route_cmd,
9321 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9322 SHOW_STR
9323 BGP_STR
9324 "Address family\n"
9325 "Detailed information on TCP and BGP neighbor connections\n"
9326 "Neighbor to display information about\n"
9327 "Neighbor to display information about\n"
9328 "Display the routes advertised to a BGP neighbor\n")
9329
9330/* old command */
paulbb46e942003-10-24 19:02:03 +00009331ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009332 ipv6_bgp_neighbor_advertised_route_cmd,
9333 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9334 SHOW_STR
9335 IPV6_STR
9336 BGP_STR
9337 "Detailed information on TCP and BGP neighbor connections\n"
9338 "Neighbor to display information about\n"
9339 "Neighbor to display information about\n"
9340 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009341
paul718e3742002-12-13 20:15:29 +00009342/* old command */
9343DEFUN (ipv6_mbgp_neighbor_advertised_route,
9344 ipv6_mbgp_neighbor_advertised_route_cmd,
9345 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9346 SHOW_STR
9347 IPV6_STR
9348 MBGP_STR
9349 "Detailed information on TCP and BGP neighbor connections\n"
9350 "Neighbor to display information about\n"
9351 "Neighbor to display information about\n"
9352 "Display the routes advertised to a BGP neighbor\n")
9353{
paulbb46e942003-10-24 19:02:03 +00009354 struct peer *peer;
9355
9356 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9357 if (! peer)
9358 return CMD_WARNING;
9359
9360 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009361}
9362#endif /* HAVE_IPV6 */
9363
9364DEFUN (show_ip_bgp_neighbor_received_routes,
9365 show_ip_bgp_neighbor_received_routes_cmd,
9366 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9367 SHOW_STR
9368 IP_STR
9369 BGP_STR
9370 "Detailed information on TCP and BGP neighbor connections\n"
9371 "Neighbor to display information about\n"
9372 "Neighbor to display information about\n"
9373 "Display the received routes from neighbor\n")
9374{
paulbb46e942003-10-24 19:02:03 +00009375 struct peer *peer;
9376
9377 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9378 if (! peer)
9379 return CMD_WARNING;
9380
9381 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009382}
9383
9384DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9385 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9386 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9387 SHOW_STR
9388 IP_STR
9389 BGP_STR
9390 "Address family\n"
9391 "Address Family modifier\n"
9392 "Address Family modifier\n"
9393 "Detailed information on TCP and BGP neighbor connections\n"
9394 "Neighbor to display information about\n"
9395 "Neighbor to display information about\n"
9396 "Display the received routes from neighbor\n")
9397{
paulbb46e942003-10-24 19:02:03 +00009398 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009399
paulbb46e942003-10-24 19:02:03 +00009400 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9401 if (! peer)
9402 return CMD_WARNING;
9403
9404 if (strncmp (argv[0], "m", 1) == 0)
9405 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9406
9407 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009408}
9409
9410DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9411 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9412 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9413 SHOW_STR
9414 IP_STR
9415 BGP_STR
9416 "Detailed information on TCP and BGP neighbor connections\n"
9417 "Neighbor to display information about\n"
9418 "Neighbor to display information about\n"
9419 "Display information received from a BGP neighbor\n"
9420 "Display the prefixlist filter\n")
9421{
9422 char name[BUFSIZ];
9423 union sockunion *su;
9424 struct peer *peer;
9425 int count;
9426
9427 su = sockunion_str2su (argv[0]);
9428 if (su == NULL)
9429 return CMD_WARNING;
9430
9431 peer = peer_lookup (NULL, su);
9432 if (! peer)
9433 return CMD_WARNING;
9434
9435 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9436 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9437 if (count)
9438 {
9439 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9440 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9441 }
9442
9443 return CMD_SUCCESS;
9444}
9445
9446DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9447 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9448 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9449 SHOW_STR
9450 IP_STR
9451 BGP_STR
9452 "Address family\n"
9453 "Address Family modifier\n"
9454 "Address Family modifier\n"
9455 "Detailed information on TCP and BGP neighbor connections\n"
9456 "Neighbor to display information about\n"
9457 "Neighbor to display information about\n"
9458 "Display information received from a BGP neighbor\n"
9459 "Display the prefixlist filter\n")
9460{
9461 char name[BUFSIZ];
9462 union sockunion *su;
9463 struct peer *peer;
9464 int count;
9465
9466 su = sockunion_str2su (argv[1]);
9467 if (su == NULL)
9468 return CMD_WARNING;
9469
9470 peer = peer_lookup (NULL, su);
9471 if (! peer)
9472 return CMD_WARNING;
9473
9474 if (strncmp (argv[0], "m", 1) == 0)
9475 {
9476 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9477 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9478 if (count)
9479 {
9480 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9481 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9482 }
9483 }
9484 else
9485 {
9486 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9487 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9488 if (count)
9489 {
9490 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9491 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9492 }
9493 }
9494
9495 return CMD_SUCCESS;
9496}
9497
9498
9499#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009500ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009501 show_bgp_neighbor_received_routes_cmd,
9502 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9503 SHOW_STR
9504 BGP_STR
9505 "Detailed information on TCP and BGP neighbor connections\n"
9506 "Neighbor to display information about\n"
9507 "Neighbor to display information about\n"
9508 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009509
paulbb46e942003-10-24 19:02:03 +00009510ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009511 show_bgp_ipv6_neighbor_received_routes_cmd,
9512 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9513 SHOW_STR
9514 BGP_STR
9515 "Address family\n"
9516 "Detailed information on TCP and BGP neighbor connections\n"
9517 "Neighbor to display information about\n"
9518 "Neighbor to display information about\n"
9519 "Display the received routes from neighbor\n")
9520
9521DEFUN (show_bgp_neighbor_received_prefix_filter,
9522 show_bgp_neighbor_received_prefix_filter_cmd,
9523 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9524 SHOW_STR
9525 BGP_STR
9526 "Detailed information on TCP and BGP neighbor connections\n"
9527 "Neighbor to display information about\n"
9528 "Neighbor to display information about\n"
9529 "Display information received from a BGP neighbor\n"
9530 "Display the prefixlist filter\n")
9531{
9532 char name[BUFSIZ];
9533 union sockunion *su;
9534 struct peer *peer;
9535 int count;
9536
9537 su = sockunion_str2su (argv[0]);
9538 if (su == NULL)
9539 return CMD_WARNING;
9540
9541 peer = peer_lookup (NULL, su);
9542 if (! peer)
9543 return CMD_WARNING;
9544
9545 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9546 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9547 if (count)
9548 {
9549 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
9550 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
9551 }
9552
9553 return CMD_SUCCESS;
9554}
9555
9556ALIAS (show_bgp_neighbor_received_prefix_filter,
9557 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
9558 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9559 SHOW_STR
9560 BGP_STR
9561 "Address family\n"
9562 "Detailed information on TCP and BGP neighbor connections\n"
9563 "Neighbor to display information about\n"
9564 "Neighbor to display information about\n"
9565 "Display information received from a BGP neighbor\n"
9566 "Display the prefixlist filter\n")
9567
9568/* old command */
paulbb46e942003-10-24 19:02:03 +00009569ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009570 ipv6_bgp_neighbor_received_routes_cmd,
9571 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9572 SHOW_STR
9573 IPV6_STR
9574 BGP_STR
9575 "Detailed information on TCP and BGP neighbor connections\n"
9576 "Neighbor to display information about\n"
9577 "Neighbor to display information about\n"
9578 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009579
9580/* old command */
9581DEFUN (ipv6_mbgp_neighbor_received_routes,
9582 ipv6_mbgp_neighbor_received_routes_cmd,
9583 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9584 SHOW_STR
9585 IPV6_STR
9586 MBGP_STR
9587 "Detailed information on TCP and BGP neighbor connections\n"
9588 "Neighbor to display information about\n"
9589 "Neighbor to display information about\n"
9590 "Display the received routes from neighbor\n")
9591{
paulbb46e942003-10-24 19:02:03 +00009592 struct peer *peer;
9593
9594 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9595 if (! peer)
9596 return CMD_WARNING;
9597
9598 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00009599}
paulbb46e942003-10-24 19:02:03 +00009600
9601DEFUN (show_bgp_view_neighbor_received_prefix_filter,
9602 show_bgp_view_neighbor_received_prefix_filter_cmd,
9603 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9604 SHOW_STR
9605 BGP_STR
9606 "BGP view\n"
9607 "View name\n"
9608 "Detailed information on TCP and BGP neighbor connections\n"
9609 "Neighbor to display information about\n"
9610 "Neighbor to display information about\n"
9611 "Display information received from a BGP neighbor\n"
9612 "Display the prefixlist filter\n")
9613{
9614 char name[BUFSIZ];
9615 union sockunion *su;
9616 struct peer *peer;
9617 struct bgp *bgp;
9618 int count;
9619
9620 /* BGP structure lookup. */
9621 bgp = bgp_lookup_by_name (argv[0]);
9622 if (bgp == NULL)
9623 {
9624 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9625 return CMD_WARNING;
9626 }
9627
9628 su = sockunion_str2su (argv[1]);
9629 if (su == NULL)
9630 return CMD_WARNING;
9631
9632 peer = peer_lookup (bgp, su);
9633 if (! peer)
9634 return CMD_WARNING;
9635
9636 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9637 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9638 if (count)
9639 {
9640 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
9641 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
9642 }
9643
9644 return CMD_SUCCESS;
9645}
9646
9647ALIAS (show_bgp_view_neighbor_received_prefix_filter,
9648 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
9649 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9650 SHOW_STR
9651 BGP_STR
9652 "BGP view\n"
9653 "View name\n"
9654 "Address family\n"
9655 "Detailed information on TCP and BGP neighbor connections\n"
9656 "Neighbor to display information about\n"
9657 "Neighbor to display information about\n"
9658 "Display information received from a BGP neighbor\n"
9659 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00009660#endif /* HAVE_IPV6 */
9661
paul94f2b392005-06-28 12:44:16 +00009662static int
paulbb46e942003-10-24 19:02:03 +00009663bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009664 safi_t safi, enum bgp_show_type type)
9665{
paul718e3742002-12-13 20:15:29 +00009666 if (! peer || ! peer->afc[afi][safi])
9667 {
9668 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009669 return CMD_WARNING;
9670 }
9671
ajs5a646652004-11-05 01:25:55 +00009672 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +00009673}
9674
9675DEFUN (show_ip_bgp_neighbor_routes,
9676 show_ip_bgp_neighbor_routes_cmd,
9677 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
9678 SHOW_STR
9679 IP_STR
9680 BGP_STR
9681 "Detailed information on TCP and BGP neighbor connections\n"
9682 "Neighbor to display information about\n"
9683 "Neighbor to display information about\n"
9684 "Display routes learned from neighbor\n")
9685{
paulbb46e942003-10-24 19:02:03 +00009686 struct peer *peer;
9687
9688 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9689 if (! peer)
9690 return CMD_WARNING;
9691
9692 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009693 bgp_show_type_neighbor);
9694}
9695
9696DEFUN (show_ip_bgp_neighbor_flap,
9697 show_ip_bgp_neighbor_flap_cmd,
9698 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9699 SHOW_STR
9700 IP_STR
9701 BGP_STR
9702 "Detailed information on TCP and BGP neighbor connections\n"
9703 "Neighbor to display information about\n"
9704 "Neighbor to display information about\n"
9705 "Display flap statistics of the routes learned from neighbor\n")
9706{
paulbb46e942003-10-24 19:02:03 +00009707 struct peer *peer;
9708
9709 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9710 if (! peer)
9711 return CMD_WARNING;
9712
9713 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009714 bgp_show_type_flap_neighbor);
9715}
9716
9717DEFUN (show_ip_bgp_neighbor_damp,
9718 show_ip_bgp_neighbor_damp_cmd,
9719 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9720 SHOW_STR
9721 IP_STR
9722 BGP_STR
9723 "Detailed information on TCP and BGP neighbor connections\n"
9724 "Neighbor to display information about\n"
9725 "Neighbor to display information about\n"
9726 "Display the dampened routes received from neighbor\n")
9727{
paulbb46e942003-10-24 19:02:03 +00009728 struct peer *peer;
9729
9730 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9731 if (! peer)
9732 return CMD_WARNING;
9733
9734 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009735 bgp_show_type_damp_neighbor);
9736}
9737
9738DEFUN (show_ip_bgp_ipv4_neighbor_routes,
9739 show_ip_bgp_ipv4_neighbor_routes_cmd,
9740 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
9741 SHOW_STR
9742 IP_STR
9743 BGP_STR
9744 "Address family\n"
9745 "Address Family modifier\n"
9746 "Address Family modifier\n"
9747 "Detailed information on TCP and BGP neighbor connections\n"
9748 "Neighbor to display information about\n"
9749 "Neighbor to display information about\n"
9750 "Display routes learned from neighbor\n")
9751{
paulbb46e942003-10-24 19:02:03 +00009752 struct peer *peer;
9753
9754 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9755 if (! peer)
9756 return CMD_WARNING;
9757
paul718e3742002-12-13 20:15:29 +00009758 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00009759 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009760 bgp_show_type_neighbor);
9761
paulbb46e942003-10-24 19:02:03 +00009762 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009763 bgp_show_type_neighbor);
9764}
paulbb46e942003-10-24 19:02:03 +00009765
paulfee0f4c2004-09-13 05:12:46 +00009766DEFUN (show_ip_bgp_view_rsclient,
9767 show_ip_bgp_view_rsclient_cmd,
9768 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9769 SHOW_STR
9770 IP_STR
9771 BGP_STR
9772 "BGP view\n"
9773 "BGP view name\n"
9774 "Information about Route Server Client\n"
9775 NEIGHBOR_ADDR_STR)
9776{
9777 struct bgp_table *table;
9778 struct peer *peer;
9779
9780 if (argc == 2)
9781 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9782 else
9783 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9784
9785 if (! peer)
9786 return CMD_WARNING;
9787
9788 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9789 {
9790 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9791 VTY_NEWLINE);
9792 return CMD_WARNING;
9793 }
9794
9795 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9796 PEER_FLAG_RSERVER_CLIENT))
9797 {
9798 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9799 VTY_NEWLINE);
9800 return CMD_WARNING;
9801 }
9802
9803 table = peer->rib[AFI_IP][SAFI_UNICAST];
9804
ajs5a646652004-11-05 01:25:55 +00009805 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009806}
9807
9808ALIAS (show_ip_bgp_view_rsclient,
9809 show_ip_bgp_rsclient_cmd,
9810 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
9811 SHOW_STR
9812 IP_STR
9813 BGP_STR
9814 "Information about Route Server Client\n"
9815 NEIGHBOR_ADDR_STR)
9816
9817DEFUN (show_ip_bgp_view_rsclient_route,
9818 show_ip_bgp_view_rsclient_route_cmd,
9819 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9820 SHOW_STR
9821 IP_STR
9822 BGP_STR
9823 "BGP view\n"
9824 "BGP view name\n"
9825 "Information about Route Server Client\n"
9826 NEIGHBOR_ADDR_STR
9827 "Network in the BGP routing table to display\n")
9828{
9829 struct bgp *bgp;
9830 struct peer *peer;
9831
9832 /* BGP structure lookup. */
9833 if (argc == 3)
9834 {
9835 bgp = bgp_lookup_by_name (argv[0]);
9836 if (bgp == NULL)
9837 {
9838 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9839 return CMD_WARNING;
9840 }
9841 }
9842 else
9843 {
9844 bgp = bgp_get_default ();
9845 if (bgp == NULL)
9846 {
9847 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9848 return CMD_WARNING;
9849 }
9850 }
9851
9852 if (argc == 3)
9853 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9854 else
9855 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9856
9857 if (! peer)
9858 return CMD_WARNING;
9859
9860 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9861 {
9862 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9863 VTY_NEWLINE);
9864 return CMD_WARNING;
9865}
9866
9867 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9868 PEER_FLAG_RSERVER_CLIENT))
9869 {
9870 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9871 VTY_NEWLINE);
9872 return CMD_WARNING;
9873 }
9874
9875 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9876 (argc == 3) ? argv[2] : argv[1],
9877 AFI_IP, SAFI_UNICAST, NULL, 0);
9878}
9879
9880ALIAS (show_ip_bgp_view_rsclient_route,
9881 show_ip_bgp_rsclient_route_cmd,
9882 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9883 SHOW_STR
9884 IP_STR
9885 BGP_STR
9886 "Information about Route Server Client\n"
9887 NEIGHBOR_ADDR_STR
9888 "Network in the BGP routing table to display\n")
9889
9890DEFUN (show_ip_bgp_view_rsclient_prefix,
9891 show_ip_bgp_view_rsclient_prefix_cmd,
9892 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9893 SHOW_STR
9894 IP_STR
9895 BGP_STR
9896 "BGP view\n"
9897 "BGP view name\n"
9898 "Information about Route Server Client\n"
9899 NEIGHBOR_ADDR_STR
9900 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9901{
9902 struct bgp *bgp;
9903 struct peer *peer;
9904
9905 /* BGP structure lookup. */
9906 if (argc == 3)
9907 {
9908 bgp = bgp_lookup_by_name (argv[0]);
9909 if (bgp == NULL)
9910 {
9911 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9912 return CMD_WARNING;
9913 }
9914 }
9915 else
9916 {
9917 bgp = bgp_get_default ();
9918 if (bgp == NULL)
9919 {
9920 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9921 return CMD_WARNING;
9922 }
9923 }
9924
9925 if (argc == 3)
9926 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9927 else
9928 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9929
9930 if (! peer)
9931 return CMD_WARNING;
9932
9933 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9934 {
9935 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9936 VTY_NEWLINE);
9937 return CMD_WARNING;
9938}
9939
9940 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9941 PEER_FLAG_RSERVER_CLIENT))
9942{
9943 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9944 VTY_NEWLINE);
9945 return CMD_WARNING;
9946 }
9947
9948 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9949 (argc == 3) ? argv[2] : argv[1],
9950 AFI_IP, SAFI_UNICAST, NULL, 1);
9951}
9952
9953ALIAS (show_ip_bgp_view_rsclient_prefix,
9954 show_ip_bgp_rsclient_prefix_cmd,
9955 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9956 SHOW_STR
9957 IP_STR
9958 BGP_STR
9959 "Information about Route Server Client\n"
9960 NEIGHBOR_ADDR_STR
9961 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9962
9963
paul718e3742002-12-13 20:15:29 +00009964#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009965DEFUN (show_bgp_view_neighbor_routes,
9966 show_bgp_view_neighbor_routes_cmd,
9967 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
9968 SHOW_STR
9969 BGP_STR
9970 "BGP view\n"
9971 "BGP view name\n"
9972 "Detailed information on TCP and BGP neighbor connections\n"
9973 "Neighbor to display information about\n"
9974 "Neighbor to display information about\n"
9975 "Display routes learned from neighbor\n")
9976{
9977 struct peer *peer;
9978
9979 if (argc == 2)
9980 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9981 else
9982 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9983
9984 if (! peer)
9985 return CMD_WARNING;
9986
9987 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9988 bgp_show_type_neighbor);
9989}
9990
9991ALIAS (show_bgp_view_neighbor_routes,
9992 show_bgp_view_ipv6_neighbor_routes_cmd,
9993 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9994 SHOW_STR
9995 BGP_STR
9996 "BGP view\n"
9997 "BGP view name\n"
9998 "Address family\n"
9999 "Detailed information on TCP and BGP neighbor connections\n"
10000 "Neighbor to display information about\n"
10001 "Neighbor to display information about\n"
10002 "Display routes learned from neighbor\n")
10003
10004DEFUN (show_bgp_view_neighbor_damp,
10005 show_bgp_view_neighbor_damp_cmd,
10006 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10007 SHOW_STR
10008 BGP_STR
10009 "BGP view\n"
10010 "BGP view name\n"
10011 "Detailed information on TCP and BGP neighbor connections\n"
10012 "Neighbor to display information about\n"
10013 "Neighbor to display information about\n"
10014 "Display the dampened routes received from neighbor\n")
10015{
10016 struct peer *peer;
10017
10018 if (argc == 2)
10019 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10020 else
10021 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10022
10023 if (! peer)
10024 return CMD_WARNING;
10025
10026 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10027 bgp_show_type_damp_neighbor);
10028}
10029
10030ALIAS (show_bgp_view_neighbor_damp,
10031 show_bgp_view_ipv6_neighbor_damp_cmd,
10032 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10033 SHOW_STR
10034 BGP_STR
10035 "BGP view\n"
10036 "BGP view name\n"
10037 "Address family\n"
10038 "Detailed information on TCP and BGP neighbor connections\n"
10039 "Neighbor to display information about\n"
10040 "Neighbor to display information about\n"
10041 "Display the dampened routes received from neighbor\n")
10042
10043DEFUN (show_bgp_view_neighbor_flap,
10044 show_bgp_view_neighbor_flap_cmd,
10045 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10046 SHOW_STR
10047 BGP_STR
10048 "BGP view\n"
10049 "BGP view name\n"
10050 "Detailed information on TCP and BGP neighbor connections\n"
10051 "Neighbor to display information about\n"
10052 "Neighbor to display information about\n"
10053 "Display flap statistics of the routes learned from neighbor\n")
10054{
10055 struct peer *peer;
10056
10057 if (argc == 2)
10058 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10059 else
10060 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10061
10062 if (! peer)
10063 return CMD_WARNING;
10064
10065 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10066 bgp_show_type_flap_neighbor);
10067}
10068
10069ALIAS (show_bgp_view_neighbor_flap,
10070 show_bgp_view_ipv6_neighbor_flap_cmd,
10071 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10072 SHOW_STR
10073 BGP_STR
10074 "BGP view\n"
10075 "BGP view name\n"
10076 "Address family\n"
10077 "Detailed information on TCP and BGP neighbor connections\n"
10078 "Neighbor to display information about\n"
10079 "Neighbor to display information about\n"
10080 "Display flap statistics of the routes learned from neighbor\n")
10081
10082ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010083 show_bgp_neighbor_routes_cmd,
10084 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10085 SHOW_STR
10086 BGP_STR
10087 "Detailed information on TCP and BGP neighbor connections\n"
10088 "Neighbor to display information about\n"
10089 "Neighbor to display information about\n"
10090 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010091
paulbb46e942003-10-24 19:02:03 +000010092
10093ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010094 show_bgp_ipv6_neighbor_routes_cmd,
10095 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10096 SHOW_STR
10097 BGP_STR
10098 "Address family\n"
10099 "Detailed information on TCP and BGP neighbor connections\n"
10100 "Neighbor to display information about\n"
10101 "Neighbor to display information about\n"
10102 "Display routes learned from neighbor\n")
10103
10104/* old command */
paulbb46e942003-10-24 19:02:03 +000010105ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010106 ipv6_bgp_neighbor_routes_cmd,
10107 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10108 SHOW_STR
10109 IPV6_STR
10110 BGP_STR
10111 "Detailed information on TCP and BGP neighbor connections\n"
10112 "Neighbor to display information about\n"
10113 "Neighbor to display information about\n"
10114 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010115
10116/* old command */
10117DEFUN (ipv6_mbgp_neighbor_routes,
10118 ipv6_mbgp_neighbor_routes_cmd,
10119 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10120 SHOW_STR
10121 IPV6_STR
10122 MBGP_STR
10123 "Detailed information on TCP and BGP neighbor connections\n"
10124 "Neighbor to display information about\n"
10125 "Neighbor to display information about\n"
10126 "Display routes learned from neighbor\n")
10127{
paulbb46e942003-10-24 19:02:03 +000010128 struct peer *peer;
10129
10130 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10131 if (! peer)
10132 return CMD_WARNING;
10133
10134 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010135 bgp_show_type_neighbor);
10136}
paulbb46e942003-10-24 19:02:03 +000010137
10138ALIAS (show_bgp_view_neighbor_flap,
10139 show_bgp_neighbor_flap_cmd,
10140 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10141 SHOW_STR
10142 BGP_STR
10143 "Detailed information on TCP and BGP neighbor connections\n"
10144 "Neighbor to display information about\n"
10145 "Neighbor to display information about\n"
10146 "Display flap statistics of the routes learned from neighbor\n")
10147
10148ALIAS (show_bgp_view_neighbor_flap,
10149 show_bgp_ipv6_neighbor_flap_cmd,
10150 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10151 SHOW_STR
10152 BGP_STR
10153 "Address family\n"
10154 "Detailed information on TCP and BGP neighbor connections\n"
10155 "Neighbor to display information about\n"
10156 "Neighbor to display information about\n"
10157 "Display flap statistics of the routes learned from neighbor\n")
10158
10159ALIAS (show_bgp_view_neighbor_damp,
10160 show_bgp_neighbor_damp_cmd,
10161 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10162 SHOW_STR
10163 BGP_STR
10164 "Detailed information on TCP and BGP neighbor connections\n"
10165 "Neighbor to display information about\n"
10166 "Neighbor to display information about\n"
10167 "Display the dampened routes received from neighbor\n")
10168
10169ALIAS (show_bgp_view_neighbor_damp,
10170 show_bgp_ipv6_neighbor_damp_cmd,
10171 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10172 SHOW_STR
10173 BGP_STR
10174 "Address family\n"
10175 "Detailed information on TCP and BGP neighbor connections\n"
10176 "Neighbor to display information about\n"
10177 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010178 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010179
10180DEFUN (show_bgp_view_rsclient,
10181 show_bgp_view_rsclient_cmd,
10182 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10183 SHOW_STR
10184 BGP_STR
10185 "BGP view\n"
10186 "BGP view name\n"
10187 "Information about Route Server Client\n"
10188 NEIGHBOR_ADDR_STR)
10189{
10190 struct bgp_table *table;
10191 struct peer *peer;
10192
10193 if (argc == 2)
10194 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10195 else
10196 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10197
10198 if (! peer)
10199 return CMD_WARNING;
10200
10201 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10202 {
10203 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10204 VTY_NEWLINE);
10205 return CMD_WARNING;
10206 }
10207
10208 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10209 PEER_FLAG_RSERVER_CLIENT))
10210 {
10211 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10212 VTY_NEWLINE);
10213 return CMD_WARNING;
10214 }
10215
10216 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10217
ajs5a646652004-11-05 01:25:55 +000010218 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010219}
10220
10221ALIAS (show_bgp_view_rsclient,
10222 show_bgp_rsclient_cmd,
10223 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10224 SHOW_STR
10225 BGP_STR
10226 "Information about Route Server Client\n"
10227 NEIGHBOR_ADDR_STR)
10228
10229DEFUN (show_bgp_view_rsclient_route,
10230 show_bgp_view_rsclient_route_cmd,
10231 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10232 SHOW_STR
10233 BGP_STR
10234 "BGP view\n"
10235 "BGP view name\n"
10236 "Information about Route Server Client\n"
10237 NEIGHBOR_ADDR_STR
10238 "Network in the BGP routing table to display\n")
10239{
10240 struct bgp *bgp;
10241 struct peer *peer;
10242
10243 /* BGP structure lookup. */
10244 if (argc == 3)
10245 {
10246 bgp = bgp_lookup_by_name (argv[0]);
10247 if (bgp == NULL)
10248 {
10249 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10250 return CMD_WARNING;
10251 }
10252 }
10253 else
10254 {
10255 bgp = bgp_get_default ();
10256 if (bgp == NULL)
10257 {
10258 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10259 return CMD_WARNING;
10260 }
10261 }
10262
10263 if (argc == 3)
10264 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10265 else
10266 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10267
10268 if (! peer)
10269 return CMD_WARNING;
10270
10271 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10272 {
10273 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10274 VTY_NEWLINE);
10275 return CMD_WARNING;
10276 }
10277
10278 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10279 PEER_FLAG_RSERVER_CLIENT))
10280 {
10281 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10282 VTY_NEWLINE);
10283 return CMD_WARNING;
10284 }
10285
10286 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10287 (argc == 3) ? argv[2] : argv[1],
10288 AFI_IP6, SAFI_UNICAST, NULL, 0);
10289}
10290
10291ALIAS (show_bgp_view_rsclient_route,
10292 show_bgp_rsclient_route_cmd,
10293 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10294 SHOW_STR
10295 BGP_STR
10296 "Information about Route Server Client\n"
10297 NEIGHBOR_ADDR_STR
10298 "Network in the BGP routing table to display\n")
10299
10300DEFUN (show_bgp_view_rsclient_prefix,
10301 show_bgp_view_rsclient_prefix_cmd,
10302 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10303 SHOW_STR
10304 BGP_STR
10305 "BGP view\n"
10306 "BGP view name\n"
10307 "Information about Route Server Client\n"
10308 NEIGHBOR_ADDR_STR
10309 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10310{
10311 struct bgp *bgp;
10312 struct peer *peer;
10313
10314 /* BGP structure lookup. */
10315 if (argc == 3)
10316 {
10317 bgp = bgp_lookup_by_name (argv[0]);
10318 if (bgp == NULL)
10319 {
10320 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10321 return CMD_WARNING;
10322 }
10323 }
10324 else
10325 {
10326 bgp = bgp_get_default ();
10327 if (bgp == NULL)
10328 {
10329 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10330 return CMD_WARNING;
10331 }
10332 }
10333
10334 if (argc == 3)
10335 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10336 else
10337 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10338
10339 if (! peer)
10340 return CMD_WARNING;
10341
10342 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10343 {
10344 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10345 VTY_NEWLINE);
10346 return CMD_WARNING;
10347 }
10348
10349 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10350 PEER_FLAG_RSERVER_CLIENT))
10351 {
10352 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10353 VTY_NEWLINE);
10354 return CMD_WARNING;
10355 }
10356
10357 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10358 (argc == 3) ? argv[2] : argv[1],
10359 AFI_IP6, SAFI_UNICAST, NULL, 1);
10360}
10361
10362ALIAS (show_bgp_view_rsclient_prefix,
10363 show_bgp_rsclient_prefix_cmd,
10364 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10365 SHOW_STR
10366 BGP_STR
10367 "Information about Route Server Client\n"
10368 NEIGHBOR_ADDR_STR
10369 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10370
paul718e3742002-12-13 20:15:29 +000010371#endif /* HAVE_IPV6 */
10372
10373struct bgp_table *bgp_distance_table;
10374
10375struct bgp_distance
10376{
10377 /* Distance value for the IP source prefix. */
10378 u_char distance;
10379
10380 /* Name of the access-list to be matched. */
10381 char *access_list;
10382};
10383
paul94f2b392005-06-28 12:44:16 +000010384static struct bgp_distance *
paul718e3742002-12-13 20:15:29 +000010385bgp_distance_new ()
10386{
10387 struct bgp_distance *new;
10388 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
10389 memset (new, 0, sizeof (struct bgp_distance));
10390 return new;
10391}
10392
paul94f2b392005-06-28 12:44:16 +000010393static void
paul718e3742002-12-13 20:15:29 +000010394bgp_distance_free (struct bgp_distance *bdistance)
10395{
10396 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10397}
10398
paul94f2b392005-06-28 12:44:16 +000010399static int
paulfd79ac92004-10-13 05:06:08 +000010400bgp_distance_set (struct vty *vty, const char *distance_str,
10401 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010402{
10403 int ret;
10404 struct prefix_ipv4 p;
10405 u_char distance;
10406 struct bgp_node *rn;
10407 struct bgp_distance *bdistance;
10408
10409 ret = str2prefix_ipv4 (ip_str, &p);
10410 if (ret == 0)
10411 {
10412 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10413 return CMD_WARNING;
10414 }
10415
10416 distance = atoi (distance_str);
10417
10418 /* Get BGP distance node. */
10419 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10420 if (rn->info)
10421 {
10422 bdistance = rn->info;
10423 bgp_unlock_node (rn);
10424 }
10425 else
10426 {
10427 bdistance = bgp_distance_new ();
10428 rn->info = bdistance;
10429 }
10430
10431 /* Set distance value. */
10432 bdistance->distance = distance;
10433
10434 /* Reset access-list configuration. */
10435 if (bdistance->access_list)
10436 {
10437 free (bdistance->access_list);
10438 bdistance->access_list = NULL;
10439 }
10440 if (access_list_str)
10441 bdistance->access_list = strdup (access_list_str);
10442
10443 return CMD_SUCCESS;
10444}
10445
paul94f2b392005-06-28 12:44:16 +000010446static int
paulfd79ac92004-10-13 05:06:08 +000010447bgp_distance_unset (struct vty *vty, const char *distance_str,
10448 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010449{
10450 int ret;
10451 struct prefix_ipv4 p;
10452 u_char distance;
10453 struct bgp_node *rn;
10454 struct bgp_distance *bdistance;
10455
10456 ret = str2prefix_ipv4 (ip_str, &p);
10457 if (ret == 0)
10458 {
10459 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10460 return CMD_WARNING;
10461 }
10462
10463 distance = atoi (distance_str);
10464
10465 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10466 if (! rn)
10467 {
10468 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10469 return CMD_WARNING;
10470 }
10471
10472 bdistance = rn->info;
10473
10474 if (bdistance->access_list)
10475 free (bdistance->access_list);
10476 bgp_distance_free (bdistance);
10477
10478 rn->info = NULL;
10479 bgp_unlock_node (rn);
10480 bgp_unlock_node (rn);
10481
10482 return CMD_SUCCESS;
10483}
10484
paul94f2b392005-06-28 12:44:16 +000010485static void
paul718e3742002-12-13 20:15:29 +000010486bgp_distance_reset ()
10487{
10488 struct bgp_node *rn;
10489 struct bgp_distance *bdistance;
10490
10491 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10492 if ((bdistance = rn->info) != NULL)
10493 {
10494 if (bdistance->access_list)
10495 free (bdistance->access_list);
10496 bgp_distance_free (bdistance);
10497 rn->info = NULL;
10498 bgp_unlock_node (rn);
10499 }
10500}
10501
10502/* Apply BGP information to distance method. */
10503u_char
10504bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10505{
10506 struct bgp_node *rn;
10507 struct prefix_ipv4 q;
10508 struct peer *peer;
10509 struct bgp_distance *bdistance;
10510 struct access_list *alist;
10511 struct bgp_static *bgp_static;
10512
10513 if (! bgp)
10514 return 0;
10515
10516 if (p->family != AF_INET)
10517 return 0;
10518
10519 peer = rinfo->peer;
10520
10521 if (peer->su.sa.sa_family != AF_INET)
10522 return 0;
10523
10524 memset (&q, 0, sizeof (struct prefix_ipv4));
10525 q.family = AF_INET;
10526 q.prefix = peer->su.sin.sin_addr;
10527 q.prefixlen = IPV4_MAX_BITLEN;
10528
10529 /* Check source address. */
10530 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
10531 if (rn)
10532 {
10533 bdistance = rn->info;
10534 bgp_unlock_node (rn);
10535
10536 if (bdistance->access_list)
10537 {
10538 alist = access_list_lookup (AFI_IP, bdistance->access_list);
10539 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
10540 return bdistance->distance;
10541 }
10542 else
10543 return bdistance->distance;
10544 }
10545
10546 /* Backdoor check. */
10547 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
10548 if (rn)
10549 {
10550 bgp_static = rn->info;
10551 bgp_unlock_node (rn);
10552
10553 if (bgp_static->backdoor)
10554 {
10555 if (bgp->distance_local)
10556 return bgp->distance_local;
10557 else
10558 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10559 }
10560 }
10561
10562 if (peer_sort (peer) == BGP_PEER_EBGP)
10563 {
10564 if (bgp->distance_ebgp)
10565 return bgp->distance_ebgp;
10566 return ZEBRA_EBGP_DISTANCE_DEFAULT;
10567 }
10568 else
10569 {
10570 if (bgp->distance_ibgp)
10571 return bgp->distance_ibgp;
10572 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10573 }
10574}
10575
10576DEFUN (bgp_distance,
10577 bgp_distance_cmd,
10578 "distance bgp <1-255> <1-255> <1-255>",
10579 "Define an administrative distance\n"
10580 "BGP distance\n"
10581 "Distance for routes external to the AS\n"
10582 "Distance for routes internal to the AS\n"
10583 "Distance for local routes\n")
10584{
10585 struct bgp *bgp;
10586
10587 bgp = vty->index;
10588
10589 bgp->distance_ebgp = atoi (argv[0]);
10590 bgp->distance_ibgp = atoi (argv[1]);
10591 bgp->distance_local = atoi (argv[2]);
10592 return CMD_SUCCESS;
10593}
10594
10595DEFUN (no_bgp_distance,
10596 no_bgp_distance_cmd,
10597 "no distance bgp <1-255> <1-255> <1-255>",
10598 NO_STR
10599 "Define an administrative distance\n"
10600 "BGP distance\n"
10601 "Distance for routes external to the AS\n"
10602 "Distance for routes internal to the AS\n"
10603 "Distance for local routes\n")
10604{
10605 struct bgp *bgp;
10606
10607 bgp = vty->index;
10608
10609 bgp->distance_ebgp= 0;
10610 bgp->distance_ibgp = 0;
10611 bgp->distance_local = 0;
10612 return CMD_SUCCESS;
10613}
10614
10615ALIAS (no_bgp_distance,
10616 no_bgp_distance2_cmd,
10617 "no distance bgp",
10618 NO_STR
10619 "Define an administrative distance\n"
10620 "BGP distance\n")
10621
10622DEFUN (bgp_distance_source,
10623 bgp_distance_source_cmd,
10624 "distance <1-255> A.B.C.D/M",
10625 "Define an administrative distance\n"
10626 "Administrative distance\n"
10627 "IP source prefix\n")
10628{
10629 bgp_distance_set (vty, argv[0], argv[1], NULL);
10630 return CMD_SUCCESS;
10631}
10632
10633DEFUN (no_bgp_distance_source,
10634 no_bgp_distance_source_cmd,
10635 "no distance <1-255> A.B.C.D/M",
10636 NO_STR
10637 "Define an administrative distance\n"
10638 "Administrative distance\n"
10639 "IP source prefix\n")
10640{
10641 bgp_distance_unset (vty, argv[0], argv[1], NULL);
10642 return CMD_SUCCESS;
10643}
10644
10645DEFUN (bgp_distance_source_access_list,
10646 bgp_distance_source_access_list_cmd,
10647 "distance <1-255> A.B.C.D/M WORD",
10648 "Define an administrative distance\n"
10649 "Administrative distance\n"
10650 "IP source prefix\n"
10651 "Access list name\n")
10652{
10653 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
10654 return CMD_SUCCESS;
10655}
10656
10657DEFUN (no_bgp_distance_source_access_list,
10658 no_bgp_distance_source_access_list_cmd,
10659 "no distance <1-255> A.B.C.D/M WORD",
10660 NO_STR
10661 "Define an administrative distance\n"
10662 "Administrative distance\n"
10663 "IP source prefix\n"
10664 "Access list name\n")
10665{
10666 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
10667 return CMD_SUCCESS;
10668}
10669
10670DEFUN (bgp_damp_set,
10671 bgp_damp_set_cmd,
10672 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10673 "BGP Specific commands\n"
10674 "Enable route-flap dampening\n"
10675 "Half-life time for the penalty\n"
10676 "Value to start reusing a route\n"
10677 "Value to start suppressing a route\n"
10678 "Maximum duration to suppress a stable route\n")
10679{
10680 struct bgp *bgp;
10681 int half = DEFAULT_HALF_LIFE * 60;
10682 int reuse = DEFAULT_REUSE;
10683 int suppress = DEFAULT_SUPPRESS;
10684 int max = 4 * half;
10685
10686 if (argc == 4)
10687 {
10688 half = atoi (argv[0]) * 60;
10689 reuse = atoi (argv[1]);
10690 suppress = atoi (argv[2]);
10691 max = atoi (argv[3]) * 60;
10692 }
10693 else if (argc == 1)
10694 {
10695 half = atoi (argv[0]) * 60;
10696 max = 4 * half;
10697 }
10698
10699 bgp = vty->index;
10700 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
10701 half, reuse, suppress, max);
10702}
10703
10704ALIAS (bgp_damp_set,
10705 bgp_damp_set2_cmd,
10706 "bgp dampening <1-45>",
10707 "BGP Specific commands\n"
10708 "Enable route-flap dampening\n"
10709 "Half-life time for the penalty\n")
10710
10711ALIAS (bgp_damp_set,
10712 bgp_damp_set3_cmd,
10713 "bgp dampening",
10714 "BGP Specific commands\n"
10715 "Enable route-flap dampening\n")
10716
10717DEFUN (bgp_damp_unset,
10718 bgp_damp_unset_cmd,
10719 "no bgp dampening",
10720 NO_STR
10721 "BGP Specific commands\n"
10722 "Enable route-flap dampening\n")
10723{
10724 struct bgp *bgp;
10725
10726 bgp = vty->index;
10727 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
10728}
10729
10730ALIAS (bgp_damp_unset,
10731 bgp_damp_unset2_cmd,
10732 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10733 NO_STR
10734 "BGP Specific commands\n"
10735 "Enable route-flap dampening\n"
10736 "Half-life time for the penalty\n"
10737 "Value to start reusing a route\n"
10738 "Value to start suppressing a route\n"
10739 "Maximum duration to suppress a stable route\n")
10740
10741DEFUN (show_ip_bgp_dampened_paths,
10742 show_ip_bgp_dampened_paths_cmd,
10743 "show ip bgp dampened-paths",
10744 SHOW_STR
10745 IP_STR
10746 BGP_STR
10747 "Display paths suppressed due to dampening\n")
10748{
ajs5a646652004-11-05 01:25:55 +000010749 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
10750 NULL);
paul718e3742002-12-13 20:15:29 +000010751}
10752
10753DEFUN (show_ip_bgp_flap_statistics,
10754 show_ip_bgp_flap_statistics_cmd,
10755 "show ip bgp flap-statistics",
10756 SHOW_STR
10757 IP_STR
10758 BGP_STR
10759 "Display flap statistics of routes\n")
10760{
ajs5a646652004-11-05 01:25:55 +000010761 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10762 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000010763}
10764
10765/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000010766static int
paulfd79ac92004-10-13 05:06:08 +000010767bgp_clear_damp_route (struct vty *vty, const char *view_name,
10768 const char *ip_str, afi_t afi, safi_t safi,
10769 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000010770{
10771 int ret;
10772 struct prefix match;
10773 struct bgp_node *rn;
10774 struct bgp_node *rm;
10775 struct bgp_info *ri;
10776 struct bgp_info *ri_temp;
10777 struct bgp *bgp;
10778 struct bgp_table *table;
10779
10780 /* BGP structure lookup. */
10781 if (view_name)
10782 {
10783 bgp = bgp_lookup_by_name (view_name);
10784 if (bgp == NULL)
10785 {
10786 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10787 return CMD_WARNING;
10788 }
10789 }
10790 else
10791 {
10792 bgp = bgp_get_default ();
10793 if (bgp == NULL)
10794 {
10795 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
10796 return CMD_WARNING;
10797 }
10798 }
10799
10800 /* Check IP address argument. */
10801 ret = str2prefix (ip_str, &match);
10802 if (! ret)
10803 {
10804 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
10805 return CMD_WARNING;
10806 }
10807
10808 match.family = afi2family (afi);
10809
10810 if (safi == SAFI_MPLS_VPN)
10811 {
10812 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
10813 {
10814 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
10815 continue;
10816
10817 if ((table = rn->info) != NULL)
10818 if ((rm = bgp_node_match (table, &match)) != NULL)
10819 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
10820 {
10821 ri = rm->info;
10822 while (ri)
10823 {
10824 if (ri->damp_info)
10825 {
10826 ri_temp = ri->next;
10827 bgp_damp_info_free (ri->damp_info, 1);
10828 ri = ri_temp;
10829 }
10830 else
10831 ri = ri->next;
10832 }
10833 }
10834 }
10835 }
10836 else
10837 {
10838 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
10839 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
10840 {
10841 ri = rn->info;
10842 while (ri)
10843 {
10844 if (ri->damp_info)
10845 {
10846 ri_temp = ri->next;
10847 bgp_damp_info_free (ri->damp_info, 1);
10848 ri = ri_temp;
10849 }
10850 else
10851 ri = ri->next;
10852 }
10853 }
10854 }
10855
10856 return CMD_SUCCESS;
10857}
10858
10859DEFUN (clear_ip_bgp_dampening,
10860 clear_ip_bgp_dampening_cmd,
10861 "clear ip bgp dampening",
10862 CLEAR_STR
10863 IP_STR
10864 BGP_STR
10865 "Clear route flap dampening information\n")
10866{
10867 bgp_damp_info_clean ();
10868 return CMD_SUCCESS;
10869}
10870
10871DEFUN (clear_ip_bgp_dampening_prefix,
10872 clear_ip_bgp_dampening_prefix_cmd,
10873 "clear ip bgp dampening A.B.C.D/M",
10874 CLEAR_STR
10875 IP_STR
10876 BGP_STR
10877 "Clear route flap dampening information\n"
10878 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10879{
10880 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10881 SAFI_UNICAST, NULL, 1);
10882}
10883
10884DEFUN (clear_ip_bgp_dampening_address,
10885 clear_ip_bgp_dampening_address_cmd,
10886 "clear ip bgp dampening A.B.C.D",
10887 CLEAR_STR
10888 IP_STR
10889 BGP_STR
10890 "Clear route flap dampening information\n"
10891 "Network to clear damping information\n")
10892{
10893 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10894 SAFI_UNICAST, NULL, 0);
10895}
10896
10897DEFUN (clear_ip_bgp_dampening_address_mask,
10898 clear_ip_bgp_dampening_address_mask_cmd,
10899 "clear ip bgp dampening A.B.C.D A.B.C.D",
10900 CLEAR_STR
10901 IP_STR
10902 BGP_STR
10903 "Clear route flap dampening information\n"
10904 "Network to clear damping information\n"
10905 "Network mask\n")
10906{
10907 int ret;
10908 char prefix_str[BUFSIZ];
10909
10910 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
10911 if (! ret)
10912 {
10913 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
10914 return CMD_WARNING;
10915 }
10916
10917 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
10918 SAFI_UNICAST, NULL, 0);
10919}
10920
paul94f2b392005-06-28 12:44:16 +000010921static int
paul718e3742002-12-13 20:15:29 +000010922bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
10923 afi_t afi, safi_t safi, int *write)
10924{
10925 struct bgp_node *prn;
10926 struct bgp_node *rn;
10927 struct bgp_table *table;
10928 struct prefix *p;
10929 struct prefix_rd *prd;
10930 struct bgp_static *bgp_static;
10931 u_int32_t label;
10932 char buf[SU_ADDRSTRLEN];
10933 char rdbuf[RD_ADDRSTRLEN];
10934
10935 /* Network configuration. */
10936 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
10937 if ((table = prn->info) != NULL)
10938 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10939 if ((bgp_static = rn->info) != NULL)
10940 {
10941 p = &rn->p;
10942 prd = (struct prefix_rd *) &prn->p;
10943
10944 /* "address-family" display. */
10945 bgp_config_write_family_header (vty, afi, safi, write);
10946
10947 /* "network" configuration display. */
10948 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
10949 label = decode_label (bgp_static->tag);
10950
10951 vty_out (vty, " network %s/%d rd %s tag %d",
10952 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10953 p->prefixlen,
10954 rdbuf, label);
10955 vty_out (vty, "%s", VTY_NEWLINE);
10956 }
10957 return 0;
10958}
10959
10960/* Configuration of static route announcement and aggregate
10961 information. */
10962int
10963bgp_config_write_network (struct vty *vty, struct bgp *bgp,
10964 afi_t afi, safi_t safi, int *write)
10965{
10966 struct bgp_node *rn;
10967 struct prefix *p;
10968 struct bgp_static *bgp_static;
10969 struct bgp_aggregate *bgp_aggregate;
10970 char buf[SU_ADDRSTRLEN];
10971
10972 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
10973 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
10974
10975 /* Network configuration. */
10976 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
10977 if ((bgp_static = rn->info) != NULL)
10978 {
10979 p = &rn->p;
10980
10981 /* "address-family" display. */
10982 bgp_config_write_family_header (vty, afi, safi, write);
10983
10984 /* "network" configuration display. */
10985 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10986 {
10987 u_int32_t destination;
10988 struct in_addr netmask;
10989
10990 destination = ntohl (p->u.prefix4.s_addr);
10991 masklen2ip (p->prefixlen, &netmask);
10992 vty_out (vty, " network %s",
10993 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
10994
10995 if ((IN_CLASSC (destination) && p->prefixlen == 24)
10996 || (IN_CLASSB (destination) && p->prefixlen == 16)
10997 || (IN_CLASSA (destination) && p->prefixlen == 8)
10998 || p->u.prefix4.s_addr == 0)
10999 {
11000 /* Natural mask is not display. */
11001 }
11002 else
11003 vty_out (vty, " mask %s", inet_ntoa (netmask));
11004 }
11005 else
11006 {
11007 vty_out (vty, " network %s/%d",
11008 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11009 p->prefixlen);
11010 }
11011
11012 if (bgp_static->rmap.name)
11013 vty_out (vty, " route-map %s", bgp_static->rmap.name);
11014 else if (bgp_static->backdoor)
11015 vty_out (vty, " backdoor");
11016
11017 vty_out (vty, "%s", VTY_NEWLINE);
11018 }
11019
11020 /* Aggregate-address configuration. */
11021 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11022 if ((bgp_aggregate = rn->info) != NULL)
11023 {
11024 p = &rn->p;
11025
11026 /* "address-family" display. */
11027 bgp_config_write_family_header (vty, afi, safi, write);
11028
11029 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11030 {
11031 struct in_addr netmask;
11032
11033 masklen2ip (p->prefixlen, &netmask);
11034 vty_out (vty, " aggregate-address %s %s",
11035 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11036 inet_ntoa (netmask));
11037 }
11038 else
11039 {
11040 vty_out (vty, " aggregate-address %s/%d",
11041 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11042 p->prefixlen);
11043 }
11044
11045 if (bgp_aggregate->as_set)
11046 vty_out (vty, " as-set");
11047
11048 if (bgp_aggregate->summary_only)
11049 vty_out (vty, " summary-only");
11050
11051 vty_out (vty, "%s", VTY_NEWLINE);
11052 }
11053
11054 return 0;
11055}
11056
11057int
11058bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11059{
11060 struct bgp_node *rn;
11061 struct bgp_distance *bdistance;
11062
11063 /* Distance configuration. */
11064 if (bgp->distance_ebgp
11065 && bgp->distance_ibgp
11066 && bgp->distance_local
11067 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11068 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11069 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11070 vty_out (vty, " distance bgp %d %d %d%s",
11071 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11072 VTY_NEWLINE);
11073
11074 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11075 if ((bdistance = rn->info) != NULL)
11076 {
11077 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11078 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11079 bdistance->access_list ? bdistance->access_list : "",
11080 VTY_NEWLINE);
11081 }
11082
11083 return 0;
11084}
11085
11086/* Allocate routing table structure and install commands. */
11087void
11088bgp_route_init ()
11089{
11090 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011091 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011092
11093 /* IPv4 BGP commands. */
11094 install_element (BGP_NODE, &bgp_network_cmd);
11095 install_element (BGP_NODE, &bgp_network_mask_cmd);
11096 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11097 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11098 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11099 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11100 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11101 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11102 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
11103 install_element (BGP_NODE, &no_bgp_network_cmd);
11104 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11105 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11106 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11107 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11108 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11109 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11110 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11111 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
11112
11113 install_element (BGP_NODE, &aggregate_address_cmd);
11114 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11115 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11116 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11117 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11118 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11119 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11120 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11121 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11122 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11123 install_element (BGP_NODE, &no_aggregate_address_cmd);
11124 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11125 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11126 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11127 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11128 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11129 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11130 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11131 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11132 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11133
11134 /* IPv4 unicast configuration. */
11135 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11136 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11137 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11138 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11139 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11140 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
11141 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
11142 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11143 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11144 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11145 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11146 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11147 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11148 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11149 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11150 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11151 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11152 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11153 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11154 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11155 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11156 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11157 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11158 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11159 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11160 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11161 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11162 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11163 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11164 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11165 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11166 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11167
11168 /* IPv4 multicast configuration. */
11169 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11170 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11171 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11172 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11173 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11174 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
11175 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11176 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11177 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11178 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11179 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11180 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11181 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11182 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11183 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11184 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11185 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11186 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11187 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11188 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11189 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11190 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11191 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11192 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11193 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11194 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11195 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11196 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11197 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11198 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11199 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11200 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11201
11202 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11203 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11204 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11205 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11206 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11207 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11208 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11209 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11210 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11211 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11212 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11213 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11214 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11215 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11216 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11217 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11218 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11219 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11220 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11221 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11222 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11223 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11224 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11225 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11226 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11227 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11228 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11229 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11230 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11231 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11232 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11233 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11234 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11235 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11236 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11237 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11238 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11239 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11240 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11241 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11242 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11243 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11244 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11245 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11246 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11247 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11248 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11249 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11250 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11251 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11252 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11253 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11254 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11255 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11256 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11257 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11258 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11259 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11260 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11261 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11262 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11263 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11264 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11265 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11266 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11267 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11268 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011269 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11270 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11271 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11272 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11273 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11274 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011275
11276 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11277 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11278 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11279 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11280 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11281 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11282 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11283 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11284 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11285 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11286 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11287 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11288 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11289 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11290 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11291 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11292 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11293 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11294 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11295 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11296 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11297 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11298 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11299 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11300 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11301 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11302 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11303 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11304 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11305 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11306 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11307 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11308 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11309 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11310 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11311 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11312 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11313 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11314 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11315 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11316 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11317 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11318 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11319 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11320 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11321 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11322 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11323 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11324 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11325 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11326 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11327 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11328 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11329 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11330 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11331 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11332 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11333 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11334 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11335 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11336 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11337 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11338 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11339 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11340 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11341 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11342 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011343 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11344 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11345 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11346 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11347 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11348 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011349
11350 /* BGP dampening clear commands */
11351 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11352 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11353 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11354 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11355
Paul Jakmaff7924f2006-09-04 01:10:36 +000011356 /* prefix count */
11357 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11358 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11359 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011360#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011361 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11362
paul718e3742002-12-13 20:15:29 +000011363 /* New config IPv6 BGP commands. */
11364 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11365 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
11366 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11367 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
11368
11369 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11370 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11371 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11372 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11373
11374 /* Old config IPv6 BGP commands. */
11375 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11376 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11377
11378 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11379 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11380 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11381 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11382
11383 install_element (VIEW_NODE, &show_bgp_cmd);
11384 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11385 install_element (VIEW_NODE, &show_bgp_route_cmd);
11386 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11387 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11388 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11389 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11390 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11391 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11392 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11393 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11394 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11395 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11396 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11397 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11398 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11399 install_element (VIEW_NODE, &show_bgp_community_cmd);
11400 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11401 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11402 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11403 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11404 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11405 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11406 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11407 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
11408 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
11409 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
11410 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
11411 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
11412 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
11413 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
11414 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
11415 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
11416 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
11417 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
11418 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11419 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
11420 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11421 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
11422 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11423 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
11424 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11425 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
11426 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11427 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11428 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011429 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
11430 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11431 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
11432 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011433 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
11434 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
11435 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011436 install_element (VIEW_NODE, &show_bgp_view_cmd);
11437 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
11438 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
11439 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
11440 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
11441 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
11442 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11443 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11444 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11445 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11446 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
11447 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11448 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11449 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11450 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
11451 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11452 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
11453 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011454 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
11455 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
11456 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011457
11458 install_element (ENABLE_NODE, &show_bgp_cmd);
11459 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
11460 install_element (ENABLE_NODE, &show_bgp_route_cmd);
11461 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
11462 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
11463 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
11464 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
11465 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
11466 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
11467 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
11468 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
11469 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
11470 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
11471 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
11472 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
11473 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
11474 install_element (ENABLE_NODE, &show_bgp_community_cmd);
11475 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
11476 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
11477 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
11478 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
11479 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
11480 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
11481 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
11482 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
11483 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
11484 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
11485 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
11486 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
11487 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
11488 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
11489 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
11490 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
11491 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
11492 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
11493 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11494 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
11495 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11496 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
11497 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11498 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
11499 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11500 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
11501 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11502 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11503 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011504 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
11505 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11506 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
11507 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011508 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
11509 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
11510 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011511 install_element (ENABLE_NODE, &show_bgp_view_cmd);
11512 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
11513 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
11514 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
11515 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
11516 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
11517 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11518 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11519 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11520 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11521 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
11522 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11523 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11524 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11525 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
11526 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11527 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
11528 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011529 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
11530 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
11531 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000011532
11533 /* Statistics */
11534 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
11535 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
11536 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
11537 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
11538
paul718e3742002-12-13 20:15:29 +000011539 /* old command */
11540 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
11541 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
11542 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
11543 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
11544 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
11545 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
11546 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
11547 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
11548 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
11549 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
11550 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
11551 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
11552 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
11553 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
11554 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
11555 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
11556 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
11557 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
11558 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
11559 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
11560 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
11561 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
11562 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
11563 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
11564 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
11565 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
11566 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
11567 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
11568 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
11569 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
11570 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
11571 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
11572 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
11573 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
11574 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
11575 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000011576
paul718e3742002-12-13 20:15:29 +000011577 /* old command */
11578 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
11579 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
11580 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
11581 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
11582 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
11583 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
11584 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
11585 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
11586 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
11587 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
11588 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
11589 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
11590 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
11591 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
11592 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
11593 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
11594 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
11595 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
11596 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
11597 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
11598 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
11599 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
11600 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
11601 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
11602 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
11603 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
11604 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
11605 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
11606 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
11607 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
11608 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
11609 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
11610 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
11611 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
11612 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
11613 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
11614
11615 /* old command */
11616 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
11617 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
11618 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
11619 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
11620
11621 /* old command */
11622 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
11623 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
11624 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
11625 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
11626
11627 /* old command */
11628 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
11629 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
11630 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
11631 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
11632#endif /* HAVE_IPV6 */
11633
11634 install_element (BGP_NODE, &bgp_distance_cmd);
11635 install_element (BGP_NODE, &no_bgp_distance_cmd);
11636 install_element (BGP_NODE, &no_bgp_distance2_cmd);
11637 install_element (BGP_NODE, &bgp_distance_source_cmd);
11638 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
11639 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
11640 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
11641
11642 install_element (BGP_NODE, &bgp_damp_set_cmd);
11643 install_element (BGP_NODE, &bgp_damp_set2_cmd);
11644 install_element (BGP_NODE, &bgp_damp_set3_cmd);
11645 install_element (BGP_NODE, &bgp_damp_unset_cmd);
11646 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
11647 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
11648 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
11649 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
11650 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
11651 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
11652}