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