blob: c33c596eec80937ef11cd762813b9173e5e62ab5 [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. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001745 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1746 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001747 {
1748
Paul Jakma1a392d42006-09-07 00:24:49 +00001749 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001750
1751 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001752 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001753 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1754 peer->host,
1755 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1756 p->prefixlen, rsclient->host);
1757
1758 bgp_unlock_node (rn);
1759 bgp_attr_unintern (attr_new);
1760
1761 return;
1762 }
1763
Paul Jakma16d2e242007-04-10 19:32:10 +00001764 /* Withdraw/Announce before we fully processed the withdraw */
1765 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1766 bgp_info_restore (rn, ri);
1767
paulfee0f4c2004-09-13 05:12:46 +00001768 /* Received Logging. */
1769 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001770 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001771 peer->host,
1772 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1773 p->prefixlen, rsclient->host);
1774
1775 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001776 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001777
1778 /* Update to new attribute. */
1779 bgp_attr_unintern (ri->attr);
1780 ri->attr = attr_new;
1781
1782 /* Update MPLS tag. */
1783 if (safi == SAFI_MPLS_VPN)
1784 memcpy (ri->tag, tag, 3);
1785
Paul Jakma1a392d42006-09-07 00:24:49 +00001786 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001787
1788 /* Process change. */
1789 bgp_process (bgp, rn, afi, safi);
1790 bgp_unlock_node (rn);
1791
1792 return;
1793 }
1794
1795 /* Received Logging. */
1796 if (BGP_DEBUG (update, UPDATE_IN))
1797 {
ajsd2c1f162004-12-08 21:10:20 +00001798 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001799 peer->host,
1800 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1801 p->prefixlen, rsclient->host);
1802 }
1803
1804 /* Make new BGP info. */
1805 new = bgp_info_new ();
1806 new->type = type;
1807 new->sub_type = sub_type;
1808 new->peer = peer;
1809 new->attr = attr_new;
1810 new->uptime = time (NULL);
1811
1812 /* Update MPLS tag. */
1813 if (safi == SAFI_MPLS_VPN)
1814 memcpy (new->tag, tag, 3);
1815
Paul Jakma1a392d42006-09-07 00:24:49 +00001816 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001817
1818 /* Register new BGP information. */
1819 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001820
1821 /* route_node_get lock */
1822 bgp_unlock_node (rn);
1823
paulfee0f4c2004-09-13 05:12:46 +00001824 /* Process change. */
1825 bgp_process (bgp, rn, afi, safi);
1826
1827 return;
1828
1829 filtered:
1830
1831 /* This BGP update is filtered. Log the reason then update BGP entry. */
1832 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001833 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001834 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1835 peer->host,
1836 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1837 p->prefixlen, rsclient->host, reason);
1838
1839 if (ri)
paulb40d9392005-08-22 22:34:41 +00001840 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001841
1842 bgp_unlock_node (rn);
1843
1844 return;
1845}
1846
paul94f2b392005-06-28 12:44:16 +00001847static void
paulfee0f4c2004-09-13 05:12:46 +00001848bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1849 struct peer *peer, struct prefix *p, int type, int sub_type,
1850 struct prefix_rd *prd, u_char *tag)
1851 {
1852 struct bgp_node *rn;
1853 struct bgp_info *ri;
1854 char buf[SU_ADDRSTRLEN];
1855
1856 if (rsclient == peer)
1857 return;
1858
1859 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1860
1861 /* Lookup withdrawn route. */
1862 for (ri = rn->info; ri; ri = ri->next)
1863 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1864 break;
1865
1866 /* Withdraw specified route from routing table. */
1867 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001868 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001869 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001870 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001871 "%s Can't find the route %s/%d", peer->host,
1872 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1873 p->prefixlen);
1874
1875 /* Unlock bgp_node_get() lock. */
1876 bgp_unlock_node (rn);
1877 }
1878
paul94f2b392005-06-28 12:44:16 +00001879static int
paulfee0f4c2004-09-13 05:12:46 +00001880bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001881 afi_t afi, safi_t safi, int type, int sub_type,
1882 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1883{
1884 int ret;
1885 int aspath_loop_count = 0;
1886 struct bgp_node *rn;
1887 struct bgp *bgp;
1888 struct attr new_attr;
1889 struct attr *attr_new;
1890 struct bgp_info *ri;
1891 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001892 const char *reason;
paul718e3742002-12-13 20:15:29 +00001893 char buf[SU_ADDRSTRLEN];
1894
1895 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00001896 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00001897
1898 /* When peer's soft reconfiguration enabled. Record input packet in
1899 Adj-RIBs-In. */
1900 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1901 && peer != bgp->peer_self && ! soft_reconfig)
1902 bgp_adj_in_set (rn, peer, attr);
1903
1904 /* Check previously received route. */
1905 for (ri = rn->info; ri; ri = ri->next)
1906 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1907 break;
1908
1909 /* AS path local-as loop check. */
1910 if (peer->change_local_as)
1911 {
1912 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
1913 aspath_loop_count = 1;
1914
1915 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
1916 {
1917 reason = "as-path contains our own AS;";
1918 goto filtered;
1919 }
1920 }
1921
1922 /* AS path loop check. */
1923 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
1924 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
1925 && aspath_loop_check(attr->aspath, bgp->confed_id)
1926 > peer->allowas_in[afi][safi]))
1927 {
1928 reason = "as-path contains our own AS;";
1929 goto filtered;
1930 }
1931
1932 /* Route reflector originator ID check. */
1933 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
1934 && IPV4_ADDR_SAME (&bgp->router_id, &attr->originator_id))
1935 {
1936 reason = "originator is us;";
1937 goto filtered;
1938 }
1939
1940 /* Route reflector cluster ID check. */
1941 if (bgp_cluster_filter (peer, attr))
1942 {
1943 reason = "reflected from the same cluster;";
1944 goto filtered;
1945 }
1946
1947 /* Apply incoming filter. */
1948 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
1949 {
1950 reason = "filter;";
1951 goto filtered;
1952 }
1953
1954 /* Apply incoming route-map. */
1955 new_attr = *attr;
1956
1957 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
1958 {
1959 reason = "route-map;";
1960 goto filtered;
1961 }
1962
1963 /* IPv4 unicast next hop check. */
1964 if (afi == AFI_IP && safi == SAFI_UNICAST)
1965 {
1966 /* If the peer is EBGP and nexthop is not on connected route,
1967 discard it. */
1968 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
1969 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00001970 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00001971 {
1972 reason = "non-connected next-hop;";
1973 goto filtered;
1974 }
1975
1976 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
1977 must not be my own address. */
1978 if (bgp_nexthop_self (afi, &new_attr)
1979 || new_attr.nexthop.s_addr == 0
1980 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1981 {
1982 reason = "martian next-hop;";
1983 goto filtered;
1984 }
1985 }
1986
1987 attr_new = bgp_attr_intern (&new_attr);
1988
1989 /* If the update is implicit withdraw. */
1990 if (ri)
1991 {
1992 ri->uptime = time (NULL);
1993
1994 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001995 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1996 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00001997 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001998 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00001999
2000 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2001 && peer_sort (peer) == BGP_PEER_EBGP
2002 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2003 {
2004 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002005 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002006 peer->host,
2007 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2008 p->prefixlen);
2009
paul902212c2006-02-05 17:51:19 +00002010 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2011 {
2012 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2013 bgp_process (bgp, rn, afi, safi);
2014 }
paul718e3742002-12-13 20:15:29 +00002015 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002016 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002017 {
2018 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002019 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002020 "%s rcvd %s/%d...duplicate ignored",
2021 peer->host,
2022 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2023 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002024
2025 /* graceful restart STALE flag unset. */
2026 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2027 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002028 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002029 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002030 }
paul718e3742002-12-13 20:15:29 +00002031 }
2032
2033 bgp_unlock_node (rn);
2034 bgp_attr_unintern (attr_new);
2035 return 0;
2036 }
2037
Paul Jakma16d2e242007-04-10 19:32:10 +00002038 /* Withdraw/Announce before we fully processed the withdraw */
2039 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2040 {
2041 if (BGP_DEBUG (update, UPDATE_IN))
2042 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2043 peer->host,
2044 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2045 p->prefixlen);
2046 bgp_info_restore (rn, ri);
2047 }
2048
paul718e3742002-12-13 20:15:29 +00002049 /* Received Logging. */
2050 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002051 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002052 peer->host,
2053 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2054 p->prefixlen);
2055
hasso93406d82005-02-02 14:40:33 +00002056 /* graceful restart STALE flag unset. */
2057 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002058 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002059
paul718e3742002-12-13 20:15:29 +00002060 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002061 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002062
2063 /* implicit withdraw, decrement aggregate and pcount here.
2064 * only if update is accepted, they'll increment below.
2065 */
paul902212c2006-02-05 17:51:19 +00002066 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2067
paul718e3742002-12-13 20:15:29 +00002068 /* Update bgp route dampening information. */
2069 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2070 && peer_sort (peer) == BGP_PEER_EBGP)
2071 {
2072 /* This is implicit withdraw so we should update dampening
2073 information. */
2074 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2075 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002076 }
2077
paul718e3742002-12-13 20:15:29 +00002078 /* Update to new attribute. */
2079 bgp_attr_unintern (ri->attr);
2080 ri->attr = attr_new;
2081
2082 /* Update MPLS tag. */
2083 if (safi == SAFI_MPLS_VPN)
2084 memcpy (ri->tag, tag, 3);
2085
2086 /* Update bgp route dampening information. */
2087 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2088 && peer_sort (peer) == BGP_PEER_EBGP)
2089 {
2090 /* Now we do normal update dampening. */
2091 ret = bgp_damp_update (ri, rn, afi, safi);
2092 if (ret == BGP_DAMP_SUPPRESSED)
2093 {
2094 bgp_unlock_node (rn);
2095 return 0;
2096 }
2097 }
2098
2099 /* Nexthop reachability check. */
2100 if ((afi == AFI_IP || afi == AFI_IP6)
2101 && safi == SAFI_UNICAST
2102 && (peer_sort (peer) == BGP_PEER_IBGP
2103 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002104 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002105 {
2106 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002107 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002108 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002109 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002110 }
2111 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002112 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002113
2114 /* Process change. */
2115 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2116
2117 bgp_process (bgp, rn, afi, safi);
2118 bgp_unlock_node (rn);
2119 return 0;
2120 }
2121
2122 /* Received Logging. */
2123 if (BGP_DEBUG (update, UPDATE_IN))
2124 {
ajsd2c1f162004-12-08 21:10:20 +00002125 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002126 peer->host,
2127 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2128 p->prefixlen);
2129 }
2130
paul718e3742002-12-13 20:15:29 +00002131 /* Make new BGP info. */
2132 new = bgp_info_new ();
2133 new->type = type;
2134 new->sub_type = sub_type;
2135 new->peer = peer;
2136 new->attr = attr_new;
2137 new->uptime = time (NULL);
2138
2139 /* Update MPLS tag. */
2140 if (safi == SAFI_MPLS_VPN)
2141 memcpy (new->tag, tag, 3);
2142
2143 /* Nexthop reachability check. */
2144 if ((afi == AFI_IP || afi == AFI_IP6)
2145 && safi == SAFI_UNICAST
2146 && (peer_sort (peer) == BGP_PEER_IBGP
2147 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002148 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002149 {
2150 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002151 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002152 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002153 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002154 }
2155 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002156 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002157
paul902212c2006-02-05 17:51:19 +00002158 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002159 bgp_aggregate_increment (bgp, p, new, afi, safi);
2160
2161 /* Register new BGP information. */
2162 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002163
2164 /* route_node_get lock */
2165 bgp_unlock_node (rn);
2166
paul718e3742002-12-13 20:15:29 +00002167 /* If maximum prefix count is configured and current prefix
2168 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002169 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2170 return -1;
paul718e3742002-12-13 20:15:29 +00002171
2172 /* Process change. */
2173 bgp_process (bgp, rn, afi, safi);
2174
2175 return 0;
2176
2177 /* This BGP update is filtered. Log the reason then update BGP
2178 entry. */
2179 filtered:
2180 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002181 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002182 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2183 peer->host,
2184 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2185 p->prefixlen, reason);
2186
2187 if (ri)
paulb40d9392005-08-22 22:34:41 +00002188 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002189
2190 bgp_unlock_node (rn);
2191
2192 return 0;
2193}
2194
2195int
paulfee0f4c2004-09-13 05:12:46 +00002196bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2197 afi_t afi, safi_t safi, int type, int sub_type,
2198 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2199{
2200 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002201 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002202 struct bgp *bgp;
2203 int ret;
2204
2205 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2206 soft_reconfig);
2207
2208 bgp = peer->bgp;
2209
2210 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002211 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002212 {
2213 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2214 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2215 sub_type, prd, tag);
2216 }
2217
2218 return ret;
2219}
2220
2221int
paul718e3742002-12-13 20:15:29 +00002222bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002223 afi_t afi, safi_t safi, int type, int sub_type,
2224 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002225{
2226 struct bgp *bgp;
2227 char buf[SU_ADDRSTRLEN];
2228 struct bgp_node *rn;
2229 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002230 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002231 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002232
2233 bgp = peer->bgp;
2234
paulfee0f4c2004-09-13 05:12:46 +00002235 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002236 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002237 {
2238 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2239 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2240 }
2241
paul718e3742002-12-13 20:15:29 +00002242 /* Logging. */
2243 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002244 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002245 peer->host,
2246 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2247 p->prefixlen);
2248
2249 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002250 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002251
2252 /* If peer is soft reconfiguration enabled. Record input packet for
2253 further calculation. */
2254 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2255 && peer != bgp->peer_self)
2256 bgp_adj_in_unset (rn, peer);
2257
2258 /* Lookup withdrawn route. */
2259 for (ri = rn->info; ri; ri = ri->next)
2260 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2261 break;
2262
2263 /* Withdraw specified route from routing table. */
2264 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002265 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002266 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002267 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002268 "%s Can't find the route %s/%d", peer->host,
2269 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2270 p->prefixlen);
2271
2272 /* Unlock bgp_node_get() lock. */
2273 bgp_unlock_node (rn);
2274
2275 return 0;
2276}
2277
2278void
2279bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2280{
2281 struct bgp *bgp;
2282 struct attr attr;
2283 struct aspath *aspath;
2284 struct prefix p;
2285 struct bgp_info binfo;
2286 struct peer *from;
2287 int ret = RMAP_DENYMATCH;
2288
2289 bgp = peer->bgp;
2290 from = bgp->peer_self;
2291
2292 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2293 aspath = attr.aspath;
2294 attr.local_pref = bgp->default_local_pref;
2295 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2296
2297 if (afi == AFI_IP)
2298 str2prefix ("0.0.0.0/0", &p);
2299#ifdef HAVE_IPV6
2300 else if (afi == AFI_IP6)
2301 {
2302 str2prefix ("::/0", &p);
2303
2304 /* IPv6 global nexthop must be included. */
2305 memcpy (&attr.mp_nexthop_global, &peer->nexthop.v6_global,
2306 IPV6_MAX_BYTELEN);
2307 attr.mp_nexthop_len = 16;
2308
2309 /* If the peer is on shared nextwork and we have link-local
2310 nexthop set it. */
2311 if (peer->shared_network
2312 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2313 {
2314 memcpy (&attr.mp_nexthop_local, &peer->nexthop.v6_local,
2315 IPV6_MAX_BYTELEN);
2316 attr.mp_nexthop_len = 32;
2317 }
2318 }
2319#endif /* HAVE_IPV6 */
2320 else
2321 return;
2322
2323 if (peer->default_rmap[afi][safi].name)
2324 {
2325 binfo.peer = bgp->peer_self;
2326 binfo.attr = &attr;
2327
paulfee0f4c2004-09-13 05:12:46 +00002328 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2329
paul718e3742002-12-13 20:15:29 +00002330 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2331 RMAP_BGP, &binfo);
2332
paulfee0f4c2004-09-13 05:12:46 +00002333 bgp->peer_self->rmap_type = 0;
2334
paul718e3742002-12-13 20:15:29 +00002335 if (ret == RMAP_DENYMATCH)
2336 {
2337 bgp_attr_flush (&attr);
2338 withdraw = 1;
2339 }
2340 }
2341
2342 if (withdraw)
2343 {
2344 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2345 bgp_default_withdraw_send (peer, afi, safi);
2346 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2347 }
2348 else
2349 {
2350 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2351 bgp_default_update_send (peer, &attr, afi, safi, from);
2352 }
2353
2354 aspath_unintern (aspath);
2355}
2356
2357static void
2358bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002359 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002360{
2361 struct bgp_node *rn;
2362 struct bgp_info *ri;
2363 struct attr attr;
2364
2365 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002366 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002367
2368 if (safi != SAFI_MPLS_VPN
2369 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2370 bgp_default_originate (peer, afi, safi, 0);
2371
2372 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2373 for (ri = rn->info; ri; ri = ri->next)
2374 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2375 {
paulfee0f4c2004-09-13 05:12:46 +00002376 if ( (rsclient) ?
2377 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2378 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002379 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2380 else
2381 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2382 }
2383}
2384
2385void
2386bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2387{
2388 struct bgp_node *rn;
2389 struct bgp_table *table;
2390
2391 if (peer->status != Established)
2392 return;
2393
2394 if (! peer->afc_nego[afi][safi])
2395 return;
2396
2397 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2398 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2399 return;
2400
2401 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002402 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002403 else
2404 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2405 rn = bgp_route_next(rn))
2406 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002407 bgp_announce_table (peer, afi, safi, table, 0);
2408
2409 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2410 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002411}
2412
2413void
2414bgp_announce_route_all (struct peer *peer)
2415{
2416 afi_t afi;
2417 safi_t safi;
2418
2419 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2420 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2421 bgp_announce_route (peer, afi, safi);
2422}
2423
2424static void
paulfee0f4c2004-09-13 05:12:46 +00002425bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2426 safi_t safi, struct bgp_table *table)
2427{
2428 struct bgp_node *rn;
2429 struct bgp_adj_in *ain;
2430
2431 if (! table)
2432 table = rsclient->bgp->rib[afi][safi];
2433
2434 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2435 for (ain = rn->adj_in; ain; ain = ain->next)
2436 {
2437 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2438 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2439 }
2440}
2441
2442void
2443bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2444{
2445 struct bgp_table *table;
2446 struct bgp_node *rn;
2447
2448 if (safi != SAFI_MPLS_VPN)
2449 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2450
2451 else
2452 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2453 rn = bgp_route_next (rn))
2454 if ((table = rn->info) != NULL)
2455 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2456}
2457
2458static void
paul718e3742002-12-13 20:15:29 +00002459bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2460 struct bgp_table *table)
2461{
2462 int ret;
2463 struct bgp_node *rn;
2464 struct bgp_adj_in *ain;
2465
2466 if (! table)
2467 table = peer->bgp->rib[afi][safi];
2468
2469 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2470 for (ain = rn->adj_in; ain; ain = ain->next)
2471 {
2472 if (ain->peer == peer)
2473 {
2474 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2475 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2476 NULL, NULL, 1);
2477 if (ret < 0)
2478 {
2479 bgp_unlock_node (rn);
2480 return;
2481 }
2482 continue;
2483 }
2484 }
2485}
2486
2487void
2488bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2489{
2490 struct bgp_node *rn;
2491 struct bgp_table *table;
2492
2493 if (peer->status != Established)
2494 return;
2495
2496 if (safi != SAFI_MPLS_VPN)
2497 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2498 else
2499 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2500 rn = bgp_route_next (rn))
2501 if ((table = rn->info) != NULL)
2502 bgp_soft_reconfig_table (peer, afi, safi, table);
2503}
2504
paul200df112005-06-01 11:17:05 +00002505static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002506bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002507{
Paul Jakma64e580a2006-02-21 01:09:01 +00002508 struct bgp_node *rn = data;
2509 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002510 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002511 afi_t afi = rn->table->afi;
2512 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002513
Paul Jakma64e580a2006-02-21 01:09:01 +00002514 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002515
Paul Jakma64e580a2006-02-21 01:09:01 +00002516 for (ri = rn->info; ri; ri = ri->next)
2517 if (ri->peer == peer)
paul200df112005-06-01 11:17:05 +00002518 {
2519 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002520 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2521 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002522 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002523 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2524 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002525 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002526 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002527 break;
2528 }
paul200df112005-06-01 11:17:05 +00002529 return WQ_SUCCESS;
2530}
2531
2532static void
paul0fb58d52005-11-14 14:31:49 +00002533bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002534{
Paul Jakma64e580a2006-02-21 01:09:01 +00002535 struct bgp_node *rn = data;
2536
2537 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002538}
2539
2540static void
paul94f2b392005-06-28 12:44:16 +00002541bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002542{
Paul Jakma64e580a2006-02-21 01:09:01 +00002543 struct peer *peer = wq->spec.data;
2544
Paul Jakma64e580a2006-02-21 01:09:01 +00002545 peer_unlock (peer); /* bgp_clear_node_complete */
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002546
2547 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002548 BGP_EVENT_ADD (peer, Clearing_Completed);
paul200df112005-06-01 11:17:05 +00002549}
2550
2551static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002552bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002553{
Paul Jakma64e580a2006-02-21 01:09:01 +00002554#define CLEAR_QUEUE_NAME_LEN 26 /* "clear 2001:123:123:123::1" */
2555 char wname[CLEAR_QUEUE_NAME_LEN];
2556
2557 snprintf (wname, CLEAR_QUEUE_NAME_LEN, "clear %s", peer->host);
2558#undef CLEAR_QUEUE_NAME_LEN
2559
2560 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002561 {
2562 zlog_err ("%s: Failed to allocate work queue", __func__);
2563 exit (1);
2564 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002565 peer->clear_node_queue->spec.hold = 10;
2566 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2567 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2568 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2569 peer->clear_node_queue->spec.max_retries = 0;
2570
2571 /* we only 'lock' this peer reference when the queue is actually active */
2572 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002573}
2574
paul718e3742002-12-13 20:15:29 +00002575static void
2576bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002577 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002578{
2579 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002580
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002581
paul718e3742002-12-13 20:15:29 +00002582 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002583 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002584
hasso6cf159b2005-03-21 10:28:14 +00002585 /* If still no table => afi/safi isn't configured at all or smth. */
2586 if (! table)
2587 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002588
2589 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2590 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002591 struct bgp_info *ri;
2592 struct bgp_adj_in *ain;
2593 struct bgp_adj_out *aout;
2594
Paul Jakma65ca75e2006-05-04 08:08:15 +00002595 if (rn->info == NULL)
2596 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002597
2598 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2599 * queued for every clearing peer, regardless of whether it is
2600 * relevant to the peer at hand.
2601 *
2602 * Overview: There are 3 different indices which need to be
2603 * scrubbed, potentially, when a peer is removed:
2604 *
2605 * 1 peer's routes visible via the RIB (ie accepted routes)
2606 * 2 peer's routes visible by the (optional) peer's adj-in index
2607 * 3 other routes visible by the peer's adj-out index
2608 *
2609 * 3 there is no hurry in scrubbing, once the struct peer is
2610 * removed from bgp->peer, we could just GC such deleted peer's
2611 * adj-outs at our leisure.
2612 *
2613 * 1 and 2 must be 'scrubbed' in some way, at least made
2614 * invisible via RIB index before peer session is allowed to be
2615 * brought back up. So one needs to know when such a 'search' is
2616 * complete.
2617 *
2618 * Ideally:
2619 *
2620 * - there'd be a single global queue or a single RIB walker
2621 * - rather than tracking which route_nodes still need to be
2622 * examined on a peer basis, we'd track which peers still
2623 * aren't cleared
2624 *
2625 * Given that our per-peer prefix-counts now should be reliable,
2626 * this may actually be achievable. It doesn't seem to be a huge
2627 * problem at this time,
2628 */
2629 for (ri = rn->info; ri; ri = ri->next)
2630 if (ri->peer == peer)
2631 {
2632 bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2633 work_queue_add (peer->clear_node_queue, rn);
2634 }
2635
2636 for (ain = rn->adj_in; ain; ain = ain->next)
2637 if (ain->peer == peer)
2638 {
2639 bgp_adj_in_remove (rn, ain);
2640 bgp_unlock_node (rn);
2641 break;
2642 }
2643 for (aout = rn->adj_out; aout; aout = aout->next)
2644 if (aout->peer == peer)
2645 {
2646 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2647 bgp_unlock_node (rn);
2648 break;
2649 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002650 }
2651 return;
2652}
2653
2654void
2655bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2656{
2657 struct bgp_node *rn;
2658 struct bgp_table *table;
2659 struct peer *rsclient;
2660 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002661
Paul Jakma64e580a2006-02-21 01:09:01 +00002662 if (peer->clear_node_queue == NULL)
2663 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002664
Paul Jakmaca058a32006-09-14 02:58:49 +00002665 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2666 * Idle until it receives a Clearing_Completed event. This protects
2667 * against peers which flap faster than we can we clear, which could
2668 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002669 *
2670 * a) race with routes from the new session being installed before
2671 * clear_route_node visits the node (to delete the route of that
2672 * peer)
2673 * b) resource exhaustion, clear_route_node likely leads to an entry
2674 * on the process_main queue. Fast-flapping could cause that queue
2675 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002676 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002677 if (!peer->clear_node_queue->thread)
2678 peer_lock (peer); /* bgp_clear_node_complete */
paul200df112005-06-01 11:17:05 +00002679
paul718e3742002-12-13 20:15:29 +00002680 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002681 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002682 else
2683 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2684 rn = bgp_route_next (rn))
2685 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002686 bgp_clear_route_table (peer, afi, safi, table, NULL);
2687
paul1eb8ef22005-04-07 07:30:20 +00002688 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002689 {
2690 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2691 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2692 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002693
Paul Jakmaca058a32006-09-14 02:58:49 +00002694 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002695 * completion function won't be run by workqueue code - call it here.
2696 * XXX: Actually, this assumption doesn't hold, see
2697 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002698 *
2699 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002700 * really needed if peer state is Established - peers in
2701 * pre-Established states shouldn't have any route-update state
2702 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002703 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002704 * We still can get here in pre-Established though, through
2705 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2706 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002707 *
2708 * At some future point, this check could be move to the top of the
2709 * function, and do a quick early-return when state is
2710 * pre-Established, avoiding above list and table scans. Once we're
2711 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002712 */
2713 if (!peer->clear_node_queue->thread)
2714 bgp_clear_node_complete (peer->clear_node_queue);
Paul Jakmaca058a32006-09-14 02:58:49 +00002715 else
2716 {
2717 /* clearing queue scheduled. Normal if in Established state
2718 * (and about to transition out of it), but otherwise...
2719 */
2720 if (peer->status != Established)
2721 {
2722 plog_err (peer->log, "%s [Error] State %s is not Established,"
2723 " but routes were cleared - bug!",
2724 peer->host, LOOKUP (bgp_status_msg, peer->status));
2725 assert (peer->status == Established);
2726 }
2727 }
paul718e3742002-12-13 20:15:29 +00002728}
2729
2730void
2731bgp_clear_route_all (struct peer *peer)
2732{
2733 afi_t afi;
2734 safi_t safi;
2735
2736 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2737 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2738 bgp_clear_route (peer, afi, safi);
2739}
2740
2741void
2742bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2743{
2744 struct bgp_table *table;
2745 struct bgp_node *rn;
2746 struct bgp_adj_in *ain;
2747
2748 table = peer->bgp->rib[afi][safi];
2749
2750 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2751 for (ain = rn->adj_in; ain ; ain = ain->next)
2752 if (ain->peer == peer)
2753 {
2754 bgp_adj_in_remove (rn, ain);
2755 bgp_unlock_node (rn);
2756 break;
2757 }
2758}
hasso93406d82005-02-02 14:40:33 +00002759
2760void
2761bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2762{
2763 struct bgp_node *rn;
2764 struct bgp_info *ri;
2765 struct bgp_table *table;
2766
2767 table = peer->bgp->rib[afi][safi];
2768
2769 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2770 {
2771 for (ri = rn->info; ri; ri = ri->next)
2772 if (ri->peer == peer)
2773 {
2774 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2775 bgp_rib_remove (rn, ri, peer, afi, safi);
2776 break;
2777 }
2778 }
2779}
paul718e3742002-12-13 20:15:29 +00002780
2781/* Delete all kernel routes. */
2782void
paul545acaf2004-04-20 15:13:15 +00002783bgp_cleanup_routes ()
paul718e3742002-12-13 20:15:29 +00002784{
2785 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002786 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002787 struct bgp_node *rn;
2788 struct bgp_table *table;
2789 struct bgp_info *ri;
2790
paul1eb8ef22005-04-07 07:30:20 +00002791 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002792 {
2793 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2794
2795 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2796 for (ri = rn->info; ri; ri = ri->next)
2797 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2798 && ri->type == ZEBRA_ROUTE_BGP
2799 && ri->sub_type == BGP_ROUTE_NORMAL)
2800 bgp_zebra_withdraw (&rn->p, ri);
2801
2802 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2803
2804 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2805 for (ri = rn->info; ri; ri = ri->next)
2806 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2807 && ri->type == ZEBRA_ROUTE_BGP
2808 && ri->sub_type == BGP_ROUTE_NORMAL)
2809 bgp_zebra_withdraw (&rn->p, ri);
2810 }
2811}
2812
2813void
2814bgp_reset ()
2815{
2816 vty_reset ();
2817 bgp_zclient_reset ();
2818 access_list_reset ();
2819 prefix_list_reset ();
2820}
2821
2822/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2823 value. */
2824int
2825bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2826{
2827 u_char *pnt;
2828 u_char *lim;
2829 struct prefix p;
2830 int psize;
2831 int ret;
2832
2833 /* Check peer status. */
2834 if (peer->status != Established)
2835 return 0;
2836
2837 pnt = packet->nlri;
2838 lim = pnt + packet->length;
2839
2840 for (; pnt < lim; pnt += psize)
2841 {
2842 /* Clear prefix structure. */
2843 memset (&p, 0, sizeof (struct prefix));
2844
2845 /* Fetch prefix length. */
2846 p.prefixlen = *pnt++;
2847 p.family = afi2family (packet->afi);
2848
2849 /* Already checked in nlri_sanity_check(). We do double check
2850 here. */
2851 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2852 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2853 return -1;
2854
2855 /* Packet size overflow check. */
2856 psize = PSIZE (p.prefixlen);
2857
2858 /* When packet overflow occur return immediately. */
2859 if (pnt + psize > lim)
2860 return -1;
2861
2862 /* Fetch prefix from NLRI packet. */
2863 memcpy (&p.u.prefix, pnt, psize);
2864
2865 /* Check address. */
2866 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2867 {
2868 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
2869 {
paulf5ba3872004-07-09 12:11:31 +00002870 /*
2871 * From draft-ietf-idr-bgp4-22, Section 6.3:
2872 * If a BGP router receives an UPDATE message with a
2873 * semantically incorrect NLRI field, in which a prefix is
2874 * semantically incorrect (eg. an unexpected multicast IP
2875 * address), it should ignore the prefix.
2876 */
paul718e3742002-12-13 20:15:29 +00002877 zlog (peer->log, LOG_ERR,
2878 "IPv4 unicast NLRI is multicast address %s",
2879 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00002880
paul718e3742002-12-13 20:15:29 +00002881 return -1;
2882 }
2883 }
2884
2885#ifdef HAVE_IPV6
2886 /* Check address. */
2887 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
2888 {
2889 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2890 {
2891 char buf[BUFSIZ];
2892
2893 zlog (peer->log, LOG_WARNING,
2894 "IPv6 link-local NLRI received %s ignore this NLRI",
2895 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
2896
2897 continue;
2898 }
2899 }
2900#endif /* HAVE_IPV6 */
2901
2902 /* Normal process. */
2903 if (attr)
2904 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
2905 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
2906 else
2907 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
2908 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2909
2910 /* Address family configuration mismatch or maximum-prefix count
2911 overflow. */
2912 if (ret < 0)
2913 return -1;
2914 }
2915
2916 /* Packet length consistency check. */
2917 if (pnt != lim)
2918 return -1;
2919
2920 return 0;
2921}
2922
2923/* NLRI encode syntax check routine. */
2924int
2925bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
2926 bgp_size_t length)
2927{
2928 u_char *end;
2929 u_char prefixlen;
2930 int psize;
2931
2932 end = pnt + length;
2933
2934 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
2935 syntactic validity. If the field is syntactically incorrect,
2936 then the Error Subcode is set to Invalid Network Field. */
2937
2938 while (pnt < end)
2939 {
2940 prefixlen = *pnt++;
2941
2942 /* Prefix length check. */
2943 if ((afi == AFI_IP && prefixlen > 32)
2944 || (afi == AFI_IP6 && prefixlen > 128))
2945 {
2946 plog_err (peer->log,
2947 "%s [Error] Update packet error (wrong prefix length %d)",
2948 peer->host, prefixlen);
2949 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2950 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2951 return -1;
2952 }
2953
2954 /* Packet size overflow check. */
2955 psize = PSIZE (prefixlen);
2956
2957 if (pnt + psize > end)
2958 {
2959 plog_err (peer->log,
2960 "%s [Error] Update packet error"
2961 " (prefix data overflow prefix size is %d)",
2962 peer->host, psize);
2963 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2964 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2965 return -1;
2966 }
2967
2968 pnt += psize;
2969 }
2970
2971 /* Packet length consistency check. */
2972 if (pnt != end)
2973 {
2974 plog_err (peer->log,
2975 "%s [Error] Update packet error"
2976 " (prefix length mismatch with total length)",
2977 peer->host);
2978 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2979 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2980 return -1;
2981 }
2982 return 0;
2983}
2984
paul94f2b392005-06-28 12:44:16 +00002985static struct bgp_static *
paul718e3742002-12-13 20:15:29 +00002986bgp_static_new ()
2987{
2988 struct bgp_static *new;
2989 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
2990 memset (new, 0, sizeof (struct bgp_static));
2991 return new;
2992}
2993
paul94f2b392005-06-28 12:44:16 +00002994static void
paul718e3742002-12-13 20:15:29 +00002995bgp_static_free (struct bgp_static *bgp_static)
2996{
2997 if (bgp_static->rmap.name)
2998 free (bgp_static->rmap.name);
2999 XFREE (MTYPE_BGP_STATIC, bgp_static);
3000}
3001
paul94f2b392005-06-28 12:44:16 +00003002static void
paulfee0f4c2004-09-13 05:12:46 +00003003bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3004 struct prefix *p, afi_t afi, safi_t safi)
3005{
3006 struct bgp_node *rn;
3007 struct bgp_info *ri;
3008
3009 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3010
3011 /* Check selected route and self inserted route. */
3012 for (ri = rn->info; ri; ri = ri->next)
3013 if (ri->peer == bgp->peer_self
3014 && ri->type == ZEBRA_ROUTE_BGP
3015 && ri->sub_type == BGP_ROUTE_STATIC)
3016 break;
3017
3018 /* Withdraw static BGP route from routing table. */
3019 if (ri)
3020 {
paulfee0f4c2004-09-13 05:12:46 +00003021 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003022 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003023 }
3024
3025 /* Unlock bgp_node_lookup. */
3026 bgp_unlock_node (rn);
3027}
3028
paul94f2b392005-06-28 12:44:16 +00003029static void
paulfee0f4c2004-09-13 05:12:46 +00003030bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
3031 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3032{
3033 struct bgp_node *rn;
3034 struct bgp_info *ri;
3035 struct bgp_info *new;
3036 struct bgp_info info;
3037 struct attr new_attr;
3038 struct attr *attr_new;
3039 struct attr attr;
3040 struct bgp *bgp;
3041 int ret;
3042 char buf[SU_ADDRSTRLEN];
3043
3044 bgp = rsclient->bgp;
3045
Paul Jakma06e110f2006-05-12 23:29:22 +00003046 assert (bgp_static);
3047 if (!bgp_static)
3048 return;
3049
paulfee0f4c2004-09-13 05:12:46 +00003050 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3051
3052 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003053
3054 attr.nexthop = bgp_static->igpnexthop;
3055 attr.med = bgp_static->igpmetric;
3056 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paulfee0f4c2004-09-13 05:12:46 +00003057
3058 new_attr = attr;
3059
3060 /* Apply network route-map for export to this rsclient. */
3061 if (bgp_static->rmap.name)
3062 {
3063 info.peer = rsclient;
3064 info.attr = &new_attr;
3065
3066 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3067 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3068
3069 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3070
3071 rsclient->rmap_type = 0;
3072
3073 if (ret == RMAP_DENYMATCH)
3074 {
3075 /* Free uninterned attribute. */
3076 bgp_attr_flush (&new_attr);
3077
3078 /* Unintern original. */
3079 aspath_unintern (attr.aspath);
3080 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3081
3082 return;
3083 }
3084 attr_new = bgp_attr_intern (&new_attr);
3085 }
3086 else
3087 attr_new = bgp_attr_intern (&attr);
3088
3089 new_attr = *attr_new;
3090
3091 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3092
3093 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) == RMAP_DENY)
3094{
3095 /* This BGP update is filtered. Log the reason then update BGP entry. */
3096 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003097 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003098 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3099 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3100 p->prefixlen, rsclient->host);
3101
3102 bgp->peer_self->rmap_type = 0;
3103
3104 bgp_attr_unintern (attr_new);
3105 aspath_unintern (attr.aspath);
3106
3107 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3108
3109 return;
3110 }
3111
3112 bgp->peer_self->rmap_type = 0;
3113
3114 bgp_attr_unintern (attr_new);
3115 attr_new = bgp_attr_intern (&new_attr);
3116
3117 for (ri = rn->info; ri; ri = ri->next)
3118 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3119 && ri->sub_type == BGP_ROUTE_STATIC)
3120 break;
3121
3122 if (ri)
3123 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003124 if (attrhash_cmp (ri->attr, attr_new) &&
3125 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003126 {
3127 bgp_unlock_node (rn);
3128 bgp_attr_unintern (attr_new);
3129 aspath_unintern (attr.aspath);
3130 return;
3131 }
3132 else
3133 {
3134 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003135 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003136
3137 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003138 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3139 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003140 bgp_attr_unintern (ri->attr);
3141 ri->attr = attr_new;
3142 ri->uptime = time (NULL);
3143
3144 /* Process change. */
3145 bgp_process (bgp, rn, afi, safi);
3146 bgp_unlock_node (rn);
3147 aspath_unintern (attr.aspath);
3148 return;
3149 }
3150}
3151
3152 /* Make new BGP info. */
3153 new = bgp_info_new ();
3154 new->type = ZEBRA_ROUTE_BGP;
3155 new->sub_type = BGP_ROUTE_STATIC;
3156 new->peer = bgp->peer_self;
3157 SET_FLAG (new->flags, BGP_INFO_VALID);
3158 new->attr = attr_new;
3159 new->uptime = time (NULL);
3160
3161 /* Register new BGP information. */
3162 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003163
3164 /* route_node_get lock */
3165 bgp_unlock_node (rn);
3166
paulfee0f4c2004-09-13 05:12:46 +00003167 /* Process change. */
3168 bgp_process (bgp, rn, afi, safi);
3169
3170 /* Unintern original. */
3171 aspath_unintern (attr.aspath);
3172}
3173
paul94f2b392005-06-28 12:44:16 +00003174static void
paulfee0f4c2004-09-13 05:12:46 +00003175bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003176 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3177{
3178 struct bgp_node *rn;
3179 struct bgp_info *ri;
3180 struct bgp_info *new;
3181 struct bgp_info info;
3182 struct attr attr;
paul286e1e72003-08-08 00:24:31 +00003183 struct attr attr_tmp;
paul718e3742002-12-13 20:15:29 +00003184 struct attr *attr_new;
3185 int ret;
3186
Paul Jakmadd8103a2006-05-12 23:27:30 +00003187 assert (bgp_static);
3188 if (!bgp_static)
3189 return;
3190
paulfee0f4c2004-09-13 05:12:46 +00003191 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003192
3193 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003194
3195 attr.nexthop = bgp_static->igpnexthop;
3196 attr.med = bgp_static->igpmetric;
3197 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003198
3199 /* Apply route-map. */
3200 if (bgp_static->rmap.name)
3201 {
paul286e1e72003-08-08 00:24:31 +00003202 attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003203 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003204 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003205
paulfee0f4c2004-09-13 05:12:46 +00003206 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3207
paul718e3742002-12-13 20:15:29 +00003208 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003209
paulfee0f4c2004-09-13 05:12:46 +00003210 bgp->peer_self->rmap_type = 0;
3211
paul718e3742002-12-13 20:15:29 +00003212 if (ret == RMAP_DENYMATCH)
3213 {
3214 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003215 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003216
3217 /* Unintern original. */
3218 aspath_unintern (attr.aspath);
3219 bgp_static_withdraw (bgp, p, afi, safi);
3220 return;
3221 }
paul286e1e72003-08-08 00:24:31 +00003222 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003223 }
paul286e1e72003-08-08 00:24:31 +00003224 else
3225 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003226
3227 for (ri = rn->info; ri; ri = ri->next)
3228 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3229 && ri->sub_type == BGP_ROUTE_STATIC)
3230 break;
3231
3232 if (ri)
3233 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003234 if (attrhash_cmp (ri->attr, attr_new) &&
3235 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003236 {
3237 bgp_unlock_node (rn);
3238 bgp_attr_unintern (attr_new);
3239 aspath_unintern (attr.aspath);
3240 return;
3241 }
3242 else
3243 {
3244 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003245 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003246
3247 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003248 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3249 bgp_info_restore(rn, ri);
3250 else
3251 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003252 bgp_attr_unintern (ri->attr);
3253 ri->attr = attr_new;
3254 ri->uptime = time (NULL);
3255
3256 /* Process change. */
3257 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3258 bgp_process (bgp, rn, afi, safi);
3259 bgp_unlock_node (rn);
3260 aspath_unintern (attr.aspath);
3261 return;
3262 }
3263 }
3264
3265 /* Make new BGP info. */
3266 new = bgp_info_new ();
3267 new->type = ZEBRA_ROUTE_BGP;
3268 new->sub_type = BGP_ROUTE_STATIC;
3269 new->peer = bgp->peer_self;
3270 SET_FLAG (new->flags, BGP_INFO_VALID);
3271 new->attr = attr_new;
3272 new->uptime = time (NULL);
3273
3274 /* Aggregate address increment. */
3275 bgp_aggregate_increment (bgp, p, new, afi, safi);
3276
3277 /* Register new BGP information. */
3278 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003279
3280 /* route_node_get lock */
3281 bgp_unlock_node (rn);
3282
paul718e3742002-12-13 20:15:29 +00003283 /* Process change. */
3284 bgp_process (bgp, rn, afi, safi);
3285
3286 /* Unintern original. */
3287 aspath_unintern (attr.aspath);
3288}
3289
3290void
paulfee0f4c2004-09-13 05:12:46 +00003291bgp_static_update (struct bgp *bgp, struct prefix *p,
3292 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3293{
3294 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003295 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003296
3297 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3298
paul1eb8ef22005-04-07 07:30:20 +00003299 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003300 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003301 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3302 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003303 }
3304}
3305
paul94f2b392005-06-28 12:44:16 +00003306static void
paul718e3742002-12-13 20:15:29 +00003307bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3308 u_char safi, struct prefix_rd *prd, u_char *tag)
3309{
3310 struct bgp_node *rn;
3311 struct bgp_info *new;
3312
paulfee0f4c2004-09-13 05:12:46 +00003313 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003314
3315 /* Make new BGP info. */
3316 new = bgp_info_new ();
3317 new->type = ZEBRA_ROUTE_BGP;
3318 new->sub_type = BGP_ROUTE_STATIC;
3319 new->peer = bgp->peer_self;
3320 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3321 SET_FLAG (new->flags, BGP_INFO_VALID);
3322 new->uptime = time (NULL);
3323 memcpy (new->tag, tag, 3);
3324
3325 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003326 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003327
3328 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003329 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003330
paul200df112005-06-01 11:17:05 +00003331 /* route_node_get lock */
3332 bgp_unlock_node (rn);
3333
paul718e3742002-12-13 20:15:29 +00003334 /* Process change. */
3335 bgp_process (bgp, rn, afi, safi);
3336}
3337
3338void
3339bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3340 safi_t safi)
3341{
3342 struct bgp_node *rn;
3343 struct bgp_info *ri;
3344
paulfee0f4c2004-09-13 05:12:46 +00003345 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003346
3347 /* Check selected route and self inserted route. */
3348 for (ri = rn->info; ri; ri = ri->next)
3349 if (ri->peer == bgp->peer_self
3350 && ri->type == ZEBRA_ROUTE_BGP
3351 && ri->sub_type == BGP_ROUTE_STATIC)
3352 break;
3353
3354 /* Withdraw static BGP route from routing table. */
3355 if (ri)
3356 {
3357 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003358 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003359 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003360 }
3361
3362 /* Unlock bgp_node_lookup. */
3363 bgp_unlock_node (rn);
3364}
3365
3366void
paulfee0f4c2004-09-13 05:12:46 +00003367bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3368{
3369 struct bgp_static *bgp_static;
3370 struct bgp *bgp;
3371 struct bgp_node *rn;
3372 struct prefix *p;
3373
3374 bgp = rsclient->bgp;
3375
3376 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3377 if ((bgp_static = rn->info) != NULL)
3378 {
3379 p = &rn->p;
3380
3381 bgp_static_update_rsclient (rsclient, p, bgp_static,
3382 afi, safi);
3383 }
3384}
3385
paul94f2b392005-06-28 12:44:16 +00003386static void
paul718e3742002-12-13 20:15:29 +00003387bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3388 u_char safi, struct prefix_rd *prd, u_char *tag)
3389{
3390 struct bgp_node *rn;
3391 struct bgp_info *ri;
3392
paulfee0f4c2004-09-13 05:12:46 +00003393 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003394
3395 /* Check selected route and self inserted route. */
3396 for (ri = rn->info; ri; ri = ri->next)
3397 if (ri->peer == bgp->peer_self
3398 && ri->type == ZEBRA_ROUTE_BGP
3399 && ri->sub_type == BGP_ROUTE_STATIC)
3400 break;
3401
3402 /* Withdraw static BGP route from routing table. */
3403 if (ri)
3404 {
3405 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003406 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003407 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003408 }
3409
3410 /* Unlock bgp_node_lookup. */
3411 bgp_unlock_node (rn);
3412}
3413
3414/* Configure static BGP network. When user don't run zebra, static
3415 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003416static int
paulfd79ac92004-10-13 05:06:08 +00003417bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
3418 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003419{
3420 int ret;
3421 struct prefix p;
3422 struct bgp_static *bgp_static;
3423 struct bgp_node *rn;
3424 int need_update = 0;
3425
3426 /* Convert IP prefix string to struct prefix. */
3427 ret = str2prefix (ip_str, &p);
3428 if (! ret)
3429 {
3430 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3431 return CMD_WARNING;
3432 }
3433#ifdef HAVE_IPV6
3434 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3435 {
3436 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3437 VTY_NEWLINE);
3438 return CMD_WARNING;
3439 }
3440#endif /* HAVE_IPV6 */
3441
3442 apply_mask (&p);
3443
3444 /* Set BGP static route configuration. */
3445 rn = bgp_node_get (bgp->route[afi][safi], &p);
3446
3447 if (rn->info)
3448 {
3449 /* Configuration change. */
3450 bgp_static = rn->info;
3451
3452 /* Check previous routes are installed into BGP. */
3453 if (! bgp_static->backdoor && bgp_static->valid)
3454 need_update = 1;
3455
3456 bgp_static->backdoor = backdoor;
3457 if (rmap)
3458 {
3459 if (bgp_static->rmap.name)
3460 free (bgp_static->rmap.name);
3461 bgp_static->rmap.name = strdup (rmap);
3462 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3463 }
3464 else
3465 {
3466 if (bgp_static->rmap.name)
3467 free (bgp_static->rmap.name);
3468 bgp_static->rmap.name = NULL;
3469 bgp_static->rmap.map = NULL;
3470 bgp_static->valid = 0;
3471 }
3472 bgp_unlock_node (rn);
3473 }
3474 else
3475 {
3476 /* New configuration. */
3477 bgp_static = bgp_static_new ();
3478 bgp_static->backdoor = backdoor;
3479 bgp_static->valid = 0;
3480 bgp_static->igpmetric = 0;
3481 bgp_static->igpnexthop.s_addr = 0;
3482 if (rmap)
3483 {
3484 if (bgp_static->rmap.name)
3485 free (bgp_static->rmap.name);
3486 bgp_static->rmap.name = strdup (rmap);
3487 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3488 }
3489 rn->info = bgp_static;
3490 }
3491
3492 /* If BGP scan is not enabled, we should install this route here. */
3493 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3494 {
3495 bgp_static->valid = 1;
3496
3497 if (need_update)
3498 bgp_static_withdraw (bgp, &p, afi, safi);
3499
3500 if (! bgp_static->backdoor)
3501 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3502 }
3503
3504 return CMD_SUCCESS;
3505}
3506
3507/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003508static int
paulfd79ac92004-10-13 05:06:08 +00003509bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003510 u_int16_t afi, u_char safi)
3511{
3512 int ret;
3513 struct prefix p;
3514 struct bgp_static *bgp_static;
3515 struct bgp_node *rn;
3516
3517 /* Convert IP prefix string to struct prefix. */
3518 ret = str2prefix (ip_str, &p);
3519 if (! ret)
3520 {
3521 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3522 return CMD_WARNING;
3523 }
3524#ifdef HAVE_IPV6
3525 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3526 {
3527 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3528 VTY_NEWLINE);
3529 return CMD_WARNING;
3530 }
3531#endif /* HAVE_IPV6 */
3532
3533 apply_mask (&p);
3534
3535 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3536 if (! rn)
3537 {
3538 vty_out (vty, "%% Can't find specified static route configuration.%s",
3539 VTY_NEWLINE);
3540 return CMD_WARNING;
3541 }
3542
3543 bgp_static = rn->info;
3544
3545 /* Update BGP RIB. */
3546 if (! bgp_static->backdoor)
3547 bgp_static_withdraw (bgp, &p, afi, safi);
3548
3549 /* Clear configuration. */
3550 bgp_static_free (bgp_static);
3551 rn->info = NULL;
3552 bgp_unlock_node (rn);
3553 bgp_unlock_node (rn);
3554
3555 return CMD_SUCCESS;
3556}
3557
3558/* Called from bgp_delete(). Delete all static routes from the BGP
3559 instance. */
3560void
3561bgp_static_delete (struct bgp *bgp)
3562{
3563 afi_t afi;
3564 safi_t safi;
3565 struct bgp_node *rn;
3566 struct bgp_node *rm;
3567 struct bgp_table *table;
3568 struct bgp_static *bgp_static;
3569
3570 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3571 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3572 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3573 if (rn->info != NULL)
3574 {
3575 if (safi == SAFI_MPLS_VPN)
3576 {
3577 table = rn->info;
3578
3579 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3580 {
3581 bgp_static = rn->info;
3582 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3583 AFI_IP, SAFI_MPLS_VPN,
3584 (struct prefix_rd *)&rn->p,
3585 bgp_static->tag);
3586 bgp_static_free (bgp_static);
3587 rn->info = NULL;
3588 bgp_unlock_node (rn);
3589 }
3590 }
3591 else
3592 {
3593 bgp_static = rn->info;
3594 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3595 bgp_static_free (bgp_static);
3596 rn->info = NULL;
3597 bgp_unlock_node (rn);
3598 }
3599 }
3600}
3601
3602int
paulfd79ac92004-10-13 05:06:08 +00003603bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3604 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003605{
3606 int ret;
3607 struct prefix p;
3608 struct prefix_rd prd;
3609 struct bgp *bgp;
3610 struct bgp_node *prn;
3611 struct bgp_node *rn;
3612 struct bgp_table *table;
3613 struct bgp_static *bgp_static;
3614 u_char tag[3];
3615
3616 bgp = vty->index;
3617
3618 ret = str2prefix (ip_str, &p);
3619 if (! ret)
3620 {
3621 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3622 return CMD_WARNING;
3623 }
3624 apply_mask (&p);
3625
3626 ret = str2prefix_rd (rd_str, &prd);
3627 if (! ret)
3628 {
3629 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3630 return CMD_WARNING;
3631 }
3632
3633 ret = str2tag (tag_str, tag);
3634 if (! ret)
3635 {
3636 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3637 return CMD_WARNING;
3638 }
3639
3640 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3641 (struct prefix *)&prd);
3642 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003643 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003644 else
3645 bgp_unlock_node (prn);
3646 table = prn->info;
3647
3648 rn = bgp_node_get (table, &p);
3649
3650 if (rn->info)
3651 {
3652 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3653 bgp_unlock_node (rn);
3654 }
3655 else
3656 {
3657 /* New configuration. */
3658 bgp_static = bgp_static_new ();
3659 bgp_static->valid = 1;
3660 memcpy (bgp_static->tag, tag, 3);
3661 rn->info = bgp_static;
3662
3663 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3664 }
3665
3666 return CMD_SUCCESS;
3667}
3668
3669/* Configure static BGP network. */
3670int
paulfd79ac92004-10-13 05:06:08 +00003671bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3672 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003673{
3674 int ret;
3675 struct bgp *bgp;
3676 struct prefix p;
3677 struct prefix_rd prd;
3678 struct bgp_node *prn;
3679 struct bgp_node *rn;
3680 struct bgp_table *table;
3681 struct bgp_static *bgp_static;
3682 u_char tag[3];
3683
3684 bgp = vty->index;
3685
3686 /* Convert IP prefix string to struct prefix. */
3687 ret = str2prefix (ip_str, &p);
3688 if (! ret)
3689 {
3690 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3691 return CMD_WARNING;
3692 }
3693 apply_mask (&p);
3694
3695 ret = str2prefix_rd (rd_str, &prd);
3696 if (! ret)
3697 {
3698 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3699 return CMD_WARNING;
3700 }
3701
3702 ret = str2tag (tag_str, tag);
3703 if (! ret)
3704 {
3705 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3706 return CMD_WARNING;
3707 }
3708
3709 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3710 (struct prefix *)&prd);
3711 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003712 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003713 else
3714 bgp_unlock_node (prn);
3715 table = prn->info;
3716
3717 rn = bgp_node_lookup (table, &p);
3718
3719 if (rn)
3720 {
3721 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3722
3723 bgp_static = rn->info;
3724 bgp_static_free (bgp_static);
3725 rn->info = NULL;
3726 bgp_unlock_node (rn);
3727 bgp_unlock_node (rn);
3728 }
3729 else
3730 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3731
3732 return CMD_SUCCESS;
3733}
3734
3735DEFUN (bgp_network,
3736 bgp_network_cmd,
3737 "network A.B.C.D/M",
3738 "Specify a network to announce via BGP\n"
3739 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3740{
3741 return bgp_static_set (vty, vty->index, argv[0],
3742 AFI_IP, bgp_node_safi (vty), NULL, 0);
3743}
3744
3745DEFUN (bgp_network_route_map,
3746 bgp_network_route_map_cmd,
3747 "network A.B.C.D/M route-map WORD",
3748 "Specify a network to announce via BGP\n"
3749 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3750 "Route-map to modify the attributes\n"
3751 "Name of the route map\n")
3752{
3753 return bgp_static_set (vty, vty->index, argv[0],
3754 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3755}
3756
3757DEFUN (bgp_network_backdoor,
3758 bgp_network_backdoor_cmd,
3759 "network A.B.C.D/M backdoor",
3760 "Specify a network to announce via BGP\n"
3761 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3762 "Specify a BGP backdoor route\n")
3763{
3764 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
3765}
3766
3767DEFUN (bgp_network_mask,
3768 bgp_network_mask_cmd,
3769 "network A.B.C.D mask A.B.C.D",
3770 "Specify a network to announce via BGP\n"
3771 "Network number\n"
3772 "Network mask\n"
3773 "Network mask\n")
3774{
3775 int ret;
3776 char prefix_str[BUFSIZ];
3777
3778 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3779 if (! ret)
3780 {
3781 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3782 return CMD_WARNING;
3783 }
3784
3785 return bgp_static_set (vty, vty->index, prefix_str,
3786 AFI_IP, bgp_node_safi (vty), NULL, 0);
3787}
3788
3789DEFUN (bgp_network_mask_route_map,
3790 bgp_network_mask_route_map_cmd,
3791 "network A.B.C.D mask A.B.C.D route-map WORD",
3792 "Specify a network to announce via BGP\n"
3793 "Network number\n"
3794 "Network mask\n"
3795 "Network mask\n"
3796 "Route-map to modify the attributes\n"
3797 "Name of the route map\n")
3798{
3799 int ret;
3800 char prefix_str[BUFSIZ];
3801
3802 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3803 if (! ret)
3804 {
3805 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3806 return CMD_WARNING;
3807 }
3808
3809 return bgp_static_set (vty, vty->index, prefix_str,
3810 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3811}
3812
3813DEFUN (bgp_network_mask_backdoor,
3814 bgp_network_mask_backdoor_cmd,
3815 "network A.B.C.D mask A.B.C.D backdoor",
3816 "Specify a network to announce via BGP\n"
3817 "Network number\n"
3818 "Network mask\n"
3819 "Network mask\n"
3820 "Specify a BGP backdoor route\n")
3821{
3822 int ret;
3823 char prefix_str[BUFSIZ];
3824
3825 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3826 if (! ret)
3827 {
3828 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3829 return CMD_WARNING;
3830 }
3831
3832 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3833}
3834
3835DEFUN (bgp_network_mask_natural,
3836 bgp_network_mask_natural_cmd,
3837 "network A.B.C.D",
3838 "Specify a network to announce via BGP\n"
3839 "Network number\n")
3840{
3841 int ret;
3842 char prefix_str[BUFSIZ];
3843
3844 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3845 if (! ret)
3846 {
3847 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3848 return CMD_WARNING;
3849 }
3850
3851 return bgp_static_set (vty, vty->index, prefix_str,
3852 AFI_IP, bgp_node_safi (vty), NULL, 0);
3853}
3854
3855DEFUN (bgp_network_mask_natural_route_map,
3856 bgp_network_mask_natural_route_map_cmd,
3857 "network A.B.C.D route-map WORD",
3858 "Specify a network to announce via BGP\n"
3859 "Network number\n"
3860 "Route-map to modify the attributes\n"
3861 "Name of the route map\n")
3862{
3863 int ret;
3864 char prefix_str[BUFSIZ];
3865
3866 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3867 if (! ret)
3868 {
3869 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3870 return CMD_WARNING;
3871 }
3872
3873 return bgp_static_set (vty, vty->index, prefix_str,
3874 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3875}
3876
3877DEFUN (bgp_network_mask_natural_backdoor,
3878 bgp_network_mask_natural_backdoor_cmd,
3879 "network A.B.C.D backdoor",
3880 "Specify a network to announce via BGP\n"
3881 "Network number\n"
3882 "Specify a BGP backdoor route\n")
3883{
3884 int ret;
3885 char prefix_str[BUFSIZ];
3886
3887 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3888 if (! ret)
3889 {
3890 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3891 return CMD_WARNING;
3892 }
3893
3894 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3895}
3896
3897DEFUN (no_bgp_network,
3898 no_bgp_network_cmd,
3899 "no network A.B.C.D/M",
3900 NO_STR
3901 "Specify a network to announce via BGP\n"
3902 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3903{
3904 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
3905 bgp_node_safi (vty));
3906}
3907
3908ALIAS (no_bgp_network,
3909 no_bgp_network_route_map_cmd,
3910 "no network A.B.C.D/M route-map WORD",
3911 NO_STR
3912 "Specify a network to announce via BGP\n"
3913 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3914 "Route-map to modify the attributes\n"
3915 "Name of the route map\n")
3916
3917ALIAS (no_bgp_network,
3918 no_bgp_network_backdoor_cmd,
3919 "no network A.B.C.D/M backdoor",
3920 NO_STR
3921 "Specify a network to announce via BGP\n"
3922 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3923 "Specify a BGP backdoor route\n")
3924
3925DEFUN (no_bgp_network_mask,
3926 no_bgp_network_mask_cmd,
3927 "no network A.B.C.D mask A.B.C.D",
3928 NO_STR
3929 "Specify a network to announce via BGP\n"
3930 "Network number\n"
3931 "Network mask\n"
3932 "Network mask\n")
3933{
3934 int ret;
3935 char prefix_str[BUFSIZ];
3936
3937 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3938 if (! ret)
3939 {
3940 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3941 return CMD_WARNING;
3942 }
3943
3944 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3945 bgp_node_safi (vty));
3946}
3947
3948ALIAS (no_bgp_network_mask,
3949 no_bgp_network_mask_route_map_cmd,
3950 "no network A.B.C.D mask A.B.C.D route-map WORD",
3951 NO_STR
3952 "Specify a network to announce via BGP\n"
3953 "Network number\n"
3954 "Network mask\n"
3955 "Network mask\n"
3956 "Route-map to modify the attributes\n"
3957 "Name of the route map\n")
3958
3959ALIAS (no_bgp_network_mask,
3960 no_bgp_network_mask_backdoor_cmd,
3961 "no network A.B.C.D mask A.B.C.D backdoor",
3962 NO_STR
3963 "Specify a network to announce via BGP\n"
3964 "Network number\n"
3965 "Network mask\n"
3966 "Network mask\n"
3967 "Specify a BGP backdoor route\n")
3968
3969DEFUN (no_bgp_network_mask_natural,
3970 no_bgp_network_mask_natural_cmd,
3971 "no network A.B.C.D",
3972 NO_STR
3973 "Specify a network to announce via BGP\n"
3974 "Network number\n")
3975{
3976 int ret;
3977 char prefix_str[BUFSIZ];
3978
3979 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3980 if (! ret)
3981 {
3982 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3983 return CMD_WARNING;
3984 }
3985
3986 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3987 bgp_node_safi (vty));
3988}
3989
3990ALIAS (no_bgp_network_mask_natural,
3991 no_bgp_network_mask_natural_route_map_cmd,
3992 "no network A.B.C.D route-map WORD",
3993 NO_STR
3994 "Specify a network to announce via BGP\n"
3995 "Network number\n"
3996 "Route-map to modify the attributes\n"
3997 "Name of the route map\n")
3998
3999ALIAS (no_bgp_network_mask_natural,
4000 no_bgp_network_mask_natural_backdoor_cmd,
4001 "no network A.B.C.D backdoor",
4002 NO_STR
4003 "Specify a network to announce via BGP\n"
4004 "Network number\n"
4005 "Specify a BGP backdoor route\n")
4006
4007#ifdef HAVE_IPV6
4008DEFUN (ipv6_bgp_network,
4009 ipv6_bgp_network_cmd,
4010 "network X:X::X:X/M",
4011 "Specify a network to announce via BGP\n"
4012 "IPv6 prefix <network>/<length>\n")
4013{
4014 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
4015}
4016
4017DEFUN (ipv6_bgp_network_route_map,
4018 ipv6_bgp_network_route_map_cmd,
4019 "network X:X::X:X/M route-map WORD",
4020 "Specify a network to announce via BGP\n"
4021 "IPv6 prefix <network>/<length>\n"
4022 "Route-map to modify the attributes\n"
4023 "Name of the route map\n")
4024{
4025 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
4026 bgp_node_safi (vty), argv[1], 0);
4027}
4028
4029DEFUN (no_ipv6_bgp_network,
4030 no_ipv6_bgp_network_cmd,
4031 "no network X:X::X:X/M",
4032 NO_STR
4033 "Specify a network to announce via BGP\n"
4034 "IPv6 prefix <network>/<length>\n")
4035{
4036 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4037}
4038
4039ALIAS (no_ipv6_bgp_network,
4040 no_ipv6_bgp_network_route_map_cmd,
4041 "no network X:X::X:X/M route-map WORD",
4042 NO_STR
4043 "Specify a network to announce via BGP\n"
4044 "IPv6 prefix <network>/<length>\n"
4045 "Route-map to modify the attributes\n"
4046 "Name of the route map\n")
4047
4048ALIAS (ipv6_bgp_network,
4049 old_ipv6_bgp_network_cmd,
4050 "ipv6 bgp network X:X::X:X/M",
4051 IPV6_STR
4052 BGP_STR
4053 "Specify a network to announce via BGP\n"
4054 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4055
4056ALIAS (no_ipv6_bgp_network,
4057 old_no_ipv6_bgp_network_cmd,
4058 "no ipv6 bgp network X:X::X:X/M",
4059 NO_STR
4060 IPV6_STR
4061 BGP_STR
4062 "Specify a network to announce via BGP\n"
4063 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4064#endif /* HAVE_IPV6 */
4065
4066/* Aggreagete address:
4067
4068 advertise-map Set condition to advertise attribute
4069 as-set Generate AS set path information
4070 attribute-map Set attributes of aggregate
4071 route-map Set parameters of aggregate
4072 summary-only Filter more specific routes from updates
4073 suppress-map Conditionally filter more specific routes from updates
4074 <cr>
4075 */
4076struct bgp_aggregate
4077{
4078 /* Summary-only flag. */
4079 u_char summary_only;
4080
4081 /* AS set generation. */
4082 u_char as_set;
4083
4084 /* Route-map for aggregated route. */
4085 struct route_map *map;
4086
4087 /* Suppress-count. */
4088 unsigned long count;
4089
4090 /* SAFI configuration. */
4091 safi_t safi;
4092};
4093
paul94f2b392005-06-28 12:44:16 +00004094static struct bgp_aggregate *
paul718e3742002-12-13 20:15:29 +00004095bgp_aggregate_new ()
4096{
4097 struct bgp_aggregate *new;
4098 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4099 memset (new, 0, sizeof (struct bgp_aggregate));
4100 return new;
4101}
4102
paul94f2b392005-06-28 12:44:16 +00004103static void
paul718e3742002-12-13 20:15:29 +00004104bgp_aggregate_free (struct bgp_aggregate *aggregate)
4105{
4106 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4107}
4108
paul94f2b392005-06-28 12:44:16 +00004109static void
paul718e3742002-12-13 20:15:29 +00004110bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4111 afi_t afi, safi_t safi, struct bgp_info *del,
4112 struct bgp_aggregate *aggregate)
4113{
4114 struct bgp_table *table;
4115 struct bgp_node *top;
4116 struct bgp_node *rn;
4117 u_char origin;
4118 struct aspath *aspath = NULL;
4119 struct aspath *asmerge = NULL;
4120 struct community *community = NULL;
4121 struct community *commerge = NULL;
4122 struct in_addr nexthop;
4123 u_int32_t med = 0;
4124 struct bgp_info *ri;
4125 struct bgp_info *new;
4126 int first = 1;
4127 unsigned long match = 0;
4128
4129 /* Record adding route's nexthop and med. */
4130 if (rinew)
4131 {
4132 nexthop = rinew->attr->nexthop;
4133 med = rinew->attr->med;
4134 }
4135
4136 /* ORIGIN attribute: If at least one route among routes that are
4137 aggregated has ORIGIN with the value INCOMPLETE, then the
4138 aggregated route must have the ORIGIN attribute with the value
4139 INCOMPLETE. Otherwise, if at least one route among routes that
4140 are aggregated has ORIGIN with the value EGP, then the aggregated
4141 route must have the origin attribute with the value EGP. In all
4142 other case the value of the ORIGIN attribute of the aggregated
4143 route is INTERNAL. */
4144 origin = BGP_ORIGIN_IGP;
4145
4146 table = bgp->rib[afi][safi];
4147
4148 top = bgp_node_get (table, p);
4149 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4150 if (rn->p.prefixlen > p->prefixlen)
4151 {
4152 match = 0;
4153
4154 for (ri = rn->info; ri; ri = ri->next)
4155 {
4156 if (BGP_INFO_HOLDDOWN (ri))
4157 continue;
4158
4159 if (del && ri == del)
4160 continue;
4161
4162 if (! rinew && first)
4163 {
4164 nexthop = ri->attr->nexthop;
4165 med = ri->attr->med;
4166 first = 0;
4167 }
4168
4169#ifdef AGGREGATE_NEXTHOP_CHECK
4170 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4171 || ri->attr->med != med)
4172 {
4173 if (aspath)
4174 aspath_free (aspath);
4175 if (community)
4176 community_free (community);
4177 bgp_unlock_node (rn);
4178 bgp_unlock_node (top);
4179 return;
4180 }
4181#endif /* AGGREGATE_NEXTHOP_CHECK */
4182
4183 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4184 {
4185 if (aggregate->summary_only)
4186 {
4187 ri->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004188 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004189 match++;
4190 }
4191
4192 aggregate->count++;
4193
4194 if (aggregate->as_set)
4195 {
4196 if (origin < ri->attr->origin)
4197 origin = ri->attr->origin;
4198
4199 if (aspath)
4200 {
4201 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4202 aspath_free (aspath);
4203 aspath = asmerge;
4204 }
4205 else
4206 aspath = aspath_dup (ri->attr->aspath);
4207
4208 if (ri->attr->community)
4209 {
4210 if (community)
4211 {
4212 commerge = community_merge (community,
4213 ri->attr->community);
4214 community = community_uniq_sort (commerge);
4215 community_free (commerge);
4216 }
4217 else
4218 community = community_dup (ri->attr->community);
4219 }
4220 }
4221 }
4222 }
4223 if (match)
4224 bgp_process (bgp, rn, afi, safi);
4225 }
4226 bgp_unlock_node (top);
4227
4228 if (rinew)
4229 {
4230 aggregate->count++;
4231
4232 if (aggregate->summary_only)
4233 rinew->suppress++;
4234
4235 if (aggregate->as_set)
4236 {
4237 if (origin < rinew->attr->origin)
4238 origin = rinew->attr->origin;
4239
4240 if (aspath)
4241 {
4242 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4243 aspath_free (aspath);
4244 aspath = asmerge;
4245 }
4246 else
4247 aspath = aspath_dup (rinew->attr->aspath);
4248
4249 if (rinew->attr->community)
4250 {
4251 if (community)
4252 {
4253 commerge = community_merge (community,
4254 rinew->attr->community);
4255 community = community_uniq_sort (commerge);
4256 community_free (commerge);
4257 }
4258 else
4259 community = community_dup (rinew->attr->community);
4260 }
4261 }
4262 }
4263
4264 if (aggregate->count > 0)
4265 {
4266 rn = bgp_node_get (table, p);
4267 new = bgp_info_new ();
4268 new->type = ZEBRA_ROUTE_BGP;
4269 new->sub_type = BGP_ROUTE_AGGREGATE;
4270 new->peer = bgp->peer_self;
4271 SET_FLAG (new->flags, BGP_INFO_VALID);
4272 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4273 new->uptime = time (NULL);
4274
4275 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004276 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004277 bgp_process (bgp, rn, afi, safi);
4278 }
4279 else
4280 {
4281 if (aspath)
4282 aspath_free (aspath);
4283 if (community)
4284 community_free (community);
4285 }
4286}
4287
4288void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4289 struct bgp_aggregate *);
4290
4291void
4292bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4293 struct bgp_info *ri, afi_t afi, safi_t safi)
4294{
4295 struct bgp_node *child;
4296 struct bgp_node *rn;
4297 struct bgp_aggregate *aggregate;
4298
4299 /* MPLS-VPN aggregation is not yet supported. */
4300 if (safi == SAFI_MPLS_VPN)
4301 return;
4302
4303 if (p->prefixlen == 0)
4304 return;
4305
4306 if (BGP_INFO_HOLDDOWN (ri))
4307 return;
4308
4309 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4310
4311 /* Aggregate address configuration check. */
4312 for (rn = child; rn; rn = rn->parent)
4313 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4314 {
4315 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004316 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004317 }
4318 bgp_unlock_node (child);
4319}
4320
4321void
4322bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4323 struct bgp_info *del, afi_t afi, safi_t safi)
4324{
4325 struct bgp_node *child;
4326 struct bgp_node *rn;
4327 struct bgp_aggregate *aggregate;
4328
4329 /* MPLS-VPN aggregation is not yet supported. */
4330 if (safi == SAFI_MPLS_VPN)
4331 return;
4332
4333 if (p->prefixlen == 0)
4334 return;
4335
4336 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4337
4338 /* Aggregate address configuration check. */
4339 for (rn = child; rn; rn = rn->parent)
4340 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4341 {
4342 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004343 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004344 }
4345 bgp_unlock_node (child);
4346}
4347
paul94f2b392005-06-28 12:44:16 +00004348static void
paul718e3742002-12-13 20:15:29 +00004349bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4350 struct bgp_aggregate *aggregate)
4351{
4352 struct bgp_table *table;
4353 struct bgp_node *top;
4354 struct bgp_node *rn;
4355 struct bgp_info *new;
4356 struct bgp_info *ri;
4357 unsigned long match;
4358 u_char origin = BGP_ORIGIN_IGP;
4359 struct aspath *aspath = NULL;
4360 struct aspath *asmerge = NULL;
4361 struct community *community = NULL;
4362 struct community *commerge = NULL;
4363
4364 table = bgp->rib[afi][safi];
4365
4366 /* Sanity check. */
4367 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4368 return;
4369 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4370 return;
4371
4372 /* If routes exists below this node, generate aggregate routes. */
4373 top = bgp_node_get (table, p);
4374 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4375 if (rn->p.prefixlen > p->prefixlen)
4376 {
4377 match = 0;
4378
4379 for (ri = rn->info; ri; ri = ri->next)
4380 {
4381 if (BGP_INFO_HOLDDOWN (ri))
4382 continue;
4383
4384 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4385 {
4386 /* summary-only aggregate route suppress aggregated
4387 route announcement. */
4388 if (aggregate->summary_only)
4389 {
4390 ri->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004391 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004392 match++;
4393 }
4394 /* as-set aggregate route generate origin, as path,
4395 community aggregation. */
4396 if (aggregate->as_set)
4397 {
4398 if (origin < ri->attr->origin)
4399 origin = ri->attr->origin;
4400
4401 if (aspath)
4402 {
4403 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4404 aspath_free (aspath);
4405 aspath = asmerge;
4406 }
4407 else
4408 aspath = aspath_dup (ri->attr->aspath);
4409
4410 if (ri->attr->community)
4411 {
4412 if (community)
4413 {
4414 commerge = community_merge (community,
4415 ri->attr->community);
4416 community = community_uniq_sort (commerge);
4417 community_free (commerge);
4418 }
4419 else
4420 community = community_dup (ri->attr->community);
4421 }
4422 }
4423 aggregate->count++;
4424 }
4425 }
4426
4427 /* If this node is suppressed, process the change. */
4428 if (match)
4429 bgp_process (bgp, rn, afi, safi);
4430 }
4431 bgp_unlock_node (top);
4432
4433 /* Add aggregate route to BGP table. */
4434 if (aggregate->count)
4435 {
4436 rn = bgp_node_get (table, p);
4437
4438 new = bgp_info_new ();
4439 new->type = ZEBRA_ROUTE_BGP;
4440 new->sub_type = BGP_ROUTE_AGGREGATE;
4441 new->peer = bgp->peer_self;
4442 SET_FLAG (new->flags, BGP_INFO_VALID);
4443 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4444 new->uptime = time (NULL);
4445
4446 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004447 bgp_unlock_node (rn);
4448
paul718e3742002-12-13 20:15:29 +00004449 /* Process change. */
4450 bgp_process (bgp, rn, afi, safi);
4451 }
4452}
4453
4454void
4455bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4456 safi_t safi, struct bgp_aggregate *aggregate)
4457{
4458 struct bgp_table *table;
4459 struct bgp_node *top;
4460 struct bgp_node *rn;
4461 struct bgp_info *ri;
4462 unsigned long match;
4463
4464 table = bgp->rib[afi][safi];
4465
4466 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4467 return;
4468 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4469 return;
4470
4471 /* If routes exists below this node, generate aggregate routes. */
4472 top = bgp_node_get (table, p);
4473 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4474 if (rn->p.prefixlen > p->prefixlen)
4475 {
4476 match = 0;
4477
4478 for (ri = rn->info; ri; ri = ri->next)
4479 {
4480 if (BGP_INFO_HOLDDOWN (ri))
4481 continue;
4482
4483 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4484 {
4485 if (aggregate->summary_only)
4486 {
4487 ri->suppress--;
4488
4489 if (ri->suppress == 0)
4490 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004491 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004492 match++;
4493 }
4494 }
4495 aggregate->count--;
4496 }
4497 }
4498
4499 /* If this node is suppressed, process the change. */
4500 if (match)
4501 bgp_process (bgp, rn, afi, safi);
4502 }
4503 bgp_unlock_node (top);
4504
4505 /* Delete aggregate route from BGP table. */
4506 rn = bgp_node_get (table, p);
4507
4508 for (ri = rn->info; ri; ri = ri->next)
4509 if (ri->peer == bgp->peer_self
4510 && ri->type == ZEBRA_ROUTE_BGP
4511 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4512 break;
4513
4514 /* Withdraw static BGP route from routing table. */
4515 if (ri)
4516 {
paul718e3742002-12-13 20:15:29 +00004517 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004518 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004519 }
4520
4521 /* Unlock bgp_node_lookup. */
4522 bgp_unlock_node (rn);
4523}
4524
4525/* Aggregate route attribute. */
4526#define AGGREGATE_SUMMARY_ONLY 1
4527#define AGGREGATE_AS_SET 1
4528
paul94f2b392005-06-28 12:44:16 +00004529static int
paulfd79ac92004-10-13 05:06:08 +00004530bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4531 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004532 u_char summary_only, u_char as_set)
4533{
4534 int ret;
4535 struct prefix p;
4536 struct bgp_node *rn;
4537 struct bgp *bgp;
4538 struct bgp_aggregate *aggregate;
4539
4540 /* Convert string to prefix structure. */
4541 ret = str2prefix (prefix_str, &p);
4542 if (!ret)
4543 {
4544 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4545 return CMD_WARNING;
4546 }
4547 apply_mask (&p);
4548
4549 /* Get BGP structure. */
4550 bgp = vty->index;
4551
4552 /* Old configuration check. */
4553 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4554
4555 if (rn->info)
4556 {
4557 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4558 bgp_unlock_node (rn);
4559 return CMD_WARNING;
4560 }
4561
4562 /* Make aggregate address structure. */
4563 aggregate = bgp_aggregate_new ();
4564 aggregate->summary_only = summary_only;
4565 aggregate->as_set = as_set;
4566 aggregate->safi = safi;
4567 rn->info = aggregate;
4568
4569 /* Aggregate address insert into BGP routing table. */
4570 if (safi & SAFI_UNICAST)
4571 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4572 if (safi & SAFI_MULTICAST)
4573 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4574
4575 return CMD_SUCCESS;
4576}
4577
paul94f2b392005-06-28 12:44:16 +00004578static int
paulfd79ac92004-10-13 05:06:08 +00004579bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4580 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004581{
4582 int ret;
4583 struct prefix p;
4584 struct bgp_node *rn;
4585 struct bgp *bgp;
4586 struct bgp_aggregate *aggregate;
4587
4588 /* Convert string to prefix structure. */
4589 ret = str2prefix (prefix_str, &p);
4590 if (!ret)
4591 {
4592 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4593 return CMD_WARNING;
4594 }
4595 apply_mask (&p);
4596
4597 /* Get BGP structure. */
4598 bgp = vty->index;
4599
4600 /* Old configuration check. */
4601 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4602 if (! rn)
4603 {
4604 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4605 VTY_NEWLINE);
4606 return CMD_WARNING;
4607 }
4608
4609 aggregate = rn->info;
4610 if (aggregate->safi & SAFI_UNICAST)
4611 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4612 if (aggregate->safi & SAFI_MULTICAST)
4613 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4614
4615 /* Unlock aggregate address configuration. */
4616 rn->info = NULL;
4617 bgp_aggregate_free (aggregate);
4618 bgp_unlock_node (rn);
4619 bgp_unlock_node (rn);
4620
4621 return CMD_SUCCESS;
4622}
4623
4624DEFUN (aggregate_address,
4625 aggregate_address_cmd,
4626 "aggregate-address A.B.C.D/M",
4627 "Configure BGP aggregate entries\n"
4628 "Aggregate prefix\n")
4629{
4630 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4631}
4632
4633DEFUN (aggregate_address_mask,
4634 aggregate_address_mask_cmd,
4635 "aggregate-address A.B.C.D A.B.C.D",
4636 "Configure BGP aggregate entries\n"
4637 "Aggregate address\n"
4638 "Aggregate mask\n")
4639{
4640 int ret;
4641 char prefix_str[BUFSIZ];
4642
4643 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4644
4645 if (! ret)
4646 {
4647 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4648 return CMD_WARNING;
4649 }
4650
4651 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4652 0, 0);
4653}
4654
4655DEFUN (aggregate_address_summary_only,
4656 aggregate_address_summary_only_cmd,
4657 "aggregate-address A.B.C.D/M summary-only",
4658 "Configure BGP aggregate entries\n"
4659 "Aggregate prefix\n"
4660 "Filter more specific routes from updates\n")
4661{
4662 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4663 AGGREGATE_SUMMARY_ONLY, 0);
4664}
4665
4666DEFUN (aggregate_address_mask_summary_only,
4667 aggregate_address_mask_summary_only_cmd,
4668 "aggregate-address A.B.C.D A.B.C.D summary-only",
4669 "Configure BGP aggregate entries\n"
4670 "Aggregate address\n"
4671 "Aggregate mask\n"
4672 "Filter more specific routes from updates\n")
4673{
4674 int ret;
4675 char prefix_str[BUFSIZ];
4676
4677 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4678
4679 if (! ret)
4680 {
4681 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4682 return CMD_WARNING;
4683 }
4684
4685 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4686 AGGREGATE_SUMMARY_ONLY, 0);
4687}
4688
4689DEFUN (aggregate_address_as_set,
4690 aggregate_address_as_set_cmd,
4691 "aggregate-address A.B.C.D/M as-set",
4692 "Configure BGP aggregate entries\n"
4693 "Aggregate prefix\n"
4694 "Generate AS set path information\n")
4695{
4696 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4697 0, AGGREGATE_AS_SET);
4698}
4699
4700DEFUN (aggregate_address_mask_as_set,
4701 aggregate_address_mask_as_set_cmd,
4702 "aggregate-address A.B.C.D A.B.C.D as-set",
4703 "Configure BGP aggregate entries\n"
4704 "Aggregate address\n"
4705 "Aggregate mask\n"
4706 "Generate AS set path information\n")
4707{
4708 int ret;
4709 char prefix_str[BUFSIZ];
4710
4711 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4712
4713 if (! ret)
4714 {
4715 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4716 return CMD_WARNING;
4717 }
4718
4719 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4720 0, AGGREGATE_AS_SET);
4721}
4722
4723
4724DEFUN (aggregate_address_as_set_summary,
4725 aggregate_address_as_set_summary_cmd,
4726 "aggregate-address A.B.C.D/M as-set summary-only",
4727 "Configure BGP aggregate entries\n"
4728 "Aggregate prefix\n"
4729 "Generate AS set path information\n"
4730 "Filter more specific routes from updates\n")
4731{
4732 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4733 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4734}
4735
4736ALIAS (aggregate_address_as_set_summary,
4737 aggregate_address_summary_as_set_cmd,
4738 "aggregate-address A.B.C.D/M summary-only as-set",
4739 "Configure BGP aggregate entries\n"
4740 "Aggregate prefix\n"
4741 "Filter more specific routes from updates\n"
4742 "Generate AS set path information\n")
4743
4744DEFUN (aggregate_address_mask_as_set_summary,
4745 aggregate_address_mask_as_set_summary_cmd,
4746 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4747 "Configure BGP aggregate entries\n"
4748 "Aggregate address\n"
4749 "Aggregate mask\n"
4750 "Generate AS set path information\n"
4751 "Filter more specific routes from updates\n")
4752{
4753 int ret;
4754 char prefix_str[BUFSIZ];
4755
4756 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4757
4758 if (! ret)
4759 {
4760 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4761 return CMD_WARNING;
4762 }
4763
4764 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4765 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4766}
4767
4768ALIAS (aggregate_address_mask_as_set_summary,
4769 aggregate_address_mask_summary_as_set_cmd,
4770 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4771 "Configure BGP aggregate entries\n"
4772 "Aggregate address\n"
4773 "Aggregate mask\n"
4774 "Filter more specific routes from updates\n"
4775 "Generate AS set path information\n")
4776
4777DEFUN (no_aggregate_address,
4778 no_aggregate_address_cmd,
4779 "no aggregate-address A.B.C.D/M",
4780 NO_STR
4781 "Configure BGP aggregate entries\n"
4782 "Aggregate prefix\n")
4783{
4784 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4785}
4786
4787ALIAS (no_aggregate_address,
4788 no_aggregate_address_summary_only_cmd,
4789 "no aggregate-address A.B.C.D/M summary-only",
4790 NO_STR
4791 "Configure BGP aggregate entries\n"
4792 "Aggregate prefix\n"
4793 "Filter more specific routes from updates\n")
4794
4795ALIAS (no_aggregate_address,
4796 no_aggregate_address_as_set_cmd,
4797 "no aggregate-address A.B.C.D/M as-set",
4798 NO_STR
4799 "Configure BGP aggregate entries\n"
4800 "Aggregate prefix\n"
4801 "Generate AS set path information\n")
4802
4803ALIAS (no_aggregate_address,
4804 no_aggregate_address_as_set_summary_cmd,
4805 "no aggregate-address A.B.C.D/M as-set summary-only",
4806 NO_STR
4807 "Configure BGP aggregate entries\n"
4808 "Aggregate prefix\n"
4809 "Generate AS set path information\n"
4810 "Filter more specific routes from updates\n")
4811
4812ALIAS (no_aggregate_address,
4813 no_aggregate_address_summary_as_set_cmd,
4814 "no aggregate-address A.B.C.D/M summary-only as-set",
4815 NO_STR
4816 "Configure BGP aggregate entries\n"
4817 "Aggregate prefix\n"
4818 "Filter more specific routes from updates\n"
4819 "Generate AS set path information\n")
4820
4821DEFUN (no_aggregate_address_mask,
4822 no_aggregate_address_mask_cmd,
4823 "no aggregate-address A.B.C.D A.B.C.D",
4824 NO_STR
4825 "Configure BGP aggregate entries\n"
4826 "Aggregate address\n"
4827 "Aggregate mask\n")
4828{
4829 int ret;
4830 char prefix_str[BUFSIZ];
4831
4832 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4833
4834 if (! ret)
4835 {
4836 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4837 return CMD_WARNING;
4838 }
4839
4840 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4841}
4842
4843ALIAS (no_aggregate_address_mask,
4844 no_aggregate_address_mask_summary_only_cmd,
4845 "no aggregate-address A.B.C.D A.B.C.D summary-only",
4846 NO_STR
4847 "Configure BGP aggregate entries\n"
4848 "Aggregate address\n"
4849 "Aggregate mask\n"
4850 "Filter more specific routes from updates\n")
4851
4852ALIAS (no_aggregate_address_mask,
4853 no_aggregate_address_mask_as_set_cmd,
4854 "no aggregate-address A.B.C.D A.B.C.D as-set",
4855 NO_STR
4856 "Configure BGP aggregate entries\n"
4857 "Aggregate address\n"
4858 "Aggregate mask\n"
4859 "Generate AS set path information\n")
4860
4861ALIAS (no_aggregate_address_mask,
4862 no_aggregate_address_mask_as_set_summary_cmd,
4863 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4864 NO_STR
4865 "Configure BGP aggregate entries\n"
4866 "Aggregate address\n"
4867 "Aggregate mask\n"
4868 "Generate AS set path information\n"
4869 "Filter more specific routes from updates\n")
4870
4871ALIAS (no_aggregate_address_mask,
4872 no_aggregate_address_mask_summary_as_set_cmd,
4873 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4874 NO_STR
4875 "Configure BGP aggregate entries\n"
4876 "Aggregate address\n"
4877 "Aggregate mask\n"
4878 "Filter more specific routes from updates\n"
4879 "Generate AS set path information\n")
4880
4881#ifdef HAVE_IPV6
4882DEFUN (ipv6_aggregate_address,
4883 ipv6_aggregate_address_cmd,
4884 "aggregate-address X:X::X:X/M",
4885 "Configure BGP aggregate entries\n"
4886 "Aggregate prefix\n")
4887{
4888 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4889}
4890
4891DEFUN (ipv6_aggregate_address_summary_only,
4892 ipv6_aggregate_address_summary_only_cmd,
4893 "aggregate-address X:X::X:X/M summary-only",
4894 "Configure BGP aggregate entries\n"
4895 "Aggregate prefix\n"
4896 "Filter more specific routes from updates\n")
4897{
4898 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4899 AGGREGATE_SUMMARY_ONLY, 0);
4900}
4901
4902DEFUN (no_ipv6_aggregate_address,
4903 no_ipv6_aggregate_address_cmd,
4904 "no aggregate-address X:X::X:X/M",
4905 NO_STR
4906 "Configure BGP aggregate entries\n"
4907 "Aggregate prefix\n")
4908{
4909 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4910}
4911
4912DEFUN (no_ipv6_aggregate_address_summary_only,
4913 no_ipv6_aggregate_address_summary_only_cmd,
4914 "no aggregate-address X:X::X:X/M summary-only",
4915 NO_STR
4916 "Configure BGP aggregate entries\n"
4917 "Aggregate prefix\n"
4918 "Filter more specific routes from updates\n")
4919{
4920 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4921}
4922
4923ALIAS (ipv6_aggregate_address,
4924 old_ipv6_aggregate_address_cmd,
4925 "ipv6 bgp aggregate-address X:X::X:X/M",
4926 IPV6_STR
4927 BGP_STR
4928 "Configure BGP aggregate entries\n"
4929 "Aggregate prefix\n")
4930
4931ALIAS (ipv6_aggregate_address_summary_only,
4932 old_ipv6_aggregate_address_summary_only_cmd,
4933 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4934 IPV6_STR
4935 BGP_STR
4936 "Configure BGP aggregate entries\n"
4937 "Aggregate prefix\n"
4938 "Filter more specific routes from updates\n")
4939
4940ALIAS (no_ipv6_aggregate_address,
4941 old_no_ipv6_aggregate_address_cmd,
4942 "no ipv6 bgp aggregate-address X:X::X:X/M",
4943 NO_STR
4944 IPV6_STR
4945 BGP_STR
4946 "Configure BGP aggregate entries\n"
4947 "Aggregate prefix\n")
4948
4949ALIAS (no_ipv6_aggregate_address_summary_only,
4950 old_no_ipv6_aggregate_address_summary_only_cmd,
4951 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4952 NO_STR
4953 IPV6_STR
4954 BGP_STR
4955 "Configure BGP aggregate entries\n"
4956 "Aggregate prefix\n"
4957 "Filter more specific routes from updates\n")
4958#endif /* HAVE_IPV6 */
4959
4960/* Redistribute route treatment. */
4961void
4962bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4963 u_int32_t metric, u_char type)
4964{
4965 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00004966 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00004967 struct bgp_info *new;
4968 struct bgp_info *bi;
4969 struct bgp_info info;
4970 struct bgp_node *bn;
4971 struct attr attr;
4972 struct attr attr_new;
4973 struct attr *new_attr;
4974 afi_t afi;
4975 int ret;
4976
4977 /* Make default attribute. */
4978 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4979 if (nexthop)
4980 attr.nexthop = *nexthop;
4981
4982 attr.med = metric;
4983 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4984
paul1eb8ef22005-04-07 07:30:20 +00004985 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00004986 {
4987 afi = family2afi (p->family);
4988
4989 if (bgp->redist[afi][type])
4990 {
4991 /* Copy attribute for modification. */
4992 attr_new = attr;
4993
4994 if (bgp->redist_metric_flag[afi][type])
4995 attr_new.med = bgp->redist_metric[afi][type];
4996
4997 /* Apply route-map. */
4998 if (bgp->rmap[afi][type].map)
4999 {
5000 info.peer = bgp->peer_self;
5001 info.attr = &attr_new;
5002
paulfee0f4c2004-09-13 05:12:46 +00005003 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5004
paul718e3742002-12-13 20:15:29 +00005005 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5006 &info);
paulfee0f4c2004-09-13 05:12:46 +00005007
5008 bgp->peer_self->rmap_type = 0;
5009
paul718e3742002-12-13 20:15:29 +00005010 if (ret == RMAP_DENYMATCH)
5011 {
5012 /* Free uninterned attribute. */
5013 bgp_attr_flush (&attr_new);
5014
5015 /* Unintern original. */
5016 aspath_unintern (attr.aspath);
5017 bgp_redistribute_delete (p, type);
5018 return;
5019 }
5020 }
5021
paulfee0f4c2004-09-13 05:12:46 +00005022 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005023 new_attr = bgp_attr_intern (&attr_new);
5024
5025 for (bi = bn->info; bi; bi = bi->next)
5026 if (bi->peer == bgp->peer_self
5027 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5028 break;
5029
5030 if (bi)
5031 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005032 if (attrhash_cmp (bi->attr, new_attr) &&
5033 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005034 {
5035 bgp_attr_unintern (new_attr);
5036 aspath_unintern (attr.aspath);
5037 bgp_unlock_node (bn);
5038 return;
5039 }
5040 else
5041 {
5042 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005043 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005044
5045 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005046 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5047 bgp_info_restore(bn, bi);
5048 else
5049 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005050 bgp_attr_unintern (bi->attr);
5051 bi->attr = new_attr;
5052 bi->uptime = time (NULL);
5053
5054 /* Process change. */
5055 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5056 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5057 bgp_unlock_node (bn);
5058 aspath_unintern (attr.aspath);
5059 return;
5060 }
5061 }
5062
5063 new = bgp_info_new ();
5064 new->type = type;
5065 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5066 new->peer = bgp->peer_self;
5067 SET_FLAG (new->flags, BGP_INFO_VALID);
5068 new->attr = new_attr;
5069 new->uptime = time (NULL);
5070
5071 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5072 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005073 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005074 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5075 }
5076 }
5077
5078 /* Unintern original. */
5079 aspath_unintern (attr.aspath);
5080}
5081
5082void
5083bgp_redistribute_delete (struct prefix *p, u_char type)
5084{
5085 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005086 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005087 afi_t afi;
5088 struct bgp_node *rn;
5089 struct bgp_info *ri;
5090
paul1eb8ef22005-04-07 07:30:20 +00005091 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005092 {
5093 afi = family2afi (p->family);
5094
5095 if (bgp->redist[afi][type])
5096 {
paulfee0f4c2004-09-13 05:12:46 +00005097 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005098
5099 for (ri = rn->info; ri; ri = ri->next)
5100 if (ri->peer == bgp->peer_self
5101 && ri->type == type)
5102 break;
5103
5104 if (ri)
5105 {
5106 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005107 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005108 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005109 }
5110 bgp_unlock_node (rn);
5111 }
5112 }
5113}
5114
5115/* Withdraw specified route type's route. */
5116void
5117bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5118{
5119 struct bgp_node *rn;
5120 struct bgp_info *ri;
5121 struct bgp_table *table;
5122
5123 table = bgp->rib[afi][SAFI_UNICAST];
5124
5125 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5126 {
5127 for (ri = rn->info; ri; ri = ri->next)
5128 if (ri->peer == bgp->peer_self
5129 && ri->type == type)
5130 break;
5131
5132 if (ri)
5133 {
5134 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005135 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005136 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005137 }
5138 }
5139}
5140
5141/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005142static void
paul718e3742002-12-13 20:15:29 +00005143route_vty_out_route (struct prefix *p, struct vty *vty)
5144{
5145 int len;
5146 u_int32_t destination;
5147 char buf[BUFSIZ];
5148
5149 if (p->family == AF_INET)
5150 {
5151 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5152 destination = ntohl (p->u.prefix4.s_addr);
5153
5154 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5155 || (IN_CLASSB (destination) && p->prefixlen == 16)
5156 || (IN_CLASSA (destination) && p->prefixlen == 8)
5157 || p->u.prefix4.s_addr == 0)
5158 {
5159 /* When mask is natural, mask is not displayed. */
5160 }
5161 else
5162 len += vty_out (vty, "/%d", p->prefixlen);
5163 }
5164 else
5165 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5166 p->prefixlen);
5167
5168 len = 17 - len;
5169 if (len < 1)
5170 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5171 else
5172 vty_out (vty, "%*s", len, " ");
5173}
5174
paul718e3742002-12-13 20:15:29 +00005175enum bgp_display_type
5176{
5177 normal_list,
5178};
5179
paulb40d9392005-08-22 22:34:41 +00005180/* Print the short form route status for a bgp_info */
5181static void
5182route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005183{
paulb40d9392005-08-22 22:34:41 +00005184 /* Route status display. */
5185 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5186 vty_out (vty, "R");
5187 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005188 vty_out (vty, "S");
5189 else if (binfo->suppress)
paul718e3742002-12-13 20:15:29 +00005190 vty_out (vty, "s");
5191 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5192 vty_out (vty, "*");
5193 else
5194 vty_out (vty, " ");
5195
5196 /* Selected */
5197 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5198 vty_out (vty, "h");
5199 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5200 vty_out (vty, "d");
5201 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5202 vty_out (vty, ">");
5203 else
5204 vty_out (vty, " ");
5205
5206 /* Internal route. */
5207 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5208 vty_out (vty, "i");
5209 else
paulb40d9392005-08-22 22:34:41 +00005210 vty_out (vty, " ");
5211}
5212
5213/* called from terminal list command */
5214void
5215route_vty_out (struct vty *vty, struct prefix *p,
5216 struct bgp_info *binfo, int display, safi_t safi)
5217{
5218 struct attr *attr;
5219
5220 /* short status lead text */
5221 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005222
5223 /* print prefix and mask */
5224 if (! display)
5225 route_vty_out_route (p, vty);
5226 else
5227 vty_out (vty, "%*s", 17, " ");
5228
5229 /* Print attribute */
5230 attr = binfo->attr;
5231 if (attr)
5232 {
5233 if (p->family == AF_INET)
5234 {
5235 if (safi == SAFI_MPLS_VPN)
5236 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5237 else
5238 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5239 }
5240#ifdef HAVE_IPV6
5241 else if (p->family == AF_INET6)
5242 {
5243 int len;
5244 char buf[BUFSIZ];
5245
5246 len = vty_out (vty, "%s",
5247 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5248 len = 16 - len;
5249 if (len < 1)
5250 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5251 else
5252 vty_out (vty, "%*s", len, " ");
5253 }
5254#endif /* HAVE_IPV6 */
5255
5256 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5257 vty_out (vty, "%10d", attr->med);
5258 else
5259 vty_out (vty, " ");
5260
5261 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5262 vty_out (vty, "%7d", attr->local_pref);
5263 else
5264 vty_out (vty, " ");
5265
5266 vty_out (vty, "%7u ",attr->weight);
5267
Paul Jakmab2518c12006-05-12 23:48:40 +00005268 /* Print aspath */
5269 if (attr->aspath)
5270 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005271
Paul Jakmab2518c12006-05-12 23:48:40 +00005272 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005273 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005274 }
paul718e3742002-12-13 20:15:29 +00005275 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005276}
5277
5278/* called from terminal list command */
5279void
5280route_vty_out_tmp (struct vty *vty, struct prefix *p,
5281 struct attr *attr, safi_t safi)
5282{
5283 /* Route status display. */
5284 vty_out (vty, "*");
5285 vty_out (vty, ">");
5286 vty_out (vty, " ");
5287
5288 /* print prefix and mask */
5289 route_vty_out_route (p, vty);
5290
5291 /* Print attribute */
5292 if (attr)
5293 {
5294 if (p->family == AF_INET)
5295 {
5296 if (safi == SAFI_MPLS_VPN)
5297 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5298 else
5299 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5300 }
5301#ifdef HAVE_IPV6
5302 else if (p->family == AF_INET6)
5303 {
5304 int len;
5305 char buf[BUFSIZ];
5306
5307 len = vty_out (vty, "%s",
5308 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5309 len = 16 - len;
5310 if (len < 1)
5311 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5312 else
5313 vty_out (vty, "%*s", len, " ");
5314 }
5315#endif /* HAVE_IPV6 */
5316
5317 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5318 vty_out (vty, "%10d", attr->med);
5319 else
5320 vty_out (vty, " ");
5321
5322 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5323 vty_out (vty, "%7d", attr->local_pref);
5324 else
5325 vty_out (vty, " ");
5326
5327 vty_out (vty, "%7d ",attr->weight);
5328
Paul Jakmab2518c12006-05-12 23:48:40 +00005329 /* Print aspath */
5330 if (attr->aspath)
5331 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005332
Paul Jakmab2518c12006-05-12 23:48:40 +00005333 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005334 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005335 }
paul718e3742002-12-13 20:15:29 +00005336
5337 vty_out (vty, "%s", VTY_NEWLINE);
5338}
5339
ajs5a646652004-11-05 01:25:55 +00005340void
paul718e3742002-12-13 20:15:29 +00005341route_vty_out_tag (struct vty *vty, struct prefix *p,
5342 struct bgp_info *binfo, int display, safi_t safi)
5343{
5344 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005345 u_int32_t label = 0;
5346
paulb40d9392005-08-22 22:34:41 +00005347 /* short status lead text */
5348 route_vty_short_status_out (vty, binfo);
5349
paul718e3742002-12-13 20:15:29 +00005350 /* print prefix and mask */
5351 if (! display)
5352 route_vty_out_route (p, vty);
5353 else
5354 vty_out (vty, "%*s", 17, " ");
5355
5356 /* Print attribute */
5357 attr = binfo->attr;
5358 if (attr)
5359 {
5360 if (p->family == AF_INET)
5361 {
5362 if (safi == SAFI_MPLS_VPN)
5363 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
5364 else
5365 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5366 }
5367#ifdef HAVE_IPV6
5368 else if (p->family == AF_INET6)
5369 {
5370 char buf[BUFSIZ];
5371 char buf1[BUFSIZ];
5372 if (attr->mp_nexthop_len == 16)
5373 vty_out (vty, "%s",
5374 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
5375 else if (attr->mp_nexthop_len == 32)
5376 vty_out (vty, "%s(%s)",
5377 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
5378 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
5379
5380 }
5381#endif /* HAVE_IPV6 */
5382 }
5383
5384 label = decode_label (binfo->tag);
5385
5386 vty_out (vty, "notag/%d", label);
5387
5388 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005389}
5390
5391/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005392static void
paul718e3742002-12-13 20:15:29 +00005393damp_route_vty_out (struct vty *vty, struct prefix *p,
5394 struct bgp_info *binfo, int display, safi_t safi)
5395{
5396 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005397 int len;
5398
paulb40d9392005-08-22 22:34:41 +00005399 /* short status lead text */
5400 route_vty_short_status_out (vty, binfo);
5401
paul718e3742002-12-13 20:15:29 +00005402 /* print prefix and mask */
5403 if (! display)
5404 route_vty_out_route (p, vty);
5405 else
5406 vty_out (vty, "%*s", 17, " ");
5407
5408 len = vty_out (vty, "%s", binfo->peer->host);
5409 len = 17 - len;
5410 if (len < 1)
5411 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5412 else
5413 vty_out (vty, "%*s", len, " ");
5414
5415 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5416
5417 /* Print attribute */
5418 attr = binfo->attr;
5419 if (attr)
5420 {
5421 /* Print aspath */
5422 if (attr->aspath)
Paul Jakmab2518c12006-05-12 23:48:40 +00005423 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005424
5425 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005426 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005427 }
5428 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005429}
5430
5431#define BGP_UPTIME_LEN 25
5432
5433/* flap route */
ajs5a646652004-11-05 01:25:55 +00005434static void
paul718e3742002-12-13 20:15:29 +00005435flap_route_vty_out (struct vty *vty, struct prefix *p,
5436 struct bgp_info *binfo, int display, safi_t safi)
5437{
5438 struct attr *attr;
5439 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005440 char timebuf[BGP_UPTIME_LEN];
5441 int len;
5442
paul718e3742002-12-13 20:15:29 +00005443 bdi = binfo->damp_info;
5444
paulb40d9392005-08-22 22:34:41 +00005445 /* short status lead text */
5446 route_vty_short_status_out (vty, binfo);
5447
paul718e3742002-12-13 20:15:29 +00005448 /* print prefix and mask */
5449 if (! display)
5450 route_vty_out_route (p, vty);
5451 else
5452 vty_out (vty, "%*s", 17, " ");
5453
5454 len = vty_out (vty, "%s", binfo->peer->host);
5455 len = 16 - len;
5456 if (len < 1)
5457 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5458 else
5459 vty_out (vty, "%*s", len, " ");
5460
5461 len = vty_out (vty, "%d", bdi->flap);
5462 len = 5 - len;
5463 if (len < 1)
5464 vty_out (vty, " ");
5465 else
5466 vty_out (vty, "%*s ", len, " ");
5467
5468 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5469 timebuf, BGP_UPTIME_LEN));
5470
5471 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5472 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5473 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5474 else
5475 vty_out (vty, "%*s ", 8, " ");
5476
5477 /* Print attribute */
5478 attr = binfo->attr;
5479 if (attr)
5480 {
5481 /* Print aspath */
5482 if (attr->aspath)
Paul Jakmab2518c12006-05-12 23:48:40 +00005483 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005484
5485 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005486 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005487 }
5488 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005489}
5490
paul94f2b392005-06-28 12:44:16 +00005491static void
paul718e3742002-12-13 20:15:29 +00005492route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5493 struct bgp_info *binfo, afi_t afi, safi_t safi)
5494{
5495 char buf[INET6_ADDRSTRLEN];
5496 char buf1[BUFSIZ];
5497 struct attr *attr;
5498 int sockunion_vty_out (struct vty *, union sockunion *);
5499
5500 attr = binfo->attr;
5501
5502 if (attr)
5503 {
5504 /* Line1 display AS-path, Aggregator */
5505 if (attr->aspath)
5506 {
5507 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005508 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005509 vty_out (vty, "Local");
5510 else
Paul Jakmab2518c12006-05-12 23:48:40 +00005511 aspath_print_vty (vty, "%s", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005512 }
5513
paulb40d9392005-08-22 22:34:41 +00005514 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5515 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005516 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5517 vty_out (vty, ", (stale)");
5518 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
5519 vty_out (vty, ", (aggregated by %d %s)", attr->aggregator_as,
5520 inet_ntoa (attr->aggregator_addr));
5521 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5522 vty_out (vty, ", (Received from a RR-client)");
5523 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5524 vty_out (vty, ", (Received from a RS-client)");
5525 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5526 vty_out (vty, ", (history entry)");
5527 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5528 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005529 vty_out (vty, "%s", VTY_NEWLINE);
5530
5531 /* Line2 display Next-hop, Neighbor, Router-id */
5532 if (p->family == AF_INET)
5533 {
5534 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5535 inet_ntoa (attr->mp_nexthop_global_in) :
5536 inet_ntoa (attr->nexthop));
5537 }
5538#ifdef HAVE_IPV6
5539 else
5540 {
5541 vty_out (vty, " %s",
5542 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5543 buf, INET6_ADDRSTRLEN));
5544 }
5545#endif /* HAVE_IPV6 */
5546
5547 if (binfo->peer == bgp->peer_self)
5548 {
5549 vty_out (vty, " from %s ",
5550 p->family == AF_INET ? "0.0.0.0" : "::");
5551 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5552 }
5553 else
5554 {
5555 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5556 vty_out (vty, " (inaccessible)");
5557 else if (binfo->igpmetric)
5558 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005559 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005560 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5561 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5562 else
5563 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5564 }
5565 vty_out (vty, "%s", VTY_NEWLINE);
5566
5567#ifdef HAVE_IPV6
5568 /* display nexthop local */
5569 if (attr->mp_nexthop_len == 32)
5570 {
5571 vty_out (vty, " (%s)%s",
5572 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5573 buf, INET6_ADDRSTRLEN),
5574 VTY_NEWLINE);
5575 }
5576#endif /* HAVE_IPV6 */
5577
5578 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5579 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5580
5581 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5582 vty_out (vty, ", metric %d", attr->med);
5583
5584 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5585 vty_out (vty, ", localpref %d", attr->local_pref);
5586 else
5587 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5588
5589 if (attr->weight != 0)
5590 vty_out (vty, ", weight %d", attr->weight);
5591
5592 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5593 vty_out (vty, ", valid");
5594
5595 if (binfo->peer != bgp->peer_self)
5596 {
5597 if (binfo->peer->as == binfo->peer->local_as)
5598 vty_out (vty, ", internal");
5599 else
5600 vty_out (vty, ", %s",
5601 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5602 }
5603 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5604 vty_out (vty, ", aggregated, local");
5605 else if (binfo->type != ZEBRA_ROUTE_BGP)
5606 vty_out (vty, ", sourced");
5607 else
5608 vty_out (vty, ", sourced, local");
5609
5610 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5611 vty_out (vty, ", atomic-aggregate");
5612
5613 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5614 vty_out (vty, ", best");
5615
5616 vty_out (vty, "%s", VTY_NEWLINE);
5617
5618 /* Line 4 display Community */
5619 if (attr->community)
5620 vty_out (vty, " Community: %s%s", attr->community->str,
5621 VTY_NEWLINE);
5622
5623 /* Line 5 display Extended-community */
5624 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5625 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5626 VTY_NEWLINE);
5627
5628 /* Line 6 display Originator, Cluster-id */
5629 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5630 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5631 {
5632 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5633 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5634
5635 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5636 {
5637 int i;
5638 vty_out (vty, ", Cluster list: ");
5639 for (i = 0; i < attr->cluster->length / 4; i++)
5640 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5641 }
5642 vty_out (vty, "%s", VTY_NEWLINE);
5643 }
5644
5645 if (binfo->damp_info)
5646 bgp_damp_info_vty (vty, binfo);
5647
5648 /* Line 7 display Uptime */
5649 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5650 }
5651 vty_out (vty, "%s", VTY_NEWLINE);
5652}
5653
paulb40d9392005-08-22 22:34:41 +00005654#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 +00005655#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005656#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5657#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5658#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5659
5660enum bgp_show_type
5661{
5662 bgp_show_type_normal,
5663 bgp_show_type_regexp,
5664 bgp_show_type_prefix_list,
5665 bgp_show_type_filter_list,
5666 bgp_show_type_route_map,
5667 bgp_show_type_neighbor,
5668 bgp_show_type_cidr_only,
5669 bgp_show_type_prefix_longer,
5670 bgp_show_type_community_all,
5671 bgp_show_type_community,
5672 bgp_show_type_community_exact,
5673 bgp_show_type_community_list,
5674 bgp_show_type_community_list_exact,
5675 bgp_show_type_flap_statistics,
5676 bgp_show_type_flap_address,
5677 bgp_show_type_flap_prefix,
5678 bgp_show_type_flap_cidr_only,
5679 bgp_show_type_flap_regexp,
5680 bgp_show_type_flap_filter_list,
5681 bgp_show_type_flap_prefix_list,
5682 bgp_show_type_flap_prefix_longer,
5683 bgp_show_type_flap_route_map,
5684 bgp_show_type_flap_neighbor,
5685 bgp_show_type_dampend_paths,
5686 bgp_show_type_damp_neighbor
5687};
5688
ajs5a646652004-11-05 01:25:55 +00005689static int
paulfee0f4c2004-09-13 05:12:46 +00005690bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00005691 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00005692{
paul718e3742002-12-13 20:15:29 +00005693 struct bgp_info *ri;
5694 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005695 int header = 1;
paul718e3742002-12-13 20:15:29 +00005696 int display;
ajs5a646652004-11-05 01:25:55 +00005697 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00005698
5699 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00005700 output_count = 0;
paul718e3742002-12-13 20:15:29 +00005701
paul718e3742002-12-13 20:15:29 +00005702 /* Start processing of routes. */
5703 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5704 if (rn->info != NULL)
5705 {
5706 display = 0;
5707
5708 for (ri = rn->info; ri; ri = ri->next)
5709 {
ajs5a646652004-11-05 01:25:55 +00005710 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00005711 || type == bgp_show_type_flap_address
5712 || type == bgp_show_type_flap_prefix
5713 || type == bgp_show_type_flap_cidr_only
5714 || type == bgp_show_type_flap_regexp
5715 || type == bgp_show_type_flap_filter_list
5716 || type == bgp_show_type_flap_prefix_list
5717 || type == bgp_show_type_flap_prefix_longer
5718 || type == bgp_show_type_flap_route_map
5719 || type == bgp_show_type_flap_neighbor
5720 || type == bgp_show_type_dampend_paths
5721 || type == bgp_show_type_damp_neighbor)
5722 {
5723 if (! ri->damp_info)
5724 continue;
5725 }
5726 if (type == bgp_show_type_regexp
5727 || type == bgp_show_type_flap_regexp)
5728 {
ajs5a646652004-11-05 01:25:55 +00005729 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00005730
5731 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5732 continue;
5733 }
5734 if (type == bgp_show_type_prefix_list
5735 || type == bgp_show_type_flap_prefix_list)
5736 {
ajs5a646652004-11-05 01:25:55 +00005737 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00005738
5739 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5740 continue;
5741 }
5742 if (type == bgp_show_type_filter_list
5743 || type == bgp_show_type_flap_filter_list)
5744 {
ajs5a646652004-11-05 01:25:55 +00005745 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00005746
5747 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5748 continue;
5749 }
5750 if (type == bgp_show_type_route_map
5751 || type == bgp_show_type_flap_route_map)
5752 {
ajs5a646652004-11-05 01:25:55 +00005753 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00005754 struct bgp_info binfo;
5755 struct attr dummy_attr;
5756 int ret;
5757
5758 dummy_attr = *ri->attr;
5759 binfo.peer = ri->peer;
5760 binfo.attr = &dummy_attr;
5761
5762 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5763
5764 if (ret == RMAP_DENYMATCH)
5765 continue;
5766 }
5767 if (type == bgp_show_type_neighbor
5768 || type == bgp_show_type_flap_neighbor
5769 || type == bgp_show_type_damp_neighbor)
5770 {
ajs5a646652004-11-05 01:25:55 +00005771 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00005772
5773 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5774 continue;
5775 }
5776 if (type == bgp_show_type_cidr_only
5777 || type == bgp_show_type_flap_cidr_only)
5778 {
5779 u_int32_t destination;
5780
5781 destination = ntohl (rn->p.u.prefix4.s_addr);
5782 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5783 continue;
5784 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5785 continue;
5786 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5787 continue;
5788 }
5789 if (type == bgp_show_type_prefix_longer
5790 || type == bgp_show_type_flap_prefix_longer)
5791 {
ajs5a646652004-11-05 01:25:55 +00005792 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005793
5794 if (! prefix_match (p, &rn->p))
5795 continue;
5796 }
5797 if (type == bgp_show_type_community_all)
5798 {
5799 if (! ri->attr->community)
5800 continue;
5801 }
5802 if (type == bgp_show_type_community)
5803 {
ajs5a646652004-11-05 01:25:55 +00005804 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005805
5806 if (! ri->attr->community ||
5807 ! community_match (ri->attr->community, com))
5808 continue;
5809 }
5810 if (type == bgp_show_type_community_exact)
5811 {
ajs5a646652004-11-05 01:25:55 +00005812 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005813
5814 if (! ri->attr->community ||
5815 ! community_cmp (ri->attr->community, com))
5816 continue;
5817 }
5818 if (type == bgp_show_type_community_list)
5819 {
ajs5a646652004-11-05 01:25:55 +00005820 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005821
5822 if (! community_list_match (ri->attr->community, list))
5823 continue;
5824 }
5825 if (type == bgp_show_type_community_list_exact)
5826 {
ajs5a646652004-11-05 01:25:55 +00005827 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005828
5829 if (! community_list_exact_match (ri->attr->community, list))
5830 continue;
5831 }
5832 if (type == bgp_show_type_flap_address
5833 || type == bgp_show_type_flap_prefix)
5834 {
ajs5a646652004-11-05 01:25:55 +00005835 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005836
5837 if (! prefix_match (&rn->p, p))
5838 continue;
5839
5840 if (type == bgp_show_type_flap_prefix)
5841 if (p->prefixlen != rn->p.prefixlen)
5842 continue;
5843 }
5844 if (type == bgp_show_type_dampend_paths
5845 || type == bgp_show_type_damp_neighbor)
5846 {
5847 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5848 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5849 continue;
5850 }
5851
5852 if (header)
5853 {
hasso93406d82005-02-02 14:40:33 +00005854 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
5855 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
5856 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005857 if (type == bgp_show_type_dampend_paths
5858 || type == bgp_show_type_damp_neighbor)
5859 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5860 else if (type == bgp_show_type_flap_statistics
5861 || type == bgp_show_type_flap_address
5862 || type == bgp_show_type_flap_prefix
5863 || type == bgp_show_type_flap_cidr_only
5864 || type == bgp_show_type_flap_regexp
5865 || type == bgp_show_type_flap_filter_list
5866 || type == bgp_show_type_flap_prefix_list
5867 || type == bgp_show_type_flap_prefix_longer
5868 || type == bgp_show_type_flap_route_map
5869 || type == bgp_show_type_flap_neighbor)
5870 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5871 else
5872 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005873 header = 0;
5874 }
5875
5876 if (type == bgp_show_type_dampend_paths
5877 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00005878 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005879 else if (type == bgp_show_type_flap_statistics
5880 || type == bgp_show_type_flap_address
5881 || type == bgp_show_type_flap_prefix
5882 || type == bgp_show_type_flap_cidr_only
5883 || type == bgp_show_type_flap_regexp
5884 || type == bgp_show_type_flap_filter_list
5885 || type == bgp_show_type_flap_prefix_list
5886 || type == bgp_show_type_flap_prefix_longer
5887 || type == bgp_show_type_flap_route_map
5888 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00005889 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005890 else
ajs5a646652004-11-05 01:25:55 +00005891 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005892 display++;
5893 }
5894 if (display)
ajs5a646652004-11-05 01:25:55 +00005895 output_count++;
paul718e3742002-12-13 20:15:29 +00005896 }
5897
5898 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00005899 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00005900 {
5901 if (type == bgp_show_type_normal)
5902 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5903 }
5904 else
5905 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00005906 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005907
5908 return CMD_SUCCESS;
5909}
5910
ajs5a646652004-11-05 01:25:55 +00005911static int
paulfee0f4c2004-09-13 05:12:46 +00005912bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00005913 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00005914{
5915 struct bgp_table *table;
5916
5917 if (bgp == NULL) {
5918 bgp = bgp_get_default ();
5919 }
5920
5921 if (bgp == NULL)
5922 {
5923 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5924 return CMD_WARNING;
5925 }
5926
5927
5928 table = bgp->rib[afi][safi];
5929
ajs5a646652004-11-05 01:25:55 +00005930 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00005931}
5932
paul718e3742002-12-13 20:15:29 +00005933/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00005934static void
paul718e3742002-12-13 20:15:29 +00005935route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5936 struct bgp_node *rn,
5937 struct prefix_rd *prd, afi_t afi, safi_t safi)
5938{
5939 struct bgp_info *ri;
5940 struct prefix *p;
5941 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00005942 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005943 char buf1[INET6_ADDRSTRLEN];
5944 char buf2[INET6_ADDRSTRLEN];
5945 int count = 0;
5946 int best = 0;
5947 int suppress = 0;
5948 int no_export = 0;
5949 int no_advertise = 0;
5950 int local_as = 0;
5951 int first = 0;
5952
5953 p = &rn->p;
5954 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5955 (safi == SAFI_MPLS_VPN ?
5956 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5957 safi == SAFI_MPLS_VPN ? ":" : "",
5958 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5959 p->prefixlen, VTY_NEWLINE);
5960
5961 for (ri = rn->info; ri; ri = ri->next)
5962 {
5963 count++;
5964 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5965 {
5966 best = count;
5967 if (ri->suppress)
5968 suppress = 1;
5969 if (ri->attr->community != NULL)
5970 {
5971 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5972 no_advertise = 1;
5973 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5974 no_export = 1;
5975 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5976 local_as = 1;
5977 }
5978 }
5979 }
5980
5981 vty_out (vty, "Paths: (%d available", count);
5982 if (best)
5983 {
5984 vty_out (vty, ", best #%d", best);
5985 if (safi == SAFI_UNICAST)
5986 vty_out (vty, ", table Default-IP-Routing-Table");
5987 }
5988 else
5989 vty_out (vty, ", no best path");
5990 if (no_advertise)
5991 vty_out (vty, ", not advertised to any peer");
5992 else if (no_export)
5993 vty_out (vty, ", not advertised to EBGP peer");
5994 else if (local_as)
5995 vty_out (vty, ", not advertised outside local AS");
5996 if (suppress)
5997 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5998 vty_out (vty, ")%s", VTY_NEWLINE);
5999
6000 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006001 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006002 {
6003 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6004 {
6005 if (! first)
6006 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6007 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6008 first = 1;
6009 }
6010 }
6011 if (! first)
6012 vty_out (vty, " Not advertised to any peer");
6013 vty_out (vty, "%s", VTY_NEWLINE);
6014}
6015
6016/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006017static int
paulfee0f4c2004-09-13 05:12:46 +00006018bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006019 struct bgp_table *rib, const char *ip_str,
6020 afi_t afi, safi_t safi, struct prefix_rd *prd,
6021 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006022{
6023 int ret;
6024 int header;
6025 int display = 0;
6026 struct prefix match;
6027 struct bgp_node *rn;
6028 struct bgp_node *rm;
6029 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006030 struct bgp_table *table;
6031
paul718e3742002-12-13 20:15:29 +00006032 /* Check IP address argument. */
6033 ret = str2prefix (ip_str, &match);
6034 if (! ret)
6035 {
6036 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6037 return CMD_WARNING;
6038 }
6039
6040 match.family = afi2family (afi);
6041
6042 if (safi == SAFI_MPLS_VPN)
6043 {
paulfee0f4c2004-09-13 05:12:46 +00006044 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006045 {
6046 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6047 continue;
6048
6049 if ((table = rn->info) != NULL)
6050 {
6051 header = 1;
6052
6053 if ((rm = bgp_node_match (table, &match)) != NULL)
6054 {
6055 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6056 continue;
6057
6058 for (ri = rm->info; ri; ri = ri->next)
6059 {
6060 if (header)
6061 {
6062 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6063 AFI_IP, SAFI_MPLS_VPN);
6064
6065 header = 0;
6066 }
6067 display++;
6068 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6069 }
6070 }
6071 }
6072 }
6073 }
6074 else
6075 {
6076 header = 1;
6077
paulfee0f4c2004-09-13 05:12:46 +00006078 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006079 {
6080 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6081 {
6082 for (ri = rn->info; ri; ri = ri->next)
6083 {
6084 if (header)
6085 {
6086 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6087 header = 0;
6088 }
6089 display++;
6090 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6091 }
6092 }
6093 }
6094 }
6095
6096 if (! display)
6097 {
6098 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6099 return CMD_WARNING;
6100 }
6101
6102 return CMD_SUCCESS;
6103}
6104
paulfee0f4c2004-09-13 05:12:46 +00006105/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006106static int
paulfd79ac92004-10-13 05:06:08 +00006107bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006108 afi_t afi, safi_t safi, struct prefix_rd *prd,
6109 int prefix_check)
6110{
6111 struct bgp *bgp;
6112
6113 /* BGP structure lookup. */
6114 if (view_name)
6115 {
6116 bgp = bgp_lookup_by_name (view_name);
6117 if (bgp == NULL)
6118 {
6119 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6120 return CMD_WARNING;
6121 }
6122 }
6123 else
6124 {
6125 bgp = bgp_get_default ();
6126 if (bgp == NULL)
6127 {
6128 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6129 return CMD_WARNING;
6130 }
6131 }
6132
6133 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6134 afi, safi, prd, prefix_check);
6135}
6136
paul718e3742002-12-13 20:15:29 +00006137/* BGP route print out function. */
6138DEFUN (show_ip_bgp,
6139 show_ip_bgp_cmd,
6140 "show ip bgp",
6141 SHOW_STR
6142 IP_STR
6143 BGP_STR)
6144{
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_ipv4,
6149 show_ip_bgp_ipv4_cmd,
6150 "show ip bgp ipv4 (unicast|multicast)",
6151 SHOW_STR
6152 IP_STR
6153 BGP_STR
6154 "Address family\n"
6155 "Address Family modifier\n"
6156 "Address Family modifier\n")
6157{
6158 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006159 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6160 NULL);
paul718e3742002-12-13 20:15:29 +00006161
ajs5a646652004-11-05 01:25:55 +00006162 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006163}
6164
6165DEFUN (show_ip_bgp_route,
6166 show_ip_bgp_route_cmd,
6167 "show ip bgp A.B.C.D",
6168 SHOW_STR
6169 IP_STR
6170 BGP_STR
6171 "Network in the BGP routing table to display\n")
6172{
6173 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6174}
6175
6176DEFUN (show_ip_bgp_ipv4_route,
6177 show_ip_bgp_ipv4_route_cmd,
6178 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6179 SHOW_STR
6180 IP_STR
6181 BGP_STR
6182 "Address family\n"
6183 "Address Family modifier\n"
6184 "Address Family modifier\n"
6185 "Network in the BGP routing table to display\n")
6186{
6187 if (strncmp (argv[0], "m", 1) == 0)
6188 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6189
6190 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6191}
6192
6193DEFUN (show_ip_bgp_vpnv4_all_route,
6194 show_ip_bgp_vpnv4_all_route_cmd,
6195 "show ip bgp vpnv4 all A.B.C.D",
6196 SHOW_STR
6197 IP_STR
6198 BGP_STR
6199 "Display VPNv4 NLRI specific information\n"
6200 "Display information about all VPNv4 NLRIs\n"
6201 "Network in the BGP routing table to display\n")
6202{
6203 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6204}
6205
6206DEFUN (show_ip_bgp_vpnv4_rd_route,
6207 show_ip_bgp_vpnv4_rd_route_cmd,
6208 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6209 SHOW_STR
6210 IP_STR
6211 BGP_STR
6212 "Display VPNv4 NLRI specific information\n"
6213 "Display information for a route distinguisher\n"
6214 "VPN Route Distinguisher\n"
6215 "Network in the BGP routing table to display\n")
6216{
6217 int ret;
6218 struct prefix_rd prd;
6219
6220 ret = str2prefix_rd (argv[0], &prd);
6221 if (! ret)
6222 {
6223 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6224 return CMD_WARNING;
6225 }
6226 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6227}
6228
6229DEFUN (show_ip_bgp_prefix,
6230 show_ip_bgp_prefix_cmd,
6231 "show ip bgp A.B.C.D/M",
6232 SHOW_STR
6233 IP_STR
6234 BGP_STR
6235 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6236{
6237 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6238}
6239
6240DEFUN (show_ip_bgp_ipv4_prefix,
6241 show_ip_bgp_ipv4_prefix_cmd,
6242 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6243 SHOW_STR
6244 IP_STR
6245 BGP_STR
6246 "Address family\n"
6247 "Address Family modifier\n"
6248 "Address Family modifier\n"
6249 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6250{
6251 if (strncmp (argv[0], "m", 1) == 0)
6252 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6253
6254 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6255}
6256
6257DEFUN (show_ip_bgp_vpnv4_all_prefix,
6258 show_ip_bgp_vpnv4_all_prefix_cmd,
6259 "show ip bgp vpnv4 all A.B.C.D/M",
6260 SHOW_STR
6261 IP_STR
6262 BGP_STR
6263 "Display VPNv4 NLRI specific information\n"
6264 "Display information about all VPNv4 NLRIs\n"
6265 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6266{
6267 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6268}
6269
6270DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6271 show_ip_bgp_vpnv4_rd_prefix_cmd,
6272 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6273 SHOW_STR
6274 IP_STR
6275 BGP_STR
6276 "Display VPNv4 NLRI specific information\n"
6277 "Display information for a route distinguisher\n"
6278 "VPN Route Distinguisher\n"
6279 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6280{
6281 int ret;
6282 struct prefix_rd prd;
6283
6284 ret = str2prefix_rd (argv[0], &prd);
6285 if (! ret)
6286 {
6287 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6288 return CMD_WARNING;
6289 }
6290 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6291}
6292
6293DEFUN (show_ip_bgp_view,
6294 show_ip_bgp_view_cmd,
6295 "show ip bgp view WORD",
6296 SHOW_STR
6297 IP_STR
6298 BGP_STR
6299 "BGP view\n"
6300 "BGP view name\n")
6301{
paulbb46e942003-10-24 19:02:03 +00006302 struct bgp *bgp;
6303
6304 /* BGP structure lookup. */
6305 bgp = bgp_lookup_by_name (argv[0]);
6306 if (bgp == NULL)
6307 {
6308 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6309 return CMD_WARNING;
6310 }
6311
ajs5a646652004-11-05 01:25:55 +00006312 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006313}
6314
6315DEFUN (show_ip_bgp_view_route,
6316 show_ip_bgp_view_route_cmd,
6317 "show ip bgp view WORD A.B.C.D",
6318 SHOW_STR
6319 IP_STR
6320 BGP_STR
6321 "BGP view\n"
6322 "BGP view name\n"
6323 "Network in the BGP routing table to display\n")
6324{
6325 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6326}
6327
6328DEFUN (show_ip_bgp_view_prefix,
6329 show_ip_bgp_view_prefix_cmd,
6330 "show ip bgp view WORD A.B.C.D/M",
6331 SHOW_STR
6332 IP_STR
6333 BGP_STR
6334 "BGP view\n"
6335 "BGP view name\n"
6336 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6337{
6338 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6339}
6340
6341#ifdef HAVE_IPV6
6342DEFUN (show_bgp,
6343 show_bgp_cmd,
6344 "show bgp",
6345 SHOW_STR
6346 BGP_STR)
6347{
ajs5a646652004-11-05 01:25:55 +00006348 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6349 NULL);
paul718e3742002-12-13 20:15:29 +00006350}
6351
6352ALIAS (show_bgp,
6353 show_bgp_ipv6_cmd,
6354 "show bgp ipv6",
6355 SHOW_STR
6356 BGP_STR
6357 "Address family\n")
6358
6359/* old command */
6360DEFUN (show_ipv6_bgp,
6361 show_ipv6_bgp_cmd,
6362 "show ipv6 bgp",
6363 SHOW_STR
6364 IP_STR
6365 BGP_STR)
6366{
ajs5a646652004-11-05 01:25:55 +00006367 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6368 NULL);
paul718e3742002-12-13 20:15:29 +00006369}
6370
6371DEFUN (show_bgp_route,
6372 show_bgp_route_cmd,
6373 "show bgp X:X::X:X",
6374 SHOW_STR
6375 BGP_STR
6376 "Network in the BGP routing table to display\n")
6377{
6378 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6379}
6380
6381ALIAS (show_bgp_route,
6382 show_bgp_ipv6_route_cmd,
6383 "show bgp ipv6 X:X::X:X",
6384 SHOW_STR
6385 BGP_STR
6386 "Address family\n"
6387 "Network in the BGP routing table to display\n")
6388
6389/* old command */
6390DEFUN (show_ipv6_bgp_route,
6391 show_ipv6_bgp_route_cmd,
6392 "show ipv6 bgp X:X::X:X",
6393 SHOW_STR
6394 IP_STR
6395 BGP_STR
6396 "Network in the BGP routing table to display\n")
6397{
6398 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6399}
6400
6401DEFUN (show_bgp_prefix,
6402 show_bgp_prefix_cmd,
6403 "show bgp X:X::X:X/M",
6404 SHOW_STR
6405 BGP_STR
6406 "IPv6 prefix <network>/<length>\n")
6407{
6408 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6409}
6410
6411ALIAS (show_bgp_prefix,
6412 show_bgp_ipv6_prefix_cmd,
6413 "show bgp ipv6 X:X::X:X/M",
6414 SHOW_STR
6415 BGP_STR
6416 "Address family\n"
6417 "IPv6 prefix <network>/<length>\n")
6418
6419/* old command */
6420DEFUN (show_ipv6_bgp_prefix,
6421 show_ipv6_bgp_prefix_cmd,
6422 "show ipv6 bgp X:X::X:X/M",
6423 SHOW_STR
6424 IP_STR
6425 BGP_STR
6426 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6427{
6428 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6429}
6430
paulbb46e942003-10-24 19:02:03 +00006431DEFUN (show_bgp_view,
6432 show_bgp_view_cmd,
6433 "show bgp view WORD",
6434 SHOW_STR
6435 BGP_STR
6436 "BGP view\n"
6437 "View name\n")
6438{
6439 struct bgp *bgp;
6440
6441 /* BGP structure lookup. */
6442 bgp = bgp_lookup_by_name (argv[0]);
6443 if (bgp == NULL)
6444 {
6445 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6446 return CMD_WARNING;
6447 }
6448
ajs5a646652004-11-05 01:25:55 +00006449 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006450}
6451
6452ALIAS (show_bgp_view,
6453 show_bgp_view_ipv6_cmd,
6454 "show bgp view WORD ipv6",
6455 SHOW_STR
6456 BGP_STR
6457 "BGP view\n"
6458 "View name\n"
6459 "Address family\n")
6460
6461DEFUN (show_bgp_view_route,
6462 show_bgp_view_route_cmd,
6463 "show bgp view WORD X:X::X:X",
6464 SHOW_STR
6465 BGP_STR
6466 "BGP view\n"
6467 "View name\n"
6468 "Network in the BGP routing table to display\n")
6469{
6470 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6471}
6472
6473ALIAS (show_bgp_view_route,
6474 show_bgp_view_ipv6_route_cmd,
6475 "show bgp view WORD ipv6 X:X::X:X",
6476 SHOW_STR
6477 BGP_STR
6478 "BGP view\n"
6479 "View name\n"
6480 "Address family\n"
6481 "Network in the BGP routing table to display\n")
6482
6483DEFUN (show_bgp_view_prefix,
6484 show_bgp_view_prefix_cmd,
6485 "show bgp view WORD X:X::X:X/M",
6486 SHOW_STR
6487 BGP_STR
6488 "BGP view\n"
6489 "View name\n"
6490 "IPv6 prefix <network>/<length>\n")
6491{
6492 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6493}
6494
6495ALIAS (show_bgp_view_prefix,
6496 show_bgp_view_ipv6_prefix_cmd,
6497 "show bgp view WORD ipv6 X:X::X:X/M",
6498 SHOW_STR
6499 BGP_STR
6500 "BGP view\n"
6501 "View name\n"
6502 "Address family\n"
6503 "IPv6 prefix <network>/<length>\n")
6504
paul718e3742002-12-13 20:15:29 +00006505/* old command */
6506DEFUN (show_ipv6_mbgp,
6507 show_ipv6_mbgp_cmd,
6508 "show ipv6 mbgp",
6509 SHOW_STR
6510 IP_STR
6511 MBGP_STR)
6512{
ajs5a646652004-11-05 01:25:55 +00006513 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6514 NULL);
paul718e3742002-12-13 20:15:29 +00006515}
6516
6517/* old command */
6518DEFUN (show_ipv6_mbgp_route,
6519 show_ipv6_mbgp_route_cmd,
6520 "show ipv6 mbgp X:X::X:X",
6521 SHOW_STR
6522 IP_STR
6523 MBGP_STR
6524 "Network in the MBGP routing table to display\n")
6525{
6526 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6527}
6528
6529/* old command */
6530DEFUN (show_ipv6_mbgp_prefix,
6531 show_ipv6_mbgp_prefix_cmd,
6532 "show ipv6 mbgp X:X::X:X/M",
6533 SHOW_STR
6534 IP_STR
6535 MBGP_STR
6536 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6537{
6538 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6539}
6540#endif
6541
paul718e3742002-12-13 20:15:29 +00006542
paul94f2b392005-06-28 12:44:16 +00006543static int
paulfd79ac92004-10-13 05:06:08 +00006544bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006545 safi_t safi, enum bgp_show_type type)
6546{
6547 int i;
6548 struct buffer *b;
6549 char *regstr;
6550 int first;
6551 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006552 int rc;
paul718e3742002-12-13 20:15:29 +00006553
6554 first = 0;
6555 b = buffer_new (1024);
6556 for (i = 0; i < argc; i++)
6557 {
6558 if (first)
6559 buffer_putc (b, ' ');
6560 else
6561 {
6562 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6563 continue;
6564 first = 1;
6565 }
6566
6567 buffer_putstr (b, argv[i]);
6568 }
6569 buffer_putc (b, '\0');
6570
6571 regstr = buffer_getstr (b);
6572 buffer_free (b);
6573
6574 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006575 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006576 if (! regex)
6577 {
6578 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6579 VTY_NEWLINE);
6580 return CMD_WARNING;
6581 }
6582
ajs5a646652004-11-05 01:25:55 +00006583 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6584 bgp_regex_free (regex);
6585 return rc;
paul718e3742002-12-13 20:15:29 +00006586}
6587
6588DEFUN (show_ip_bgp_regexp,
6589 show_ip_bgp_regexp_cmd,
6590 "show ip bgp regexp .LINE",
6591 SHOW_STR
6592 IP_STR
6593 BGP_STR
6594 "Display routes matching the AS path regular expression\n"
6595 "A regular-expression to match the BGP AS paths\n")
6596{
6597 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6598 bgp_show_type_regexp);
6599}
6600
6601DEFUN (show_ip_bgp_flap_regexp,
6602 show_ip_bgp_flap_regexp_cmd,
6603 "show ip bgp flap-statistics regexp .LINE",
6604 SHOW_STR
6605 IP_STR
6606 BGP_STR
6607 "Display flap statistics of routes\n"
6608 "Display routes matching the AS path regular expression\n"
6609 "A regular-expression to match the BGP AS paths\n")
6610{
6611 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6612 bgp_show_type_flap_regexp);
6613}
6614
6615DEFUN (show_ip_bgp_ipv4_regexp,
6616 show_ip_bgp_ipv4_regexp_cmd,
6617 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6618 SHOW_STR
6619 IP_STR
6620 BGP_STR
6621 "Address family\n"
6622 "Address Family modifier\n"
6623 "Address Family modifier\n"
6624 "Display routes matching the AS path regular expression\n"
6625 "A regular-expression to match the BGP AS paths\n")
6626{
6627 if (strncmp (argv[0], "m", 1) == 0)
6628 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6629 bgp_show_type_regexp);
6630
6631 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6632 bgp_show_type_regexp);
6633}
6634
6635#ifdef HAVE_IPV6
6636DEFUN (show_bgp_regexp,
6637 show_bgp_regexp_cmd,
6638 "show bgp regexp .LINE",
6639 SHOW_STR
6640 BGP_STR
6641 "Display routes matching the AS path regular expression\n"
6642 "A regular-expression to match the BGP AS paths\n")
6643{
6644 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6645 bgp_show_type_regexp);
6646}
6647
6648ALIAS (show_bgp_regexp,
6649 show_bgp_ipv6_regexp_cmd,
6650 "show bgp ipv6 regexp .LINE",
6651 SHOW_STR
6652 BGP_STR
6653 "Address family\n"
6654 "Display routes matching the AS path regular expression\n"
6655 "A regular-expression to match the BGP AS paths\n")
6656
6657/* old command */
6658DEFUN (show_ipv6_bgp_regexp,
6659 show_ipv6_bgp_regexp_cmd,
6660 "show ipv6 bgp regexp .LINE",
6661 SHOW_STR
6662 IP_STR
6663 BGP_STR
6664 "Display routes matching the AS path regular expression\n"
6665 "A regular-expression to match the BGP AS paths\n")
6666{
6667 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6668 bgp_show_type_regexp);
6669}
6670
6671/* old command */
6672DEFUN (show_ipv6_mbgp_regexp,
6673 show_ipv6_mbgp_regexp_cmd,
6674 "show ipv6 mbgp regexp .LINE",
6675 SHOW_STR
6676 IP_STR
6677 BGP_STR
6678 "Display routes matching the AS path regular expression\n"
6679 "A regular-expression to match the MBGP AS paths\n")
6680{
6681 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6682 bgp_show_type_regexp);
6683}
6684#endif /* HAVE_IPV6 */
6685
paul94f2b392005-06-28 12:44:16 +00006686static int
paulfd79ac92004-10-13 05:06:08 +00006687bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006688 safi_t safi, enum bgp_show_type type)
6689{
6690 struct prefix_list *plist;
6691
6692 plist = prefix_list_lookup (afi, prefix_list_str);
6693 if (plist == NULL)
6694 {
6695 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6696 prefix_list_str, VTY_NEWLINE);
6697 return CMD_WARNING;
6698 }
6699
ajs5a646652004-11-05 01:25:55 +00006700 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00006701}
6702
6703DEFUN (show_ip_bgp_prefix_list,
6704 show_ip_bgp_prefix_list_cmd,
6705 "show ip bgp prefix-list WORD",
6706 SHOW_STR
6707 IP_STR
6708 BGP_STR
6709 "Display routes conforming to the prefix-list\n"
6710 "IP prefix-list name\n")
6711{
6712 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6713 bgp_show_type_prefix_list);
6714}
6715
6716DEFUN (show_ip_bgp_flap_prefix_list,
6717 show_ip_bgp_flap_prefix_list_cmd,
6718 "show ip bgp flap-statistics prefix-list WORD",
6719 SHOW_STR
6720 IP_STR
6721 BGP_STR
6722 "Display flap statistics of routes\n"
6723 "Display routes conforming to the prefix-list\n"
6724 "IP prefix-list name\n")
6725{
6726 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6727 bgp_show_type_flap_prefix_list);
6728}
6729
6730DEFUN (show_ip_bgp_ipv4_prefix_list,
6731 show_ip_bgp_ipv4_prefix_list_cmd,
6732 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6733 SHOW_STR
6734 IP_STR
6735 BGP_STR
6736 "Address family\n"
6737 "Address Family modifier\n"
6738 "Address Family modifier\n"
6739 "Display routes conforming to the prefix-list\n"
6740 "IP prefix-list name\n")
6741{
6742 if (strncmp (argv[0], "m", 1) == 0)
6743 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6744 bgp_show_type_prefix_list);
6745
6746 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6747 bgp_show_type_prefix_list);
6748}
6749
6750#ifdef HAVE_IPV6
6751DEFUN (show_bgp_prefix_list,
6752 show_bgp_prefix_list_cmd,
6753 "show bgp prefix-list WORD",
6754 SHOW_STR
6755 BGP_STR
6756 "Display routes conforming to the prefix-list\n"
6757 "IPv6 prefix-list name\n")
6758{
6759 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6760 bgp_show_type_prefix_list);
6761}
6762
6763ALIAS (show_bgp_prefix_list,
6764 show_bgp_ipv6_prefix_list_cmd,
6765 "show bgp ipv6 prefix-list WORD",
6766 SHOW_STR
6767 BGP_STR
6768 "Address family\n"
6769 "Display routes conforming to the prefix-list\n"
6770 "IPv6 prefix-list name\n")
6771
6772/* old command */
6773DEFUN (show_ipv6_bgp_prefix_list,
6774 show_ipv6_bgp_prefix_list_cmd,
6775 "show ipv6 bgp prefix-list WORD",
6776 SHOW_STR
6777 IPV6_STR
6778 BGP_STR
6779 "Display routes matching the prefix-list\n"
6780 "IPv6 prefix-list name\n")
6781{
6782 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6783 bgp_show_type_prefix_list);
6784}
6785
6786/* old command */
6787DEFUN (show_ipv6_mbgp_prefix_list,
6788 show_ipv6_mbgp_prefix_list_cmd,
6789 "show ipv6 mbgp prefix-list WORD",
6790 SHOW_STR
6791 IPV6_STR
6792 MBGP_STR
6793 "Display routes matching the prefix-list\n"
6794 "IPv6 prefix-list name\n")
6795{
6796 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6797 bgp_show_type_prefix_list);
6798}
6799#endif /* HAVE_IPV6 */
6800
paul94f2b392005-06-28 12:44:16 +00006801static int
paulfd79ac92004-10-13 05:06:08 +00006802bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006803 safi_t safi, enum bgp_show_type type)
6804{
6805 struct as_list *as_list;
6806
6807 as_list = as_list_lookup (filter);
6808 if (as_list == NULL)
6809 {
6810 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6811 return CMD_WARNING;
6812 }
6813
ajs5a646652004-11-05 01:25:55 +00006814 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00006815}
6816
6817DEFUN (show_ip_bgp_filter_list,
6818 show_ip_bgp_filter_list_cmd,
6819 "show ip bgp filter-list WORD",
6820 SHOW_STR
6821 IP_STR
6822 BGP_STR
6823 "Display routes conforming to the filter-list\n"
6824 "Regular expression access list name\n")
6825{
6826 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6827 bgp_show_type_filter_list);
6828}
6829
6830DEFUN (show_ip_bgp_flap_filter_list,
6831 show_ip_bgp_flap_filter_list_cmd,
6832 "show ip bgp flap-statistics filter-list WORD",
6833 SHOW_STR
6834 IP_STR
6835 BGP_STR
6836 "Display flap statistics of routes\n"
6837 "Display routes conforming to the filter-list\n"
6838 "Regular expression access list name\n")
6839{
6840 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6841 bgp_show_type_flap_filter_list);
6842}
6843
6844DEFUN (show_ip_bgp_ipv4_filter_list,
6845 show_ip_bgp_ipv4_filter_list_cmd,
6846 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6847 SHOW_STR
6848 IP_STR
6849 BGP_STR
6850 "Address family\n"
6851 "Address Family modifier\n"
6852 "Address Family modifier\n"
6853 "Display routes conforming to the filter-list\n"
6854 "Regular expression access list name\n")
6855{
6856 if (strncmp (argv[0], "m", 1) == 0)
6857 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6858 bgp_show_type_filter_list);
6859
6860 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6861 bgp_show_type_filter_list);
6862}
6863
6864#ifdef HAVE_IPV6
6865DEFUN (show_bgp_filter_list,
6866 show_bgp_filter_list_cmd,
6867 "show bgp filter-list WORD",
6868 SHOW_STR
6869 BGP_STR
6870 "Display routes conforming to the filter-list\n"
6871 "Regular expression access list name\n")
6872{
6873 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6874 bgp_show_type_filter_list);
6875}
6876
6877ALIAS (show_bgp_filter_list,
6878 show_bgp_ipv6_filter_list_cmd,
6879 "show bgp ipv6 filter-list WORD",
6880 SHOW_STR
6881 BGP_STR
6882 "Address family\n"
6883 "Display routes conforming to the filter-list\n"
6884 "Regular expression access list name\n")
6885
6886/* old command */
6887DEFUN (show_ipv6_bgp_filter_list,
6888 show_ipv6_bgp_filter_list_cmd,
6889 "show ipv6 bgp filter-list WORD",
6890 SHOW_STR
6891 IPV6_STR
6892 BGP_STR
6893 "Display routes conforming to the filter-list\n"
6894 "Regular expression access list name\n")
6895{
6896 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6897 bgp_show_type_filter_list);
6898}
6899
6900/* old command */
6901DEFUN (show_ipv6_mbgp_filter_list,
6902 show_ipv6_mbgp_filter_list_cmd,
6903 "show ipv6 mbgp filter-list WORD",
6904 SHOW_STR
6905 IPV6_STR
6906 MBGP_STR
6907 "Display routes conforming to the filter-list\n"
6908 "Regular expression access list name\n")
6909{
6910 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6911 bgp_show_type_filter_list);
6912}
6913#endif /* HAVE_IPV6 */
6914
paul94f2b392005-06-28 12:44:16 +00006915static int
paulfd79ac92004-10-13 05:06:08 +00006916bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006917 safi_t safi, enum bgp_show_type type)
6918{
6919 struct route_map *rmap;
6920
6921 rmap = route_map_lookup_by_name (rmap_str);
6922 if (! rmap)
6923 {
6924 vty_out (vty, "%% %s is not a valid route-map name%s",
6925 rmap_str, VTY_NEWLINE);
6926 return CMD_WARNING;
6927 }
6928
ajs5a646652004-11-05 01:25:55 +00006929 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00006930}
6931
6932DEFUN (show_ip_bgp_route_map,
6933 show_ip_bgp_route_map_cmd,
6934 "show ip bgp route-map WORD",
6935 SHOW_STR
6936 IP_STR
6937 BGP_STR
6938 "Display routes matching the route-map\n"
6939 "A route-map to match on\n")
6940{
6941 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6942 bgp_show_type_route_map);
6943}
6944
6945DEFUN (show_ip_bgp_flap_route_map,
6946 show_ip_bgp_flap_route_map_cmd,
6947 "show ip bgp flap-statistics route-map WORD",
6948 SHOW_STR
6949 IP_STR
6950 BGP_STR
6951 "Display flap statistics of routes\n"
6952 "Display routes matching the route-map\n"
6953 "A route-map to match on\n")
6954{
6955 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6956 bgp_show_type_flap_route_map);
6957}
6958
6959DEFUN (show_ip_bgp_ipv4_route_map,
6960 show_ip_bgp_ipv4_route_map_cmd,
6961 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6962 SHOW_STR
6963 IP_STR
6964 BGP_STR
6965 "Address family\n"
6966 "Address Family modifier\n"
6967 "Address Family modifier\n"
6968 "Display routes matching the route-map\n"
6969 "A route-map to match on\n")
6970{
6971 if (strncmp (argv[0], "m", 1) == 0)
6972 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6973 bgp_show_type_route_map);
6974
6975 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6976 bgp_show_type_route_map);
6977}
6978
6979DEFUN (show_bgp_route_map,
6980 show_bgp_route_map_cmd,
6981 "show bgp route-map WORD",
6982 SHOW_STR
6983 BGP_STR
6984 "Display routes matching the route-map\n"
6985 "A route-map to match on\n")
6986{
6987 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6988 bgp_show_type_route_map);
6989}
6990
6991ALIAS (show_bgp_route_map,
6992 show_bgp_ipv6_route_map_cmd,
6993 "show bgp ipv6 route-map WORD",
6994 SHOW_STR
6995 BGP_STR
6996 "Address family\n"
6997 "Display routes matching the route-map\n"
6998 "A route-map to match on\n")
6999
7000DEFUN (show_ip_bgp_cidr_only,
7001 show_ip_bgp_cidr_only_cmd,
7002 "show ip bgp cidr-only",
7003 SHOW_STR
7004 IP_STR
7005 BGP_STR
7006 "Display only routes with non-natural netmasks\n")
7007{
7008 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007009 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007010}
7011
7012DEFUN (show_ip_bgp_flap_cidr_only,
7013 show_ip_bgp_flap_cidr_only_cmd,
7014 "show ip bgp flap-statistics cidr-only",
7015 SHOW_STR
7016 IP_STR
7017 BGP_STR
7018 "Display flap statistics of routes\n"
7019 "Display only routes with non-natural netmasks\n")
7020{
7021 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007022 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007023}
7024
7025DEFUN (show_ip_bgp_ipv4_cidr_only,
7026 show_ip_bgp_ipv4_cidr_only_cmd,
7027 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7028 SHOW_STR
7029 IP_STR
7030 BGP_STR
7031 "Address family\n"
7032 "Address Family modifier\n"
7033 "Address Family modifier\n"
7034 "Display only routes with non-natural netmasks\n")
7035{
7036 if (strncmp (argv[0], "m", 1) == 0)
7037 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007038 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007039
7040 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007041 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007042}
7043
7044DEFUN (show_ip_bgp_community_all,
7045 show_ip_bgp_community_all_cmd,
7046 "show ip bgp community",
7047 SHOW_STR
7048 IP_STR
7049 BGP_STR
7050 "Display routes matching the communities\n")
7051{
7052 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007053 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007054}
7055
7056DEFUN (show_ip_bgp_ipv4_community_all,
7057 show_ip_bgp_ipv4_community_all_cmd,
7058 "show ip bgp ipv4 (unicast|multicast) community",
7059 SHOW_STR
7060 IP_STR
7061 BGP_STR
7062 "Address family\n"
7063 "Address Family modifier\n"
7064 "Address Family modifier\n"
7065 "Display routes matching the communities\n")
7066{
7067 if (strncmp (argv[0], "m", 1) == 0)
7068 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007069 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007070
7071 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007072 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007073}
7074
7075#ifdef HAVE_IPV6
7076DEFUN (show_bgp_community_all,
7077 show_bgp_community_all_cmd,
7078 "show bgp community",
7079 SHOW_STR
7080 BGP_STR
7081 "Display routes matching the communities\n")
7082{
7083 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007084 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007085}
7086
7087ALIAS (show_bgp_community_all,
7088 show_bgp_ipv6_community_all_cmd,
7089 "show bgp ipv6 community",
7090 SHOW_STR
7091 BGP_STR
7092 "Address family\n"
7093 "Display routes matching the communities\n")
7094
7095/* old command */
7096DEFUN (show_ipv6_bgp_community_all,
7097 show_ipv6_bgp_community_all_cmd,
7098 "show ipv6 bgp community",
7099 SHOW_STR
7100 IPV6_STR
7101 BGP_STR
7102 "Display routes matching the communities\n")
7103{
7104 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007105 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007106}
7107
7108/* old command */
7109DEFUN (show_ipv6_mbgp_community_all,
7110 show_ipv6_mbgp_community_all_cmd,
7111 "show ipv6 mbgp community",
7112 SHOW_STR
7113 IPV6_STR
7114 MBGP_STR
7115 "Display routes matching the communities\n")
7116{
7117 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007118 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007119}
7120#endif /* HAVE_IPV6 */
7121
paul94f2b392005-06-28 12:44:16 +00007122static int
paulfd79ac92004-10-13 05:06:08 +00007123bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7124 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007125{
7126 struct community *com;
7127 struct buffer *b;
7128 int i;
7129 char *str;
7130 int first = 0;
7131
7132 b = buffer_new (1024);
7133 for (i = 0; i < argc; i++)
7134 {
7135 if (first)
7136 buffer_putc (b, ' ');
7137 else
7138 {
7139 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7140 continue;
7141 first = 1;
7142 }
7143
7144 buffer_putstr (b, argv[i]);
7145 }
7146 buffer_putc (b, '\0');
7147
7148 str = buffer_getstr (b);
7149 buffer_free (b);
7150
7151 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007152 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007153 if (! com)
7154 {
7155 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7156 return CMD_WARNING;
7157 }
7158
ajs5a646652004-11-05 01:25:55 +00007159 return bgp_show (vty, NULL, afi, safi,
7160 (exact ? bgp_show_type_community_exact :
7161 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007162}
7163
7164DEFUN (show_ip_bgp_community,
7165 show_ip_bgp_community_cmd,
7166 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7167 SHOW_STR
7168 IP_STR
7169 BGP_STR
7170 "Display routes matching the communities\n"
7171 "community number\n"
7172 "Do not send outside local AS (well-known community)\n"
7173 "Do not advertise to any peer (well-known community)\n"
7174 "Do not export to next AS (well-known community)\n")
7175{
7176 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7177}
7178
7179ALIAS (show_ip_bgp_community,
7180 show_ip_bgp_community2_cmd,
7181 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7182 SHOW_STR
7183 IP_STR
7184 BGP_STR
7185 "Display routes matching the communities\n"
7186 "community number\n"
7187 "Do not send outside local AS (well-known community)\n"
7188 "Do not advertise to any peer (well-known community)\n"
7189 "Do not export to next AS (well-known community)\n"
7190 "community number\n"
7191 "Do not send outside local AS (well-known community)\n"
7192 "Do not advertise to any peer (well-known community)\n"
7193 "Do not export to next AS (well-known community)\n")
7194
7195ALIAS (show_ip_bgp_community,
7196 show_ip_bgp_community3_cmd,
7197 "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)",
7198 SHOW_STR
7199 IP_STR
7200 BGP_STR
7201 "Display routes matching the communities\n"
7202 "community number\n"
7203 "Do not send outside local AS (well-known community)\n"
7204 "Do not advertise to any peer (well-known community)\n"
7205 "Do not export to next AS (well-known community)\n"
7206 "community number\n"
7207 "Do not send outside local AS (well-known community)\n"
7208 "Do not advertise to any peer (well-known community)\n"
7209 "Do not export to next AS (well-known community)\n"
7210 "community number\n"
7211 "Do not send outside local AS (well-known community)\n"
7212 "Do not advertise to any peer (well-known community)\n"
7213 "Do not export to next AS (well-known community)\n")
7214
7215ALIAS (show_ip_bgp_community,
7216 show_ip_bgp_community4_cmd,
7217 "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)",
7218 SHOW_STR
7219 IP_STR
7220 BGP_STR
7221 "Display routes matching the communities\n"
7222 "community number\n"
7223 "Do not send outside local AS (well-known community)\n"
7224 "Do not advertise to any peer (well-known community)\n"
7225 "Do not export to next AS (well-known community)\n"
7226 "community number\n"
7227 "Do not send outside local AS (well-known community)\n"
7228 "Do not advertise to any peer (well-known community)\n"
7229 "Do not export to next AS (well-known community)\n"
7230 "community number\n"
7231 "Do not send outside local AS (well-known community)\n"
7232 "Do not advertise to any peer (well-known community)\n"
7233 "Do not export to next AS (well-known community)\n"
7234 "community number\n"
7235 "Do not send outside local AS (well-known community)\n"
7236 "Do not advertise to any peer (well-known community)\n"
7237 "Do not export to next AS (well-known community)\n")
7238
7239DEFUN (show_ip_bgp_ipv4_community,
7240 show_ip_bgp_ipv4_community_cmd,
7241 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7242 SHOW_STR
7243 IP_STR
7244 BGP_STR
7245 "Address family\n"
7246 "Address Family modifier\n"
7247 "Address Family modifier\n"
7248 "Display routes matching the communities\n"
7249 "community number\n"
7250 "Do not send outside local AS (well-known community)\n"
7251 "Do not advertise to any peer (well-known community)\n"
7252 "Do not export to next AS (well-known community)\n")
7253{
7254 if (strncmp (argv[0], "m", 1) == 0)
7255 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7256
7257 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7258}
7259
7260ALIAS (show_ip_bgp_ipv4_community,
7261 show_ip_bgp_ipv4_community2_cmd,
7262 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7263 SHOW_STR
7264 IP_STR
7265 BGP_STR
7266 "Address family\n"
7267 "Address Family modifier\n"
7268 "Address Family modifier\n"
7269 "Display routes matching the communities\n"
7270 "community number\n"
7271 "Do not send outside local AS (well-known community)\n"
7272 "Do not advertise to any peer (well-known community)\n"
7273 "Do not export to next AS (well-known community)\n"
7274 "community number\n"
7275 "Do not send outside local AS (well-known community)\n"
7276 "Do not advertise to any peer (well-known community)\n"
7277 "Do not export to next AS (well-known community)\n")
7278
7279ALIAS (show_ip_bgp_ipv4_community,
7280 show_ip_bgp_ipv4_community3_cmd,
7281 "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)",
7282 SHOW_STR
7283 IP_STR
7284 BGP_STR
7285 "Address family\n"
7286 "Address Family modifier\n"
7287 "Address Family modifier\n"
7288 "Display routes matching the communities\n"
7289 "community number\n"
7290 "Do not send outside local AS (well-known community)\n"
7291 "Do not advertise to any peer (well-known community)\n"
7292 "Do not export to next AS (well-known community)\n"
7293 "community number\n"
7294 "Do not send outside local AS (well-known community)\n"
7295 "Do not advertise to any peer (well-known community)\n"
7296 "Do not export to next AS (well-known community)\n"
7297 "community number\n"
7298 "Do not send outside local AS (well-known community)\n"
7299 "Do not advertise to any peer (well-known community)\n"
7300 "Do not export to next AS (well-known community)\n")
7301
7302ALIAS (show_ip_bgp_ipv4_community,
7303 show_ip_bgp_ipv4_community4_cmd,
7304 "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)",
7305 SHOW_STR
7306 IP_STR
7307 BGP_STR
7308 "Address family\n"
7309 "Address Family modifier\n"
7310 "Address Family modifier\n"
7311 "Display routes matching the communities\n"
7312 "community number\n"
7313 "Do not send outside local AS (well-known community)\n"
7314 "Do not advertise to any peer (well-known community)\n"
7315 "Do not export to next AS (well-known community)\n"
7316 "community number\n"
7317 "Do not send outside local AS (well-known community)\n"
7318 "Do not advertise to any peer (well-known community)\n"
7319 "Do not export to next AS (well-known community)\n"
7320 "community number\n"
7321 "Do not send outside local AS (well-known community)\n"
7322 "Do not advertise to any peer (well-known community)\n"
7323 "Do not export to next AS (well-known community)\n"
7324 "community number\n"
7325 "Do not send outside local AS (well-known community)\n"
7326 "Do not advertise to any peer (well-known community)\n"
7327 "Do not export to next AS (well-known community)\n")
7328
7329DEFUN (show_ip_bgp_community_exact,
7330 show_ip_bgp_community_exact_cmd,
7331 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7332 SHOW_STR
7333 IP_STR
7334 BGP_STR
7335 "Display routes matching the communities\n"
7336 "community number\n"
7337 "Do not send outside local AS (well-known community)\n"
7338 "Do not advertise to any peer (well-known community)\n"
7339 "Do not export to next AS (well-known community)\n"
7340 "Exact match of the communities")
7341{
7342 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7343}
7344
7345ALIAS (show_ip_bgp_community_exact,
7346 show_ip_bgp_community2_exact_cmd,
7347 "show ip bgp community (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 "Exact match of the communities")
7361
7362ALIAS (show_ip_bgp_community_exact,
7363 show_ip_bgp_community3_exact_cmd,
7364 "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",
7365 SHOW_STR
7366 IP_STR
7367 BGP_STR
7368 "Display routes matching the communities\n"
7369 "community number\n"
7370 "Do not send outside local AS (well-known community)\n"
7371 "Do not advertise to any peer (well-known community)\n"
7372 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
7382
7383ALIAS (show_ip_bgp_community_exact,
7384 show_ip_bgp_community4_exact_cmd,
7385 "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",
7386 SHOW_STR
7387 IP_STR
7388 BGP_STR
7389 "Display routes matching the communities\n"
7390 "community number\n"
7391 "Do not send outside local AS (well-known community)\n"
7392 "Do not advertise to any peer (well-known community)\n"
7393 "Do not export to next AS (well-known community)\n"
7394 "community number\n"
7395 "Do not send outside local AS (well-known community)\n"
7396 "Do not advertise to any peer (well-known community)\n"
7397 "Do not export to next AS (well-known community)\n"
7398 "community number\n"
7399 "Do not send outside local AS (well-known community)\n"
7400 "Do not advertise to any peer (well-known community)\n"
7401 "Do not export to next AS (well-known community)\n"
7402 "community number\n"
7403 "Do not send outside local AS (well-known community)\n"
7404 "Do not advertise to any peer (well-known community)\n"
7405 "Do not export to next AS (well-known community)\n"
7406 "Exact match of the communities")
7407
7408DEFUN (show_ip_bgp_ipv4_community_exact,
7409 show_ip_bgp_ipv4_community_exact_cmd,
7410 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7411 SHOW_STR
7412 IP_STR
7413 BGP_STR
7414 "Address family\n"
7415 "Address Family modifier\n"
7416 "Address Family modifier\n"
7417 "Display routes matching the communities\n"
7418 "community number\n"
7419 "Do not send outside local AS (well-known community)\n"
7420 "Do not advertise to any peer (well-known community)\n"
7421 "Do not export to next AS (well-known community)\n"
7422 "Exact match of the communities")
7423{
7424 if (strncmp (argv[0], "m", 1) == 0)
7425 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7426
7427 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7428}
7429
7430ALIAS (show_ip_bgp_ipv4_community_exact,
7431 show_ip_bgp_ipv4_community2_exact_cmd,
7432 "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",
7433 SHOW_STR
7434 IP_STR
7435 BGP_STR
7436 "Address family\n"
7437 "Address Family modifier\n"
7438 "Address Family modifier\n"
7439 "Display routes matching the communities\n"
7440 "community number\n"
7441 "Do not send outside local AS (well-known community)\n"
7442 "Do not advertise to any peer (well-known community)\n"
7443 "Do not export to next AS (well-known community)\n"
7444 "community number\n"
7445 "Do not send outside local AS (well-known community)\n"
7446 "Do not advertise to any peer (well-known community)\n"
7447 "Do not export to next AS (well-known community)\n"
7448 "Exact match of the communities")
7449
7450ALIAS (show_ip_bgp_ipv4_community_exact,
7451 show_ip_bgp_ipv4_community3_exact_cmd,
7452 "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",
7453 SHOW_STR
7454 IP_STR
7455 BGP_STR
7456 "Address family\n"
7457 "Address Family modifier\n"
7458 "Address Family modifier\n"
7459 "Display routes matching the communities\n"
7460 "community number\n"
7461 "Do not send outside local AS (well-known community)\n"
7462 "Do not advertise to any peer (well-known community)\n"
7463 "Do not export to next AS (well-known community)\n"
7464 "community number\n"
7465 "Do not send outside local AS (well-known community)\n"
7466 "Do not advertise to any peer (well-known community)\n"
7467 "Do not export to next AS (well-known community)\n"
7468 "community number\n"
7469 "Do not send outside local AS (well-known community)\n"
7470 "Do not advertise to any peer (well-known community)\n"
7471 "Do not export to next AS (well-known community)\n"
7472 "Exact match of the communities")
7473
7474ALIAS (show_ip_bgp_ipv4_community_exact,
7475 show_ip_bgp_ipv4_community4_exact_cmd,
7476 "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",
7477 SHOW_STR
7478 IP_STR
7479 BGP_STR
7480 "Address family\n"
7481 "Address Family modifier\n"
7482 "Address Family modifier\n"
7483 "Display routes matching the communities\n"
7484 "community number\n"
7485 "Do not send outside local AS (well-known community)\n"
7486 "Do not advertise to any peer (well-known community)\n"
7487 "Do not export to next AS (well-known community)\n"
7488 "community number\n"
7489 "Do not send outside local AS (well-known community)\n"
7490 "Do not advertise to any peer (well-known community)\n"
7491 "Do not export to next AS (well-known community)\n"
7492 "community number\n"
7493 "Do not send outside local AS (well-known community)\n"
7494 "Do not advertise to any peer (well-known community)\n"
7495 "Do not export to next AS (well-known community)\n"
7496 "community number\n"
7497 "Do not send outside local AS (well-known community)\n"
7498 "Do not advertise to any peer (well-known community)\n"
7499 "Do not export to next AS (well-known community)\n"
7500 "Exact match of the communities")
7501
7502#ifdef HAVE_IPV6
7503DEFUN (show_bgp_community,
7504 show_bgp_community_cmd,
7505 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7506 SHOW_STR
7507 BGP_STR
7508 "Display routes matching the communities\n"
7509 "community number\n"
7510 "Do not send outside local AS (well-known community)\n"
7511 "Do not advertise to any peer (well-known community)\n"
7512 "Do not export to next AS (well-known community)\n")
7513{
7514 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7515}
7516
7517ALIAS (show_bgp_community,
7518 show_bgp_ipv6_community_cmd,
7519 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7520 SHOW_STR
7521 BGP_STR
7522 "Address family\n"
7523 "Display routes matching the communities\n"
7524 "community number\n"
7525 "Do not send outside local AS (well-known community)\n"
7526 "Do not advertise to any peer (well-known community)\n"
7527 "Do not export to next AS (well-known community)\n")
7528
7529ALIAS (show_bgp_community,
7530 show_bgp_community2_cmd,
7531 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7532 SHOW_STR
7533 BGP_STR
7534 "Display routes matching the communities\n"
7535 "community number\n"
7536 "Do not send outside local AS (well-known community)\n"
7537 "Do not advertise to any peer (well-known community)\n"
7538 "Do not export to next AS (well-known community)\n"
7539 "community number\n"
7540 "Do not send outside local AS (well-known community)\n"
7541 "Do not advertise to any peer (well-known community)\n"
7542 "Do not export to next AS (well-known community)\n")
7543
7544ALIAS (show_bgp_community,
7545 show_bgp_ipv6_community2_cmd,
7546 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7547 SHOW_STR
7548 BGP_STR
7549 "Address family\n"
7550 "Display routes matching the communities\n"
7551 "community number\n"
7552 "Do not send outside local AS (well-known community)\n"
7553 "Do not advertise to any peer (well-known community)\n"
7554 "Do not export to next AS (well-known community)\n"
7555 "community number\n"
7556 "Do not send outside local AS (well-known community)\n"
7557 "Do not advertise to any peer (well-known community)\n"
7558 "Do not export to next AS (well-known community)\n")
7559
7560ALIAS (show_bgp_community,
7561 show_bgp_community3_cmd,
7562 "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)",
7563 SHOW_STR
7564 BGP_STR
7565 "Display routes matching the communities\n"
7566 "community number\n"
7567 "Do not send outside local AS (well-known community)\n"
7568 "Do not advertise to any peer (well-known community)\n"
7569 "Do not export to next AS (well-known community)\n"
7570 "community number\n"
7571 "Do not send outside local AS (well-known community)\n"
7572 "Do not advertise to any peer (well-known community)\n"
7573 "Do not export to next AS (well-known community)\n"
7574 "community number\n"
7575 "Do not send outside local AS (well-known community)\n"
7576 "Do not advertise to any peer (well-known community)\n"
7577 "Do not export to next AS (well-known community)\n")
7578
7579ALIAS (show_bgp_community,
7580 show_bgp_ipv6_community3_cmd,
7581 "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)",
7582 SHOW_STR
7583 BGP_STR
7584 "Address family\n"
7585 "Display routes matching the communities\n"
7586 "community number\n"
7587 "Do not send outside local AS (well-known community)\n"
7588 "Do not advertise to any peer (well-known community)\n"
7589 "Do not export to next AS (well-known community)\n"
7590 "community number\n"
7591 "Do not send outside local AS (well-known community)\n"
7592 "Do not advertise to any peer (well-known community)\n"
7593 "Do not export to next AS (well-known community)\n"
7594 "community number\n"
7595 "Do not send outside local AS (well-known community)\n"
7596 "Do not advertise to any peer (well-known community)\n"
7597 "Do not export to next AS (well-known community)\n")
7598
7599ALIAS (show_bgp_community,
7600 show_bgp_community4_cmd,
7601 "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)",
7602 SHOW_STR
7603 BGP_STR
7604 "Display routes matching the communities\n"
7605 "community number\n"
7606 "Do not send outside local AS (well-known community)\n"
7607 "Do not advertise to any peer (well-known community)\n"
7608 "Do not export to next AS (well-known community)\n"
7609 "community number\n"
7610 "Do not send outside local AS (well-known community)\n"
7611 "Do not advertise to any peer (well-known community)\n"
7612 "Do not export to next AS (well-known community)\n"
7613 "community number\n"
7614 "Do not send outside local AS (well-known community)\n"
7615 "Do not advertise to any peer (well-known community)\n"
7616 "Do not export to next AS (well-known community)\n"
7617 "community number\n"
7618 "Do not send outside local AS (well-known community)\n"
7619 "Do not advertise to any peer (well-known community)\n"
7620 "Do not export to next AS (well-known community)\n")
7621
7622ALIAS (show_bgp_community,
7623 show_bgp_ipv6_community4_cmd,
7624 "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)",
7625 SHOW_STR
7626 BGP_STR
7627 "Address family\n"
7628 "Display routes matching the communities\n"
7629 "community number\n"
7630 "Do not send outside local AS (well-known community)\n"
7631 "Do not advertise to any peer (well-known community)\n"
7632 "Do not export to next AS (well-known community)\n"
7633 "community number\n"
7634 "Do not send outside local AS (well-known community)\n"
7635 "Do not advertise to any peer (well-known community)\n"
7636 "Do not export to next AS (well-known community)\n"
7637 "community number\n"
7638 "Do not send outside local AS (well-known community)\n"
7639 "Do not advertise to any peer (well-known community)\n"
7640 "Do not export to next AS (well-known community)\n"
7641 "community number\n"
7642 "Do not send outside local AS (well-known community)\n"
7643 "Do not advertise to any peer (well-known community)\n"
7644 "Do not export to next AS (well-known community)\n")
7645
7646/* old command */
7647DEFUN (show_ipv6_bgp_community,
7648 show_ipv6_bgp_community_cmd,
7649 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7650 SHOW_STR
7651 IPV6_STR
7652 BGP_STR
7653 "Display routes matching the communities\n"
7654 "community number\n"
7655 "Do not send outside local AS (well-known community)\n"
7656 "Do not advertise to any peer (well-known community)\n"
7657 "Do not export to next AS (well-known community)\n")
7658{
7659 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7660}
7661
7662/* old command */
7663ALIAS (show_ipv6_bgp_community,
7664 show_ipv6_bgp_community2_cmd,
7665 "show ipv6 bgp community (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
7679/* old command */
7680ALIAS (show_ipv6_bgp_community,
7681 show_ipv6_bgp_community3_cmd,
7682 "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)",
7683 SHOW_STR
7684 IPV6_STR
7685 BGP_STR
7686 "Display routes matching the communities\n"
7687 "community number\n"
7688 "Do not send outside local AS (well-known community)\n"
7689 "Do not advertise to any peer (well-known community)\n"
7690 "Do not export to next AS (well-known community)\n"
7691 "community number\n"
7692 "Do not send outside local AS (well-known community)\n"
7693 "Do not advertise to any peer (well-known community)\n"
7694 "Do not export to next AS (well-known community)\n"
7695 "community number\n"
7696 "Do not send outside local AS (well-known community)\n"
7697 "Do not advertise to any peer (well-known community)\n"
7698 "Do not export to next AS (well-known community)\n")
7699
7700/* old command */
7701ALIAS (show_ipv6_bgp_community,
7702 show_ipv6_bgp_community4_cmd,
7703 "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)",
7704 SHOW_STR
7705 IPV6_STR
7706 BGP_STR
7707 "Display routes matching the communities\n"
7708 "community number\n"
7709 "Do not send outside local AS (well-known community)\n"
7710 "Do not advertise to any peer (well-known community)\n"
7711 "Do not export to next AS (well-known community)\n"
7712 "community number\n"
7713 "Do not send outside local AS (well-known community)\n"
7714 "Do not advertise to any peer (well-known community)\n"
7715 "Do not export to next AS (well-known community)\n"
7716 "community number\n"
7717 "Do not send outside local AS (well-known community)\n"
7718 "Do not advertise to any peer (well-known community)\n"
7719 "Do not export to next AS (well-known community)\n"
7720 "community number\n"
7721 "Do not send outside local AS (well-known community)\n"
7722 "Do not advertise to any peer (well-known community)\n"
7723 "Do not export to next AS (well-known community)\n")
7724
7725DEFUN (show_bgp_community_exact,
7726 show_bgp_community_exact_cmd,
7727 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7728 SHOW_STR
7729 BGP_STR
7730 "Display routes matching the communities\n"
7731 "community number\n"
7732 "Do not send outside local AS (well-known community)\n"
7733 "Do not advertise to any peer (well-known community)\n"
7734 "Do not export to next AS (well-known community)\n"
7735 "Exact match of the communities")
7736{
7737 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7738}
7739
7740ALIAS (show_bgp_community_exact,
7741 show_bgp_ipv6_community_exact_cmd,
7742 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7743 SHOW_STR
7744 BGP_STR
7745 "Address family\n"
7746 "Display routes matching the communities\n"
7747 "community number\n"
7748 "Do not send outside local AS (well-known community)\n"
7749 "Do not advertise to any peer (well-known community)\n"
7750 "Do not export to next AS (well-known community)\n"
7751 "Exact match of the communities")
7752
7753ALIAS (show_bgp_community_exact,
7754 show_bgp_community2_exact_cmd,
7755 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7756 SHOW_STR
7757 BGP_STR
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_ipv6_community2_exact_cmd,
7771 "show bgp ipv6 community (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 "Address family\n"
7775 "Display routes matching the communities\n"
7776 "community number\n"
7777 "Do not send outside local AS (well-known community)\n"
7778 "Do not advertise to any peer (well-known community)\n"
7779 "Do not export to next AS (well-known community)\n"
7780 "community number\n"
7781 "Do not send outside local AS (well-known community)\n"
7782 "Do not advertise to any peer (well-known community)\n"
7783 "Do not export to next AS (well-known community)\n"
7784 "Exact match of the communities")
7785
7786ALIAS (show_bgp_community_exact,
7787 show_bgp_community3_exact_cmd,
7788 "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",
7789 SHOW_STR
7790 BGP_STR
7791 "Display routes matching the communities\n"
7792 "community number\n"
7793 "Do not send outside local AS (well-known community)\n"
7794 "Do not advertise to any peer (well-known community)\n"
7795 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
7805
7806ALIAS (show_bgp_community_exact,
7807 show_bgp_ipv6_community3_exact_cmd,
7808 "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",
7809 SHOW_STR
7810 BGP_STR
7811 "Address family\n"
7812 "Display routes matching the communities\n"
7813 "community number\n"
7814 "Do not send outside local AS (well-known community)\n"
7815 "Do not advertise to any peer (well-known community)\n"
7816 "Do not export to next AS (well-known community)\n"
7817 "community number\n"
7818 "Do not send outside local AS (well-known community)\n"
7819 "Do not advertise to any peer (well-known community)\n"
7820 "Do not export to next AS (well-known community)\n"
7821 "community number\n"
7822 "Do not send outside local AS (well-known community)\n"
7823 "Do not advertise to any peer (well-known community)\n"
7824 "Do not export to next AS (well-known community)\n"
7825 "Exact match of the communities")
7826
7827ALIAS (show_bgp_community_exact,
7828 show_bgp_community4_exact_cmd,
7829 "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",
7830 SHOW_STR
7831 BGP_STR
7832 "Display routes matching the communities\n"
7833 "community number\n"
7834 "Do not send outside local AS (well-known community)\n"
7835 "Do not advertise to any peer (well-known community)\n"
7836 "Do not export to next AS (well-known community)\n"
7837 "community number\n"
7838 "Do not send outside local AS (well-known community)\n"
7839 "Do not advertise to any peer (well-known community)\n"
7840 "Do not export to next AS (well-known community)\n"
7841 "community number\n"
7842 "Do not send outside local AS (well-known community)\n"
7843 "Do not advertise to any peer (well-known community)\n"
7844 "Do not export to next AS (well-known community)\n"
7845 "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 "Exact match of the communities")
7850
7851ALIAS (show_bgp_community_exact,
7852 show_bgp_ipv6_community4_exact_cmd,
7853 "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",
7854 SHOW_STR
7855 BGP_STR
7856 "Address family\n"
7857 "Display routes matching the communities\n"
7858 "community number\n"
7859 "Do not send outside local AS (well-known community)\n"
7860 "Do not advertise to any peer (well-known community)\n"
7861 "Do not export to next AS (well-known community)\n"
7862 "community number\n"
7863 "Do not send outside local AS (well-known community)\n"
7864 "Do not advertise to any peer (well-known community)\n"
7865 "Do not export to next AS (well-known community)\n"
7866 "community number\n"
7867 "Do not send outside local AS (well-known community)\n"
7868 "Do not advertise to any peer (well-known community)\n"
7869 "Do not export to next AS (well-known community)\n"
7870 "community number\n"
7871 "Do not send outside local AS (well-known community)\n"
7872 "Do not advertise to any peer (well-known community)\n"
7873 "Do not export to next AS (well-known community)\n"
7874 "Exact match of the communities")
7875
7876/* old command */
7877DEFUN (show_ipv6_bgp_community_exact,
7878 show_ipv6_bgp_community_exact_cmd,
7879 "show ipv6 bgp community (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 "Exact match of the communities")
7889{
7890 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7891}
7892
7893/* old command */
7894ALIAS (show_ipv6_bgp_community_exact,
7895 show_ipv6_bgp_community2_exact_cmd,
7896 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7897 SHOW_STR
7898 IPV6_STR
7899 BGP_STR
7900 "Display routes matching the communities\n"
7901 "community number\n"
7902 "Do not send outside local AS (well-known community)\n"
7903 "Do not advertise to any peer (well-known community)\n"
7904 "Do not export to next AS (well-known community)\n"
7905 "community number\n"
7906 "Do not send outside local AS (well-known community)\n"
7907 "Do not advertise to any peer (well-known community)\n"
7908 "Do not export to next AS (well-known community)\n"
7909 "Exact match of the communities")
7910
7911/* old command */
7912ALIAS (show_ipv6_bgp_community_exact,
7913 show_ipv6_bgp_community3_exact_cmd,
7914 "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",
7915 SHOW_STR
7916 IPV6_STR
7917 BGP_STR
7918 "Display routes matching the communities\n"
7919 "community number\n"
7920 "Do not send outside local AS (well-known community)\n"
7921 "Do not advertise to any peer (well-known community)\n"
7922 "Do not export to next AS (well-known community)\n"
7923 "community number\n"
7924 "Do not send outside local AS (well-known community)\n"
7925 "Do not advertise to any peer (well-known community)\n"
7926 "Do not export to next AS (well-known community)\n"
7927 "community number\n"
7928 "Do not send outside local AS (well-known community)\n"
7929 "Do not advertise to any peer (well-known community)\n"
7930 "Do not export to next AS (well-known community)\n"
7931 "Exact match of the communities")
7932
7933/* old command */
7934ALIAS (show_ipv6_bgp_community_exact,
7935 show_ipv6_bgp_community4_exact_cmd,
7936 "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",
7937 SHOW_STR
7938 IPV6_STR
7939 BGP_STR
7940 "Display routes matching the communities\n"
7941 "community number\n"
7942 "Do not send outside local AS (well-known community)\n"
7943 "Do not advertise to any peer (well-known community)\n"
7944 "Do not export to next AS (well-known community)\n"
7945 "community number\n"
7946 "Do not send outside local AS (well-known community)\n"
7947 "Do not advertise to any peer (well-known community)\n"
7948 "Do not export to next AS (well-known community)\n"
7949 "community number\n"
7950 "Do not send outside local AS (well-known community)\n"
7951 "Do not advertise to any peer (well-known community)\n"
7952 "Do not export to next AS (well-known community)\n"
7953 "community number\n"
7954 "Do not send outside local AS (well-known community)\n"
7955 "Do not advertise to any peer (well-known community)\n"
7956 "Do not export to next AS (well-known community)\n"
7957 "Exact match of the communities")
7958
7959/* old command */
7960DEFUN (show_ipv6_mbgp_community,
7961 show_ipv6_mbgp_community_cmd,
7962 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7963 SHOW_STR
7964 IPV6_STR
7965 MBGP_STR
7966 "Display routes matching the communities\n"
7967 "community number\n"
7968 "Do not send outside local AS (well-known community)\n"
7969 "Do not advertise to any peer (well-known community)\n"
7970 "Do not export to next AS (well-known community)\n")
7971{
7972 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7973}
7974
7975/* old command */
7976ALIAS (show_ipv6_mbgp_community,
7977 show_ipv6_mbgp_community2_cmd,
7978 "show ipv6 mbgp community (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
7992/* old command */
7993ALIAS (show_ipv6_mbgp_community,
7994 show_ipv6_mbgp_community3_cmd,
7995 "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)",
7996 SHOW_STR
7997 IPV6_STR
7998 MBGP_STR
7999 "Display routes matching the communities\n"
8000 "community number\n"
8001 "Do not send outside local AS (well-known community)\n"
8002 "Do not advertise to any peer (well-known community)\n"
8003 "Do not export to next AS (well-known community)\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
8013/* old command */
8014ALIAS (show_ipv6_mbgp_community,
8015 show_ipv6_mbgp_community4_cmd,
8016 "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)",
8017 SHOW_STR
8018 IPV6_STR
8019 MBGP_STR
8020 "Display routes matching the communities\n"
8021 "community number\n"
8022 "Do not send outside local AS (well-known community)\n"
8023 "Do not advertise to any peer (well-known community)\n"
8024 "Do not export to next AS (well-known community)\n"
8025 "community number\n"
8026 "Do not send outside local AS (well-known community)\n"
8027 "Do not advertise to any peer (well-known community)\n"
8028 "Do not export to next AS (well-known community)\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 "community number\n"
8034 "Do not send outside local AS (well-known community)\n"
8035 "Do not advertise to any peer (well-known community)\n"
8036 "Do not export to next AS (well-known community)\n")
8037
8038/* old command */
8039DEFUN (show_ipv6_mbgp_community_exact,
8040 show_ipv6_mbgp_community_exact_cmd,
8041 "show ipv6 mbgp community (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 "Exact match of the communities")
8051{
8052 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8053}
8054
8055/* old command */
8056ALIAS (show_ipv6_mbgp_community_exact,
8057 show_ipv6_mbgp_community2_exact_cmd,
8058 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8059 SHOW_STR
8060 IPV6_STR
8061 MBGP_STR
8062 "Display routes matching the communities\n"
8063 "community number\n"
8064 "Do not send outside local AS (well-known community)\n"
8065 "Do not advertise to any peer (well-known community)\n"
8066 "Do not export to next AS (well-known community)\n"
8067 "community number\n"
8068 "Do not send outside local AS (well-known community)\n"
8069 "Do not advertise to any peer (well-known community)\n"
8070 "Do not export to next AS (well-known community)\n"
8071 "Exact match of the communities")
8072
8073/* old command */
8074ALIAS (show_ipv6_mbgp_community_exact,
8075 show_ipv6_mbgp_community3_exact_cmd,
8076 "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",
8077 SHOW_STR
8078 IPV6_STR
8079 MBGP_STR
8080 "Display routes matching the communities\n"
8081 "community number\n"
8082 "Do not send outside local AS (well-known community)\n"
8083 "Do not advertise to any peer (well-known community)\n"
8084 "Do not export to next AS (well-known community)\n"
8085 "community number\n"
8086 "Do not send outside local AS (well-known community)\n"
8087 "Do not advertise to any peer (well-known community)\n"
8088 "Do not export to next AS (well-known community)\n"
8089 "community number\n"
8090 "Do not send outside local AS (well-known community)\n"
8091 "Do not advertise to any peer (well-known community)\n"
8092 "Do not export to next AS (well-known community)\n"
8093 "Exact match of the communities")
8094
8095/* old command */
8096ALIAS (show_ipv6_mbgp_community_exact,
8097 show_ipv6_mbgp_community4_exact_cmd,
8098 "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",
8099 SHOW_STR
8100 IPV6_STR
8101 MBGP_STR
8102 "Display routes matching the communities\n"
8103 "community number\n"
8104 "Do not send outside local AS (well-known community)\n"
8105 "Do not advertise to any peer (well-known community)\n"
8106 "Do not export to next AS (well-known community)\n"
8107 "community number\n"
8108 "Do not send outside local AS (well-known community)\n"
8109 "Do not advertise to any peer (well-known community)\n"
8110 "Do not export to next AS (well-known community)\n"
8111 "community number\n"
8112 "Do not send outside local AS (well-known community)\n"
8113 "Do not advertise to any peer (well-known community)\n"
8114 "Do not export to next AS (well-known community)\n"
8115 "community number\n"
8116 "Do not send outside local AS (well-known community)\n"
8117 "Do not advertise to any peer (well-known community)\n"
8118 "Do not export to next AS (well-known community)\n"
8119 "Exact match of the communities")
8120#endif /* HAVE_IPV6 */
8121
paul94f2b392005-06-28 12:44:16 +00008122static int
paulfd79ac92004-10-13 05:06:08 +00008123bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008124 u_int16_t afi, u_char safi)
8125{
8126 struct community_list *list;
8127
hassofee6e4e2005-02-02 16:29:31 +00008128 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008129 if (list == NULL)
8130 {
8131 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8132 VTY_NEWLINE);
8133 return CMD_WARNING;
8134 }
8135
ajs5a646652004-11-05 01:25:55 +00008136 return bgp_show (vty, NULL, afi, safi,
8137 (exact ? bgp_show_type_community_list_exact :
8138 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008139}
8140
8141DEFUN (show_ip_bgp_community_list,
8142 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008143 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008144 SHOW_STR
8145 IP_STR
8146 BGP_STR
8147 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008148 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008149 "community-list name\n")
8150{
8151 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8152}
8153
8154DEFUN (show_ip_bgp_ipv4_community_list,
8155 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008156 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008157 SHOW_STR
8158 IP_STR
8159 BGP_STR
8160 "Address family\n"
8161 "Address Family modifier\n"
8162 "Address Family modifier\n"
8163 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008164 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008165 "community-list name\n")
8166{
8167 if (strncmp (argv[0], "m", 1) == 0)
8168 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8169
8170 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8171}
8172
8173DEFUN (show_ip_bgp_community_list_exact,
8174 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008175 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008176 SHOW_STR
8177 IP_STR
8178 BGP_STR
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 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8185}
8186
8187DEFUN (show_ip_bgp_ipv4_community_list_exact,
8188 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008189 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008190 SHOW_STR
8191 IP_STR
8192 BGP_STR
8193 "Address family\n"
8194 "Address Family modifier\n"
8195 "Address Family modifier\n"
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 "Exact match of the communities\n")
8200{
8201 if (strncmp (argv[0], "m", 1) == 0)
8202 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8203
8204 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8205}
8206
8207#ifdef HAVE_IPV6
8208DEFUN (show_bgp_community_list,
8209 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008210 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008211 SHOW_STR
8212 BGP_STR
8213 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008214 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008215 "community-list name\n")
8216{
8217 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8218}
8219
8220ALIAS (show_bgp_community_list,
8221 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008222 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008223 SHOW_STR
8224 BGP_STR
8225 "Address family\n"
8226 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008227 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008228 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008229
8230/* old command */
8231DEFUN (show_ipv6_bgp_community_list,
8232 show_ipv6_bgp_community_list_cmd,
8233 "show ipv6 bgp community-list WORD",
8234 SHOW_STR
8235 IPV6_STR
8236 BGP_STR
8237 "Display routes matching the community-list\n"
8238 "community-list name\n")
8239{
8240 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8241}
8242
8243/* old command */
8244DEFUN (show_ipv6_mbgp_community_list,
8245 show_ipv6_mbgp_community_list_cmd,
8246 "show ipv6 mbgp community-list WORD",
8247 SHOW_STR
8248 IPV6_STR
8249 MBGP_STR
8250 "Display routes matching the community-list\n"
8251 "community-list name\n")
8252{
8253 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8254}
8255
8256DEFUN (show_bgp_community_list_exact,
8257 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008258 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008259 SHOW_STR
8260 BGP_STR
8261 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008262 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008263 "community-list name\n"
8264 "Exact match of the communities\n")
8265{
8266 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8267}
8268
8269ALIAS (show_bgp_community_list_exact,
8270 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008271 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008272 SHOW_STR
8273 BGP_STR
8274 "Address family\n"
8275 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008276 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008277 "community-list name\n"
8278 "Exact match of the communities\n")
8279
8280/* old command */
8281DEFUN (show_ipv6_bgp_community_list_exact,
8282 show_ipv6_bgp_community_list_exact_cmd,
8283 "show ipv6 bgp community-list WORD exact-match",
8284 SHOW_STR
8285 IPV6_STR
8286 BGP_STR
8287 "Display routes matching the community-list\n"
8288 "community-list name\n"
8289 "Exact match of the communities\n")
8290{
8291 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8292}
8293
8294/* old command */
8295DEFUN (show_ipv6_mbgp_community_list_exact,
8296 show_ipv6_mbgp_community_list_exact_cmd,
8297 "show ipv6 mbgp community-list WORD exact-match",
8298 SHOW_STR
8299 IPV6_STR
8300 MBGP_STR
8301 "Display routes matching the community-list\n"
8302 "community-list name\n"
8303 "Exact match of the communities\n")
8304{
8305 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8306}
8307#endif /* HAVE_IPV6 */
8308
paul94f2b392005-06-28 12:44:16 +00008309static int
paulfd79ac92004-10-13 05:06:08 +00008310bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008311 safi_t safi, enum bgp_show_type type)
8312{
8313 int ret;
8314 struct prefix *p;
8315
8316 p = prefix_new();
8317
8318 ret = str2prefix (prefix, p);
8319 if (! ret)
8320 {
8321 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8322 return CMD_WARNING;
8323 }
8324
ajs5a646652004-11-05 01:25:55 +00008325 ret = bgp_show (vty, NULL, afi, safi, type, p);
8326 prefix_free(p);
8327 return ret;
paul718e3742002-12-13 20:15:29 +00008328}
8329
8330DEFUN (show_ip_bgp_prefix_longer,
8331 show_ip_bgp_prefix_longer_cmd,
8332 "show ip bgp A.B.C.D/M longer-prefixes",
8333 SHOW_STR
8334 IP_STR
8335 BGP_STR
8336 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8337 "Display route and more specific routes\n")
8338{
8339 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8340 bgp_show_type_prefix_longer);
8341}
8342
8343DEFUN (show_ip_bgp_flap_prefix_longer,
8344 show_ip_bgp_flap_prefix_longer_cmd,
8345 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8346 SHOW_STR
8347 IP_STR
8348 BGP_STR
8349 "Display flap statistics of routes\n"
8350 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8351 "Display route and more specific routes\n")
8352{
8353 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8354 bgp_show_type_flap_prefix_longer);
8355}
8356
8357DEFUN (show_ip_bgp_ipv4_prefix_longer,
8358 show_ip_bgp_ipv4_prefix_longer_cmd,
8359 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8360 SHOW_STR
8361 IP_STR
8362 BGP_STR
8363 "Address family\n"
8364 "Address Family modifier\n"
8365 "Address Family modifier\n"
8366 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8367 "Display route and more specific routes\n")
8368{
8369 if (strncmp (argv[0], "m", 1) == 0)
8370 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8371 bgp_show_type_prefix_longer);
8372
8373 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8374 bgp_show_type_prefix_longer);
8375}
8376
8377DEFUN (show_ip_bgp_flap_address,
8378 show_ip_bgp_flap_address_cmd,
8379 "show ip bgp flap-statistics A.B.C.D",
8380 SHOW_STR
8381 IP_STR
8382 BGP_STR
8383 "Display flap statistics of routes\n"
8384 "Network in the BGP routing table to display\n")
8385{
8386 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8387 bgp_show_type_flap_address);
8388}
8389
8390DEFUN (show_ip_bgp_flap_prefix,
8391 show_ip_bgp_flap_prefix_cmd,
8392 "show ip bgp flap-statistics A.B.C.D/M",
8393 SHOW_STR
8394 IP_STR
8395 BGP_STR
8396 "Display flap statistics of routes\n"
8397 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8398{
8399 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8400 bgp_show_type_flap_prefix);
8401}
8402#ifdef HAVE_IPV6
8403DEFUN (show_bgp_prefix_longer,
8404 show_bgp_prefix_longer_cmd,
8405 "show bgp X:X::X:X/M longer-prefixes",
8406 SHOW_STR
8407 BGP_STR
8408 "IPv6 prefix <network>/<length>\n"
8409 "Display route and more specific routes\n")
8410{
8411 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8412 bgp_show_type_prefix_longer);
8413}
8414
8415ALIAS (show_bgp_prefix_longer,
8416 show_bgp_ipv6_prefix_longer_cmd,
8417 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8418 SHOW_STR
8419 BGP_STR
8420 "Address family\n"
8421 "IPv6 prefix <network>/<length>\n"
8422 "Display route and more specific routes\n")
8423
8424/* old command */
8425DEFUN (show_ipv6_bgp_prefix_longer,
8426 show_ipv6_bgp_prefix_longer_cmd,
8427 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8428 SHOW_STR
8429 IPV6_STR
8430 BGP_STR
8431 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8432 "Display route and more specific routes\n")
8433{
8434 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8435 bgp_show_type_prefix_longer);
8436}
8437
8438/* old command */
8439DEFUN (show_ipv6_mbgp_prefix_longer,
8440 show_ipv6_mbgp_prefix_longer_cmd,
8441 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8442 SHOW_STR
8443 IPV6_STR
8444 MBGP_STR
8445 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8446 "Display route and more specific routes\n")
8447{
8448 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8449 bgp_show_type_prefix_longer);
8450}
8451#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008452
paul94f2b392005-06-28 12:44:16 +00008453static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008454peer_lookup_in_view (struct vty *vty, const char *view_name,
8455 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008456{
8457 int ret;
8458 struct bgp *bgp;
8459 struct peer *peer;
8460 union sockunion su;
8461
8462 /* BGP structure lookup. */
8463 if (view_name)
8464 {
8465 bgp = bgp_lookup_by_name (view_name);
8466 if (! bgp)
8467 {
8468 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8469 return NULL;
8470 }
8471 }
paul5228ad22004-06-04 17:58:18 +00008472 else
paulbb46e942003-10-24 19:02:03 +00008473 {
8474 bgp = bgp_get_default ();
8475 if (! bgp)
8476 {
8477 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8478 return NULL;
8479 }
8480 }
8481
8482 /* Get peer sockunion. */
8483 ret = str2sockunion (ip_str, &su);
8484 if (ret < 0)
8485 {
8486 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8487 return NULL;
8488 }
8489
8490 /* Peer structure lookup. */
8491 peer = peer_lookup (bgp, &su);
8492 if (! peer)
8493 {
8494 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8495 return NULL;
8496 }
8497
8498 return peer;
8499}
Paul Jakma2815e612006-09-14 02:56:07 +00008500
8501enum bgp_stats
8502{
8503 BGP_STATS_MAXBITLEN = 0,
8504 BGP_STATS_RIB,
8505 BGP_STATS_PREFIXES,
8506 BGP_STATS_TOTPLEN,
8507 BGP_STATS_UNAGGREGATEABLE,
8508 BGP_STATS_MAX_AGGREGATEABLE,
8509 BGP_STATS_AGGREGATES,
8510 BGP_STATS_SPACE,
8511 BGP_STATS_ASPATH_COUNT,
8512 BGP_STATS_ASPATH_MAXHOPS,
8513 BGP_STATS_ASPATH_TOTHOPS,
8514 BGP_STATS_ASPATH_MAXSIZE,
8515 BGP_STATS_ASPATH_TOTSIZE,
8516 BGP_STATS_ASN_HIGHEST,
8517 BGP_STATS_MAX,
8518};
paulbb46e942003-10-24 19:02:03 +00008519
Paul Jakma2815e612006-09-14 02:56:07 +00008520static const char *table_stats_strs[] =
8521{
8522 [BGP_STATS_PREFIXES] = "Total Prefixes",
8523 [BGP_STATS_TOTPLEN] = "Average prefix length",
8524 [BGP_STATS_RIB] = "Total Advertisements",
8525 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8526 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8527 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8528 [BGP_STATS_SPACE] = "Address space advertised",
8529 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8530 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8531 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8532 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
8533 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
8534 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
8535 [BGP_STATS_MAX] = NULL,
8536};
8537
8538struct bgp_table_stats
8539{
8540 struct bgp_table *table;
8541 unsigned long long counts[BGP_STATS_MAX];
8542};
8543
8544#if 0
8545#define TALLY_SIGFIG 100000
8546static unsigned long
8547ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
8548{
8549 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
8550 unsigned long res = (newtot * TALLY_SIGFIG) / count;
8551 unsigned long ret = newtot / count;
8552
8553 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
8554 return ret + 1;
8555 else
8556 return ret;
8557}
8558#endif
8559
8560static int
8561bgp_table_stats_walker (struct thread *t)
8562{
8563 struct bgp_node *rn;
8564 struct bgp_node *top;
8565 struct bgp_table_stats *ts = THREAD_ARG (t);
8566 unsigned int space = 0;
8567
Paul Jakma53d9f672006-10-15 23:41:16 +00008568 if (!(top = bgp_table_top (ts->table)))
8569 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00008570
8571 switch (top->p.family)
8572 {
8573 case AF_INET:
8574 space = IPV4_MAX_BITLEN;
8575 break;
8576 case AF_INET6:
8577 space = IPV6_MAX_BITLEN;
8578 break;
8579 }
8580
8581 ts->counts[BGP_STATS_MAXBITLEN] = space;
8582
8583 for (rn = top; rn; rn = bgp_route_next (rn))
8584 {
8585 struct bgp_info *ri;
8586 struct bgp_node *prn = rn->parent;
8587 unsigned int rinum = 0;
8588
8589 if (rn == top)
8590 continue;
8591
8592 if (!rn->info)
8593 continue;
8594
8595 ts->counts[BGP_STATS_PREFIXES]++;
8596 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
8597
8598#if 0
8599 ts->counts[BGP_STATS_AVGPLEN]
8600 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
8601 ts->counts[BGP_STATS_AVGPLEN],
8602 rn->p.prefixlen);
8603#endif
8604
8605 /* check if the prefix is included by any other announcements */
8606 while (prn && !prn->info)
8607 prn = prn->parent;
8608
8609 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00008610 {
8611 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
8612 /* announced address space */
8613 if (space)
8614 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
8615 }
Paul Jakma2815e612006-09-14 02:56:07 +00008616 else if (prn->info)
8617 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
8618
Paul Jakma2815e612006-09-14 02:56:07 +00008619 for (ri = rn->info; ri; ri = ri->next)
8620 {
8621 rinum++;
8622 ts->counts[BGP_STATS_RIB]++;
8623
8624 if (ri->attr &&
8625 (CHECK_FLAG (ri->attr->flag,
8626 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
8627 ts->counts[BGP_STATS_AGGREGATES]++;
8628
8629 /* as-path stats */
8630 if (ri->attr && ri->attr->aspath)
8631 {
8632 unsigned int hops = aspath_count_hops (ri->attr->aspath);
8633 unsigned int size = aspath_size (ri->attr->aspath);
8634 as_t highest = aspath_highest (ri->attr->aspath);
8635
8636 ts->counts[BGP_STATS_ASPATH_COUNT]++;
8637
8638 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
8639 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
8640
8641 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
8642 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
8643
8644 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
8645 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
8646#if 0
8647 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
8648 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8649 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
8650 hops);
8651 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
8652 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8653 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
8654 size);
8655#endif
8656 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
8657 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
8658 }
8659 }
8660 }
8661 return 0;
8662}
8663
8664static int
8665bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
8666{
8667 struct bgp_table_stats ts;
8668 unsigned int i;
8669
8670 if (!bgp->rib[afi][safi])
8671 {
8672 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
8673 return CMD_WARNING;
8674 }
8675
8676 memset (&ts, 0, sizeof (ts));
8677 ts.table = bgp->rib[afi][safi];
8678 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
8679
8680 vty_out (vty, "BGP %s RIB statistics%s%s",
8681 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
8682
8683 for (i = 0; i < BGP_STATS_MAX; i++)
8684 {
8685 if (!table_stats_strs[i])
8686 continue;
8687
8688 switch (i)
8689 {
8690#if 0
8691 case BGP_STATS_ASPATH_AVGHOPS:
8692 case BGP_STATS_ASPATH_AVGSIZE:
8693 case BGP_STATS_AVGPLEN:
8694 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8695 vty_out (vty, "%12.2f",
8696 (float)ts.counts[i] / (float)TALLY_SIGFIG);
8697 break;
8698#endif
8699 case BGP_STATS_ASPATH_TOTHOPS:
8700 case BGP_STATS_ASPATH_TOTSIZE:
8701 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8702 vty_out (vty, "%12.2f",
8703 ts.counts[i] ?
8704 (float)ts.counts[i] /
8705 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
8706 : 0);
8707 break;
8708 case BGP_STATS_TOTPLEN:
8709 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8710 vty_out (vty, "%12.2f",
8711 ts.counts[i] ?
8712 (float)ts.counts[i] /
8713 (float)ts.counts[BGP_STATS_PREFIXES]
8714 : 0);
8715 break;
8716 case BGP_STATS_SPACE:
8717 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8718 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
8719 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
8720 break;
8721 vty_out (vty, "%30s: ", "\% announced ");
8722 vty_out (vty, "%12.2f%s",
8723 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00008724 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00008725 VTY_NEWLINE);
8726 vty_out (vty, "%30s: ", "/8 equivalent ");
8727 vty_out (vty, "%12.2f%s",
8728 (float)ts.counts[BGP_STATS_SPACE] /
8729 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
8730 VTY_NEWLINE);
8731 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
8732 break;
8733 vty_out (vty, "%30s: ", "/24 equivalent ");
8734 vty_out (vty, "%12.2f",
8735 (float)ts.counts[BGP_STATS_SPACE] /
8736 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
8737 break;
8738 default:
8739 vty_out (vty, "%-30s: ", table_stats_strs[i]);
8740 vty_out (vty, "%12llu", ts.counts[i]);
8741 }
8742
8743 vty_out (vty, "%s", VTY_NEWLINE);
8744 }
8745 return CMD_SUCCESS;
8746}
8747
8748static int
8749bgp_table_stats_vty (struct vty *vty, const char *name,
8750 const char *afi_str, const char *safi_str)
8751{
8752 struct bgp *bgp;
8753 afi_t afi;
8754 safi_t safi;
8755
8756 if (name)
8757 bgp = bgp_lookup_by_name (name);
8758 else
8759 bgp = bgp_get_default ();
8760
8761 if (!bgp)
8762 {
8763 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
8764 return CMD_WARNING;
8765 }
8766 if (strncmp (afi_str, "ipv", 3) == 0)
8767 {
8768 if (strncmp (afi_str, "ipv4", 4) == 0)
8769 afi = AFI_IP;
8770 else if (strncmp (afi_str, "ipv6", 4) == 0)
8771 afi = AFI_IP6;
8772 else
8773 {
8774 vty_out (vty, "%% Invalid address family %s%s",
8775 afi_str, VTY_NEWLINE);
8776 return CMD_WARNING;
8777 }
8778 if (strncmp (safi_str, "m", 1) == 0)
8779 safi = SAFI_MULTICAST;
8780 else if (strncmp (safi_str, "u", 1) == 0)
8781 safi = SAFI_UNICAST;
8782 else if (strncmp (safi_str, "vpnv4", 5) == 0)
8783 safi = BGP_SAFI_VPNV4;
8784 else if (strncmp (safi_str, "vpnv6", 6) == 0)
8785 safi = BGP_SAFI_VPNV6;
8786 else
8787 {
8788 vty_out (vty, "%% Invalid subsequent address family %s%s",
8789 safi_str, VTY_NEWLINE);
8790 return CMD_WARNING;
8791 }
8792 }
8793 else
8794 {
8795 vty_out (vty, "%% Invalid address family %s%s",
8796 afi_str, VTY_NEWLINE);
8797 return CMD_WARNING;
8798 }
8799
8800 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
8801 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
8802 {
8803 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
8804 afi_str, safi_str, VTY_NEWLINE);
8805 return CMD_WARNING;
8806 }
8807 return bgp_table_stats (vty, bgp, afi, safi);
8808}
8809
8810DEFUN (show_bgp_statistics,
8811 show_bgp_statistics_cmd,
8812 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
8813 SHOW_STR
8814 BGP_STR
8815 "Address family\n"
8816 "Address family\n"
8817 "Address Family modifier\n"
8818 "Address Family modifier\n"
8819 "BGP RIB advertisement statistics\n")
8820{
8821 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
8822}
8823
8824ALIAS (show_bgp_statistics,
8825 show_bgp_statistics_vpnv4_cmd,
8826 "show bgp (ipv4) (vpnv4) statistics",
8827 SHOW_STR
8828 BGP_STR
8829 "Address family\n"
8830 "Address Family modifier\n"
8831 "BGP RIB advertisement statistics\n")
8832
8833DEFUN (show_bgp_statistics_view,
8834 show_bgp_statistics_view_cmd,
8835 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
8836 SHOW_STR
8837 BGP_STR
8838 "BGP view\n"
8839 "Address family\n"
8840 "Address family\n"
8841 "Address Family modifier\n"
8842 "Address Family modifier\n"
8843 "BGP RIB advertisement statistics\n")
8844{
8845 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
8846}
8847
8848ALIAS (show_bgp_statistics_view,
8849 show_bgp_statistics_view_vpnv4_cmd,
8850 "show bgp view WORD (ipv4) (vpnv4) statistics",
8851 SHOW_STR
8852 BGP_STR
8853 "BGP view\n"
8854 "Address family\n"
8855 "Address Family modifier\n"
8856 "BGP RIB advertisement statistics\n")
8857
Paul Jakmaff7924f2006-09-04 01:10:36 +00008858enum bgp_pcounts
8859{
8860 PCOUNT_ADJ_IN = 0,
8861 PCOUNT_DAMPED,
8862 PCOUNT_REMOVED,
8863 PCOUNT_HISTORY,
8864 PCOUNT_STALE,
8865 PCOUNT_VALID,
8866 PCOUNT_ALL,
8867 PCOUNT_COUNTED,
8868 PCOUNT_PFCNT, /* the figure we display to users */
8869 PCOUNT_MAX,
8870};
8871
8872static const char *pcount_strs[] =
8873{
8874 [PCOUNT_ADJ_IN] = "Adj-in",
8875 [PCOUNT_DAMPED] = "Damped",
8876 [PCOUNT_REMOVED] = "Removed",
8877 [PCOUNT_HISTORY] = "History",
8878 [PCOUNT_STALE] = "Stale",
8879 [PCOUNT_VALID] = "Valid",
8880 [PCOUNT_ALL] = "All RIB",
8881 [PCOUNT_COUNTED] = "PfxCt counted",
8882 [PCOUNT_PFCNT] = "Useable",
8883 [PCOUNT_MAX] = NULL,
8884};
8885
Paul Jakma2815e612006-09-14 02:56:07 +00008886struct peer_pcounts
8887{
8888 unsigned int count[PCOUNT_MAX];
8889 const struct peer *peer;
8890 const struct bgp_table *table;
8891};
8892
Paul Jakmaff7924f2006-09-04 01:10:36 +00008893static int
Paul Jakma2815e612006-09-14 02:56:07 +00008894bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00008895{
8896 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00008897 struct peer_pcounts *pc = THREAD_ARG (t);
8898 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008899
Paul Jakma2815e612006-09-14 02:56:07 +00008900 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00008901 {
8902 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00008903 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008904
8905 for (ain = rn->adj_in; ain; ain = ain->next)
8906 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00008907 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008908
Paul Jakmaff7924f2006-09-04 01:10:36 +00008909 for (ri = rn->info; ri; ri = ri->next)
8910 {
8911 char buf[SU_ADDRSTRLEN];
8912
8913 if (ri->peer != peer)
8914 continue;
8915
Paul Jakma2815e612006-09-14 02:56:07 +00008916 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008917
8918 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00008919 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008920 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00008921 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008922 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00008923 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008924 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00008925 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008926 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00008927 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00008928 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00008929 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00008930
8931 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
8932 {
Paul Jakma2815e612006-09-14 02:56:07 +00008933 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00008934 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00008935 plog_warn (peer->log,
8936 "%s [pcount] %s/%d is counted but flags 0x%x",
8937 peer->host,
8938 inet_ntop(rn->p.family, &rn->p.u.prefix,
8939 buf, SU_ADDRSTRLEN),
8940 rn->p.prefixlen,
8941 ri->flags);
8942 }
8943 else
8944 {
Paul Jakma1a392d42006-09-07 00:24:49 +00008945 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00008946 plog_warn (peer->log,
8947 "%s [pcount] %s/%d not counted but flags 0x%x",
8948 peer->host,
8949 inet_ntop(rn->p.family, &rn->p.u.prefix,
8950 buf, SU_ADDRSTRLEN),
8951 rn->p.prefixlen,
8952 ri->flags);
8953 }
8954 }
8955 }
Paul Jakma2815e612006-09-14 02:56:07 +00008956 return 0;
8957}
Paul Jakmaff7924f2006-09-04 01:10:36 +00008958
Paul Jakma2815e612006-09-14 02:56:07 +00008959static int
8960bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
8961{
8962 struct peer_pcounts pcounts = { .peer = peer };
8963 unsigned int i;
8964
8965 if (!peer || !peer->bgp || !peer->afc[afi][safi]
8966 || !peer->bgp->rib[afi][safi])
8967 {
8968 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8969 return CMD_WARNING;
8970 }
8971
8972 memset (&pcounts, 0, sizeof(pcounts));
8973 pcounts.peer = peer;
8974 pcounts.table = peer->bgp->rib[afi][safi];
8975
8976 /* in-place call via thread subsystem so as to record execution time
8977 * stats for the thread-walk (i.e. ensure this can't be blamed on
8978 * on just vty_read()).
8979 */
8980 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
8981
Paul Jakmaff7924f2006-09-04 01:10:36 +00008982 vty_out (vty, "Prefix counts for %s, %s%s",
8983 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
8984 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
8985 vty_out (vty, "%sCounts from RIB table walk:%s%s",
8986 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
8987
8988 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00008989 vty_out (vty, "%20s: %-10d%s",
8990 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00008991
Paul Jakma2815e612006-09-14 02:56:07 +00008992 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00008993 {
8994 vty_out (vty, "%s [pcount] PfxCt drift!%s",
8995 peer->host, VTY_NEWLINE);
8996 vty_out (vty, "Please report this bug, with the above command output%s",
8997 VTY_NEWLINE);
8998 }
8999
9000 return CMD_SUCCESS;
9001}
9002
9003DEFUN (show_ip_bgp_neighbor_prefix_counts,
9004 show_ip_bgp_neighbor_prefix_counts_cmd,
9005 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9006 SHOW_STR
9007 IP_STR
9008 BGP_STR
9009 "Detailed information on TCP and BGP neighbor connections\n"
9010 "Neighbor to display information about\n"
9011 "Neighbor to display information about\n"
9012 "Display detailed prefix count information\n")
9013{
9014 struct peer *peer;
9015
9016 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9017 if (! peer)
9018 return CMD_WARNING;
9019
9020 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9021}
9022
9023DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9024 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9025 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9026 SHOW_STR
9027 BGP_STR
9028 "Address family\n"
9029 "Detailed information on TCP and BGP neighbor connections\n"
9030 "Neighbor to display information about\n"
9031 "Neighbor to display information about\n"
9032 "Display detailed prefix count information\n")
9033{
9034 struct peer *peer;
9035
9036 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9037 if (! peer)
9038 return CMD_WARNING;
9039
9040 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9041}
9042
9043DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9044 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9045 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9046 SHOW_STR
9047 IP_STR
9048 BGP_STR
9049 "Address family\n"
9050 "Address Family modifier\n"
9051 "Address Family modifier\n"
9052 "Detailed information on TCP and BGP neighbor connections\n"
9053 "Neighbor to display information about\n"
9054 "Neighbor to display information about\n"
9055 "Display detailed prefix count information\n")
9056{
9057 struct peer *peer;
9058
9059 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9060 if (! peer)
9061 return CMD_WARNING;
9062
9063 if (strncmp (argv[0], "m", 1) == 0)
9064 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9065
9066 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9067}
9068
9069DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9070 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9071 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9072 SHOW_STR
9073 IP_STR
9074 BGP_STR
9075 "Address family\n"
9076 "Address Family modifier\n"
9077 "Address Family modifier\n"
9078 "Detailed information on TCP and BGP neighbor connections\n"
9079 "Neighbor to display information about\n"
9080 "Neighbor to display information about\n"
9081 "Display detailed prefix count information\n")
9082{
9083 struct peer *peer;
9084
9085 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9086 if (! peer)
9087 return CMD_WARNING;
9088
9089 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9090}
9091
9092
paul94f2b392005-06-28 12:44:16 +00009093static void
paul718e3742002-12-13 20:15:29 +00009094show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9095 int in)
9096{
9097 struct bgp_table *table;
9098 struct bgp_adj_in *ain;
9099 struct bgp_adj_out *adj;
9100 unsigned long output_count;
9101 struct bgp_node *rn;
9102 int header1 = 1;
9103 struct bgp *bgp;
9104 int header2 = 1;
9105
paulbb46e942003-10-24 19:02:03 +00009106 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009107
9108 if (! bgp)
9109 return;
9110
9111 table = bgp->rib[afi][safi];
9112
9113 output_count = 0;
9114
9115 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9116 PEER_STATUS_DEFAULT_ORIGINATE))
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
9122 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9123 VTY_NEWLINE, VTY_NEWLINE);
9124 header1 = 0;
9125 }
9126
9127 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9128 if (in)
9129 {
9130 for (ain = rn->adj_in; ain; ain = ain->next)
9131 if (ain->peer == peer)
9132 {
9133 if (header1)
9134 {
9135 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 +00009136 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9137 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009138 header1 = 0;
9139 }
9140 if (header2)
9141 {
9142 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9143 header2 = 0;
9144 }
9145 if (ain->attr)
9146 {
9147 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9148 output_count++;
9149 }
9150 }
9151 }
9152 else
9153 {
9154 for (adj = rn->adj_out; adj; adj = adj->next)
9155 if (adj->peer == peer)
9156 {
9157 if (header1)
9158 {
9159 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 +00009160 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9161 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009162 header1 = 0;
9163 }
9164 if (header2)
9165 {
9166 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9167 header2 = 0;
9168 }
9169 if (adj->attr)
9170 {
9171 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9172 output_count++;
9173 }
9174 }
9175 }
9176
9177 if (output_count != 0)
9178 vty_out (vty, "%sTotal number of prefixes %ld%s",
9179 VTY_NEWLINE, output_count, VTY_NEWLINE);
9180}
9181
paul94f2b392005-06-28 12:44:16 +00009182static int
paulbb46e942003-10-24 19:02:03 +00009183peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9184{
paul718e3742002-12-13 20:15:29 +00009185 if (! peer || ! peer->afc[afi][safi])
9186 {
9187 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9188 return CMD_WARNING;
9189 }
9190
9191 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9192 {
9193 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9194 VTY_NEWLINE);
9195 return CMD_WARNING;
9196 }
9197
9198 show_adj_route (vty, peer, afi, safi, in);
9199
9200 return CMD_SUCCESS;
9201}
9202
9203DEFUN (show_ip_bgp_neighbor_advertised_route,
9204 show_ip_bgp_neighbor_advertised_route_cmd,
9205 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9206 SHOW_STR
9207 IP_STR
9208 BGP_STR
9209 "Detailed information on TCP and BGP neighbor connections\n"
9210 "Neighbor to display information about\n"
9211 "Neighbor to display information about\n"
9212 "Display the routes advertised to a BGP neighbor\n")
9213{
paulbb46e942003-10-24 19:02:03 +00009214 struct peer *peer;
9215
9216 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9217 if (! peer)
9218 return CMD_WARNING;
9219
9220 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009221}
9222
9223DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9224 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9225 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9226 SHOW_STR
9227 IP_STR
9228 BGP_STR
9229 "Address family\n"
9230 "Address Family modifier\n"
9231 "Address Family modifier\n"
9232 "Detailed information on TCP and BGP neighbor connections\n"
9233 "Neighbor to display information about\n"
9234 "Neighbor to display information about\n"
9235 "Display the routes advertised to a BGP neighbor\n")
9236{
paulbb46e942003-10-24 19:02:03 +00009237 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009238
paulbb46e942003-10-24 19:02:03 +00009239 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9240 if (! peer)
9241 return CMD_WARNING;
9242
9243 if (strncmp (argv[0], "m", 1) == 0)
9244 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9245
9246 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009247}
9248
9249#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009250DEFUN (show_bgp_view_neighbor_advertised_route,
9251 show_bgp_view_neighbor_advertised_route_cmd,
9252 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9253 SHOW_STR
9254 BGP_STR
9255 "BGP view\n"
9256 "View name\n"
9257 "Detailed information on TCP and BGP neighbor connections\n"
9258 "Neighbor to display information about\n"
9259 "Neighbor to display information about\n"
9260 "Display the routes advertised to a BGP neighbor\n")
9261{
9262 struct peer *peer;
9263
9264 if (argc == 2)
9265 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9266 else
9267 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9268
9269 if (! peer)
9270 return CMD_WARNING;
9271
9272 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9273}
9274
9275ALIAS (show_bgp_view_neighbor_advertised_route,
9276 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9277 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9278 SHOW_STR
9279 BGP_STR
9280 "BGP view\n"
9281 "View name\n"
9282 "Address family\n"
9283 "Detailed information on TCP and BGP neighbor connections\n"
9284 "Neighbor to display information about\n"
9285 "Neighbor to display information about\n"
9286 "Display the routes advertised to a BGP neighbor\n")
9287
9288DEFUN (show_bgp_view_neighbor_received_routes,
9289 show_bgp_view_neighbor_received_routes_cmd,
9290 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9291 SHOW_STR
9292 BGP_STR
9293 "BGP view\n"
9294 "View name\n"
9295 "Detailed information on TCP and BGP neighbor connections\n"
9296 "Neighbor to display information about\n"
9297 "Neighbor to display information about\n"
9298 "Display the received routes from neighbor\n")
9299{
9300 struct peer *peer;
9301
9302 if (argc == 2)
9303 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9304 else
9305 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9306
9307 if (! peer)
9308 return CMD_WARNING;
9309
9310 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9311}
9312
9313ALIAS (show_bgp_view_neighbor_received_routes,
9314 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9315 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9316 SHOW_STR
9317 BGP_STR
9318 "BGP view\n"
9319 "View name\n"
9320 "Address family\n"
9321 "Detailed information on TCP and BGP neighbor connections\n"
9322 "Neighbor to display information about\n"
9323 "Neighbor to display information about\n"
9324 "Display the received routes from neighbor\n")
9325
9326ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009327 show_bgp_neighbor_advertised_route_cmd,
9328 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9329 SHOW_STR
9330 BGP_STR
9331 "Detailed information on TCP and BGP neighbor connections\n"
9332 "Neighbor to display information about\n"
9333 "Neighbor to display information about\n"
9334 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009335
9336ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009337 show_bgp_ipv6_neighbor_advertised_route_cmd,
9338 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9339 SHOW_STR
9340 BGP_STR
9341 "Address family\n"
9342 "Detailed information on TCP and BGP neighbor connections\n"
9343 "Neighbor to display information about\n"
9344 "Neighbor to display information about\n"
9345 "Display the routes advertised to a BGP neighbor\n")
9346
9347/* old command */
paulbb46e942003-10-24 19:02:03 +00009348ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009349 ipv6_bgp_neighbor_advertised_route_cmd,
9350 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9351 SHOW_STR
9352 IPV6_STR
9353 BGP_STR
9354 "Detailed information on TCP and BGP neighbor connections\n"
9355 "Neighbor to display information about\n"
9356 "Neighbor to display information about\n"
9357 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009358
paul718e3742002-12-13 20:15:29 +00009359/* old command */
9360DEFUN (ipv6_mbgp_neighbor_advertised_route,
9361 ipv6_mbgp_neighbor_advertised_route_cmd,
9362 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9363 SHOW_STR
9364 IPV6_STR
9365 MBGP_STR
9366 "Detailed information on TCP and BGP neighbor connections\n"
9367 "Neighbor to display information about\n"
9368 "Neighbor to display information about\n"
9369 "Display the routes advertised to a BGP neighbor\n")
9370{
paulbb46e942003-10-24 19:02:03 +00009371 struct peer *peer;
9372
9373 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9374 if (! peer)
9375 return CMD_WARNING;
9376
9377 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009378}
9379#endif /* HAVE_IPV6 */
9380
9381DEFUN (show_ip_bgp_neighbor_received_routes,
9382 show_ip_bgp_neighbor_received_routes_cmd,
9383 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9384 SHOW_STR
9385 IP_STR
9386 BGP_STR
9387 "Detailed information on TCP and BGP neighbor connections\n"
9388 "Neighbor to display information about\n"
9389 "Neighbor to display information about\n"
9390 "Display the received routes from neighbor\n")
9391{
paulbb46e942003-10-24 19:02:03 +00009392 struct peer *peer;
9393
9394 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9395 if (! peer)
9396 return CMD_WARNING;
9397
9398 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009399}
9400
9401DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9402 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9403 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9404 SHOW_STR
9405 IP_STR
9406 BGP_STR
9407 "Address family\n"
9408 "Address Family modifier\n"
9409 "Address Family modifier\n"
9410 "Detailed information on TCP and BGP neighbor connections\n"
9411 "Neighbor to display information about\n"
9412 "Neighbor to display information about\n"
9413 "Display the received routes from neighbor\n")
9414{
paulbb46e942003-10-24 19:02:03 +00009415 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009416
paulbb46e942003-10-24 19:02:03 +00009417 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9418 if (! peer)
9419 return CMD_WARNING;
9420
9421 if (strncmp (argv[0], "m", 1) == 0)
9422 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9423
9424 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009425}
9426
9427DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9428 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9429 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9430 SHOW_STR
9431 IP_STR
9432 BGP_STR
9433 "Detailed information on TCP and BGP neighbor connections\n"
9434 "Neighbor to display information about\n"
9435 "Neighbor to display information about\n"
9436 "Display information received from a BGP neighbor\n"
9437 "Display the prefixlist filter\n")
9438{
9439 char name[BUFSIZ];
9440 union sockunion *su;
9441 struct peer *peer;
9442 int count;
9443
9444 su = sockunion_str2su (argv[0]);
9445 if (su == NULL)
9446 return CMD_WARNING;
9447
9448 peer = peer_lookup (NULL, su);
9449 if (! peer)
9450 return CMD_WARNING;
9451
9452 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9453 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9454 if (count)
9455 {
9456 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9457 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9458 }
9459
9460 return CMD_SUCCESS;
9461}
9462
9463DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9464 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9465 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9466 SHOW_STR
9467 IP_STR
9468 BGP_STR
9469 "Address family\n"
9470 "Address Family modifier\n"
9471 "Address Family modifier\n"
9472 "Detailed information on TCP and BGP neighbor connections\n"
9473 "Neighbor to display information about\n"
9474 "Neighbor to display information about\n"
9475 "Display information received from a BGP neighbor\n"
9476 "Display the prefixlist filter\n")
9477{
9478 char name[BUFSIZ];
9479 union sockunion *su;
9480 struct peer *peer;
9481 int count;
9482
9483 su = sockunion_str2su (argv[1]);
9484 if (su == NULL)
9485 return CMD_WARNING;
9486
9487 peer = peer_lookup (NULL, su);
9488 if (! peer)
9489 return CMD_WARNING;
9490
9491 if (strncmp (argv[0], "m", 1) == 0)
9492 {
9493 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9494 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9495 if (count)
9496 {
9497 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9498 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9499 }
9500 }
9501 else
9502 {
9503 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9504 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9505 if (count)
9506 {
9507 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9508 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9509 }
9510 }
9511
9512 return CMD_SUCCESS;
9513}
9514
9515
9516#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009517ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009518 show_bgp_neighbor_received_routes_cmd,
9519 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9520 SHOW_STR
9521 BGP_STR
9522 "Detailed information on TCP and BGP neighbor connections\n"
9523 "Neighbor to display information about\n"
9524 "Neighbor to display information about\n"
9525 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009526
paulbb46e942003-10-24 19:02:03 +00009527ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009528 show_bgp_ipv6_neighbor_received_routes_cmd,
9529 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9530 SHOW_STR
9531 BGP_STR
9532 "Address family\n"
9533 "Detailed information on TCP and BGP neighbor connections\n"
9534 "Neighbor to display information about\n"
9535 "Neighbor to display information about\n"
9536 "Display the received routes from neighbor\n")
9537
9538DEFUN (show_bgp_neighbor_received_prefix_filter,
9539 show_bgp_neighbor_received_prefix_filter_cmd,
9540 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9541 SHOW_STR
9542 BGP_STR
9543 "Detailed information on TCP and BGP neighbor connections\n"
9544 "Neighbor to display information about\n"
9545 "Neighbor to display information about\n"
9546 "Display information received from a BGP neighbor\n"
9547 "Display the prefixlist filter\n")
9548{
9549 char name[BUFSIZ];
9550 union sockunion *su;
9551 struct peer *peer;
9552 int count;
9553
9554 su = sockunion_str2su (argv[0]);
9555 if (su == NULL)
9556 return CMD_WARNING;
9557
9558 peer = peer_lookup (NULL, su);
9559 if (! peer)
9560 return CMD_WARNING;
9561
9562 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9563 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9564 if (count)
9565 {
9566 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
9567 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
9568 }
9569
9570 return CMD_SUCCESS;
9571}
9572
9573ALIAS (show_bgp_neighbor_received_prefix_filter,
9574 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
9575 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9576 SHOW_STR
9577 BGP_STR
9578 "Address family\n"
9579 "Detailed information on TCP and BGP neighbor connections\n"
9580 "Neighbor to display information about\n"
9581 "Neighbor to display information about\n"
9582 "Display information received from a BGP neighbor\n"
9583 "Display the prefixlist filter\n")
9584
9585/* old command */
paulbb46e942003-10-24 19:02:03 +00009586ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009587 ipv6_bgp_neighbor_received_routes_cmd,
9588 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9589 SHOW_STR
9590 IPV6_STR
9591 BGP_STR
9592 "Detailed information on TCP and BGP neighbor connections\n"
9593 "Neighbor to display information about\n"
9594 "Neighbor to display information about\n"
9595 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009596
9597/* old command */
9598DEFUN (ipv6_mbgp_neighbor_received_routes,
9599 ipv6_mbgp_neighbor_received_routes_cmd,
9600 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9601 SHOW_STR
9602 IPV6_STR
9603 MBGP_STR
9604 "Detailed information on TCP and BGP neighbor connections\n"
9605 "Neighbor to display information about\n"
9606 "Neighbor to display information about\n"
9607 "Display the received routes from neighbor\n")
9608{
paulbb46e942003-10-24 19:02:03 +00009609 struct peer *peer;
9610
9611 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9612 if (! peer)
9613 return CMD_WARNING;
9614
9615 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00009616}
paulbb46e942003-10-24 19:02:03 +00009617
9618DEFUN (show_bgp_view_neighbor_received_prefix_filter,
9619 show_bgp_view_neighbor_received_prefix_filter_cmd,
9620 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9621 SHOW_STR
9622 BGP_STR
9623 "BGP view\n"
9624 "View name\n"
9625 "Detailed information on TCP and BGP neighbor connections\n"
9626 "Neighbor to display information about\n"
9627 "Neighbor to display information about\n"
9628 "Display information received from a BGP neighbor\n"
9629 "Display the prefixlist filter\n")
9630{
9631 char name[BUFSIZ];
9632 union sockunion *su;
9633 struct peer *peer;
9634 struct bgp *bgp;
9635 int count;
9636
9637 /* BGP structure lookup. */
9638 bgp = bgp_lookup_by_name (argv[0]);
9639 if (bgp == NULL)
9640 {
9641 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9642 return CMD_WARNING;
9643 }
9644
9645 su = sockunion_str2su (argv[1]);
9646 if (su == NULL)
9647 return CMD_WARNING;
9648
9649 peer = peer_lookup (bgp, su);
9650 if (! peer)
9651 return CMD_WARNING;
9652
9653 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9654 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9655 if (count)
9656 {
9657 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
9658 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
9659 }
9660
9661 return CMD_SUCCESS;
9662}
9663
9664ALIAS (show_bgp_view_neighbor_received_prefix_filter,
9665 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
9666 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9667 SHOW_STR
9668 BGP_STR
9669 "BGP view\n"
9670 "View name\n"
9671 "Address family\n"
9672 "Detailed information on TCP and BGP neighbor connections\n"
9673 "Neighbor to display information about\n"
9674 "Neighbor to display information about\n"
9675 "Display information received from a BGP neighbor\n"
9676 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00009677#endif /* HAVE_IPV6 */
9678
paul94f2b392005-06-28 12:44:16 +00009679static int
paulbb46e942003-10-24 19:02:03 +00009680bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009681 safi_t safi, enum bgp_show_type type)
9682{
paul718e3742002-12-13 20:15:29 +00009683 if (! peer || ! peer->afc[afi][safi])
9684 {
9685 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009686 return CMD_WARNING;
9687 }
9688
ajs5a646652004-11-05 01:25:55 +00009689 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +00009690}
9691
9692DEFUN (show_ip_bgp_neighbor_routes,
9693 show_ip_bgp_neighbor_routes_cmd,
9694 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
9695 SHOW_STR
9696 IP_STR
9697 BGP_STR
9698 "Detailed information on TCP and BGP neighbor connections\n"
9699 "Neighbor to display information about\n"
9700 "Neighbor to display information about\n"
9701 "Display routes learned from neighbor\n")
9702{
paulbb46e942003-10-24 19:02:03 +00009703 struct peer *peer;
9704
9705 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9706 if (! peer)
9707 return CMD_WARNING;
9708
9709 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009710 bgp_show_type_neighbor);
9711}
9712
9713DEFUN (show_ip_bgp_neighbor_flap,
9714 show_ip_bgp_neighbor_flap_cmd,
9715 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9716 SHOW_STR
9717 IP_STR
9718 BGP_STR
9719 "Detailed information on TCP and BGP neighbor connections\n"
9720 "Neighbor to display information about\n"
9721 "Neighbor to display information about\n"
9722 "Display flap statistics of the routes learned from neighbor\n")
9723{
paulbb46e942003-10-24 19:02:03 +00009724 struct peer *peer;
9725
9726 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9727 if (! peer)
9728 return CMD_WARNING;
9729
9730 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009731 bgp_show_type_flap_neighbor);
9732}
9733
9734DEFUN (show_ip_bgp_neighbor_damp,
9735 show_ip_bgp_neighbor_damp_cmd,
9736 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9737 SHOW_STR
9738 IP_STR
9739 BGP_STR
9740 "Detailed information on TCP and BGP neighbor connections\n"
9741 "Neighbor to display information about\n"
9742 "Neighbor to display information about\n"
9743 "Display the dampened routes received from neighbor\n")
9744{
paulbb46e942003-10-24 19:02:03 +00009745 struct peer *peer;
9746
9747 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9748 if (! peer)
9749 return CMD_WARNING;
9750
9751 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009752 bgp_show_type_damp_neighbor);
9753}
9754
9755DEFUN (show_ip_bgp_ipv4_neighbor_routes,
9756 show_ip_bgp_ipv4_neighbor_routes_cmd,
9757 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
9758 SHOW_STR
9759 IP_STR
9760 BGP_STR
9761 "Address family\n"
9762 "Address Family modifier\n"
9763 "Address Family modifier\n"
9764 "Detailed information on TCP and BGP neighbor connections\n"
9765 "Neighbor to display information about\n"
9766 "Neighbor to display information about\n"
9767 "Display routes learned from neighbor\n")
9768{
paulbb46e942003-10-24 19:02:03 +00009769 struct peer *peer;
9770
9771 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9772 if (! peer)
9773 return CMD_WARNING;
9774
paul718e3742002-12-13 20:15:29 +00009775 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00009776 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009777 bgp_show_type_neighbor);
9778
paulbb46e942003-10-24 19:02:03 +00009779 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009780 bgp_show_type_neighbor);
9781}
paulbb46e942003-10-24 19:02:03 +00009782
paulfee0f4c2004-09-13 05:12:46 +00009783DEFUN (show_ip_bgp_view_rsclient,
9784 show_ip_bgp_view_rsclient_cmd,
9785 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9786 SHOW_STR
9787 IP_STR
9788 BGP_STR
9789 "BGP view\n"
9790 "BGP view name\n"
9791 "Information about Route Server Client\n"
9792 NEIGHBOR_ADDR_STR)
9793{
9794 struct bgp_table *table;
9795 struct peer *peer;
9796
9797 if (argc == 2)
9798 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9799 else
9800 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9801
9802 if (! peer)
9803 return CMD_WARNING;
9804
9805 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9806 {
9807 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9808 VTY_NEWLINE);
9809 return CMD_WARNING;
9810 }
9811
9812 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9813 PEER_FLAG_RSERVER_CLIENT))
9814 {
9815 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9816 VTY_NEWLINE);
9817 return CMD_WARNING;
9818 }
9819
9820 table = peer->rib[AFI_IP][SAFI_UNICAST];
9821
ajs5a646652004-11-05 01:25:55 +00009822 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009823}
9824
9825ALIAS (show_ip_bgp_view_rsclient,
9826 show_ip_bgp_rsclient_cmd,
9827 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
9828 SHOW_STR
9829 IP_STR
9830 BGP_STR
9831 "Information about Route Server Client\n"
9832 NEIGHBOR_ADDR_STR)
9833
9834DEFUN (show_ip_bgp_view_rsclient_route,
9835 show_ip_bgp_view_rsclient_route_cmd,
9836 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9837 SHOW_STR
9838 IP_STR
9839 BGP_STR
9840 "BGP view\n"
9841 "BGP view name\n"
9842 "Information about Route Server Client\n"
9843 NEIGHBOR_ADDR_STR
9844 "Network in the BGP routing table to display\n")
9845{
9846 struct bgp *bgp;
9847 struct peer *peer;
9848
9849 /* BGP structure lookup. */
9850 if (argc == 3)
9851 {
9852 bgp = bgp_lookup_by_name (argv[0]);
9853 if (bgp == NULL)
9854 {
9855 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9856 return CMD_WARNING;
9857 }
9858 }
9859 else
9860 {
9861 bgp = bgp_get_default ();
9862 if (bgp == NULL)
9863 {
9864 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9865 return CMD_WARNING;
9866 }
9867 }
9868
9869 if (argc == 3)
9870 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9871 else
9872 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9873
9874 if (! peer)
9875 return CMD_WARNING;
9876
9877 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9878 {
9879 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9880 VTY_NEWLINE);
9881 return CMD_WARNING;
9882}
9883
9884 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9885 PEER_FLAG_RSERVER_CLIENT))
9886 {
9887 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9888 VTY_NEWLINE);
9889 return CMD_WARNING;
9890 }
9891
9892 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9893 (argc == 3) ? argv[2] : argv[1],
9894 AFI_IP, SAFI_UNICAST, NULL, 0);
9895}
9896
9897ALIAS (show_ip_bgp_view_rsclient_route,
9898 show_ip_bgp_rsclient_route_cmd,
9899 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9900 SHOW_STR
9901 IP_STR
9902 BGP_STR
9903 "Information about Route Server Client\n"
9904 NEIGHBOR_ADDR_STR
9905 "Network in the BGP routing table to display\n")
9906
9907DEFUN (show_ip_bgp_view_rsclient_prefix,
9908 show_ip_bgp_view_rsclient_prefix_cmd,
9909 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9910 SHOW_STR
9911 IP_STR
9912 BGP_STR
9913 "BGP view\n"
9914 "BGP view name\n"
9915 "Information about Route Server Client\n"
9916 NEIGHBOR_ADDR_STR
9917 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9918{
9919 struct bgp *bgp;
9920 struct peer *peer;
9921
9922 /* BGP structure lookup. */
9923 if (argc == 3)
9924 {
9925 bgp = bgp_lookup_by_name (argv[0]);
9926 if (bgp == NULL)
9927 {
9928 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9929 return CMD_WARNING;
9930 }
9931 }
9932 else
9933 {
9934 bgp = bgp_get_default ();
9935 if (bgp == NULL)
9936 {
9937 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9938 return CMD_WARNING;
9939 }
9940 }
9941
9942 if (argc == 3)
9943 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9944 else
9945 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9946
9947 if (! peer)
9948 return CMD_WARNING;
9949
9950 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9951 {
9952 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9953 VTY_NEWLINE);
9954 return CMD_WARNING;
9955}
9956
9957 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9958 PEER_FLAG_RSERVER_CLIENT))
9959{
9960 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9961 VTY_NEWLINE);
9962 return CMD_WARNING;
9963 }
9964
9965 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9966 (argc == 3) ? argv[2] : argv[1],
9967 AFI_IP, SAFI_UNICAST, NULL, 1);
9968}
9969
9970ALIAS (show_ip_bgp_view_rsclient_prefix,
9971 show_ip_bgp_rsclient_prefix_cmd,
9972 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9973 SHOW_STR
9974 IP_STR
9975 BGP_STR
9976 "Information about Route Server Client\n"
9977 NEIGHBOR_ADDR_STR
9978 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9979
9980
paul718e3742002-12-13 20:15:29 +00009981#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009982DEFUN (show_bgp_view_neighbor_routes,
9983 show_bgp_view_neighbor_routes_cmd,
9984 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
9985 SHOW_STR
9986 BGP_STR
9987 "BGP view\n"
9988 "BGP view name\n"
9989 "Detailed information on TCP and BGP neighbor connections\n"
9990 "Neighbor to display information about\n"
9991 "Neighbor to display information about\n"
9992 "Display routes learned from neighbor\n")
9993{
9994 struct peer *peer;
9995
9996 if (argc == 2)
9997 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9998 else
9999 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10000
10001 if (! peer)
10002 return CMD_WARNING;
10003
10004 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10005 bgp_show_type_neighbor);
10006}
10007
10008ALIAS (show_bgp_view_neighbor_routes,
10009 show_bgp_view_ipv6_neighbor_routes_cmd,
10010 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10011 SHOW_STR
10012 BGP_STR
10013 "BGP view\n"
10014 "BGP view name\n"
10015 "Address family\n"
10016 "Detailed information on TCP and BGP neighbor connections\n"
10017 "Neighbor to display information about\n"
10018 "Neighbor to display information about\n"
10019 "Display routes learned from neighbor\n")
10020
10021DEFUN (show_bgp_view_neighbor_damp,
10022 show_bgp_view_neighbor_damp_cmd,
10023 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10024 SHOW_STR
10025 BGP_STR
10026 "BGP view\n"
10027 "BGP view name\n"
10028 "Detailed information on TCP and BGP neighbor connections\n"
10029 "Neighbor to display information about\n"
10030 "Neighbor to display information about\n"
10031 "Display the dampened routes received from neighbor\n")
10032{
10033 struct peer *peer;
10034
10035 if (argc == 2)
10036 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10037 else
10038 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10039
10040 if (! peer)
10041 return CMD_WARNING;
10042
10043 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10044 bgp_show_type_damp_neighbor);
10045}
10046
10047ALIAS (show_bgp_view_neighbor_damp,
10048 show_bgp_view_ipv6_neighbor_damp_cmd,
10049 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10050 SHOW_STR
10051 BGP_STR
10052 "BGP view\n"
10053 "BGP view name\n"
10054 "Address family\n"
10055 "Detailed information on TCP and BGP neighbor connections\n"
10056 "Neighbor to display information about\n"
10057 "Neighbor to display information about\n"
10058 "Display the dampened routes received from neighbor\n")
10059
10060DEFUN (show_bgp_view_neighbor_flap,
10061 show_bgp_view_neighbor_flap_cmd,
10062 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10063 SHOW_STR
10064 BGP_STR
10065 "BGP view\n"
10066 "BGP view name\n"
10067 "Detailed information on TCP and BGP neighbor connections\n"
10068 "Neighbor to display information about\n"
10069 "Neighbor to display information about\n"
10070 "Display flap statistics of the routes learned from neighbor\n")
10071{
10072 struct peer *peer;
10073
10074 if (argc == 2)
10075 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10076 else
10077 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10078
10079 if (! peer)
10080 return CMD_WARNING;
10081
10082 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10083 bgp_show_type_flap_neighbor);
10084}
10085
10086ALIAS (show_bgp_view_neighbor_flap,
10087 show_bgp_view_ipv6_neighbor_flap_cmd,
10088 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10089 SHOW_STR
10090 BGP_STR
10091 "BGP view\n"
10092 "BGP view name\n"
10093 "Address family\n"
10094 "Detailed information on TCP and BGP neighbor connections\n"
10095 "Neighbor to display information about\n"
10096 "Neighbor to display information about\n"
10097 "Display flap statistics of the routes learned from neighbor\n")
10098
10099ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010100 show_bgp_neighbor_routes_cmd,
10101 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10102 SHOW_STR
10103 BGP_STR
10104 "Detailed information on TCP and BGP neighbor connections\n"
10105 "Neighbor to display information about\n"
10106 "Neighbor to display information about\n"
10107 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010108
paulbb46e942003-10-24 19:02:03 +000010109
10110ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010111 show_bgp_ipv6_neighbor_routes_cmd,
10112 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10113 SHOW_STR
10114 BGP_STR
10115 "Address family\n"
10116 "Detailed information on TCP and BGP neighbor connections\n"
10117 "Neighbor to display information about\n"
10118 "Neighbor to display information about\n"
10119 "Display routes learned from neighbor\n")
10120
10121/* old command */
paulbb46e942003-10-24 19:02:03 +000010122ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010123 ipv6_bgp_neighbor_routes_cmd,
10124 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10125 SHOW_STR
10126 IPV6_STR
10127 BGP_STR
10128 "Detailed information on TCP and BGP neighbor connections\n"
10129 "Neighbor to display information about\n"
10130 "Neighbor to display information about\n"
10131 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010132
10133/* old command */
10134DEFUN (ipv6_mbgp_neighbor_routes,
10135 ipv6_mbgp_neighbor_routes_cmd,
10136 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10137 SHOW_STR
10138 IPV6_STR
10139 MBGP_STR
10140 "Detailed information on TCP and BGP neighbor connections\n"
10141 "Neighbor to display information about\n"
10142 "Neighbor to display information about\n"
10143 "Display routes learned from neighbor\n")
10144{
paulbb46e942003-10-24 19:02:03 +000010145 struct peer *peer;
10146
10147 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10148 if (! peer)
10149 return CMD_WARNING;
10150
10151 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010152 bgp_show_type_neighbor);
10153}
paulbb46e942003-10-24 19:02:03 +000010154
10155ALIAS (show_bgp_view_neighbor_flap,
10156 show_bgp_neighbor_flap_cmd,
10157 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10158 SHOW_STR
10159 BGP_STR
10160 "Detailed information on TCP and BGP neighbor connections\n"
10161 "Neighbor to display information about\n"
10162 "Neighbor to display information about\n"
10163 "Display flap statistics of the routes learned from neighbor\n")
10164
10165ALIAS (show_bgp_view_neighbor_flap,
10166 show_bgp_ipv6_neighbor_flap_cmd,
10167 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10168 SHOW_STR
10169 BGP_STR
10170 "Address family\n"
10171 "Detailed information on TCP and BGP neighbor connections\n"
10172 "Neighbor to display information about\n"
10173 "Neighbor to display information about\n"
10174 "Display flap statistics of the routes learned from neighbor\n")
10175
10176ALIAS (show_bgp_view_neighbor_damp,
10177 show_bgp_neighbor_damp_cmd,
10178 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10179 SHOW_STR
10180 BGP_STR
10181 "Detailed information on TCP and BGP neighbor connections\n"
10182 "Neighbor to display information about\n"
10183 "Neighbor to display information about\n"
10184 "Display the dampened routes received from neighbor\n")
10185
10186ALIAS (show_bgp_view_neighbor_damp,
10187 show_bgp_ipv6_neighbor_damp_cmd,
10188 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10189 SHOW_STR
10190 BGP_STR
10191 "Address family\n"
10192 "Detailed information on TCP and BGP neighbor connections\n"
10193 "Neighbor to display information about\n"
10194 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010195 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010196
10197DEFUN (show_bgp_view_rsclient,
10198 show_bgp_view_rsclient_cmd,
10199 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10200 SHOW_STR
10201 BGP_STR
10202 "BGP view\n"
10203 "BGP view name\n"
10204 "Information about Route Server Client\n"
10205 NEIGHBOR_ADDR_STR)
10206{
10207 struct bgp_table *table;
10208 struct peer *peer;
10209
10210 if (argc == 2)
10211 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10212 else
10213 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10214
10215 if (! peer)
10216 return CMD_WARNING;
10217
10218 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10219 {
10220 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10221 VTY_NEWLINE);
10222 return CMD_WARNING;
10223 }
10224
10225 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10226 PEER_FLAG_RSERVER_CLIENT))
10227 {
10228 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10229 VTY_NEWLINE);
10230 return CMD_WARNING;
10231 }
10232
10233 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10234
ajs5a646652004-11-05 01:25:55 +000010235 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010236}
10237
10238ALIAS (show_bgp_view_rsclient,
10239 show_bgp_rsclient_cmd,
10240 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10241 SHOW_STR
10242 BGP_STR
10243 "Information about Route Server Client\n"
10244 NEIGHBOR_ADDR_STR)
10245
10246DEFUN (show_bgp_view_rsclient_route,
10247 show_bgp_view_rsclient_route_cmd,
10248 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10249 SHOW_STR
10250 BGP_STR
10251 "BGP view\n"
10252 "BGP view name\n"
10253 "Information about Route Server Client\n"
10254 NEIGHBOR_ADDR_STR
10255 "Network in the BGP routing table to display\n")
10256{
10257 struct bgp *bgp;
10258 struct peer *peer;
10259
10260 /* BGP structure lookup. */
10261 if (argc == 3)
10262 {
10263 bgp = bgp_lookup_by_name (argv[0]);
10264 if (bgp == NULL)
10265 {
10266 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10267 return CMD_WARNING;
10268 }
10269 }
10270 else
10271 {
10272 bgp = bgp_get_default ();
10273 if (bgp == NULL)
10274 {
10275 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10276 return CMD_WARNING;
10277 }
10278 }
10279
10280 if (argc == 3)
10281 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10282 else
10283 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10284
10285 if (! peer)
10286 return CMD_WARNING;
10287
10288 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10289 {
10290 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10291 VTY_NEWLINE);
10292 return CMD_WARNING;
10293 }
10294
10295 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10296 PEER_FLAG_RSERVER_CLIENT))
10297 {
10298 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10299 VTY_NEWLINE);
10300 return CMD_WARNING;
10301 }
10302
10303 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10304 (argc == 3) ? argv[2] : argv[1],
10305 AFI_IP6, SAFI_UNICAST, NULL, 0);
10306}
10307
10308ALIAS (show_bgp_view_rsclient_route,
10309 show_bgp_rsclient_route_cmd,
10310 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10311 SHOW_STR
10312 BGP_STR
10313 "Information about Route Server Client\n"
10314 NEIGHBOR_ADDR_STR
10315 "Network in the BGP routing table to display\n")
10316
10317DEFUN (show_bgp_view_rsclient_prefix,
10318 show_bgp_view_rsclient_prefix_cmd,
10319 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10320 SHOW_STR
10321 BGP_STR
10322 "BGP view\n"
10323 "BGP view name\n"
10324 "Information about Route Server Client\n"
10325 NEIGHBOR_ADDR_STR
10326 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10327{
10328 struct bgp *bgp;
10329 struct peer *peer;
10330
10331 /* BGP structure lookup. */
10332 if (argc == 3)
10333 {
10334 bgp = bgp_lookup_by_name (argv[0]);
10335 if (bgp == NULL)
10336 {
10337 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10338 return CMD_WARNING;
10339 }
10340 }
10341 else
10342 {
10343 bgp = bgp_get_default ();
10344 if (bgp == NULL)
10345 {
10346 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10347 return CMD_WARNING;
10348 }
10349 }
10350
10351 if (argc == 3)
10352 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10353 else
10354 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10355
10356 if (! peer)
10357 return CMD_WARNING;
10358
10359 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10360 {
10361 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10362 VTY_NEWLINE);
10363 return CMD_WARNING;
10364 }
10365
10366 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10367 PEER_FLAG_RSERVER_CLIENT))
10368 {
10369 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10370 VTY_NEWLINE);
10371 return CMD_WARNING;
10372 }
10373
10374 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10375 (argc == 3) ? argv[2] : argv[1],
10376 AFI_IP6, SAFI_UNICAST, NULL, 1);
10377}
10378
10379ALIAS (show_bgp_view_rsclient_prefix,
10380 show_bgp_rsclient_prefix_cmd,
10381 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10382 SHOW_STR
10383 BGP_STR
10384 "Information about Route Server Client\n"
10385 NEIGHBOR_ADDR_STR
10386 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10387
paul718e3742002-12-13 20:15:29 +000010388#endif /* HAVE_IPV6 */
10389
10390struct bgp_table *bgp_distance_table;
10391
10392struct bgp_distance
10393{
10394 /* Distance value for the IP source prefix. */
10395 u_char distance;
10396
10397 /* Name of the access-list to be matched. */
10398 char *access_list;
10399};
10400
paul94f2b392005-06-28 12:44:16 +000010401static struct bgp_distance *
paul718e3742002-12-13 20:15:29 +000010402bgp_distance_new ()
10403{
10404 struct bgp_distance *new;
10405 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
10406 memset (new, 0, sizeof (struct bgp_distance));
10407 return new;
10408}
10409
paul94f2b392005-06-28 12:44:16 +000010410static void
paul718e3742002-12-13 20:15:29 +000010411bgp_distance_free (struct bgp_distance *bdistance)
10412{
10413 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10414}
10415
paul94f2b392005-06-28 12:44:16 +000010416static int
paulfd79ac92004-10-13 05:06:08 +000010417bgp_distance_set (struct vty *vty, const char *distance_str,
10418 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010419{
10420 int ret;
10421 struct prefix_ipv4 p;
10422 u_char distance;
10423 struct bgp_node *rn;
10424 struct bgp_distance *bdistance;
10425
10426 ret = str2prefix_ipv4 (ip_str, &p);
10427 if (ret == 0)
10428 {
10429 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10430 return CMD_WARNING;
10431 }
10432
10433 distance = atoi (distance_str);
10434
10435 /* Get BGP distance node. */
10436 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10437 if (rn->info)
10438 {
10439 bdistance = rn->info;
10440 bgp_unlock_node (rn);
10441 }
10442 else
10443 {
10444 bdistance = bgp_distance_new ();
10445 rn->info = bdistance;
10446 }
10447
10448 /* Set distance value. */
10449 bdistance->distance = distance;
10450
10451 /* Reset access-list configuration. */
10452 if (bdistance->access_list)
10453 {
10454 free (bdistance->access_list);
10455 bdistance->access_list = NULL;
10456 }
10457 if (access_list_str)
10458 bdistance->access_list = strdup (access_list_str);
10459
10460 return CMD_SUCCESS;
10461}
10462
paul94f2b392005-06-28 12:44:16 +000010463static int
paulfd79ac92004-10-13 05:06:08 +000010464bgp_distance_unset (struct vty *vty, const char *distance_str,
10465 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010466{
10467 int ret;
10468 struct prefix_ipv4 p;
10469 u_char distance;
10470 struct bgp_node *rn;
10471 struct bgp_distance *bdistance;
10472
10473 ret = str2prefix_ipv4 (ip_str, &p);
10474 if (ret == 0)
10475 {
10476 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10477 return CMD_WARNING;
10478 }
10479
10480 distance = atoi (distance_str);
10481
10482 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10483 if (! rn)
10484 {
10485 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10486 return CMD_WARNING;
10487 }
10488
10489 bdistance = rn->info;
10490
10491 if (bdistance->access_list)
10492 free (bdistance->access_list);
10493 bgp_distance_free (bdistance);
10494
10495 rn->info = NULL;
10496 bgp_unlock_node (rn);
10497 bgp_unlock_node (rn);
10498
10499 return CMD_SUCCESS;
10500}
10501
paul94f2b392005-06-28 12:44:16 +000010502static void
paul718e3742002-12-13 20:15:29 +000010503bgp_distance_reset ()
10504{
10505 struct bgp_node *rn;
10506 struct bgp_distance *bdistance;
10507
10508 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10509 if ((bdistance = rn->info) != NULL)
10510 {
10511 if (bdistance->access_list)
10512 free (bdistance->access_list);
10513 bgp_distance_free (bdistance);
10514 rn->info = NULL;
10515 bgp_unlock_node (rn);
10516 }
10517}
10518
10519/* Apply BGP information to distance method. */
10520u_char
10521bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10522{
10523 struct bgp_node *rn;
10524 struct prefix_ipv4 q;
10525 struct peer *peer;
10526 struct bgp_distance *bdistance;
10527 struct access_list *alist;
10528 struct bgp_static *bgp_static;
10529
10530 if (! bgp)
10531 return 0;
10532
10533 if (p->family != AF_INET)
10534 return 0;
10535
10536 peer = rinfo->peer;
10537
10538 if (peer->su.sa.sa_family != AF_INET)
10539 return 0;
10540
10541 memset (&q, 0, sizeof (struct prefix_ipv4));
10542 q.family = AF_INET;
10543 q.prefix = peer->su.sin.sin_addr;
10544 q.prefixlen = IPV4_MAX_BITLEN;
10545
10546 /* Check source address. */
10547 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
10548 if (rn)
10549 {
10550 bdistance = rn->info;
10551 bgp_unlock_node (rn);
10552
10553 if (bdistance->access_list)
10554 {
10555 alist = access_list_lookup (AFI_IP, bdistance->access_list);
10556 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
10557 return bdistance->distance;
10558 }
10559 else
10560 return bdistance->distance;
10561 }
10562
10563 /* Backdoor check. */
10564 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
10565 if (rn)
10566 {
10567 bgp_static = rn->info;
10568 bgp_unlock_node (rn);
10569
10570 if (bgp_static->backdoor)
10571 {
10572 if (bgp->distance_local)
10573 return bgp->distance_local;
10574 else
10575 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10576 }
10577 }
10578
10579 if (peer_sort (peer) == BGP_PEER_EBGP)
10580 {
10581 if (bgp->distance_ebgp)
10582 return bgp->distance_ebgp;
10583 return ZEBRA_EBGP_DISTANCE_DEFAULT;
10584 }
10585 else
10586 {
10587 if (bgp->distance_ibgp)
10588 return bgp->distance_ibgp;
10589 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10590 }
10591}
10592
10593DEFUN (bgp_distance,
10594 bgp_distance_cmd,
10595 "distance bgp <1-255> <1-255> <1-255>",
10596 "Define an administrative distance\n"
10597 "BGP distance\n"
10598 "Distance for routes external to the AS\n"
10599 "Distance for routes internal to the AS\n"
10600 "Distance for local routes\n")
10601{
10602 struct bgp *bgp;
10603
10604 bgp = vty->index;
10605
10606 bgp->distance_ebgp = atoi (argv[0]);
10607 bgp->distance_ibgp = atoi (argv[1]);
10608 bgp->distance_local = atoi (argv[2]);
10609 return CMD_SUCCESS;
10610}
10611
10612DEFUN (no_bgp_distance,
10613 no_bgp_distance_cmd,
10614 "no distance bgp <1-255> <1-255> <1-255>",
10615 NO_STR
10616 "Define an administrative distance\n"
10617 "BGP distance\n"
10618 "Distance for routes external to the AS\n"
10619 "Distance for routes internal to the AS\n"
10620 "Distance for local routes\n")
10621{
10622 struct bgp *bgp;
10623
10624 bgp = vty->index;
10625
10626 bgp->distance_ebgp= 0;
10627 bgp->distance_ibgp = 0;
10628 bgp->distance_local = 0;
10629 return CMD_SUCCESS;
10630}
10631
10632ALIAS (no_bgp_distance,
10633 no_bgp_distance2_cmd,
10634 "no distance bgp",
10635 NO_STR
10636 "Define an administrative distance\n"
10637 "BGP distance\n")
10638
10639DEFUN (bgp_distance_source,
10640 bgp_distance_source_cmd,
10641 "distance <1-255> A.B.C.D/M",
10642 "Define an administrative distance\n"
10643 "Administrative distance\n"
10644 "IP source prefix\n")
10645{
10646 bgp_distance_set (vty, argv[0], argv[1], NULL);
10647 return CMD_SUCCESS;
10648}
10649
10650DEFUN (no_bgp_distance_source,
10651 no_bgp_distance_source_cmd,
10652 "no distance <1-255> A.B.C.D/M",
10653 NO_STR
10654 "Define an administrative distance\n"
10655 "Administrative distance\n"
10656 "IP source prefix\n")
10657{
10658 bgp_distance_unset (vty, argv[0], argv[1], NULL);
10659 return CMD_SUCCESS;
10660}
10661
10662DEFUN (bgp_distance_source_access_list,
10663 bgp_distance_source_access_list_cmd,
10664 "distance <1-255> A.B.C.D/M WORD",
10665 "Define an administrative distance\n"
10666 "Administrative distance\n"
10667 "IP source prefix\n"
10668 "Access list name\n")
10669{
10670 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
10671 return CMD_SUCCESS;
10672}
10673
10674DEFUN (no_bgp_distance_source_access_list,
10675 no_bgp_distance_source_access_list_cmd,
10676 "no distance <1-255> A.B.C.D/M WORD",
10677 NO_STR
10678 "Define an administrative distance\n"
10679 "Administrative distance\n"
10680 "IP source prefix\n"
10681 "Access list name\n")
10682{
10683 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
10684 return CMD_SUCCESS;
10685}
10686
10687DEFUN (bgp_damp_set,
10688 bgp_damp_set_cmd,
10689 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10690 "BGP Specific commands\n"
10691 "Enable route-flap dampening\n"
10692 "Half-life time for the penalty\n"
10693 "Value to start reusing a route\n"
10694 "Value to start suppressing a route\n"
10695 "Maximum duration to suppress a stable route\n")
10696{
10697 struct bgp *bgp;
10698 int half = DEFAULT_HALF_LIFE * 60;
10699 int reuse = DEFAULT_REUSE;
10700 int suppress = DEFAULT_SUPPRESS;
10701 int max = 4 * half;
10702
10703 if (argc == 4)
10704 {
10705 half = atoi (argv[0]) * 60;
10706 reuse = atoi (argv[1]);
10707 suppress = atoi (argv[2]);
10708 max = atoi (argv[3]) * 60;
10709 }
10710 else if (argc == 1)
10711 {
10712 half = atoi (argv[0]) * 60;
10713 max = 4 * half;
10714 }
10715
10716 bgp = vty->index;
10717 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
10718 half, reuse, suppress, max);
10719}
10720
10721ALIAS (bgp_damp_set,
10722 bgp_damp_set2_cmd,
10723 "bgp dampening <1-45>",
10724 "BGP Specific commands\n"
10725 "Enable route-flap dampening\n"
10726 "Half-life time for the penalty\n")
10727
10728ALIAS (bgp_damp_set,
10729 bgp_damp_set3_cmd,
10730 "bgp dampening",
10731 "BGP Specific commands\n"
10732 "Enable route-flap dampening\n")
10733
10734DEFUN (bgp_damp_unset,
10735 bgp_damp_unset_cmd,
10736 "no bgp dampening",
10737 NO_STR
10738 "BGP Specific commands\n"
10739 "Enable route-flap dampening\n")
10740{
10741 struct bgp *bgp;
10742
10743 bgp = vty->index;
10744 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
10745}
10746
10747ALIAS (bgp_damp_unset,
10748 bgp_damp_unset2_cmd,
10749 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10750 NO_STR
10751 "BGP Specific commands\n"
10752 "Enable route-flap dampening\n"
10753 "Half-life time for the penalty\n"
10754 "Value to start reusing a route\n"
10755 "Value to start suppressing a route\n"
10756 "Maximum duration to suppress a stable route\n")
10757
10758DEFUN (show_ip_bgp_dampened_paths,
10759 show_ip_bgp_dampened_paths_cmd,
10760 "show ip bgp dampened-paths",
10761 SHOW_STR
10762 IP_STR
10763 BGP_STR
10764 "Display paths suppressed due to dampening\n")
10765{
ajs5a646652004-11-05 01:25:55 +000010766 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
10767 NULL);
paul718e3742002-12-13 20:15:29 +000010768}
10769
10770DEFUN (show_ip_bgp_flap_statistics,
10771 show_ip_bgp_flap_statistics_cmd,
10772 "show ip bgp flap-statistics",
10773 SHOW_STR
10774 IP_STR
10775 BGP_STR
10776 "Display flap statistics of routes\n")
10777{
ajs5a646652004-11-05 01:25:55 +000010778 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
10779 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000010780}
10781
10782/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000010783static int
paulfd79ac92004-10-13 05:06:08 +000010784bgp_clear_damp_route (struct vty *vty, const char *view_name,
10785 const char *ip_str, afi_t afi, safi_t safi,
10786 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000010787{
10788 int ret;
10789 struct prefix match;
10790 struct bgp_node *rn;
10791 struct bgp_node *rm;
10792 struct bgp_info *ri;
10793 struct bgp_info *ri_temp;
10794 struct bgp *bgp;
10795 struct bgp_table *table;
10796
10797 /* BGP structure lookup. */
10798 if (view_name)
10799 {
10800 bgp = bgp_lookup_by_name (view_name);
10801 if (bgp == NULL)
10802 {
10803 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10804 return CMD_WARNING;
10805 }
10806 }
10807 else
10808 {
10809 bgp = bgp_get_default ();
10810 if (bgp == NULL)
10811 {
10812 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
10813 return CMD_WARNING;
10814 }
10815 }
10816
10817 /* Check IP address argument. */
10818 ret = str2prefix (ip_str, &match);
10819 if (! ret)
10820 {
10821 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
10822 return CMD_WARNING;
10823 }
10824
10825 match.family = afi2family (afi);
10826
10827 if (safi == SAFI_MPLS_VPN)
10828 {
10829 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
10830 {
10831 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
10832 continue;
10833
10834 if ((table = rn->info) != NULL)
10835 if ((rm = bgp_node_match (table, &match)) != NULL)
10836 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
10837 {
10838 ri = rm->info;
10839 while (ri)
10840 {
10841 if (ri->damp_info)
10842 {
10843 ri_temp = ri->next;
10844 bgp_damp_info_free (ri->damp_info, 1);
10845 ri = ri_temp;
10846 }
10847 else
10848 ri = ri->next;
10849 }
10850 }
10851 }
10852 }
10853 else
10854 {
10855 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
10856 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
10857 {
10858 ri = rn->info;
10859 while (ri)
10860 {
10861 if (ri->damp_info)
10862 {
10863 ri_temp = ri->next;
10864 bgp_damp_info_free (ri->damp_info, 1);
10865 ri = ri_temp;
10866 }
10867 else
10868 ri = ri->next;
10869 }
10870 }
10871 }
10872
10873 return CMD_SUCCESS;
10874}
10875
10876DEFUN (clear_ip_bgp_dampening,
10877 clear_ip_bgp_dampening_cmd,
10878 "clear ip bgp dampening",
10879 CLEAR_STR
10880 IP_STR
10881 BGP_STR
10882 "Clear route flap dampening information\n")
10883{
10884 bgp_damp_info_clean ();
10885 return CMD_SUCCESS;
10886}
10887
10888DEFUN (clear_ip_bgp_dampening_prefix,
10889 clear_ip_bgp_dampening_prefix_cmd,
10890 "clear ip bgp dampening A.B.C.D/M",
10891 CLEAR_STR
10892 IP_STR
10893 BGP_STR
10894 "Clear route flap dampening information\n"
10895 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10896{
10897 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10898 SAFI_UNICAST, NULL, 1);
10899}
10900
10901DEFUN (clear_ip_bgp_dampening_address,
10902 clear_ip_bgp_dampening_address_cmd,
10903 "clear ip bgp dampening A.B.C.D",
10904 CLEAR_STR
10905 IP_STR
10906 BGP_STR
10907 "Clear route flap dampening information\n"
10908 "Network to clear damping information\n")
10909{
10910 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10911 SAFI_UNICAST, NULL, 0);
10912}
10913
10914DEFUN (clear_ip_bgp_dampening_address_mask,
10915 clear_ip_bgp_dampening_address_mask_cmd,
10916 "clear ip bgp dampening A.B.C.D A.B.C.D",
10917 CLEAR_STR
10918 IP_STR
10919 BGP_STR
10920 "Clear route flap dampening information\n"
10921 "Network to clear damping information\n"
10922 "Network mask\n")
10923{
10924 int ret;
10925 char prefix_str[BUFSIZ];
10926
10927 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
10928 if (! ret)
10929 {
10930 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
10931 return CMD_WARNING;
10932 }
10933
10934 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
10935 SAFI_UNICAST, NULL, 0);
10936}
10937
paul94f2b392005-06-28 12:44:16 +000010938static int
paul718e3742002-12-13 20:15:29 +000010939bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
10940 afi_t afi, safi_t safi, int *write)
10941{
10942 struct bgp_node *prn;
10943 struct bgp_node *rn;
10944 struct bgp_table *table;
10945 struct prefix *p;
10946 struct prefix_rd *prd;
10947 struct bgp_static *bgp_static;
10948 u_int32_t label;
10949 char buf[SU_ADDRSTRLEN];
10950 char rdbuf[RD_ADDRSTRLEN];
10951
10952 /* Network configuration. */
10953 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
10954 if ((table = prn->info) != NULL)
10955 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10956 if ((bgp_static = rn->info) != NULL)
10957 {
10958 p = &rn->p;
10959 prd = (struct prefix_rd *) &prn->p;
10960
10961 /* "address-family" display. */
10962 bgp_config_write_family_header (vty, afi, safi, write);
10963
10964 /* "network" configuration display. */
10965 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
10966 label = decode_label (bgp_static->tag);
10967
10968 vty_out (vty, " network %s/%d rd %s tag %d",
10969 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10970 p->prefixlen,
10971 rdbuf, label);
10972 vty_out (vty, "%s", VTY_NEWLINE);
10973 }
10974 return 0;
10975}
10976
10977/* Configuration of static route announcement and aggregate
10978 information. */
10979int
10980bgp_config_write_network (struct vty *vty, struct bgp *bgp,
10981 afi_t afi, safi_t safi, int *write)
10982{
10983 struct bgp_node *rn;
10984 struct prefix *p;
10985 struct bgp_static *bgp_static;
10986 struct bgp_aggregate *bgp_aggregate;
10987 char buf[SU_ADDRSTRLEN];
10988
10989 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
10990 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
10991
10992 /* Network configuration. */
10993 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
10994 if ((bgp_static = rn->info) != NULL)
10995 {
10996 p = &rn->p;
10997
10998 /* "address-family" display. */
10999 bgp_config_write_family_header (vty, afi, safi, write);
11000
11001 /* "network" configuration display. */
11002 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11003 {
11004 u_int32_t destination;
11005 struct in_addr netmask;
11006
11007 destination = ntohl (p->u.prefix4.s_addr);
11008 masklen2ip (p->prefixlen, &netmask);
11009 vty_out (vty, " network %s",
11010 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11011
11012 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11013 || (IN_CLASSB (destination) && p->prefixlen == 16)
11014 || (IN_CLASSA (destination) && p->prefixlen == 8)
11015 || p->u.prefix4.s_addr == 0)
11016 {
11017 /* Natural mask is not display. */
11018 }
11019 else
11020 vty_out (vty, " mask %s", inet_ntoa (netmask));
11021 }
11022 else
11023 {
11024 vty_out (vty, " network %s/%d",
11025 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11026 p->prefixlen);
11027 }
11028
11029 if (bgp_static->rmap.name)
11030 vty_out (vty, " route-map %s", bgp_static->rmap.name);
11031 else if (bgp_static->backdoor)
11032 vty_out (vty, " backdoor");
11033
11034 vty_out (vty, "%s", VTY_NEWLINE);
11035 }
11036
11037 /* Aggregate-address configuration. */
11038 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11039 if ((bgp_aggregate = rn->info) != NULL)
11040 {
11041 p = &rn->p;
11042
11043 /* "address-family" display. */
11044 bgp_config_write_family_header (vty, afi, safi, write);
11045
11046 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11047 {
11048 struct in_addr netmask;
11049
11050 masklen2ip (p->prefixlen, &netmask);
11051 vty_out (vty, " aggregate-address %s %s",
11052 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11053 inet_ntoa (netmask));
11054 }
11055 else
11056 {
11057 vty_out (vty, " aggregate-address %s/%d",
11058 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11059 p->prefixlen);
11060 }
11061
11062 if (bgp_aggregate->as_set)
11063 vty_out (vty, " as-set");
11064
11065 if (bgp_aggregate->summary_only)
11066 vty_out (vty, " summary-only");
11067
11068 vty_out (vty, "%s", VTY_NEWLINE);
11069 }
11070
11071 return 0;
11072}
11073
11074int
11075bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11076{
11077 struct bgp_node *rn;
11078 struct bgp_distance *bdistance;
11079
11080 /* Distance configuration. */
11081 if (bgp->distance_ebgp
11082 && bgp->distance_ibgp
11083 && bgp->distance_local
11084 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11085 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11086 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11087 vty_out (vty, " distance bgp %d %d %d%s",
11088 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11089 VTY_NEWLINE);
11090
11091 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11092 if ((bdistance = rn->info) != NULL)
11093 {
11094 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11095 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11096 bdistance->access_list ? bdistance->access_list : "",
11097 VTY_NEWLINE);
11098 }
11099
11100 return 0;
11101}
11102
11103/* Allocate routing table structure and install commands. */
11104void
11105bgp_route_init ()
11106{
11107 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011108 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011109
11110 /* IPv4 BGP commands. */
11111 install_element (BGP_NODE, &bgp_network_cmd);
11112 install_element (BGP_NODE, &bgp_network_mask_cmd);
11113 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11114 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11115 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11116 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11117 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11118 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11119 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
11120 install_element (BGP_NODE, &no_bgp_network_cmd);
11121 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11122 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11123 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11124 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11125 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11126 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11127 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11128 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
11129
11130 install_element (BGP_NODE, &aggregate_address_cmd);
11131 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11132 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11133 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11134 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11135 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11136 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11137 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11138 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11139 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11140 install_element (BGP_NODE, &no_aggregate_address_cmd);
11141 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11142 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11143 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11144 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11145 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11146 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11147 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11148 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11149 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11150
11151 /* IPv4 unicast configuration. */
11152 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11153 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11154 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11155 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11156 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11157 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
11158 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
11159 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11160 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11161 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11162 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11163 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11164 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11165 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11166 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11167 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11168 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11169 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11170 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11171 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11172 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11173 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11174 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11175 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11176 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11177 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11178 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11179 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11180 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11181 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11182 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11183 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11184
11185 /* IPv4 multicast configuration. */
11186 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11187 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11188 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11189 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11190 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11191 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
11192 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11193 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11194 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11195 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11196 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11197 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11198 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11199 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11200 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11201 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11202 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11203 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11204 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11205 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11206 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11207 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11208 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11209 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11210 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11211 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11212 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11213 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11214 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11215 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11216 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11217 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11218
11219 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11220 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11221 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11222 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11223 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11224 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11225 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11226 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11227 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11228 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11229 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11230 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11231 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11232 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11233 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11234 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11235 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11236 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11237 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11238 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11239 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11240 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11241 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11242 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11243 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11244 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11245 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11246 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11247 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11248 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11249 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11250 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11251 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11252 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11253 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11254 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11255 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11256 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11257 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11258 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11259 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11260 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11261 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11262 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11263 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11264 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11265 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11266 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11267 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11268 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11269 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11270 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11271 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11272 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11273 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11274 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11275 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11276 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11277 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11278 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11279 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11280 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11281 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11282 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11283 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11284 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11285 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011286 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11287 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11288 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11289 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11290 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11291 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011292
11293 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11294 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11295 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11296 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11297 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11298 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11299 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11300 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11301 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11302 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11303 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11304 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11305 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11306 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11307 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11308 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11309 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11310 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11311 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11312 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11313 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11314 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11315 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11316 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11317 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11318 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11319 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11320 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11321 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11322 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11323 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11324 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11325 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11326 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11327 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11328 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11329 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11330 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11331 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11332 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11333 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11334 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11335 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11336 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11337 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11338 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11339 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11340 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11341 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11342 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11343 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11344 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11345 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11346 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11347 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11348 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11349 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11350 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11351 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11352 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11353 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11354 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11355 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11356 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11357 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11358 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11359 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011360 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11361 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11362 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11363 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11364 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11365 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011366
11367 /* BGP dampening clear commands */
11368 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11369 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11370 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11371 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11372
Paul Jakmaff7924f2006-09-04 01:10:36 +000011373 /* prefix count */
11374 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11375 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11376 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011377#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011378 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11379
paul718e3742002-12-13 20:15:29 +000011380 /* New config IPv6 BGP commands. */
11381 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11382 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
11383 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11384 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
11385
11386 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11387 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11388 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11389 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11390
11391 /* Old config IPv6 BGP commands. */
11392 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11393 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11394
11395 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11396 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11397 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11398 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11399
11400 install_element (VIEW_NODE, &show_bgp_cmd);
11401 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11402 install_element (VIEW_NODE, &show_bgp_route_cmd);
11403 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11404 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11405 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11406 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11407 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11408 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11409 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11410 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11411 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11412 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11413 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11414 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11415 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11416 install_element (VIEW_NODE, &show_bgp_community_cmd);
11417 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11418 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11419 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11420 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11421 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11422 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11423 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11424 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
11425 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
11426 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
11427 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
11428 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
11429 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
11430 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
11431 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
11432 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
11433 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
11434 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
11435 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11436 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
11437 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11438 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
11439 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11440 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
11441 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11442 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
11443 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11444 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11445 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011446 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
11447 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11448 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
11449 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011450 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
11451 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
11452 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011453 install_element (VIEW_NODE, &show_bgp_view_cmd);
11454 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
11455 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
11456 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
11457 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
11458 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
11459 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11460 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11461 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11462 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11463 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
11464 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11465 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11466 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11467 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
11468 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11469 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
11470 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011471 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
11472 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
11473 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011474
11475 install_element (ENABLE_NODE, &show_bgp_cmd);
11476 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
11477 install_element (ENABLE_NODE, &show_bgp_route_cmd);
11478 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
11479 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
11480 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
11481 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
11482 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
11483 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
11484 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
11485 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
11486 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
11487 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
11488 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
11489 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
11490 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
11491 install_element (ENABLE_NODE, &show_bgp_community_cmd);
11492 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
11493 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
11494 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
11495 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
11496 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
11497 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
11498 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
11499 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
11500 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
11501 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
11502 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
11503 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
11504 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
11505 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
11506 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
11507 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
11508 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
11509 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
11510 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11511 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
11512 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11513 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
11514 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11515 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
11516 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11517 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
11518 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11519 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11520 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011521 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
11522 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11523 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
11524 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011525 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
11526 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
11527 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011528 install_element (ENABLE_NODE, &show_bgp_view_cmd);
11529 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
11530 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
11531 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
11532 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
11533 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
11534 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11535 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11536 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11537 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11538 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
11539 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11540 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11541 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11542 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
11543 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11544 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
11545 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011546 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
11547 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
11548 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000011549
11550 /* Statistics */
11551 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
11552 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
11553 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
11554 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
11555
paul718e3742002-12-13 20:15:29 +000011556 /* old command */
11557 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
11558 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
11559 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
11560 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
11561 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
11562 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
11563 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
11564 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
11565 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
11566 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
11567 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
11568 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
11569 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
11570 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
11571 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
11572 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
11573 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
11574 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
11575 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
11576 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
11577 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
11578 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
11579 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
11580 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
11581 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
11582 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
11583 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
11584 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
11585 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
11586 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
11587 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
11588 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
11589 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
11590 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
11591 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
11592 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000011593
paul718e3742002-12-13 20:15:29 +000011594 /* old command */
11595 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
11596 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
11597 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
11598 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
11599 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
11600 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
11601 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
11602 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
11603 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
11604 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
11605 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
11606 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
11607 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
11608 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
11609 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
11610 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
11611 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
11612 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
11613 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
11614 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
11615 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
11616 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
11617 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
11618 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
11619 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
11620 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
11621 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
11622 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
11623 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
11624 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
11625 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
11626 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
11627 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
11628 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
11629 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
11630 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
11631
11632 /* old command */
11633 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
11634 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
11635 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
11636 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
11637
11638 /* old command */
11639 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
11640 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
11641 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
11642 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
11643
11644 /* old command */
11645 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
11646 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
11647 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
11648 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
11649#endif /* HAVE_IPV6 */
11650
11651 install_element (BGP_NODE, &bgp_distance_cmd);
11652 install_element (BGP_NODE, &no_bgp_distance_cmd);
11653 install_element (BGP_NODE, &no_bgp_distance2_cmd);
11654 install_element (BGP_NODE, &bgp_distance_source_cmd);
11655 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
11656 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
11657 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
11658
11659 install_element (BGP_NODE, &bgp_damp_set_cmd);
11660 install_element (BGP_NODE, &bgp_damp_set2_cmd);
11661 install_element (BGP_NODE, &bgp_damp_set3_cmd);
11662 install_element (BGP_NODE, &bgp_damp_unset_cmd);
11663 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
11664 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
11665 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
11666 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
11667 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
11668 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
11669}