blob: 5d406a6ef1efc16a928510157b8752a1affd3cd5 [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;
paulfd79ac92004-10-13 05:06:08 +00001402 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001403 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;
paulfd79ac92004-10-13 05:06:08 +00001615 const char *reason;
paul718e3742002-12-13 20:15:29 +00001616 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
paulfd79ac92004-10-13 05:06:08 +00002923bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
2924 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00002925{
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
paulfd79ac92004-10-13 05:06:08 +00003015bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003016 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
paulfd79ac92004-10-13 05:06:08 +00003109bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3110 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003111{
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
paulfd79ac92004-10-13 05:06:08 +00003177bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3178 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003179{
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
paulfd79ac92004-10-13 05:06:08 +00004037bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4038 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004039 u_char summary_only, u_char as_set)
4040{
4041 int ret;
4042 struct prefix p;
4043 struct bgp_node *rn;
4044 struct bgp *bgp;
4045 struct bgp_aggregate *aggregate;
4046
4047 /* Convert string to prefix structure. */
4048 ret = str2prefix (prefix_str, &p);
4049 if (!ret)
4050 {
4051 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4052 return CMD_WARNING;
4053 }
4054 apply_mask (&p);
4055
4056 /* Get BGP structure. */
4057 bgp = vty->index;
4058
4059 /* Old configuration check. */
4060 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4061
4062 if (rn->info)
4063 {
4064 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4065 bgp_unlock_node (rn);
4066 return CMD_WARNING;
4067 }
4068
4069 /* Make aggregate address structure. */
4070 aggregate = bgp_aggregate_new ();
4071 aggregate->summary_only = summary_only;
4072 aggregate->as_set = as_set;
4073 aggregate->safi = safi;
4074 rn->info = aggregate;
4075
4076 /* Aggregate address insert into BGP routing table. */
4077 if (safi & SAFI_UNICAST)
4078 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4079 if (safi & SAFI_MULTICAST)
4080 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4081
4082 return CMD_SUCCESS;
4083}
4084
4085int
paulfd79ac92004-10-13 05:06:08 +00004086bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4087 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004088{
4089 int ret;
4090 struct prefix p;
4091 struct bgp_node *rn;
4092 struct bgp *bgp;
4093 struct bgp_aggregate *aggregate;
4094
4095 /* Convert string to prefix structure. */
4096 ret = str2prefix (prefix_str, &p);
4097 if (!ret)
4098 {
4099 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4100 return CMD_WARNING;
4101 }
4102 apply_mask (&p);
4103
4104 /* Get BGP structure. */
4105 bgp = vty->index;
4106
4107 /* Old configuration check. */
4108 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4109 if (! rn)
4110 {
4111 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4112 VTY_NEWLINE);
4113 return CMD_WARNING;
4114 }
4115
4116 aggregate = rn->info;
4117 if (aggregate->safi & SAFI_UNICAST)
4118 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4119 if (aggregate->safi & SAFI_MULTICAST)
4120 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4121
4122 /* Unlock aggregate address configuration. */
4123 rn->info = NULL;
4124 bgp_aggregate_free (aggregate);
4125 bgp_unlock_node (rn);
4126 bgp_unlock_node (rn);
4127
4128 return CMD_SUCCESS;
4129}
4130
4131DEFUN (aggregate_address,
4132 aggregate_address_cmd,
4133 "aggregate-address A.B.C.D/M",
4134 "Configure BGP aggregate entries\n"
4135 "Aggregate prefix\n")
4136{
4137 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4138}
4139
4140DEFUN (aggregate_address_mask,
4141 aggregate_address_mask_cmd,
4142 "aggregate-address A.B.C.D A.B.C.D",
4143 "Configure BGP aggregate entries\n"
4144 "Aggregate address\n"
4145 "Aggregate mask\n")
4146{
4147 int ret;
4148 char prefix_str[BUFSIZ];
4149
4150 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4151
4152 if (! ret)
4153 {
4154 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4155 return CMD_WARNING;
4156 }
4157
4158 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4159 0, 0);
4160}
4161
4162DEFUN (aggregate_address_summary_only,
4163 aggregate_address_summary_only_cmd,
4164 "aggregate-address A.B.C.D/M summary-only",
4165 "Configure BGP aggregate entries\n"
4166 "Aggregate prefix\n"
4167 "Filter more specific routes from updates\n")
4168{
4169 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4170 AGGREGATE_SUMMARY_ONLY, 0);
4171}
4172
4173DEFUN (aggregate_address_mask_summary_only,
4174 aggregate_address_mask_summary_only_cmd,
4175 "aggregate-address A.B.C.D A.B.C.D summary-only",
4176 "Configure BGP aggregate entries\n"
4177 "Aggregate address\n"
4178 "Aggregate mask\n"
4179 "Filter more specific routes from updates\n")
4180{
4181 int ret;
4182 char prefix_str[BUFSIZ];
4183
4184 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4185
4186 if (! ret)
4187 {
4188 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4189 return CMD_WARNING;
4190 }
4191
4192 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4193 AGGREGATE_SUMMARY_ONLY, 0);
4194}
4195
4196DEFUN (aggregate_address_as_set,
4197 aggregate_address_as_set_cmd,
4198 "aggregate-address A.B.C.D/M as-set",
4199 "Configure BGP aggregate entries\n"
4200 "Aggregate prefix\n"
4201 "Generate AS set path information\n")
4202{
4203 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4204 0, AGGREGATE_AS_SET);
4205}
4206
4207DEFUN (aggregate_address_mask_as_set,
4208 aggregate_address_mask_as_set_cmd,
4209 "aggregate-address A.B.C.D A.B.C.D as-set",
4210 "Configure BGP aggregate entries\n"
4211 "Aggregate address\n"
4212 "Aggregate mask\n"
4213 "Generate AS set path information\n")
4214{
4215 int ret;
4216 char prefix_str[BUFSIZ];
4217
4218 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4219
4220 if (! ret)
4221 {
4222 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4223 return CMD_WARNING;
4224 }
4225
4226 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4227 0, AGGREGATE_AS_SET);
4228}
4229
4230
4231DEFUN (aggregate_address_as_set_summary,
4232 aggregate_address_as_set_summary_cmd,
4233 "aggregate-address A.B.C.D/M as-set summary-only",
4234 "Configure BGP aggregate entries\n"
4235 "Aggregate prefix\n"
4236 "Generate AS set path information\n"
4237 "Filter more specific routes from updates\n")
4238{
4239 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4240 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4241}
4242
4243ALIAS (aggregate_address_as_set_summary,
4244 aggregate_address_summary_as_set_cmd,
4245 "aggregate-address A.B.C.D/M summary-only as-set",
4246 "Configure BGP aggregate entries\n"
4247 "Aggregate prefix\n"
4248 "Filter more specific routes from updates\n"
4249 "Generate AS set path information\n")
4250
4251DEFUN (aggregate_address_mask_as_set_summary,
4252 aggregate_address_mask_as_set_summary_cmd,
4253 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4254 "Configure BGP aggregate entries\n"
4255 "Aggregate address\n"
4256 "Aggregate mask\n"
4257 "Generate AS set path information\n"
4258 "Filter more specific routes from updates\n")
4259{
4260 int ret;
4261 char prefix_str[BUFSIZ];
4262
4263 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4264
4265 if (! ret)
4266 {
4267 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4268 return CMD_WARNING;
4269 }
4270
4271 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4272 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4273}
4274
4275ALIAS (aggregate_address_mask_as_set_summary,
4276 aggregate_address_mask_summary_as_set_cmd,
4277 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4278 "Configure BGP aggregate entries\n"
4279 "Aggregate address\n"
4280 "Aggregate mask\n"
4281 "Filter more specific routes from updates\n"
4282 "Generate AS set path information\n")
4283
4284DEFUN (no_aggregate_address,
4285 no_aggregate_address_cmd,
4286 "no aggregate-address A.B.C.D/M",
4287 NO_STR
4288 "Configure BGP aggregate entries\n"
4289 "Aggregate prefix\n")
4290{
4291 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4292}
4293
4294ALIAS (no_aggregate_address,
4295 no_aggregate_address_summary_only_cmd,
4296 "no aggregate-address A.B.C.D/M summary-only",
4297 NO_STR
4298 "Configure BGP aggregate entries\n"
4299 "Aggregate prefix\n"
4300 "Filter more specific routes from updates\n")
4301
4302ALIAS (no_aggregate_address,
4303 no_aggregate_address_as_set_cmd,
4304 "no aggregate-address A.B.C.D/M as-set",
4305 NO_STR
4306 "Configure BGP aggregate entries\n"
4307 "Aggregate prefix\n"
4308 "Generate AS set path information\n")
4309
4310ALIAS (no_aggregate_address,
4311 no_aggregate_address_as_set_summary_cmd,
4312 "no aggregate-address A.B.C.D/M as-set summary-only",
4313 NO_STR
4314 "Configure BGP aggregate entries\n"
4315 "Aggregate prefix\n"
4316 "Generate AS set path information\n"
4317 "Filter more specific routes from updates\n")
4318
4319ALIAS (no_aggregate_address,
4320 no_aggregate_address_summary_as_set_cmd,
4321 "no aggregate-address A.B.C.D/M summary-only as-set",
4322 NO_STR
4323 "Configure BGP aggregate entries\n"
4324 "Aggregate prefix\n"
4325 "Filter more specific routes from updates\n"
4326 "Generate AS set path information\n")
4327
4328DEFUN (no_aggregate_address_mask,
4329 no_aggregate_address_mask_cmd,
4330 "no aggregate-address A.B.C.D A.B.C.D",
4331 NO_STR
4332 "Configure BGP aggregate entries\n"
4333 "Aggregate address\n"
4334 "Aggregate mask\n")
4335{
4336 int ret;
4337 char prefix_str[BUFSIZ];
4338
4339 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4340
4341 if (! ret)
4342 {
4343 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4344 return CMD_WARNING;
4345 }
4346
4347 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4348}
4349
4350ALIAS (no_aggregate_address_mask,
4351 no_aggregate_address_mask_summary_only_cmd,
4352 "no aggregate-address A.B.C.D A.B.C.D summary-only",
4353 NO_STR
4354 "Configure BGP aggregate entries\n"
4355 "Aggregate address\n"
4356 "Aggregate mask\n"
4357 "Filter more specific routes from updates\n")
4358
4359ALIAS (no_aggregate_address_mask,
4360 no_aggregate_address_mask_as_set_cmd,
4361 "no aggregate-address A.B.C.D A.B.C.D as-set",
4362 NO_STR
4363 "Configure BGP aggregate entries\n"
4364 "Aggregate address\n"
4365 "Aggregate mask\n"
4366 "Generate AS set path information\n")
4367
4368ALIAS (no_aggregate_address_mask,
4369 no_aggregate_address_mask_as_set_summary_cmd,
4370 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4371 NO_STR
4372 "Configure BGP aggregate entries\n"
4373 "Aggregate address\n"
4374 "Aggregate mask\n"
4375 "Generate AS set path information\n"
4376 "Filter more specific routes from updates\n")
4377
4378ALIAS (no_aggregate_address_mask,
4379 no_aggregate_address_mask_summary_as_set_cmd,
4380 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4381 NO_STR
4382 "Configure BGP aggregate entries\n"
4383 "Aggregate address\n"
4384 "Aggregate mask\n"
4385 "Filter more specific routes from updates\n"
4386 "Generate AS set path information\n")
4387
4388#ifdef HAVE_IPV6
4389DEFUN (ipv6_aggregate_address,
4390 ipv6_aggregate_address_cmd,
4391 "aggregate-address X:X::X:X/M",
4392 "Configure BGP aggregate entries\n"
4393 "Aggregate prefix\n")
4394{
4395 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4396}
4397
4398DEFUN (ipv6_aggregate_address_summary_only,
4399 ipv6_aggregate_address_summary_only_cmd,
4400 "aggregate-address X:X::X:X/M summary-only",
4401 "Configure BGP aggregate entries\n"
4402 "Aggregate prefix\n"
4403 "Filter more specific routes from updates\n")
4404{
4405 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4406 AGGREGATE_SUMMARY_ONLY, 0);
4407}
4408
4409DEFUN (no_ipv6_aggregate_address,
4410 no_ipv6_aggregate_address_cmd,
4411 "no aggregate-address X:X::X:X/M",
4412 NO_STR
4413 "Configure BGP aggregate entries\n"
4414 "Aggregate prefix\n")
4415{
4416 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4417}
4418
4419DEFUN (no_ipv6_aggregate_address_summary_only,
4420 no_ipv6_aggregate_address_summary_only_cmd,
4421 "no aggregate-address X:X::X:X/M summary-only",
4422 NO_STR
4423 "Configure BGP aggregate entries\n"
4424 "Aggregate prefix\n"
4425 "Filter more specific routes from updates\n")
4426{
4427 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4428}
4429
4430ALIAS (ipv6_aggregate_address,
4431 old_ipv6_aggregate_address_cmd,
4432 "ipv6 bgp aggregate-address X:X::X:X/M",
4433 IPV6_STR
4434 BGP_STR
4435 "Configure BGP aggregate entries\n"
4436 "Aggregate prefix\n")
4437
4438ALIAS (ipv6_aggregate_address_summary_only,
4439 old_ipv6_aggregate_address_summary_only_cmd,
4440 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4441 IPV6_STR
4442 BGP_STR
4443 "Configure BGP aggregate entries\n"
4444 "Aggregate prefix\n"
4445 "Filter more specific routes from updates\n")
4446
4447ALIAS (no_ipv6_aggregate_address,
4448 old_no_ipv6_aggregate_address_cmd,
4449 "no ipv6 bgp aggregate-address X:X::X:X/M",
4450 NO_STR
4451 IPV6_STR
4452 BGP_STR
4453 "Configure BGP aggregate entries\n"
4454 "Aggregate prefix\n")
4455
4456ALIAS (no_ipv6_aggregate_address_summary_only,
4457 old_no_ipv6_aggregate_address_summary_only_cmd,
4458 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4459 NO_STR
4460 IPV6_STR
4461 BGP_STR
4462 "Configure BGP aggregate entries\n"
4463 "Aggregate prefix\n"
4464 "Filter more specific routes from updates\n")
4465#endif /* HAVE_IPV6 */
4466
4467/* Redistribute route treatment. */
4468void
4469bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4470 u_int32_t metric, u_char type)
4471{
4472 struct bgp *bgp;
4473 struct listnode *nn;
4474 struct bgp_info *new;
4475 struct bgp_info *bi;
4476 struct bgp_info info;
4477 struct bgp_node *bn;
4478 struct attr attr;
4479 struct attr attr_new;
4480 struct attr *new_attr;
4481 afi_t afi;
4482 int ret;
4483
4484 /* Make default attribute. */
4485 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4486 if (nexthop)
4487 attr.nexthop = *nexthop;
4488
4489 attr.med = metric;
4490 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4491
4492 LIST_LOOP (bm->bgp, bgp, nn)
4493 {
4494 afi = family2afi (p->family);
4495
4496 if (bgp->redist[afi][type])
4497 {
4498 /* Copy attribute for modification. */
4499 attr_new = attr;
4500
4501 if (bgp->redist_metric_flag[afi][type])
4502 attr_new.med = bgp->redist_metric[afi][type];
4503
4504 /* Apply route-map. */
4505 if (bgp->rmap[afi][type].map)
4506 {
4507 info.peer = bgp->peer_self;
4508 info.attr = &attr_new;
4509
paulfee0f4c2004-09-13 05:12:46 +00004510 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
4511
paul718e3742002-12-13 20:15:29 +00004512 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
4513 &info);
paulfee0f4c2004-09-13 05:12:46 +00004514
4515 bgp->peer_self->rmap_type = 0;
4516
paul718e3742002-12-13 20:15:29 +00004517 if (ret == RMAP_DENYMATCH)
4518 {
4519 /* Free uninterned attribute. */
4520 bgp_attr_flush (&attr_new);
4521
4522 /* Unintern original. */
4523 aspath_unintern (attr.aspath);
4524 bgp_redistribute_delete (p, type);
4525 return;
4526 }
4527 }
4528
paulfee0f4c2004-09-13 05:12:46 +00004529 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004530 new_attr = bgp_attr_intern (&attr_new);
4531
4532 for (bi = bn->info; bi; bi = bi->next)
4533 if (bi->peer == bgp->peer_self
4534 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
4535 break;
4536
4537 if (bi)
4538 {
4539 if (attrhash_cmp (bi->attr, new_attr))
4540 {
4541 bgp_attr_unintern (new_attr);
4542 aspath_unintern (attr.aspath);
4543 bgp_unlock_node (bn);
4544 return;
4545 }
4546 else
4547 {
4548 /* The attribute is changed. */
4549 SET_FLAG (bi->flags, BGP_INFO_ATTR_CHANGED);
4550
4551 /* Rewrite BGP route information. */
4552 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
4553 bgp_attr_unintern (bi->attr);
4554 bi->attr = new_attr;
4555 bi->uptime = time (NULL);
4556
4557 /* Process change. */
4558 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
4559 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4560 bgp_unlock_node (bn);
4561 aspath_unintern (attr.aspath);
4562 return;
4563 }
4564 }
4565
4566 new = bgp_info_new ();
4567 new->type = type;
4568 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
4569 new->peer = bgp->peer_self;
4570 SET_FLAG (new->flags, BGP_INFO_VALID);
4571 new->attr = new_attr;
4572 new->uptime = time (NULL);
4573
4574 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
4575 bgp_info_add (bn, new);
4576 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4577 }
4578 }
4579
4580 /* Unintern original. */
4581 aspath_unintern (attr.aspath);
4582}
4583
4584void
4585bgp_redistribute_delete (struct prefix *p, u_char type)
4586{
4587 struct bgp *bgp;
4588 struct listnode *nn;
4589 afi_t afi;
4590 struct bgp_node *rn;
4591 struct bgp_info *ri;
4592
4593 LIST_LOOP (bm->bgp, bgp, nn)
4594 {
4595 afi = family2afi (p->family);
4596
4597 if (bgp->redist[afi][type])
4598 {
paulfee0f4c2004-09-13 05:12:46 +00004599 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004600
4601 for (ri = rn->info; ri; ri = ri->next)
4602 if (ri->peer == bgp->peer_self
4603 && ri->type == type)
4604 break;
4605
4606 if (ri)
4607 {
4608 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
4609 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4610 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4611 bgp_info_delete (rn, ri);
4612 bgp_info_free (ri);
4613 bgp_unlock_node (rn);
4614 }
4615 bgp_unlock_node (rn);
4616 }
4617 }
4618}
4619
4620/* Withdraw specified route type's route. */
4621void
4622bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
4623{
4624 struct bgp_node *rn;
4625 struct bgp_info *ri;
4626 struct bgp_table *table;
4627
4628 table = bgp->rib[afi][SAFI_UNICAST];
4629
4630 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4631 {
4632 for (ri = rn->info; ri; ri = ri->next)
4633 if (ri->peer == bgp->peer_self
4634 && ri->type == type)
4635 break;
4636
4637 if (ri)
4638 {
4639 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
4640 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4641 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4642 bgp_info_delete (rn, ri);
4643 bgp_info_free (ri);
4644 bgp_unlock_node (rn);
4645 }
4646 }
4647}
4648
4649/* Static function to display route. */
4650void
4651route_vty_out_route (struct prefix *p, struct vty *vty)
4652{
4653 int len;
4654 u_int32_t destination;
4655 char buf[BUFSIZ];
4656
4657 if (p->family == AF_INET)
4658 {
4659 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
4660 destination = ntohl (p->u.prefix4.s_addr);
4661
4662 if ((IN_CLASSC (destination) && p->prefixlen == 24)
4663 || (IN_CLASSB (destination) && p->prefixlen == 16)
4664 || (IN_CLASSA (destination) && p->prefixlen == 8)
4665 || p->u.prefix4.s_addr == 0)
4666 {
4667 /* When mask is natural, mask is not displayed. */
4668 }
4669 else
4670 len += vty_out (vty, "/%d", p->prefixlen);
4671 }
4672 else
4673 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
4674 p->prefixlen);
4675
4676 len = 17 - len;
4677 if (len < 1)
4678 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
4679 else
4680 vty_out (vty, "%*s", len, " ");
4681}
4682
paul718e3742002-12-13 20:15:29 +00004683enum bgp_display_type
4684{
4685 normal_list,
4686};
4687
4688/* called from terminal list command */
ajs5a646652004-11-05 01:25:55 +00004689void
paul718e3742002-12-13 20:15:29 +00004690route_vty_out (struct vty *vty, struct prefix *p,
4691 struct bgp_info *binfo, int display, safi_t safi)
4692{
4693 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00004694
4695 /* Route status display. */
4696 if (binfo->suppress)
4697 vty_out (vty, "s");
4698 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4699 vty_out (vty, "*");
4700 else
4701 vty_out (vty, " ");
4702
4703 /* Selected */
4704 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4705 vty_out (vty, "h");
4706 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4707 vty_out (vty, "d");
4708 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4709 vty_out (vty, ">");
4710 else
4711 vty_out (vty, " ");
4712
4713 /* Internal route. */
4714 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
4715 vty_out (vty, "i");
4716 else
4717 vty_out (vty, " ");
4718
4719 /* print prefix and mask */
4720 if (! display)
4721 route_vty_out_route (p, vty);
4722 else
4723 vty_out (vty, "%*s", 17, " ");
4724
4725 /* Print attribute */
4726 attr = binfo->attr;
4727 if (attr)
4728 {
4729 if (p->family == AF_INET)
4730 {
4731 if (safi == SAFI_MPLS_VPN)
4732 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
4733 else
4734 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
4735 }
4736#ifdef HAVE_IPV6
4737 else if (p->family == AF_INET6)
4738 {
4739 int len;
4740 char buf[BUFSIZ];
4741
4742 len = vty_out (vty, "%s",
4743 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
4744 len = 16 - len;
4745 if (len < 1)
4746 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
4747 else
4748 vty_out (vty, "%*s", len, " ");
4749 }
4750#endif /* HAVE_IPV6 */
4751
4752 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
4753 vty_out (vty, "%10d", attr->med);
4754 else
4755 vty_out (vty, " ");
4756
4757 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
4758 vty_out (vty, "%7d", attr->local_pref);
4759 else
4760 vty_out (vty, " ");
4761
4762 vty_out (vty, "%7u ",attr->weight);
4763
4764 /* Print aspath */
4765 if (attr->aspath)
4766 aspath_print_vty (vty, attr->aspath);
4767
4768 /* Print origin */
4769 if (strlen (attr->aspath->str) == 0)
4770 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4771 else
4772 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4773 }
4774 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00004775}
4776
4777/* called from terminal list command */
4778void
4779route_vty_out_tmp (struct vty *vty, struct prefix *p,
4780 struct attr *attr, safi_t safi)
4781{
4782 /* Route status display. */
4783 vty_out (vty, "*");
4784 vty_out (vty, ">");
4785 vty_out (vty, " ");
4786
4787 /* print prefix and mask */
4788 route_vty_out_route (p, vty);
4789
4790 /* Print attribute */
4791 if (attr)
4792 {
4793 if (p->family == AF_INET)
4794 {
4795 if (safi == SAFI_MPLS_VPN)
4796 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
4797 else
4798 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
4799 }
4800#ifdef HAVE_IPV6
4801 else if (p->family == AF_INET6)
4802 {
4803 int len;
4804 char buf[BUFSIZ];
4805
4806 len = vty_out (vty, "%s",
4807 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
4808 len = 16 - len;
4809 if (len < 1)
4810 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
4811 else
4812 vty_out (vty, "%*s", len, " ");
4813 }
4814#endif /* HAVE_IPV6 */
4815
4816 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
4817 vty_out (vty, "%10d", attr->med);
4818 else
4819 vty_out (vty, " ");
4820
4821 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
4822 vty_out (vty, "%7d", attr->local_pref);
4823 else
4824 vty_out (vty, " ");
4825
4826 vty_out (vty, "%7d ",attr->weight);
4827
4828 /* Print aspath */
4829 if (attr->aspath)
4830 aspath_print_vty (vty, attr->aspath);
4831
4832 /* Print origin */
4833 if (strlen (attr->aspath->str) == 0)
4834 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4835 else
4836 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4837 }
4838
4839 vty_out (vty, "%s", VTY_NEWLINE);
4840}
4841
ajs5a646652004-11-05 01:25:55 +00004842void
paul718e3742002-12-13 20:15:29 +00004843route_vty_out_tag (struct vty *vty, struct prefix *p,
4844 struct bgp_info *binfo, int display, safi_t safi)
4845{
4846 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00004847 u_int32_t label = 0;
4848
paul718e3742002-12-13 20:15:29 +00004849 /* Route status display. */
4850 if (binfo->suppress)
4851 vty_out (vty, "s");
4852 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4853 vty_out (vty, "*");
4854 else
4855 vty_out (vty, " ");
4856
4857 /* Selected */
4858 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4859 vty_out (vty, "h");
4860 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4861 vty_out (vty, "d");
4862 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4863 vty_out (vty, ">");
4864 else
4865 vty_out (vty, " ");
4866
4867 /* Internal route. */
4868 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
4869 vty_out (vty, "i");
4870 else
4871 vty_out (vty, " ");
4872
4873 /* print prefix and mask */
4874 if (! display)
4875 route_vty_out_route (p, vty);
4876 else
4877 vty_out (vty, "%*s", 17, " ");
4878
4879 /* Print attribute */
4880 attr = binfo->attr;
4881 if (attr)
4882 {
4883 if (p->family == AF_INET)
4884 {
4885 if (safi == SAFI_MPLS_VPN)
4886 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
4887 else
4888 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
4889 }
4890#ifdef HAVE_IPV6
4891 else if (p->family == AF_INET6)
4892 {
4893 char buf[BUFSIZ];
4894 char buf1[BUFSIZ];
4895 if (attr->mp_nexthop_len == 16)
4896 vty_out (vty, "%s",
4897 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
4898 else if (attr->mp_nexthop_len == 32)
4899 vty_out (vty, "%s(%s)",
4900 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
4901 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
4902
4903 }
4904#endif /* HAVE_IPV6 */
4905 }
4906
4907 label = decode_label (binfo->tag);
4908
4909 vty_out (vty, "notag/%d", label);
4910
4911 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00004912}
4913
4914/* dampening route */
ajs5a646652004-11-05 01:25:55 +00004915static void
paul718e3742002-12-13 20:15:29 +00004916damp_route_vty_out (struct vty *vty, struct prefix *p,
4917 struct bgp_info *binfo, int display, safi_t safi)
4918{
4919 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00004920 int len;
4921
paul718e3742002-12-13 20:15:29 +00004922 /* Route status display. */
4923 if (binfo->suppress)
4924 vty_out (vty, "s");
4925 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4926 vty_out (vty, "*");
4927 else
4928 vty_out (vty, " ");
4929
4930 /* Selected */
4931 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4932 vty_out (vty, "h");
4933 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4934 vty_out (vty, "d");
4935 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4936 vty_out (vty, ">");
4937 else
4938 vty_out (vty, " ");
4939
4940 vty_out (vty, " ");
4941
4942 /* print prefix and mask */
4943 if (! display)
4944 route_vty_out_route (p, vty);
4945 else
4946 vty_out (vty, "%*s", 17, " ");
4947
4948 len = vty_out (vty, "%s", binfo->peer->host);
4949 len = 17 - len;
4950 if (len < 1)
4951 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
4952 else
4953 vty_out (vty, "%*s", len, " ");
4954
4955 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
4956
4957 /* Print attribute */
4958 attr = binfo->attr;
4959 if (attr)
4960 {
4961 /* Print aspath */
4962 if (attr->aspath)
4963 aspath_print_vty (vty, attr->aspath);
4964
4965 /* Print origin */
4966 if (strlen (attr->aspath->str) == 0)
4967 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4968 else
4969 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4970 }
4971 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00004972}
4973
4974#define BGP_UPTIME_LEN 25
4975
4976/* flap route */
ajs5a646652004-11-05 01:25:55 +00004977static void
paul718e3742002-12-13 20:15:29 +00004978flap_route_vty_out (struct vty *vty, struct prefix *p,
4979 struct bgp_info *binfo, int display, safi_t safi)
4980{
4981 struct attr *attr;
4982 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00004983 char timebuf[BGP_UPTIME_LEN];
4984 int len;
4985
paul718e3742002-12-13 20:15:29 +00004986 bdi = binfo->damp_info;
4987
4988 /* Route status display. */
4989 if (binfo->suppress)
4990 vty_out (vty, "s");
4991 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4992 vty_out (vty, "*");
4993 else
4994 vty_out (vty, " ");
4995
4996 /* Selected */
4997 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4998 vty_out (vty, "h");
4999 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5000 vty_out (vty, "d");
5001 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5002 vty_out (vty, ">");
5003 else
5004 vty_out (vty, " ");
5005
5006 vty_out (vty, " ");
5007
5008 /* print prefix and mask */
5009 if (! display)
5010 route_vty_out_route (p, vty);
5011 else
5012 vty_out (vty, "%*s", 17, " ");
5013
5014 len = vty_out (vty, "%s", binfo->peer->host);
5015 len = 16 - len;
5016 if (len < 1)
5017 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5018 else
5019 vty_out (vty, "%*s", len, " ");
5020
5021 len = vty_out (vty, "%d", bdi->flap);
5022 len = 5 - len;
5023 if (len < 1)
5024 vty_out (vty, " ");
5025 else
5026 vty_out (vty, "%*s ", len, " ");
5027
5028 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5029 timebuf, BGP_UPTIME_LEN));
5030
5031 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5032 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5033 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5034 else
5035 vty_out (vty, "%*s ", 8, " ");
5036
5037 /* Print attribute */
5038 attr = binfo->attr;
5039 if (attr)
5040 {
5041 /* Print aspath */
5042 if (attr->aspath)
5043 aspath_print_vty (vty, attr->aspath);
5044
5045 /* Print origin */
5046 if (strlen (attr->aspath->str) == 0)
5047 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5048 else
5049 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5050 }
5051 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005052}
5053
5054void
5055route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5056 struct bgp_info *binfo, afi_t afi, safi_t safi)
5057{
5058 char buf[INET6_ADDRSTRLEN];
5059 char buf1[BUFSIZ];
5060 struct attr *attr;
5061 int sockunion_vty_out (struct vty *, union sockunion *);
5062
5063 attr = binfo->attr;
5064
5065 if (attr)
5066 {
5067 /* Line1 display AS-path, Aggregator */
5068 if (attr->aspath)
5069 {
5070 vty_out (vty, " ");
5071 if (attr->aspath->length == 0)
5072 vty_out (vty, "Local");
5073 else
5074 aspath_print_vty (vty, attr->aspath);
5075 }
5076
5077 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR)
5078 || CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)
5079 || CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
5080 || CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)
5081 || CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5082 {
5083 vty_out (vty, ",");
5084
5085 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR))
5086 vty_out (vty, " (aggregated by %d %s)", attr->aggregator_as,
5087 inet_ntoa (attr->aggregator_addr));
5088 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5089 vty_out (vty, " (Received from a RR-client)");
5090 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5091 vty_out (vty, " (Received from a RS-client)");
5092 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5093 vty_out (vty, " (history entry)");
5094 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5095 vty_out (vty, " (suppressed due to dampening)");
5096 }
5097 vty_out (vty, "%s", VTY_NEWLINE);
5098
5099 /* Line2 display Next-hop, Neighbor, Router-id */
5100 if (p->family == AF_INET)
5101 {
5102 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5103 inet_ntoa (attr->mp_nexthop_global_in) :
5104 inet_ntoa (attr->nexthop));
5105 }
5106#ifdef HAVE_IPV6
5107 else
5108 {
5109 vty_out (vty, " %s",
5110 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5111 buf, INET6_ADDRSTRLEN));
5112 }
5113#endif /* HAVE_IPV6 */
5114
5115 if (binfo->peer == bgp->peer_self)
5116 {
5117 vty_out (vty, " from %s ",
5118 p->family == AF_INET ? "0.0.0.0" : "::");
5119 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5120 }
5121 else
5122 {
5123 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5124 vty_out (vty, " (inaccessible)");
5125 else if (binfo->igpmetric)
5126 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005127 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005128 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5129 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5130 else
5131 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5132 }
5133 vty_out (vty, "%s", VTY_NEWLINE);
5134
5135#ifdef HAVE_IPV6
5136 /* display nexthop local */
5137 if (attr->mp_nexthop_len == 32)
5138 {
5139 vty_out (vty, " (%s)%s",
5140 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5141 buf, INET6_ADDRSTRLEN),
5142 VTY_NEWLINE);
5143 }
5144#endif /* HAVE_IPV6 */
5145
5146 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5147 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5148
5149 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5150 vty_out (vty, ", metric %d", attr->med);
5151
5152 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5153 vty_out (vty, ", localpref %d", attr->local_pref);
5154 else
5155 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5156
5157 if (attr->weight != 0)
5158 vty_out (vty, ", weight %d", attr->weight);
5159
5160 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5161 vty_out (vty, ", valid");
5162
5163 if (binfo->peer != bgp->peer_self)
5164 {
5165 if (binfo->peer->as == binfo->peer->local_as)
5166 vty_out (vty, ", internal");
5167 else
5168 vty_out (vty, ", %s",
5169 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5170 }
5171 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5172 vty_out (vty, ", aggregated, local");
5173 else if (binfo->type != ZEBRA_ROUTE_BGP)
5174 vty_out (vty, ", sourced");
5175 else
5176 vty_out (vty, ", sourced, local");
5177
5178 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5179 vty_out (vty, ", atomic-aggregate");
5180
5181 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5182 vty_out (vty, ", best");
5183
5184 vty_out (vty, "%s", VTY_NEWLINE);
5185
5186 /* Line 4 display Community */
5187 if (attr->community)
5188 vty_out (vty, " Community: %s%s", attr->community->str,
5189 VTY_NEWLINE);
5190
5191 /* Line 5 display Extended-community */
5192 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5193 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5194 VTY_NEWLINE);
5195
5196 /* Line 6 display Originator, Cluster-id */
5197 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5198 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5199 {
5200 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5201 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5202
5203 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5204 {
5205 int i;
5206 vty_out (vty, ", Cluster list: ");
5207 for (i = 0; i < attr->cluster->length / 4; i++)
5208 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5209 }
5210 vty_out (vty, "%s", VTY_NEWLINE);
5211 }
5212
5213 if (binfo->damp_info)
5214 bgp_damp_info_vty (vty, binfo);
5215
5216 /* Line 7 display Uptime */
5217 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5218 }
5219 vty_out (vty, "%s", VTY_NEWLINE);
5220}
5221
5222#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5223#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5224#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5225
5226enum bgp_show_type
5227{
5228 bgp_show_type_normal,
5229 bgp_show_type_regexp,
5230 bgp_show_type_prefix_list,
5231 bgp_show_type_filter_list,
5232 bgp_show_type_route_map,
5233 bgp_show_type_neighbor,
5234 bgp_show_type_cidr_only,
5235 bgp_show_type_prefix_longer,
5236 bgp_show_type_community_all,
5237 bgp_show_type_community,
5238 bgp_show_type_community_exact,
5239 bgp_show_type_community_list,
5240 bgp_show_type_community_list_exact,
5241 bgp_show_type_flap_statistics,
5242 bgp_show_type_flap_address,
5243 bgp_show_type_flap_prefix,
5244 bgp_show_type_flap_cidr_only,
5245 bgp_show_type_flap_regexp,
5246 bgp_show_type_flap_filter_list,
5247 bgp_show_type_flap_prefix_list,
5248 bgp_show_type_flap_prefix_longer,
5249 bgp_show_type_flap_route_map,
5250 bgp_show_type_flap_neighbor,
5251 bgp_show_type_dampend_paths,
5252 bgp_show_type_damp_neighbor
5253};
5254
ajs5a646652004-11-05 01:25:55 +00005255static int
paulfee0f4c2004-09-13 05:12:46 +00005256bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00005257 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00005258{
paul718e3742002-12-13 20:15:29 +00005259 struct bgp_info *ri;
5260 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005261 int header = 1;
paul718e3742002-12-13 20:15:29 +00005262 int display;
ajs5a646652004-11-05 01:25:55 +00005263 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00005264
5265 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00005266 output_count = 0;
paul718e3742002-12-13 20:15:29 +00005267
paul718e3742002-12-13 20:15:29 +00005268 /* Start processing of routes. */
5269 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5270 if (rn->info != NULL)
5271 {
5272 display = 0;
5273
5274 for (ri = rn->info; ri; ri = ri->next)
5275 {
ajs5a646652004-11-05 01:25:55 +00005276 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00005277 || type == bgp_show_type_flap_address
5278 || type == bgp_show_type_flap_prefix
5279 || type == bgp_show_type_flap_cidr_only
5280 || type == bgp_show_type_flap_regexp
5281 || type == bgp_show_type_flap_filter_list
5282 || type == bgp_show_type_flap_prefix_list
5283 || type == bgp_show_type_flap_prefix_longer
5284 || type == bgp_show_type_flap_route_map
5285 || type == bgp_show_type_flap_neighbor
5286 || type == bgp_show_type_dampend_paths
5287 || type == bgp_show_type_damp_neighbor)
5288 {
5289 if (! ri->damp_info)
5290 continue;
5291 }
5292 if (type == bgp_show_type_regexp
5293 || type == bgp_show_type_flap_regexp)
5294 {
ajs5a646652004-11-05 01:25:55 +00005295 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00005296
5297 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5298 continue;
5299 }
5300 if (type == bgp_show_type_prefix_list
5301 || type == bgp_show_type_flap_prefix_list)
5302 {
ajs5a646652004-11-05 01:25:55 +00005303 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00005304
5305 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5306 continue;
5307 }
5308 if (type == bgp_show_type_filter_list
5309 || type == bgp_show_type_flap_filter_list)
5310 {
ajs5a646652004-11-05 01:25:55 +00005311 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00005312
5313 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5314 continue;
5315 }
5316 if (type == bgp_show_type_route_map
5317 || type == bgp_show_type_flap_route_map)
5318 {
ajs5a646652004-11-05 01:25:55 +00005319 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00005320 struct bgp_info binfo;
5321 struct attr dummy_attr;
5322 int ret;
5323
5324 dummy_attr = *ri->attr;
5325 binfo.peer = ri->peer;
5326 binfo.attr = &dummy_attr;
5327
5328 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5329
5330 if (ret == RMAP_DENYMATCH)
5331 continue;
5332 }
5333 if (type == bgp_show_type_neighbor
5334 || type == bgp_show_type_flap_neighbor
5335 || type == bgp_show_type_damp_neighbor)
5336 {
ajs5a646652004-11-05 01:25:55 +00005337 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00005338
5339 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5340 continue;
5341 }
5342 if (type == bgp_show_type_cidr_only
5343 || type == bgp_show_type_flap_cidr_only)
5344 {
5345 u_int32_t destination;
5346
5347 destination = ntohl (rn->p.u.prefix4.s_addr);
5348 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5349 continue;
5350 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5351 continue;
5352 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5353 continue;
5354 }
5355 if (type == bgp_show_type_prefix_longer
5356 || type == bgp_show_type_flap_prefix_longer)
5357 {
ajs5a646652004-11-05 01:25:55 +00005358 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005359
5360 if (! prefix_match (p, &rn->p))
5361 continue;
5362 }
5363 if (type == bgp_show_type_community_all)
5364 {
5365 if (! ri->attr->community)
5366 continue;
5367 }
5368 if (type == bgp_show_type_community)
5369 {
ajs5a646652004-11-05 01:25:55 +00005370 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005371
5372 if (! ri->attr->community ||
5373 ! community_match (ri->attr->community, com))
5374 continue;
5375 }
5376 if (type == bgp_show_type_community_exact)
5377 {
ajs5a646652004-11-05 01:25:55 +00005378 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005379
5380 if (! ri->attr->community ||
5381 ! community_cmp (ri->attr->community, com))
5382 continue;
5383 }
5384 if (type == bgp_show_type_community_list)
5385 {
ajs5a646652004-11-05 01:25:55 +00005386 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005387
5388 if (! community_list_match (ri->attr->community, list))
5389 continue;
5390 }
5391 if (type == bgp_show_type_community_list_exact)
5392 {
ajs5a646652004-11-05 01:25:55 +00005393 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005394
5395 if (! community_list_exact_match (ri->attr->community, list))
5396 continue;
5397 }
5398 if (type == bgp_show_type_flap_address
5399 || type == bgp_show_type_flap_prefix)
5400 {
ajs5a646652004-11-05 01:25:55 +00005401 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005402
5403 if (! prefix_match (&rn->p, p))
5404 continue;
5405
5406 if (type == bgp_show_type_flap_prefix)
5407 if (p->prefixlen != rn->p.prefixlen)
5408 continue;
5409 }
5410 if (type == bgp_show_type_dampend_paths
5411 || type == bgp_show_type_damp_neighbor)
5412 {
5413 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5414 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5415 continue;
5416 }
5417
5418 if (header)
5419 {
paulfee0f4c2004-09-13 05:12:46 +00005420 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 +00005421 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
5422 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
5423 if (type == bgp_show_type_dampend_paths
5424 || type == bgp_show_type_damp_neighbor)
5425 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5426 else if (type == bgp_show_type_flap_statistics
5427 || type == bgp_show_type_flap_address
5428 || type == bgp_show_type_flap_prefix
5429 || type == bgp_show_type_flap_cidr_only
5430 || type == bgp_show_type_flap_regexp
5431 || type == bgp_show_type_flap_filter_list
5432 || type == bgp_show_type_flap_prefix_list
5433 || type == bgp_show_type_flap_prefix_longer
5434 || type == bgp_show_type_flap_route_map
5435 || type == bgp_show_type_flap_neighbor)
5436 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5437 else
5438 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005439 header = 0;
5440 }
5441
5442 if (type == bgp_show_type_dampend_paths
5443 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00005444 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005445 else if (type == bgp_show_type_flap_statistics
5446 || type == bgp_show_type_flap_address
5447 || type == bgp_show_type_flap_prefix
5448 || type == bgp_show_type_flap_cidr_only
5449 || type == bgp_show_type_flap_regexp
5450 || type == bgp_show_type_flap_filter_list
5451 || type == bgp_show_type_flap_prefix_list
5452 || type == bgp_show_type_flap_prefix_longer
5453 || type == bgp_show_type_flap_route_map
5454 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00005455 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005456 else
ajs5a646652004-11-05 01:25:55 +00005457 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005458 display++;
5459 }
5460 if (display)
ajs5a646652004-11-05 01:25:55 +00005461 output_count++;
paul718e3742002-12-13 20:15:29 +00005462 }
5463
5464 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00005465 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00005466 {
5467 if (type == bgp_show_type_normal)
5468 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5469 }
5470 else
5471 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00005472 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005473
5474 return CMD_SUCCESS;
5475}
5476
ajs5a646652004-11-05 01:25:55 +00005477static int
paulfee0f4c2004-09-13 05:12:46 +00005478bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00005479 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00005480{
5481 struct bgp_table *table;
5482
5483 if (bgp == NULL) {
5484 bgp = bgp_get_default ();
5485 }
5486
5487 if (bgp == NULL)
5488 {
5489 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5490 return CMD_WARNING;
5491 }
5492
5493
5494 table = bgp->rib[afi][safi];
5495
ajs5a646652004-11-05 01:25:55 +00005496 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00005497}
5498
paul718e3742002-12-13 20:15:29 +00005499/* Header of detailed BGP route information */
5500void
5501route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5502 struct bgp_node *rn,
5503 struct prefix_rd *prd, afi_t afi, safi_t safi)
5504{
5505 struct bgp_info *ri;
5506 struct prefix *p;
5507 struct peer *peer;
5508 struct listnode *nn;
5509 char buf1[INET6_ADDRSTRLEN];
5510 char buf2[INET6_ADDRSTRLEN];
5511 int count = 0;
5512 int best = 0;
5513 int suppress = 0;
5514 int no_export = 0;
5515 int no_advertise = 0;
5516 int local_as = 0;
5517 int first = 0;
5518
5519 p = &rn->p;
5520 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5521 (safi == SAFI_MPLS_VPN ?
5522 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5523 safi == SAFI_MPLS_VPN ? ":" : "",
5524 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5525 p->prefixlen, VTY_NEWLINE);
5526
5527 for (ri = rn->info; ri; ri = ri->next)
5528 {
5529 count++;
5530 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5531 {
5532 best = count;
5533 if (ri->suppress)
5534 suppress = 1;
5535 if (ri->attr->community != NULL)
5536 {
5537 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5538 no_advertise = 1;
5539 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5540 no_export = 1;
5541 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5542 local_as = 1;
5543 }
5544 }
5545 }
5546
5547 vty_out (vty, "Paths: (%d available", count);
5548 if (best)
5549 {
5550 vty_out (vty, ", best #%d", best);
5551 if (safi == SAFI_UNICAST)
5552 vty_out (vty, ", table Default-IP-Routing-Table");
5553 }
5554 else
5555 vty_out (vty, ", no best path");
5556 if (no_advertise)
5557 vty_out (vty, ", not advertised to any peer");
5558 else if (no_export)
5559 vty_out (vty, ", not advertised to EBGP peer");
5560 else if (local_as)
5561 vty_out (vty, ", not advertised outside local AS");
5562 if (suppress)
5563 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5564 vty_out (vty, ")%s", VTY_NEWLINE);
5565
5566 /* advertised peer */
5567 LIST_LOOP (bgp->peer, peer, nn)
5568 {
5569 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5570 {
5571 if (! first)
5572 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5573 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5574 first = 1;
5575 }
5576 }
5577 if (! first)
5578 vty_out (vty, " Not advertised to any peer");
5579 vty_out (vty, "%s", VTY_NEWLINE);
5580}
5581
5582/* Display specified route of BGP table. */
5583int
paulfee0f4c2004-09-13 05:12:46 +00005584bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00005585 struct bgp_table *rib, const char *ip_str,
5586 afi_t afi, safi_t safi, struct prefix_rd *prd,
5587 int prefix_check)
paul718e3742002-12-13 20:15:29 +00005588{
5589 int ret;
5590 int header;
5591 int display = 0;
5592 struct prefix match;
5593 struct bgp_node *rn;
5594 struct bgp_node *rm;
5595 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00005596 struct bgp_table *table;
5597
paul718e3742002-12-13 20:15:29 +00005598 /* Check IP address argument. */
5599 ret = str2prefix (ip_str, &match);
5600 if (! ret)
5601 {
5602 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5603 return CMD_WARNING;
5604 }
5605
5606 match.family = afi2family (afi);
5607
5608 if (safi == SAFI_MPLS_VPN)
5609 {
paulfee0f4c2004-09-13 05:12:46 +00005610 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00005611 {
5612 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5613 continue;
5614
5615 if ((table = rn->info) != NULL)
5616 {
5617 header = 1;
5618
5619 if ((rm = bgp_node_match (table, &match)) != NULL)
5620 {
5621 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5622 continue;
5623
5624 for (ri = rm->info; ri; ri = ri->next)
5625 {
5626 if (header)
5627 {
5628 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5629 AFI_IP, SAFI_MPLS_VPN);
5630
5631 header = 0;
5632 }
5633 display++;
5634 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5635 }
5636 }
5637 }
5638 }
5639 }
5640 else
5641 {
5642 header = 1;
5643
paulfee0f4c2004-09-13 05:12:46 +00005644 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00005645 {
5646 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5647 {
5648 for (ri = rn->info; ri; ri = ri->next)
5649 {
5650 if (header)
5651 {
5652 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
5653 header = 0;
5654 }
5655 display++;
5656 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
5657 }
5658 }
5659 }
5660 }
5661
5662 if (! display)
5663 {
5664 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5665 return CMD_WARNING;
5666 }
5667
5668 return CMD_SUCCESS;
5669}
5670
paulfee0f4c2004-09-13 05:12:46 +00005671/* Display specified route of Main RIB */
5672int
paulfd79ac92004-10-13 05:06:08 +00005673bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00005674 afi_t afi, safi_t safi, struct prefix_rd *prd,
5675 int prefix_check)
5676{
5677 struct bgp *bgp;
5678
5679 /* BGP structure lookup. */
5680 if (view_name)
5681 {
5682 bgp = bgp_lookup_by_name (view_name);
5683 if (bgp == NULL)
5684 {
5685 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
5686 return CMD_WARNING;
5687 }
5688 }
5689 else
5690 {
5691 bgp = bgp_get_default ();
5692 if (bgp == NULL)
5693 {
5694 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5695 return CMD_WARNING;
5696 }
5697 }
5698
5699 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
5700 afi, safi, prd, prefix_check);
5701}
5702
paul718e3742002-12-13 20:15:29 +00005703/* BGP route print out function. */
5704DEFUN (show_ip_bgp,
5705 show_ip_bgp_cmd,
5706 "show ip bgp",
5707 SHOW_STR
5708 IP_STR
5709 BGP_STR)
5710{
ajs5a646652004-11-05 01:25:55 +00005711 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00005712}
5713
5714DEFUN (show_ip_bgp_ipv4,
5715 show_ip_bgp_ipv4_cmd,
5716 "show ip bgp ipv4 (unicast|multicast)",
5717 SHOW_STR
5718 IP_STR
5719 BGP_STR
5720 "Address family\n"
5721 "Address Family modifier\n"
5722 "Address Family modifier\n")
5723{
5724 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00005725 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
5726 NULL);
paul718e3742002-12-13 20:15:29 +00005727
ajs5a646652004-11-05 01:25:55 +00005728 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00005729}
5730
5731DEFUN (show_ip_bgp_route,
5732 show_ip_bgp_route_cmd,
5733 "show ip bgp A.B.C.D",
5734 SHOW_STR
5735 IP_STR
5736 BGP_STR
5737 "Network in the BGP routing table to display\n")
5738{
5739 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
5740}
5741
5742DEFUN (show_ip_bgp_ipv4_route,
5743 show_ip_bgp_ipv4_route_cmd,
5744 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
5745 SHOW_STR
5746 IP_STR
5747 BGP_STR
5748 "Address family\n"
5749 "Address Family modifier\n"
5750 "Address Family modifier\n"
5751 "Network in the BGP routing table to display\n")
5752{
5753 if (strncmp (argv[0], "m", 1) == 0)
5754 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
5755
5756 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
5757}
5758
5759DEFUN (show_ip_bgp_vpnv4_all_route,
5760 show_ip_bgp_vpnv4_all_route_cmd,
5761 "show ip bgp vpnv4 all A.B.C.D",
5762 SHOW_STR
5763 IP_STR
5764 BGP_STR
5765 "Display VPNv4 NLRI specific information\n"
5766 "Display information about all VPNv4 NLRIs\n"
5767 "Network in the BGP routing table to display\n")
5768{
5769 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
5770}
5771
5772DEFUN (show_ip_bgp_vpnv4_rd_route,
5773 show_ip_bgp_vpnv4_rd_route_cmd,
5774 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
5775 SHOW_STR
5776 IP_STR
5777 BGP_STR
5778 "Display VPNv4 NLRI specific information\n"
5779 "Display information for a route distinguisher\n"
5780 "VPN Route Distinguisher\n"
5781 "Network in the BGP routing table to display\n")
5782{
5783 int ret;
5784 struct prefix_rd prd;
5785
5786 ret = str2prefix_rd (argv[0], &prd);
5787 if (! ret)
5788 {
5789 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
5790 return CMD_WARNING;
5791 }
5792 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
5793}
5794
5795DEFUN (show_ip_bgp_prefix,
5796 show_ip_bgp_prefix_cmd,
5797 "show ip bgp A.B.C.D/M",
5798 SHOW_STR
5799 IP_STR
5800 BGP_STR
5801 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5802{
5803 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
5804}
5805
5806DEFUN (show_ip_bgp_ipv4_prefix,
5807 show_ip_bgp_ipv4_prefix_cmd,
5808 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
5809 SHOW_STR
5810 IP_STR
5811 BGP_STR
5812 "Address family\n"
5813 "Address Family modifier\n"
5814 "Address Family modifier\n"
5815 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5816{
5817 if (strncmp (argv[0], "m", 1) == 0)
5818 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
5819
5820 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
5821}
5822
5823DEFUN (show_ip_bgp_vpnv4_all_prefix,
5824 show_ip_bgp_vpnv4_all_prefix_cmd,
5825 "show ip bgp vpnv4 all A.B.C.D/M",
5826 SHOW_STR
5827 IP_STR
5828 BGP_STR
5829 "Display VPNv4 NLRI specific information\n"
5830 "Display information about all VPNv4 NLRIs\n"
5831 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5832{
5833 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
5834}
5835
5836DEFUN (show_ip_bgp_vpnv4_rd_prefix,
5837 show_ip_bgp_vpnv4_rd_prefix_cmd,
5838 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
5839 SHOW_STR
5840 IP_STR
5841 BGP_STR
5842 "Display VPNv4 NLRI specific information\n"
5843 "Display information for a route distinguisher\n"
5844 "VPN Route Distinguisher\n"
5845 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5846{
5847 int ret;
5848 struct prefix_rd prd;
5849
5850 ret = str2prefix_rd (argv[0], &prd);
5851 if (! ret)
5852 {
5853 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
5854 return CMD_WARNING;
5855 }
5856 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
5857}
5858
5859DEFUN (show_ip_bgp_view,
5860 show_ip_bgp_view_cmd,
5861 "show ip bgp view WORD",
5862 SHOW_STR
5863 IP_STR
5864 BGP_STR
5865 "BGP view\n"
5866 "BGP view name\n")
5867{
paulbb46e942003-10-24 19:02:03 +00005868 struct bgp *bgp;
5869
5870 /* BGP structure lookup. */
5871 bgp = bgp_lookup_by_name (argv[0]);
5872 if (bgp == NULL)
5873 {
5874 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
5875 return CMD_WARNING;
5876 }
5877
ajs5a646652004-11-05 01:25:55 +00005878 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00005879}
5880
5881DEFUN (show_ip_bgp_view_route,
5882 show_ip_bgp_view_route_cmd,
5883 "show ip bgp view WORD A.B.C.D",
5884 SHOW_STR
5885 IP_STR
5886 BGP_STR
5887 "BGP view\n"
5888 "BGP view name\n"
5889 "Network in the BGP routing table to display\n")
5890{
5891 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
5892}
5893
5894DEFUN (show_ip_bgp_view_prefix,
5895 show_ip_bgp_view_prefix_cmd,
5896 "show ip bgp view WORD A.B.C.D/M",
5897 SHOW_STR
5898 IP_STR
5899 BGP_STR
5900 "BGP view\n"
5901 "BGP view name\n"
5902 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5903{
5904 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
5905}
5906
5907#ifdef HAVE_IPV6
5908DEFUN (show_bgp,
5909 show_bgp_cmd,
5910 "show bgp",
5911 SHOW_STR
5912 BGP_STR)
5913{
ajs5a646652004-11-05 01:25:55 +00005914 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
5915 NULL);
paul718e3742002-12-13 20:15:29 +00005916}
5917
5918ALIAS (show_bgp,
5919 show_bgp_ipv6_cmd,
5920 "show bgp ipv6",
5921 SHOW_STR
5922 BGP_STR
5923 "Address family\n")
5924
5925/* old command */
5926DEFUN (show_ipv6_bgp,
5927 show_ipv6_bgp_cmd,
5928 "show ipv6 bgp",
5929 SHOW_STR
5930 IP_STR
5931 BGP_STR)
5932{
ajs5a646652004-11-05 01:25:55 +00005933 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
5934 NULL);
paul718e3742002-12-13 20:15:29 +00005935}
5936
5937DEFUN (show_bgp_route,
5938 show_bgp_route_cmd,
5939 "show bgp X:X::X:X",
5940 SHOW_STR
5941 BGP_STR
5942 "Network in the BGP routing table to display\n")
5943{
5944 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
5945}
5946
5947ALIAS (show_bgp_route,
5948 show_bgp_ipv6_route_cmd,
5949 "show bgp ipv6 X:X::X:X",
5950 SHOW_STR
5951 BGP_STR
5952 "Address family\n"
5953 "Network in the BGP routing table to display\n")
5954
5955/* old command */
5956DEFUN (show_ipv6_bgp_route,
5957 show_ipv6_bgp_route_cmd,
5958 "show ipv6 bgp X:X::X:X",
5959 SHOW_STR
5960 IP_STR
5961 BGP_STR
5962 "Network in the BGP routing table to display\n")
5963{
5964 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
5965}
5966
5967DEFUN (show_bgp_prefix,
5968 show_bgp_prefix_cmd,
5969 "show bgp X:X::X:X/M",
5970 SHOW_STR
5971 BGP_STR
5972 "IPv6 prefix <network>/<length>\n")
5973{
5974 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
5975}
5976
5977ALIAS (show_bgp_prefix,
5978 show_bgp_ipv6_prefix_cmd,
5979 "show bgp ipv6 X:X::X:X/M",
5980 SHOW_STR
5981 BGP_STR
5982 "Address family\n"
5983 "IPv6 prefix <network>/<length>\n")
5984
5985/* old command */
5986DEFUN (show_ipv6_bgp_prefix,
5987 show_ipv6_bgp_prefix_cmd,
5988 "show ipv6 bgp X:X::X:X/M",
5989 SHOW_STR
5990 IP_STR
5991 BGP_STR
5992 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5993{
5994 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
5995}
5996
paulbb46e942003-10-24 19:02:03 +00005997DEFUN (show_bgp_view,
5998 show_bgp_view_cmd,
5999 "show bgp view WORD",
6000 SHOW_STR
6001 BGP_STR
6002 "BGP view\n"
6003 "View name\n")
6004{
6005 struct bgp *bgp;
6006
6007 /* BGP structure lookup. */
6008 bgp = bgp_lookup_by_name (argv[0]);
6009 if (bgp == NULL)
6010 {
6011 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6012 return CMD_WARNING;
6013 }
6014
ajs5a646652004-11-05 01:25:55 +00006015 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006016}
6017
6018ALIAS (show_bgp_view,
6019 show_bgp_view_ipv6_cmd,
6020 "show bgp view WORD ipv6",
6021 SHOW_STR
6022 BGP_STR
6023 "BGP view\n"
6024 "View name\n"
6025 "Address family\n")
6026
6027DEFUN (show_bgp_view_route,
6028 show_bgp_view_route_cmd,
6029 "show bgp view WORD X:X::X:X",
6030 SHOW_STR
6031 BGP_STR
6032 "BGP view\n"
6033 "View name\n"
6034 "Network in the BGP routing table to display\n")
6035{
6036 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6037}
6038
6039ALIAS (show_bgp_view_route,
6040 show_bgp_view_ipv6_route_cmd,
6041 "show bgp view WORD ipv6 X:X::X:X",
6042 SHOW_STR
6043 BGP_STR
6044 "BGP view\n"
6045 "View name\n"
6046 "Address family\n"
6047 "Network in the BGP routing table to display\n")
6048
6049DEFUN (show_bgp_view_prefix,
6050 show_bgp_view_prefix_cmd,
6051 "show bgp view WORD X:X::X:X/M",
6052 SHOW_STR
6053 BGP_STR
6054 "BGP view\n"
6055 "View name\n"
6056 "IPv6 prefix <network>/<length>\n")
6057{
6058 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6059}
6060
6061ALIAS (show_bgp_view_prefix,
6062 show_bgp_view_ipv6_prefix_cmd,
6063 "show bgp view WORD ipv6 X:X::X:X/M",
6064 SHOW_STR
6065 BGP_STR
6066 "BGP view\n"
6067 "View name\n"
6068 "Address family\n"
6069 "IPv6 prefix <network>/<length>\n")
6070
paul718e3742002-12-13 20:15:29 +00006071/* old command */
6072DEFUN (show_ipv6_mbgp,
6073 show_ipv6_mbgp_cmd,
6074 "show ipv6 mbgp",
6075 SHOW_STR
6076 IP_STR
6077 MBGP_STR)
6078{
ajs5a646652004-11-05 01:25:55 +00006079 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6080 NULL);
paul718e3742002-12-13 20:15:29 +00006081}
6082
6083/* old command */
6084DEFUN (show_ipv6_mbgp_route,
6085 show_ipv6_mbgp_route_cmd,
6086 "show ipv6 mbgp X:X::X:X",
6087 SHOW_STR
6088 IP_STR
6089 MBGP_STR
6090 "Network in the MBGP routing table to display\n")
6091{
6092 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6093}
6094
6095/* old command */
6096DEFUN (show_ipv6_mbgp_prefix,
6097 show_ipv6_mbgp_prefix_cmd,
6098 "show ipv6 mbgp X:X::X:X/M",
6099 SHOW_STR
6100 IP_STR
6101 MBGP_STR
6102 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6103{
6104 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6105}
6106#endif
6107
paul718e3742002-12-13 20:15:29 +00006108
6109int
paulfd79ac92004-10-13 05:06:08 +00006110bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006111 safi_t safi, enum bgp_show_type type)
6112{
6113 int i;
6114 struct buffer *b;
6115 char *regstr;
6116 int first;
6117 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006118 int rc;
paul718e3742002-12-13 20:15:29 +00006119
6120 first = 0;
6121 b = buffer_new (1024);
6122 for (i = 0; i < argc; i++)
6123 {
6124 if (first)
6125 buffer_putc (b, ' ');
6126 else
6127 {
6128 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6129 continue;
6130 first = 1;
6131 }
6132
6133 buffer_putstr (b, argv[i]);
6134 }
6135 buffer_putc (b, '\0');
6136
6137 regstr = buffer_getstr (b);
6138 buffer_free (b);
6139
6140 regex = bgp_regcomp (regstr);
6141 if (! regex)
6142 {
6143 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6144 VTY_NEWLINE);
6145 return CMD_WARNING;
6146 }
6147
ajs5a646652004-11-05 01:25:55 +00006148 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6149 bgp_regex_free (regex);
6150 return rc;
paul718e3742002-12-13 20:15:29 +00006151}
6152
6153DEFUN (show_ip_bgp_regexp,
6154 show_ip_bgp_regexp_cmd,
6155 "show ip bgp regexp .LINE",
6156 SHOW_STR
6157 IP_STR
6158 BGP_STR
6159 "Display routes matching the AS path regular expression\n"
6160 "A regular-expression to match the BGP AS paths\n")
6161{
6162 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6163 bgp_show_type_regexp);
6164}
6165
6166DEFUN (show_ip_bgp_flap_regexp,
6167 show_ip_bgp_flap_regexp_cmd,
6168 "show ip bgp flap-statistics regexp .LINE",
6169 SHOW_STR
6170 IP_STR
6171 BGP_STR
6172 "Display flap statistics of routes\n"
6173 "Display routes matching the AS path regular expression\n"
6174 "A regular-expression to match the BGP AS paths\n")
6175{
6176 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6177 bgp_show_type_flap_regexp);
6178}
6179
6180DEFUN (show_ip_bgp_ipv4_regexp,
6181 show_ip_bgp_ipv4_regexp_cmd,
6182 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6183 SHOW_STR
6184 IP_STR
6185 BGP_STR
6186 "Address family\n"
6187 "Address Family modifier\n"
6188 "Address Family modifier\n"
6189 "Display routes matching the AS path regular expression\n"
6190 "A regular-expression to match the BGP AS paths\n")
6191{
6192 if (strncmp (argv[0], "m", 1) == 0)
6193 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6194 bgp_show_type_regexp);
6195
6196 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6197 bgp_show_type_regexp);
6198}
6199
6200#ifdef HAVE_IPV6
6201DEFUN (show_bgp_regexp,
6202 show_bgp_regexp_cmd,
6203 "show bgp regexp .LINE",
6204 SHOW_STR
6205 BGP_STR
6206 "Display routes matching the AS path regular expression\n"
6207 "A regular-expression to match the BGP AS paths\n")
6208{
6209 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6210 bgp_show_type_regexp);
6211}
6212
6213ALIAS (show_bgp_regexp,
6214 show_bgp_ipv6_regexp_cmd,
6215 "show bgp ipv6 regexp .LINE",
6216 SHOW_STR
6217 BGP_STR
6218 "Address family\n"
6219 "Display routes matching the AS path regular expression\n"
6220 "A regular-expression to match the BGP AS paths\n")
6221
6222/* old command */
6223DEFUN (show_ipv6_bgp_regexp,
6224 show_ipv6_bgp_regexp_cmd,
6225 "show ipv6 bgp regexp .LINE",
6226 SHOW_STR
6227 IP_STR
6228 BGP_STR
6229 "Display routes matching the AS path regular expression\n"
6230 "A regular-expression to match the BGP AS paths\n")
6231{
6232 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6233 bgp_show_type_regexp);
6234}
6235
6236/* old command */
6237DEFUN (show_ipv6_mbgp_regexp,
6238 show_ipv6_mbgp_regexp_cmd,
6239 "show ipv6 mbgp regexp .LINE",
6240 SHOW_STR
6241 IP_STR
6242 BGP_STR
6243 "Display routes matching the AS path regular expression\n"
6244 "A regular-expression to match the MBGP AS paths\n")
6245{
6246 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6247 bgp_show_type_regexp);
6248}
6249#endif /* HAVE_IPV6 */
6250
6251int
paulfd79ac92004-10-13 05:06:08 +00006252bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006253 safi_t safi, enum bgp_show_type type)
6254{
6255 struct prefix_list *plist;
6256
6257 plist = prefix_list_lookup (afi, prefix_list_str);
6258 if (plist == NULL)
6259 {
6260 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6261 prefix_list_str, VTY_NEWLINE);
6262 return CMD_WARNING;
6263 }
6264
ajs5a646652004-11-05 01:25:55 +00006265 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00006266}
6267
6268DEFUN (show_ip_bgp_prefix_list,
6269 show_ip_bgp_prefix_list_cmd,
6270 "show ip bgp prefix-list WORD",
6271 SHOW_STR
6272 IP_STR
6273 BGP_STR
6274 "Display routes conforming to the prefix-list\n"
6275 "IP prefix-list name\n")
6276{
6277 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6278 bgp_show_type_prefix_list);
6279}
6280
6281DEFUN (show_ip_bgp_flap_prefix_list,
6282 show_ip_bgp_flap_prefix_list_cmd,
6283 "show ip bgp flap-statistics prefix-list WORD",
6284 SHOW_STR
6285 IP_STR
6286 BGP_STR
6287 "Display flap statistics of routes\n"
6288 "Display routes conforming to the prefix-list\n"
6289 "IP prefix-list name\n")
6290{
6291 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6292 bgp_show_type_flap_prefix_list);
6293}
6294
6295DEFUN (show_ip_bgp_ipv4_prefix_list,
6296 show_ip_bgp_ipv4_prefix_list_cmd,
6297 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6298 SHOW_STR
6299 IP_STR
6300 BGP_STR
6301 "Address family\n"
6302 "Address Family modifier\n"
6303 "Address Family modifier\n"
6304 "Display routes conforming to the prefix-list\n"
6305 "IP prefix-list name\n")
6306{
6307 if (strncmp (argv[0], "m", 1) == 0)
6308 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6309 bgp_show_type_prefix_list);
6310
6311 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6312 bgp_show_type_prefix_list);
6313}
6314
6315#ifdef HAVE_IPV6
6316DEFUN (show_bgp_prefix_list,
6317 show_bgp_prefix_list_cmd,
6318 "show bgp prefix-list WORD",
6319 SHOW_STR
6320 BGP_STR
6321 "Display routes conforming to the prefix-list\n"
6322 "IPv6 prefix-list name\n")
6323{
6324 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6325 bgp_show_type_prefix_list);
6326}
6327
6328ALIAS (show_bgp_prefix_list,
6329 show_bgp_ipv6_prefix_list_cmd,
6330 "show bgp ipv6 prefix-list WORD",
6331 SHOW_STR
6332 BGP_STR
6333 "Address family\n"
6334 "Display routes conforming to the prefix-list\n"
6335 "IPv6 prefix-list name\n")
6336
6337/* old command */
6338DEFUN (show_ipv6_bgp_prefix_list,
6339 show_ipv6_bgp_prefix_list_cmd,
6340 "show ipv6 bgp prefix-list WORD",
6341 SHOW_STR
6342 IPV6_STR
6343 BGP_STR
6344 "Display routes matching the prefix-list\n"
6345 "IPv6 prefix-list name\n")
6346{
6347 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6348 bgp_show_type_prefix_list);
6349}
6350
6351/* old command */
6352DEFUN (show_ipv6_mbgp_prefix_list,
6353 show_ipv6_mbgp_prefix_list_cmd,
6354 "show ipv6 mbgp prefix-list WORD",
6355 SHOW_STR
6356 IPV6_STR
6357 MBGP_STR
6358 "Display routes matching the prefix-list\n"
6359 "IPv6 prefix-list name\n")
6360{
6361 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6362 bgp_show_type_prefix_list);
6363}
6364#endif /* HAVE_IPV6 */
6365
6366int
paulfd79ac92004-10-13 05:06:08 +00006367bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006368 safi_t safi, enum bgp_show_type type)
6369{
6370 struct as_list *as_list;
6371
6372 as_list = as_list_lookup (filter);
6373 if (as_list == NULL)
6374 {
6375 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6376 return CMD_WARNING;
6377 }
6378
ajs5a646652004-11-05 01:25:55 +00006379 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00006380}
6381
6382DEFUN (show_ip_bgp_filter_list,
6383 show_ip_bgp_filter_list_cmd,
6384 "show ip bgp filter-list WORD",
6385 SHOW_STR
6386 IP_STR
6387 BGP_STR
6388 "Display routes conforming to the filter-list\n"
6389 "Regular expression access list name\n")
6390{
6391 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6392 bgp_show_type_filter_list);
6393}
6394
6395DEFUN (show_ip_bgp_flap_filter_list,
6396 show_ip_bgp_flap_filter_list_cmd,
6397 "show ip bgp flap-statistics filter-list WORD",
6398 SHOW_STR
6399 IP_STR
6400 BGP_STR
6401 "Display flap statistics of routes\n"
6402 "Display routes conforming to the filter-list\n"
6403 "Regular expression access list name\n")
6404{
6405 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6406 bgp_show_type_flap_filter_list);
6407}
6408
6409DEFUN (show_ip_bgp_ipv4_filter_list,
6410 show_ip_bgp_ipv4_filter_list_cmd,
6411 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6412 SHOW_STR
6413 IP_STR
6414 BGP_STR
6415 "Address family\n"
6416 "Address Family modifier\n"
6417 "Address Family modifier\n"
6418 "Display routes conforming to the filter-list\n"
6419 "Regular expression access list name\n")
6420{
6421 if (strncmp (argv[0], "m", 1) == 0)
6422 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6423 bgp_show_type_filter_list);
6424
6425 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6426 bgp_show_type_filter_list);
6427}
6428
6429#ifdef HAVE_IPV6
6430DEFUN (show_bgp_filter_list,
6431 show_bgp_filter_list_cmd,
6432 "show bgp filter-list WORD",
6433 SHOW_STR
6434 BGP_STR
6435 "Display routes conforming to the filter-list\n"
6436 "Regular expression access list name\n")
6437{
6438 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6439 bgp_show_type_filter_list);
6440}
6441
6442ALIAS (show_bgp_filter_list,
6443 show_bgp_ipv6_filter_list_cmd,
6444 "show bgp ipv6 filter-list WORD",
6445 SHOW_STR
6446 BGP_STR
6447 "Address family\n"
6448 "Display routes conforming to the filter-list\n"
6449 "Regular expression access list name\n")
6450
6451/* old command */
6452DEFUN (show_ipv6_bgp_filter_list,
6453 show_ipv6_bgp_filter_list_cmd,
6454 "show ipv6 bgp filter-list WORD",
6455 SHOW_STR
6456 IPV6_STR
6457 BGP_STR
6458 "Display routes conforming to the filter-list\n"
6459 "Regular expression access list name\n")
6460{
6461 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6462 bgp_show_type_filter_list);
6463}
6464
6465/* old command */
6466DEFUN (show_ipv6_mbgp_filter_list,
6467 show_ipv6_mbgp_filter_list_cmd,
6468 "show ipv6 mbgp filter-list WORD",
6469 SHOW_STR
6470 IPV6_STR
6471 MBGP_STR
6472 "Display routes conforming to the filter-list\n"
6473 "Regular expression access list name\n")
6474{
6475 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6476 bgp_show_type_filter_list);
6477}
6478#endif /* HAVE_IPV6 */
6479
6480int
paulfd79ac92004-10-13 05:06:08 +00006481bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006482 safi_t safi, enum bgp_show_type type)
6483{
6484 struct route_map *rmap;
6485
6486 rmap = route_map_lookup_by_name (rmap_str);
6487 if (! rmap)
6488 {
6489 vty_out (vty, "%% %s is not a valid route-map name%s",
6490 rmap_str, VTY_NEWLINE);
6491 return CMD_WARNING;
6492 }
6493
ajs5a646652004-11-05 01:25:55 +00006494 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00006495}
6496
6497DEFUN (show_ip_bgp_route_map,
6498 show_ip_bgp_route_map_cmd,
6499 "show ip bgp route-map WORD",
6500 SHOW_STR
6501 IP_STR
6502 BGP_STR
6503 "Display routes matching the route-map\n"
6504 "A route-map to match on\n")
6505{
6506 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6507 bgp_show_type_route_map);
6508}
6509
6510DEFUN (show_ip_bgp_flap_route_map,
6511 show_ip_bgp_flap_route_map_cmd,
6512 "show ip bgp flap-statistics route-map WORD",
6513 SHOW_STR
6514 IP_STR
6515 BGP_STR
6516 "Display flap statistics of routes\n"
6517 "Display routes matching the route-map\n"
6518 "A route-map to match on\n")
6519{
6520 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6521 bgp_show_type_flap_route_map);
6522}
6523
6524DEFUN (show_ip_bgp_ipv4_route_map,
6525 show_ip_bgp_ipv4_route_map_cmd,
6526 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6527 SHOW_STR
6528 IP_STR
6529 BGP_STR
6530 "Address family\n"
6531 "Address Family modifier\n"
6532 "Address Family modifier\n"
6533 "Display routes matching the route-map\n"
6534 "A route-map to match on\n")
6535{
6536 if (strncmp (argv[0], "m", 1) == 0)
6537 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6538 bgp_show_type_route_map);
6539
6540 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6541 bgp_show_type_route_map);
6542}
6543
6544DEFUN (show_bgp_route_map,
6545 show_bgp_route_map_cmd,
6546 "show bgp route-map WORD",
6547 SHOW_STR
6548 BGP_STR
6549 "Display routes matching the route-map\n"
6550 "A route-map to match on\n")
6551{
6552 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6553 bgp_show_type_route_map);
6554}
6555
6556ALIAS (show_bgp_route_map,
6557 show_bgp_ipv6_route_map_cmd,
6558 "show bgp ipv6 route-map WORD",
6559 SHOW_STR
6560 BGP_STR
6561 "Address family\n"
6562 "Display routes matching the route-map\n"
6563 "A route-map to match on\n")
6564
6565DEFUN (show_ip_bgp_cidr_only,
6566 show_ip_bgp_cidr_only_cmd,
6567 "show ip bgp cidr-only",
6568 SHOW_STR
6569 IP_STR
6570 BGP_STR
6571 "Display only routes with non-natural netmasks\n")
6572{
6573 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006574 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006575}
6576
6577DEFUN (show_ip_bgp_flap_cidr_only,
6578 show_ip_bgp_flap_cidr_only_cmd,
6579 "show ip bgp flap-statistics cidr-only",
6580 SHOW_STR
6581 IP_STR
6582 BGP_STR
6583 "Display flap statistics of routes\n"
6584 "Display only routes with non-natural netmasks\n")
6585{
6586 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006587 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006588}
6589
6590DEFUN (show_ip_bgp_ipv4_cidr_only,
6591 show_ip_bgp_ipv4_cidr_only_cmd,
6592 "show ip bgp ipv4 (unicast|multicast) cidr-only",
6593 SHOW_STR
6594 IP_STR
6595 BGP_STR
6596 "Address family\n"
6597 "Address Family modifier\n"
6598 "Address Family modifier\n"
6599 "Display only routes with non-natural netmasks\n")
6600{
6601 if (strncmp (argv[0], "m", 1) == 0)
6602 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006603 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006604
6605 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006606 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006607}
6608
6609DEFUN (show_ip_bgp_community_all,
6610 show_ip_bgp_community_all_cmd,
6611 "show ip bgp community",
6612 SHOW_STR
6613 IP_STR
6614 BGP_STR
6615 "Display routes matching the communities\n")
6616{
6617 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006618 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006619}
6620
6621DEFUN (show_ip_bgp_ipv4_community_all,
6622 show_ip_bgp_ipv4_community_all_cmd,
6623 "show ip bgp ipv4 (unicast|multicast) community",
6624 SHOW_STR
6625 IP_STR
6626 BGP_STR
6627 "Address family\n"
6628 "Address Family modifier\n"
6629 "Address Family modifier\n"
6630 "Display routes matching the communities\n")
6631{
6632 if (strncmp (argv[0], "m", 1) == 0)
6633 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006634 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006635
6636 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006637 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006638}
6639
6640#ifdef HAVE_IPV6
6641DEFUN (show_bgp_community_all,
6642 show_bgp_community_all_cmd,
6643 "show bgp community",
6644 SHOW_STR
6645 BGP_STR
6646 "Display routes matching the communities\n")
6647{
6648 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006649 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006650}
6651
6652ALIAS (show_bgp_community_all,
6653 show_bgp_ipv6_community_all_cmd,
6654 "show bgp ipv6 community",
6655 SHOW_STR
6656 BGP_STR
6657 "Address family\n"
6658 "Display routes matching the communities\n")
6659
6660/* old command */
6661DEFUN (show_ipv6_bgp_community_all,
6662 show_ipv6_bgp_community_all_cmd,
6663 "show ipv6 bgp community",
6664 SHOW_STR
6665 IPV6_STR
6666 BGP_STR
6667 "Display routes matching the communities\n")
6668{
6669 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006670 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006671}
6672
6673/* old command */
6674DEFUN (show_ipv6_mbgp_community_all,
6675 show_ipv6_mbgp_community_all_cmd,
6676 "show ipv6 mbgp community",
6677 SHOW_STR
6678 IPV6_STR
6679 MBGP_STR
6680 "Display routes matching the communities\n")
6681{
6682 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006683 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006684}
6685#endif /* HAVE_IPV6 */
6686
6687int
paulfd79ac92004-10-13 05:06:08 +00006688bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
6689 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00006690{
6691 struct community *com;
6692 struct buffer *b;
6693 int i;
6694 char *str;
6695 int first = 0;
6696
6697 b = buffer_new (1024);
6698 for (i = 0; i < argc; i++)
6699 {
6700 if (first)
6701 buffer_putc (b, ' ');
6702 else
6703 {
6704 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6705 continue;
6706 first = 1;
6707 }
6708
6709 buffer_putstr (b, argv[i]);
6710 }
6711 buffer_putc (b, '\0');
6712
6713 str = buffer_getstr (b);
6714 buffer_free (b);
6715
6716 com = community_str2com (str);
6717 free (str);
6718 if (! com)
6719 {
6720 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
6721 return CMD_WARNING;
6722 }
6723
ajs5a646652004-11-05 01:25:55 +00006724 return bgp_show (vty, NULL, afi, safi,
6725 (exact ? bgp_show_type_community_exact :
6726 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00006727}
6728
6729DEFUN (show_ip_bgp_community,
6730 show_ip_bgp_community_cmd,
6731 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
6732 SHOW_STR
6733 IP_STR
6734 BGP_STR
6735 "Display routes matching the communities\n"
6736 "community number\n"
6737 "Do not send outside local AS (well-known community)\n"
6738 "Do not advertise to any peer (well-known community)\n"
6739 "Do not export to next AS (well-known community)\n")
6740{
6741 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
6742}
6743
6744ALIAS (show_ip_bgp_community,
6745 show_ip_bgp_community2_cmd,
6746 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6747 SHOW_STR
6748 IP_STR
6749 BGP_STR
6750 "Display routes matching the communities\n"
6751 "community number\n"
6752 "Do not send outside local AS (well-known community)\n"
6753 "Do not advertise to any peer (well-known community)\n"
6754 "Do not export to next AS (well-known community)\n"
6755 "community number\n"
6756 "Do not send outside local AS (well-known community)\n"
6757 "Do not advertise to any peer (well-known community)\n"
6758 "Do not export to next AS (well-known community)\n")
6759
6760ALIAS (show_ip_bgp_community,
6761 show_ip_bgp_community3_cmd,
6762 "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)",
6763 SHOW_STR
6764 IP_STR
6765 BGP_STR
6766 "Display routes matching the communities\n"
6767 "community number\n"
6768 "Do not send outside local AS (well-known community)\n"
6769 "Do not advertise to any peer (well-known community)\n"
6770 "Do not export to next AS (well-known community)\n"
6771 "community number\n"
6772 "Do not send outside local AS (well-known community)\n"
6773 "Do not advertise to any peer (well-known community)\n"
6774 "Do not export to next AS (well-known community)\n"
6775 "community number\n"
6776 "Do not send outside local AS (well-known community)\n"
6777 "Do not advertise to any peer (well-known community)\n"
6778 "Do not export to next AS (well-known community)\n")
6779
6780ALIAS (show_ip_bgp_community,
6781 show_ip_bgp_community4_cmd,
6782 "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)",
6783 SHOW_STR
6784 IP_STR
6785 BGP_STR
6786 "Display routes matching the communities\n"
6787 "community number\n"
6788 "Do not send outside local AS (well-known community)\n"
6789 "Do not advertise to any peer (well-known community)\n"
6790 "Do not export to next AS (well-known community)\n"
6791 "community number\n"
6792 "Do not send outside local AS (well-known community)\n"
6793 "Do not advertise to any peer (well-known community)\n"
6794 "Do not export to next AS (well-known community)\n"
6795 "community number\n"
6796 "Do not send outside local AS (well-known community)\n"
6797 "Do not advertise to any peer (well-known community)\n"
6798 "Do not export to next AS (well-known community)\n"
6799 "community number\n"
6800 "Do not send outside local AS (well-known community)\n"
6801 "Do not advertise to any peer (well-known community)\n"
6802 "Do not export to next AS (well-known community)\n")
6803
6804DEFUN (show_ip_bgp_ipv4_community,
6805 show_ip_bgp_ipv4_community_cmd,
6806 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
6807 SHOW_STR
6808 IP_STR
6809 BGP_STR
6810 "Address family\n"
6811 "Address Family modifier\n"
6812 "Address Family modifier\n"
6813 "Display routes matching the communities\n"
6814 "community number\n"
6815 "Do not send outside local AS (well-known community)\n"
6816 "Do not advertise to any peer (well-known community)\n"
6817 "Do not export to next AS (well-known community)\n")
6818{
6819 if (strncmp (argv[0], "m", 1) == 0)
6820 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
6821
6822 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
6823}
6824
6825ALIAS (show_ip_bgp_ipv4_community,
6826 show_ip_bgp_ipv4_community2_cmd,
6827 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6828 SHOW_STR
6829 IP_STR
6830 BGP_STR
6831 "Address family\n"
6832 "Address Family modifier\n"
6833 "Address Family modifier\n"
6834 "Display routes matching the communities\n"
6835 "community number\n"
6836 "Do not send outside local AS (well-known community)\n"
6837 "Do not advertise to any peer (well-known community)\n"
6838 "Do not export to next AS (well-known community)\n"
6839 "community number\n"
6840 "Do not send outside local AS (well-known community)\n"
6841 "Do not advertise to any peer (well-known community)\n"
6842 "Do not export to next AS (well-known community)\n")
6843
6844ALIAS (show_ip_bgp_ipv4_community,
6845 show_ip_bgp_ipv4_community3_cmd,
6846 "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)",
6847 SHOW_STR
6848 IP_STR
6849 BGP_STR
6850 "Address family\n"
6851 "Address Family modifier\n"
6852 "Address Family modifier\n"
6853 "Display routes matching the communities\n"
6854 "community number\n"
6855 "Do not send outside local AS (well-known community)\n"
6856 "Do not advertise to any peer (well-known community)\n"
6857 "Do not export to next AS (well-known community)\n"
6858 "community number\n"
6859 "Do not send outside local AS (well-known community)\n"
6860 "Do not advertise to any peer (well-known community)\n"
6861 "Do not export to next AS (well-known community)\n"
6862 "community number\n"
6863 "Do not send outside local AS (well-known community)\n"
6864 "Do not advertise to any peer (well-known community)\n"
6865 "Do not export to next AS (well-known community)\n")
6866
6867ALIAS (show_ip_bgp_ipv4_community,
6868 show_ip_bgp_ipv4_community4_cmd,
6869 "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)",
6870 SHOW_STR
6871 IP_STR
6872 BGP_STR
6873 "Address family\n"
6874 "Address Family modifier\n"
6875 "Address Family modifier\n"
6876 "Display routes matching the communities\n"
6877 "community number\n"
6878 "Do not send outside local AS (well-known community)\n"
6879 "Do not advertise to any peer (well-known community)\n"
6880 "Do not export to next AS (well-known community)\n"
6881 "community number\n"
6882 "Do not send outside local AS (well-known community)\n"
6883 "Do not advertise to any peer (well-known community)\n"
6884 "Do not export to next AS (well-known community)\n"
6885 "community number\n"
6886 "Do not send outside local AS (well-known community)\n"
6887 "Do not advertise to any peer (well-known community)\n"
6888 "Do not export to next AS (well-known community)\n"
6889 "community number\n"
6890 "Do not send outside local AS (well-known community)\n"
6891 "Do not advertise to any peer (well-known community)\n"
6892 "Do not export to next AS (well-known community)\n")
6893
6894DEFUN (show_ip_bgp_community_exact,
6895 show_ip_bgp_community_exact_cmd,
6896 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6897 SHOW_STR
6898 IP_STR
6899 BGP_STR
6900 "Display routes matching the communities\n"
6901 "community number\n"
6902 "Do not send outside local AS (well-known community)\n"
6903 "Do not advertise to any peer (well-known community)\n"
6904 "Do not export to next AS (well-known community)\n"
6905 "Exact match of the communities")
6906{
6907 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
6908}
6909
6910ALIAS (show_ip_bgp_community_exact,
6911 show_ip_bgp_community2_exact_cmd,
6912 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6913 SHOW_STR
6914 IP_STR
6915 BGP_STR
6916 "Display routes matching the communities\n"
6917 "community number\n"
6918 "Do not send outside local AS (well-known community)\n"
6919 "Do not advertise to any peer (well-known community)\n"
6920 "Do not export to next AS (well-known community)\n"
6921 "community number\n"
6922 "Do not send outside local AS (well-known community)\n"
6923 "Do not advertise to any peer (well-known community)\n"
6924 "Do not export to next AS (well-known community)\n"
6925 "Exact match of the communities")
6926
6927ALIAS (show_ip_bgp_community_exact,
6928 show_ip_bgp_community3_exact_cmd,
6929 "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",
6930 SHOW_STR
6931 IP_STR
6932 BGP_STR
6933 "Display routes matching the communities\n"
6934 "community number\n"
6935 "Do not send outside local AS (well-known community)\n"
6936 "Do not advertise to any peer (well-known community)\n"
6937 "Do not export to next AS (well-known community)\n"
6938 "community number\n"
6939 "Do not send outside local AS (well-known community)\n"
6940 "Do not advertise to any peer (well-known community)\n"
6941 "Do not export to next AS (well-known community)\n"
6942 "community number\n"
6943 "Do not send outside local AS (well-known community)\n"
6944 "Do not advertise to any peer (well-known community)\n"
6945 "Do not export to next AS (well-known community)\n"
6946 "Exact match of the communities")
6947
6948ALIAS (show_ip_bgp_community_exact,
6949 show_ip_bgp_community4_exact_cmd,
6950 "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",
6951 SHOW_STR
6952 IP_STR
6953 BGP_STR
6954 "Display routes matching the communities\n"
6955 "community number\n"
6956 "Do not send outside local AS (well-known community)\n"
6957 "Do not advertise to any peer (well-known community)\n"
6958 "Do not export to next AS (well-known community)\n"
6959 "community number\n"
6960 "Do not send outside local AS (well-known community)\n"
6961 "Do not advertise to any peer (well-known community)\n"
6962 "Do not export to next AS (well-known community)\n"
6963 "community number\n"
6964 "Do not send outside local AS (well-known community)\n"
6965 "Do not advertise to any peer (well-known community)\n"
6966 "Do not export to next AS (well-known community)\n"
6967 "community number\n"
6968 "Do not send outside local AS (well-known community)\n"
6969 "Do not advertise to any peer (well-known community)\n"
6970 "Do not export to next AS (well-known community)\n"
6971 "Exact match of the communities")
6972
6973DEFUN (show_ip_bgp_ipv4_community_exact,
6974 show_ip_bgp_ipv4_community_exact_cmd,
6975 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6976 SHOW_STR
6977 IP_STR
6978 BGP_STR
6979 "Address family\n"
6980 "Address Family modifier\n"
6981 "Address Family modifier\n"
6982 "Display routes matching the communities\n"
6983 "community number\n"
6984 "Do not send outside local AS (well-known community)\n"
6985 "Do not advertise to any peer (well-known community)\n"
6986 "Do not export to next AS (well-known community)\n"
6987 "Exact match of the communities")
6988{
6989 if (strncmp (argv[0], "m", 1) == 0)
6990 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
6991
6992 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
6993}
6994
6995ALIAS (show_ip_bgp_ipv4_community_exact,
6996 show_ip_bgp_ipv4_community2_exact_cmd,
6997 "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",
6998 SHOW_STR
6999 IP_STR
7000 BGP_STR
7001 "Address family\n"
7002 "Address Family modifier\n"
7003 "Address Family modifier\n"
7004 "Display routes matching the communities\n"
7005 "community number\n"
7006 "Do not send outside local AS (well-known community)\n"
7007 "Do not advertise to any peer (well-known community)\n"
7008 "Do not export to next AS (well-known community)\n"
7009 "community number\n"
7010 "Do not send outside local AS (well-known community)\n"
7011 "Do not advertise to any peer (well-known community)\n"
7012 "Do not export to next AS (well-known community)\n"
7013 "Exact match of the communities")
7014
7015ALIAS (show_ip_bgp_ipv4_community_exact,
7016 show_ip_bgp_ipv4_community3_exact_cmd,
7017 "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",
7018 SHOW_STR
7019 IP_STR
7020 BGP_STR
7021 "Address family\n"
7022 "Address Family modifier\n"
7023 "Address Family modifier\n"
7024 "Display routes matching the communities\n"
7025 "community number\n"
7026 "Do not send outside local AS (well-known community)\n"
7027 "Do not advertise to any peer (well-known community)\n"
7028 "Do not export to next AS (well-known community)\n"
7029 "community number\n"
7030 "Do not send outside local AS (well-known community)\n"
7031 "Do not advertise to any peer (well-known community)\n"
7032 "Do not export to next AS (well-known community)\n"
7033 "community number\n"
7034 "Do not send outside local AS (well-known community)\n"
7035 "Do not advertise to any peer (well-known community)\n"
7036 "Do not export to next AS (well-known community)\n"
7037 "Exact match of the communities")
7038
7039ALIAS (show_ip_bgp_ipv4_community_exact,
7040 show_ip_bgp_ipv4_community4_exact_cmd,
7041 "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",
7042 SHOW_STR
7043 IP_STR
7044 BGP_STR
7045 "Address family\n"
7046 "Address Family modifier\n"
7047 "Address Family modifier\n"
7048 "Display routes matching the communities\n"
7049 "community number\n"
7050 "Do not send outside local AS (well-known community)\n"
7051 "Do not advertise to any peer (well-known community)\n"
7052 "Do not export to next AS (well-known community)\n"
7053 "community number\n"
7054 "Do not send outside local AS (well-known community)\n"
7055 "Do not advertise to any peer (well-known community)\n"
7056 "Do not export to next AS (well-known community)\n"
7057 "community number\n"
7058 "Do not send outside local AS (well-known community)\n"
7059 "Do not advertise to any peer (well-known community)\n"
7060 "Do not export to next AS (well-known community)\n"
7061 "community number\n"
7062 "Do not send outside local AS (well-known community)\n"
7063 "Do not advertise to any peer (well-known community)\n"
7064 "Do not export to next AS (well-known community)\n"
7065 "Exact match of the communities")
7066
7067#ifdef HAVE_IPV6
7068DEFUN (show_bgp_community,
7069 show_bgp_community_cmd,
7070 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7071 SHOW_STR
7072 BGP_STR
7073 "Display routes matching the communities\n"
7074 "community number\n"
7075 "Do not send outside local AS (well-known community)\n"
7076 "Do not advertise to any peer (well-known community)\n"
7077 "Do not export to next AS (well-known community)\n")
7078{
7079 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7080}
7081
7082ALIAS (show_bgp_community,
7083 show_bgp_ipv6_community_cmd,
7084 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7085 SHOW_STR
7086 BGP_STR
7087 "Address family\n"
7088 "Display routes matching the communities\n"
7089 "community number\n"
7090 "Do not send outside local AS (well-known community)\n"
7091 "Do not advertise to any peer (well-known community)\n"
7092 "Do not export to next AS (well-known community)\n")
7093
7094ALIAS (show_bgp_community,
7095 show_bgp_community2_cmd,
7096 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7097 SHOW_STR
7098 BGP_STR
7099 "Display routes matching the communities\n"
7100 "community number\n"
7101 "Do not send outside local AS (well-known community)\n"
7102 "Do not advertise to any peer (well-known community)\n"
7103 "Do not export to next AS (well-known community)\n"
7104 "community number\n"
7105 "Do not send outside local AS (well-known community)\n"
7106 "Do not advertise to any peer (well-known community)\n"
7107 "Do not export to next AS (well-known community)\n")
7108
7109ALIAS (show_bgp_community,
7110 show_bgp_ipv6_community2_cmd,
7111 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7112 SHOW_STR
7113 BGP_STR
7114 "Address family\n"
7115 "Display routes matching the communities\n"
7116 "community number\n"
7117 "Do not send outside local AS (well-known community)\n"
7118 "Do not advertise to any peer (well-known community)\n"
7119 "Do not export to next AS (well-known community)\n"
7120 "community number\n"
7121 "Do not send outside local AS (well-known community)\n"
7122 "Do not advertise to any peer (well-known community)\n"
7123 "Do not export to next AS (well-known community)\n")
7124
7125ALIAS (show_bgp_community,
7126 show_bgp_community3_cmd,
7127 "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)",
7128 SHOW_STR
7129 BGP_STR
7130 "Display routes matching the communities\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 "community number\n"
7136 "Do not send outside local AS (well-known community)\n"
7137 "Do not advertise to any peer (well-known community)\n"
7138 "Do not export to next AS (well-known community)\n"
7139 "community number\n"
7140 "Do not send outside local AS (well-known community)\n"
7141 "Do not advertise to any peer (well-known community)\n"
7142 "Do not export to next AS (well-known community)\n")
7143
7144ALIAS (show_bgp_community,
7145 show_bgp_ipv6_community3_cmd,
7146 "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)",
7147 SHOW_STR
7148 BGP_STR
7149 "Address family\n"
7150 "Display routes matching the communities\n"
7151 "community number\n"
7152 "Do not send outside local AS (well-known community)\n"
7153 "Do not advertise to any peer (well-known community)\n"
7154 "Do not export to next AS (well-known community)\n"
7155 "community number\n"
7156 "Do not send outside local AS (well-known community)\n"
7157 "Do not advertise to any peer (well-known community)\n"
7158 "Do not export to next AS (well-known community)\n"
7159 "community number\n"
7160 "Do not send outside local AS (well-known community)\n"
7161 "Do not advertise to any peer (well-known community)\n"
7162 "Do not export to next AS (well-known community)\n")
7163
7164ALIAS (show_bgp_community,
7165 show_bgp_community4_cmd,
7166 "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)",
7167 SHOW_STR
7168 BGP_STR
7169 "Display routes matching the communities\n"
7170 "community number\n"
7171 "Do not send outside local AS (well-known community)\n"
7172 "Do not advertise to any peer (well-known community)\n"
7173 "Do not export to next AS (well-known community)\n"
7174 "community number\n"
7175 "Do not send outside local AS (well-known community)\n"
7176 "Do not advertise to any peer (well-known community)\n"
7177 "Do not export to next AS (well-known community)\n"
7178 "community number\n"
7179 "Do not send outside local AS (well-known community)\n"
7180 "Do not advertise to any peer (well-known community)\n"
7181 "Do not export to next AS (well-known community)\n"
7182 "community number\n"
7183 "Do not send outside local AS (well-known community)\n"
7184 "Do not advertise to any peer (well-known community)\n"
7185 "Do not export to next AS (well-known community)\n")
7186
7187ALIAS (show_bgp_community,
7188 show_bgp_ipv6_community4_cmd,
7189 "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)",
7190 SHOW_STR
7191 BGP_STR
7192 "Address family\n"
7193 "Display routes matching the communities\n"
7194 "community number\n"
7195 "Do not send outside local AS (well-known community)\n"
7196 "Do not advertise to any peer (well-known community)\n"
7197 "Do not export to next AS (well-known community)\n"
7198 "community number\n"
7199 "Do not send outside local AS (well-known community)\n"
7200 "Do not advertise to any peer (well-known community)\n"
7201 "Do not export to next AS (well-known community)\n"
7202 "community number\n"
7203 "Do not send outside local AS (well-known community)\n"
7204 "Do not advertise to any peer (well-known community)\n"
7205 "Do not export to next AS (well-known community)\n"
7206 "community number\n"
7207 "Do not send outside local AS (well-known community)\n"
7208 "Do not advertise to any peer (well-known community)\n"
7209 "Do not export to next AS (well-known community)\n")
7210
7211/* old command */
7212DEFUN (show_ipv6_bgp_community,
7213 show_ipv6_bgp_community_cmd,
7214 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7215 SHOW_STR
7216 IPV6_STR
7217 BGP_STR
7218 "Display routes matching the communities\n"
7219 "community number\n"
7220 "Do not send outside local AS (well-known community)\n"
7221 "Do not advertise to any peer (well-known community)\n"
7222 "Do not export to next AS (well-known community)\n")
7223{
7224 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7225}
7226
7227/* old command */
7228ALIAS (show_ipv6_bgp_community,
7229 show_ipv6_bgp_community2_cmd,
7230 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7231 SHOW_STR
7232 IPV6_STR
7233 BGP_STR
7234 "Display routes matching the communities\n"
7235 "community number\n"
7236 "Do not send outside local AS (well-known community)\n"
7237 "Do not advertise to any peer (well-known community)\n"
7238 "Do not export to next AS (well-known community)\n"
7239 "community number\n"
7240 "Do not send outside local AS (well-known community)\n"
7241 "Do not advertise to any peer (well-known community)\n"
7242 "Do not export to next AS (well-known community)\n")
7243
7244/* old command */
7245ALIAS (show_ipv6_bgp_community,
7246 show_ipv6_bgp_community3_cmd,
7247 "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)",
7248 SHOW_STR
7249 IPV6_STR
7250 BGP_STR
7251 "Display routes matching the communities\n"
7252 "community number\n"
7253 "Do not send outside local AS (well-known community)\n"
7254 "Do not advertise to any peer (well-known community)\n"
7255 "Do not export to next AS (well-known community)\n"
7256 "community number\n"
7257 "Do not send outside local AS (well-known community)\n"
7258 "Do not advertise to any peer (well-known community)\n"
7259 "Do not export to next AS (well-known community)\n"
7260 "community number\n"
7261 "Do not send outside local AS (well-known community)\n"
7262 "Do not advertise to any peer (well-known community)\n"
7263 "Do not export to next AS (well-known community)\n")
7264
7265/* old command */
7266ALIAS (show_ipv6_bgp_community,
7267 show_ipv6_bgp_community4_cmd,
7268 "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)",
7269 SHOW_STR
7270 IPV6_STR
7271 BGP_STR
7272 "Display routes matching the communities\n"
7273 "community number\n"
7274 "Do not send outside local AS (well-known community)\n"
7275 "Do not advertise to any peer (well-known community)\n"
7276 "Do not export to next AS (well-known community)\n"
7277 "community number\n"
7278 "Do not send outside local AS (well-known community)\n"
7279 "Do not advertise to any peer (well-known community)\n"
7280 "Do not export to next AS (well-known community)\n"
7281 "community number\n"
7282 "Do not send outside local AS (well-known community)\n"
7283 "Do not advertise to any peer (well-known community)\n"
7284 "Do not export to next AS (well-known community)\n"
7285 "community number\n"
7286 "Do not send outside local AS (well-known community)\n"
7287 "Do not advertise to any peer (well-known community)\n"
7288 "Do not export to next AS (well-known community)\n")
7289
7290DEFUN (show_bgp_community_exact,
7291 show_bgp_community_exact_cmd,
7292 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7293 SHOW_STR
7294 BGP_STR
7295 "Display routes matching the communities\n"
7296 "community number\n"
7297 "Do not send outside local AS (well-known community)\n"
7298 "Do not advertise to any peer (well-known community)\n"
7299 "Do not export to next AS (well-known community)\n"
7300 "Exact match of the communities")
7301{
7302 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7303}
7304
7305ALIAS (show_bgp_community_exact,
7306 show_bgp_ipv6_community_exact_cmd,
7307 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7308 SHOW_STR
7309 BGP_STR
7310 "Address family\n"
7311 "Display routes matching the communities\n"
7312 "community number\n"
7313 "Do not send outside local AS (well-known community)\n"
7314 "Do not advertise to any peer (well-known community)\n"
7315 "Do not export to next AS (well-known community)\n"
7316 "Exact match of the communities")
7317
7318ALIAS (show_bgp_community_exact,
7319 show_bgp_community2_exact_cmd,
7320 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7321 SHOW_STR
7322 BGP_STR
7323 "Display routes matching the communities\n"
7324 "community number\n"
7325 "Do not send outside local AS (well-known community)\n"
7326 "Do not advertise to any peer (well-known community)\n"
7327 "Do not export to next AS (well-known community)\n"
7328 "community number\n"
7329 "Do not send outside local AS (well-known community)\n"
7330 "Do not advertise to any peer (well-known community)\n"
7331 "Do not export to next AS (well-known community)\n"
7332 "Exact match of the communities")
7333
7334ALIAS (show_bgp_community_exact,
7335 show_bgp_ipv6_community2_exact_cmd,
7336 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7337 SHOW_STR
7338 BGP_STR
7339 "Address family\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 "Exact match of the communities")
7350
7351ALIAS (show_bgp_community_exact,
7352 show_bgp_community3_exact_cmd,
7353 "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",
7354 SHOW_STR
7355 BGP_STR
7356 "Display routes matching the communities\n"
7357 "community number\n"
7358 "Do not send outside local AS (well-known community)\n"
7359 "Do not advertise to any peer (well-known community)\n"
7360 "Do not export to next AS (well-known community)\n"
7361 "community number\n"
7362 "Do not send outside local AS (well-known community)\n"
7363 "Do not advertise to any peer (well-known community)\n"
7364 "Do not export to next AS (well-known community)\n"
7365 "community number\n"
7366 "Do not send outside local AS (well-known community)\n"
7367 "Do not advertise to any peer (well-known community)\n"
7368 "Do not export to next AS (well-known community)\n"
7369 "Exact match of the communities")
7370
7371ALIAS (show_bgp_community_exact,
7372 show_bgp_ipv6_community3_exact_cmd,
7373 "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",
7374 SHOW_STR
7375 BGP_STR
7376 "Address family\n"
7377 "Display routes matching the communities\n"
7378 "community number\n"
7379 "Do not send outside local AS (well-known community)\n"
7380 "Do not advertise to any peer (well-known community)\n"
7381 "Do not export to next AS (well-known community)\n"
7382 "community number\n"
7383 "Do not send outside local AS (well-known community)\n"
7384 "Do not advertise to any peer (well-known community)\n"
7385 "Do not export to next AS (well-known community)\n"
7386 "community number\n"
7387 "Do not send outside local AS (well-known community)\n"
7388 "Do not advertise to any peer (well-known community)\n"
7389 "Do not export to next AS (well-known community)\n"
7390 "Exact match of the communities")
7391
7392ALIAS (show_bgp_community_exact,
7393 show_bgp_community4_exact_cmd,
7394 "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",
7395 SHOW_STR
7396 BGP_STR
7397 "Display routes matching the communities\n"
7398 "community number\n"
7399 "Do not send outside local AS (well-known community)\n"
7400 "Do not advertise to any peer (well-known community)\n"
7401 "Do not export to next AS (well-known community)\n"
7402 "community number\n"
7403 "Do not send outside local AS (well-known community)\n"
7404 "Do not advertise to any peer (well-known community)\n"
7405 "Do not export to next AS (well-known community)\n"
7406 "community number\n"
7407 "Do not send outside local AS (well-known community)\n"
7408 "Do not advertise to any peer (well-known community)\n"
7409 "Do not export to next AS (well-known community)\n"
7410 "community number\n"
7411 "Do not send outside local AS (well-known community)\n"
7412 "Do not advertise to any peer (well-known community)\n"
7413 "Do not export to next AS (well-known community)\n"
7414 "Exact match of the communities")
7415
7416ALIAS (show_bgp_community_exact,
7417 show_bgp_ipv6_community4_exact_cmd,
7418 "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",
7419 SHOW_STR
7420 BGP_STR
7421 "Address family\n"
7422 "Display routes matching the communities\n"
7423 "community number\n"
7424 "Do not send outside local AS (well-known community)\n"
7425 "Do not advertise to any peer (well-known community)\n"
7426 "Do not export to next AS (well-known community)\n"
7427 "community number\n"
7428 "Do not send outside local AS (well-known community)\n"
7429 "Do not advertise to any peer (well-known community)\n"
7430 "Do not export to next AS (well-known community)\n"
7431 "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 "community number\n"
7436 "Do not send outside local AS (well-known community)\n"
7437 "Do not advertise to any peer (well-known community)\n"
7438 "Do not export to next AS (well-known community)\n"
7439 "Exact match of the communities")
7440
7441/* old command */
7442DEFUN (show_ipv6_bgp_community_exact,
7443 show_ipv6_bgp_community_exact_cmd,
7444 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7445 SHOW_STR
7446 IPV6_STR
7447 BGP_STR
7448 "Display routes matching the communities\n"
7449 "community number\n"
7450 "Do not send outside local AS (well-known community)\n"
7451 "Do not advertise to any peer (well-known community)\n"
7452 "Do not export to next AS (well-known community)\n"
7453 "Exact match of the communities")
7454{
7455 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7456}
7457
7458/* old command */
7459ALIAS (show_ipv6_bgp_community_exact,
7460 show_ipv6_bgp_community2_exact_cmd,
7461 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7462 SHOW_STR
7463 IPV6_STR
7464 BGP_STR
7465 "Display routes matching the communities\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 "Exact match of the communities")
7475
7476/* old command */
7477ALIAS (show_ipv6_bgp_community_exact,
7478 show_ipv6_bgp_community3_exact_cmd,
7479 "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",
7480 SHOW_STR
7481 IPV6_STR
7482 BGP_STR
7483 "Display routes matching the communities\n"
7484 "community number\n"
7485 "Do not send outside local AS (well-known community)\n"
7486 "Do not advertise to any peer (well-known community)\n"
7487 "Do not export to next AS (well-known community)\n"
7488 "community number\n"
7489 "Do not send outside local AS (well-known community)\n"
7490 "Do not advertise to any peer (well-known community)\n"
7491 "Do not export to next AS (well-known community)\n"
7492 "community number\n"
7493 "Do not send outside local AS (well-known community)\n"
7494 "Do not advertise to any peer (well-known community)\n"
7495 "Do not export to next AS (well-known community)\n"
7496 "Exact match of the communities")
7497
7498/* old command */
7499ALIAS (show_ipv6_bgp_community_exact,
7500 show_ipv6_bgp_community4_exact_cmd,
7501 "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",
7502 SHOW_STR
7503 IPV6_STR
7504 BGP_STR
7505 "Display routes matching the communities\n"
7506 "community number\n"
7507 "Do not send outside local AS (well-known community)\n"
7508 "Do not advertise to any peer (well-known community)\n"
7509 "Do not export to next AS (well-known community)\n"
7510 "community number\n"
7511 "Do not send outside local AS (well-known community)\n"
7512 "Do not advertise to any peer (well-known community)\n"
7513 "Do not export to next AS (well-known community)\n"
7514 "community number\n"
7515 "Do not send outside local AS (well-known community)\n"
7516 "Do not advertise to any peer (well-known community)\n"
7517 "Do not export to next AS (well-known community)\n"
7518 "community number\n"
7519 "Do not send outside local AS (well-known community)\n"
7520 "Do not advertise to any peer (well-known community)\n"
7521 "Do not export to next AS (well-known community)\n"
7522 "Exact match of the communities")
7523
7524/* old command */
7525DEFUN (show_ipv6_mbgp_community,
7526 show_ipv6_mbgp_community_cmd,
7527 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7528 SHOW_STR
7529 IPV6_STR
7530 MBGP_STR
7531 "Display routes matching the communities\n"
7532 "community number\n"
7533 "Do not send outside local AS (well-known community)\n"
7534 "Do not advertise to any peer (well-known community)\n"
7535 "Do not export to next AS (well-known community)\n")
7536{
7537 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7538}
7539
7540/* old command */
7541ALIAS (show_ipv6_mbgp_community,
7542 show_ipv6_mbgp_community2_cmd,
7543 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7544 SHOW_STR
7545 IPV6_STR
7546 MBGP_STR
7547 "Display routes matching the communities\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_mbgp_community,
7559 show_ipv6_mbgp_community3_cmd,
7560 "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)",
7561 SHOW_STR
7562 IPV6_STR
7563 MBGP_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
7578/* old command */
7579ALIAS (show_ipv6_mbgp_community,
7580 show_ipv6_mbgp_community4_cmd,
7581 "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)",
7582 SHOW_STR
7583 IPV6_STR
7584 MBGP_STR
7585 "Display routes matching the communities\n"
7586 "community number\n"
7587 "Do not send outside local AS (well-known community)\n"
7588 "Do not advertise to any peer (well-known community)\n"
7589 "Do not export to next AS (well-known community)\n"
7590 "community number\n"
7591 "Do not send outside local AS (well-known community)\n"
7592 "Do not advertise to any peer (well-known community)\n"
7593 "Do not export to next AS (well-known community)\n"
7594 "community number\n"
7595 "Do not send outside local AS (well-known community)\n"
7596 "Do not advertise to any peer (well-known community)\n"
7597 "Do not export to next AS (well-known community)\n"
7598 "community number\n"
7599 "Do not send outside local AS (well-known community)\n"
7600 "Do not advertise to any peer (well-known community)\n"
7601 "Do not export to next AS (well-known community)\n")
7602
7603/* old command */
7604DEFUN (show_ipv6_mbgp_community_exact,
7605 show_ipv6_mbgp_community_exact_cmd,
7606 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7607 SHOW_STR
7608 IPV6_STR
7609 MBGP_STR
7610 "Display routes matching the communities\n"
7611 "community number\n"
7612 "Do not send outside local AS (well-known community)\n"
7613 "Do not advertise to any peer (well-known community)\n"
7614 "Do not export to next AS (well-known community)\n"
7615 "Exact match of the communities")
7616{
7617 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7618}
7619
7620/* old command */
7621ALIAS (show_ipv6_mbgp_community_exact,
7622 show_ipv6_mbgp_community2_exact_cmd,
7623 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7624 SHOW_STR
7625 IPV6_STR
7626 MBGP_STR
7627 "Display routes matching the communities\n"
7628 "community number\n"
7629 "Do not send outside local AS (well-known community)\n"
7630 "Do not advertise to any peer (well-known community)\n"
7631 "Do not export to next AS (well-known community)\n"
7632 "community number\n"
7633 "Do not send outside local AS (well-known community)\n"
7634 "Do not advertise to any peer (well-known community)\n"
7635 "Do not export to next AS (well-known community)\n"
7636 "Exact match of the communities")
7637
7638/* old command */
7639ALIAS (show_ipv6_mbgp_community_exact,
7640 show_ipv6_mbgp_community3_exact_cmd,
7641 "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",
7642 SHOW_STR
7643 IPV6_STR
7644 MBGP_STR
7645 "Display routes matching the communities\n"
7646 "community number\n"
7647 "Do not send outside local AS (well-known community)\n"
7648 "Do not advertise to any peer (well-known community)\n"
7649 "Do not export to next AS (well-known community)\n"
7650 "community number\n"
7651 "Do not send outside local AS (well-known community)\n"
7652 "Do not advertise to any peer (well-known community)\n"
7653 "Do not export to next AS (well-known community)\n"
7654 "community number\n"
7655 "Do not send outside local AS (well-known community)\n"
7656 "Do not advertise to any peer (well-known community)\n"
7657 "Do not export to next AS (well-known community)\n"
7658 "Exact match of the communities")
7659
7660/* old command */
7661ALIAS (show_ipv6_mbgp_community_exact,
7662 show_ipv6_mbgp_community4_exact_cmd,
7663 "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",
7664 SHOW_STR
7665 IPV6_STR
7666 MBGP_STR
7667 "Display routes matching the communities\n"
7668 "community number\n"
7669 "Do not send outside local AS (well-known community)\n"
7670 "Do not advertise to any peer (well-known community)\n"
7671 "Do not export to next AS (well-known community)\n"
7672 "community number\n"
7673 "Do not send outside local AS (well-known community)\n"
7674 "Do not advertise to any peer (well-known community)\n"
7675 "Do not export to next AS (well-known community)\n"
7676 "community number\n"
7677 "Do not send outside local AS (well-known community)\n"
7678 "Do not advertise to any peer (well-known community)\n"
7679 "Do not export to next AS (well-known community)\n"
7680 "community number\n"
7681 "Do not send outside local AS (well-known community)\n"
7682 "Do not advertise to any peer (well-known community)\n"
7683 "Do not export to next AS (well-known community)\n"
7684 "Exact match of the communities")
7685#endif /* HAVE_IPV6 */
7686
7687int
paulfd79ac92004-10-13 05:06:08 +00007688bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00007689 u_int16_t afi, u_char safi)
7690{
7691 struct community_list *list;
7692
7693 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_AUTO);
7694 if (list == NULL)
7695 {
7696 vty_out (vty, "%% %s is not a valid community-list name%s", com,
7697 VTY_NEWLINE);
7698 return CMD_WARNING;
7699 }
7700
ajs5a646652004-11-05 01:25:55 +00007701 return bgp_show (vty, NULL, afi, safi,
7702 (exact ? bgp_show_type_community_list_exact :
7703 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00007704}
7705
7706DEFUN (show_ip_bgp_community_list,
7707 show_ip_bgp_community_list_cmd,
7708 "show ip bgp community-list WORD",
7709 SHOW_STR
7710 IP_STR
7711 BGP_STR
7712 "Display routes matching the community-list\n"
7713 "community-list name\n")
7714{
7715 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
7716}
7717
7718DEFUN (show_ip_bgp_ipv4_community_list,
7719 show_ip_bgp_ipv4_community_list_cmd,
7720 "show ip bgp ipv4 (unicast|multicast) community-list WORD",
7721 SHOW_STR
7722 IP_STR
7723 BGP_STR
7724 "Address family\n"
7725 "Address Family modifier\n"
7726 "Address Family modifier\n"
7727 "Display routes matching the community-list\n"
7728 "community-list name\n")
7729{
7730 if (strncmp (argv[0], "m", 1) == 0)
7731 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
7732
7733 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
7734}
7735
7736DEFUN (show_ip_bgp_community_list_exact,
7737 show_ip_bgp_community_list_exact_cmd,
7738 "show ip bgp community-list WORD exact-match",
7739 SHOW_STR
7740 IP_STR
7741 BGP_STR
7742 "Display routes matching the community-list\n"
7743 "community-list name\n"
7744 "Exact match of the communities\n")
7745{
7746 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
7747}
7748
7749DEFUN (show_ip_bgp_ipv4_community_list_exact,
7750 show_ip_bgp_ipv4_community_list_exact_cmd,
7751 "show ip bgp ipv4 (unicast|multicast) community-list WORD exact-match",
7752 SHOW_STR
7753 IP_STR
7754 BGP_STR
7755 "Address family\n"
7756 "Address Family modifier\n"
7757 "Address Family modifier\n"
7758 "Display routes matching the community-list\n"
7759 "community-list name\n"
7760 "Exact match of the communities\n")
7761{
7762 if (strncmp (argv[0], "m", 1) == 0)
7763 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
7764
7765 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
7766}
7767
7768#ifdef HAVE_IPV6
7769DEFUN (show_bgp_community_list,
7770 show_bgp_community_list_cmd,
7771 "show bgp community-list WORD",
7772 SHOW_STR
7773 BGP_STR
7774 "Display routes matching the community-list\n"
7775 "community-list name\n")
7776{
7777 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
7778}
7779
7780ALIAS (show_bgp_community_list,
7781 show_bgp_ipv6_community_list_cmd,
7782 "show bgp ipv6 community-list WORD",
7783 SHOW_STR
7784 BGP_STR
7785 "Address family\n"
7786 "Display routes matching the community-list\n"
7787 "community-list name\n")
7788
7789/* old command */
7790DEFUN (show_ipv6_bgp_community_list,
7791 show_ipv6_bgp_community_list_cmd,
7792 "show ipv6 bgp community-list WORD",
7793 SHOW_STR
7794 IPV6_STR
7795 BGP_STR
7796 "Display routes matching the community-list\n"
7797 "community-list name\n")
7798{
7799 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
7800}
7801
7802/* old command */
7803DEFUN (show_ipv6_mbgp_community_list,
7804 show_ipv6_mbgp_community_list_cmd,
7805 "show ipv6 mbgp community-list WORD",
7806 SHOW_STR
7807 IPV6_STR
7808 MBGP_STR
7809 "Display routes matching the community-list\n"
7810 "community-list name\n")
7811{
7812 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
7813}
7814
7815DEFUN (show_bgp_community_list_exact,
7816 show_bgp_community_list_exact_cmd,
7817 "show bgp community-list WORD exact-match",
7818 SHOW_STR
7819 BGP_STR
7820 "Display routes matching the community-list\n"
7821 "community-list name\n"
7822 "Exact match of the communities\n")
7823{
7824 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
7825}
7826
7827ALIAS (show_bgp_community_list_exact,
7828 show_bgp_ipv6_community_list_exact_cmd,
7829 "show bgp ipv6 community-list WORD exact-match",
7830 SHOW_STR
7831 BGP_STR
7832 "Address family\n"
7833 "Display routes matching the community-list\n"
7834 "community-list name\n"
7835 "Exact match of the communities\n")
7836
7837/* old command */
7838DEFUN (show_ipv6_bgp_community_list_exact,
7839 show_ipv6_bgp_community_list_exact_cmd,
7840 "show ipv6 bgp community-list WORD exact-match",
7841 SHOW_STR
7842 IPV6_STR
7843 BGP_STR
7844 "Display routes matching the community-list\n"
7845 "community-list name\n"
7846 "Exact match of the communities\n")
7847{
7848 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
7849}
7850
7851/* old command */
7852DEFUN (show_ipv6_mbgp_community_list_exact,
7853 show_ipv6_mbgp_community_list_exact_cmd,
7854 "show ipv6 mbgp community-list WORD exact-match",
7855 SHOW_STR
7856 IPV6_STR
7857 MBGP_STR
7858 "Display routes matching the community-list\n"
7859 "community-list name\n"
7860 "Exact match of the communities\n")
7861{
7862 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
7863}
7864#endif /* HAVE_IPV6 */
7865
paul718e3742002-12-13 20:15:29 +00007866int
paulfd79ac92004-10-13 05:06:08 +00007867bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007868 safi_t safi, enum bgp_show_type type)
7869{
7870 int ret;
7871 struct prefix *p;
7872
7873 p = prefix_new();
7874
7875 ret = str2prefix (prefix, p);
7876 if (! ret)
7877 {
7878 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
7879 return CMD_WARNING;
7880 }
7881
ajs5a646652004-11-05 01:25:55 +00007882 ret = bgp_show (vty, NULL, afi, safi, type, p);
7883 prefix_free(p);
7884 return ret;
paul718e3742002-12-13 20:15:29 +00007885}
7886
7887DEFUN (show_ip_bgp_prefix_longer,
7888 show_ip_bgp_prefix_longer_cmd,
7889 "show ip bgp A.B.C.D/M longer-prefixes",
7890 SHOW_STR
7891 IP_STR
7892 BGP_STR
7893 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7894 "Display route and more specific routes\n")
7895{
7896 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7897 bgp_show_type_prefix_longer);
7898}
7899
7900DEFUN (show_ip_bgp_flap_prefix_longer,
7901 show_ip_bgp_flap_prefix_longer_cmd,
7902 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
7903 SHOW_STR
7904 IP_STR
7905 BGP_STR
7906 "Display flap statistics of routes\n"
7907 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7908 "Display route and more specific routes\n")
7909{
7910 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7911 bgp_show_type_flap_prefix_longer);
7912}
7913
7914DEFUN (show_ip_bgp_ipv4_prefix_longer,
7915 show_ip_bgp_ipv4_prefix_longer_cmd,
7916 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
7917 SHOW_STR
7918 IP_STR
7919 BGP_STR
7920 "Address family\n"
7921 "Address Family modifier\n"
7922 "Address Family modifier\n"
7923 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7924 "Display route and more specific routes\n")
7925{
7926 if (strncmp (argv[0], "m", 1) == 0)
7927 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7928 bgp_show_type_prefix_longer);
7929
7930 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
7931 bgp_show_type_prefix_longer);
7932}
7933
7934DEFUN (show_ip_bgp_flap_address,
7935 show_ip_bgp_flap_address_cmd,
7936 "show ip bgp flap-statistics A.B.C.D",
7937 SHOW_STR
7938 IP_STR
7939 BGP_STR
7940 "Display flap statistics of routes\n"
7941 "Network in the BGP routing table to display\n")
7942{
7943 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7944 bgp_show_type_flap_address);
7945}
7946
7947DEFUN (show_ip_bgp_flap_prefix,
7948 show_ip_bgp_flap_prefix_cmd,
7949 "show ip bgp flap-statistics A.B.C.D/M",
7950 SHOW_STR
7951 IP_STR
7952 BGP_STR
7953 "Display flap statistics of routes\n"
7954 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7955{
7956 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7957 bgp_show_type_flap_prefix);
7958}
7959#ifdef HAVE_IPV6
7960DEFUN (show_bgp_prefix_longer,
7961 show_bgp_prefix_longer_cmd,
7962 "show bgp X:X::X:X/M longer-prefixes",
7963 SHOW_STR
7964 BGP_STR
7965 "IPv6 prefix <network>/<length>\n"
7966 "Display route and more specific routes\n")
7967{
7968 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7969 bgp_show_type_prefix_longer);
7970}
7971
7972ALIAS (show_bgp_prefix_longer,
7973 show_bgp_ipv6_prefix_longer_cmd,
7974 "show bgp ipv6 X:X::X:X/M longer-prefixes",
7975 SHOW_STR
7976 BGP_STR
7977 "Address family\n"
7978 "IPv6 prefix <network>/<length>\n"
7979 "Display route and more specific routes\n")
7980
7981/* old command */
7982DEFUN (show_ipv6_bgp_prefix_longer,
7983 show_ipv6_bgp_prefix_longer_cmd,
7984 "show ipv6 bgp X:X::X:X/M longer-prefixes",
7985 SHOW_STR
7986 IPV6_STR
7987 BGP_STR
7988 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7989 "Display route and more specific routes\n")
7990{
7991 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7992 bgp_show_type_prefix_longer);
7993}
7994
7995/* old command */
7996DEFUN (show_ipv6_mbgp_prefix_longer,
7997 show_ipv6_mbgp_prefix_longer_cmd,
7998 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
7999 SHOW_STR
8000 IPV6_STR
8001 MBGP_STR
8002 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8003 "Display route and more specific routes\n")
8004{
8005 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8006 bgp_show_type_prefix_longer);
8007}
8008#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008009
8010struct peer *
paulfd79ac92004-10-13 05:06:08 +00008011peer_lookup_in_view (struct vty *vty, const char *view_name,
8012 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008013{
8014 int ret;
8015 struct bgp *bgp;
8016 struct peer *peer;
8017 union sockunion su;
8018
8019 /* BGP structure lookup. */
8020 if (view_name)
8021 {
8022 bgp = bgp_lookup_by_name (view_name);
8023 if (! bgp)
8024 {
8025 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8026 return NULL;
8027 }
8028 }
paul5228ad22004-06-04 17:58:18 +00008029 else
paulbb46e942003-10-24 19:02:03 +00008030 {
8031 bgp = bgp_get_default ();
8032 if (! bgp)
8033 {
8034 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8035 return NULL;
8036 }
8037 }
8038
8039 /* Get peer sockunion. */
8040 ret = str2sockunion (ip_str, &su);
8041 if (ret < 0)
8042 {
8043 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8044 return NULL;
8045 }
8046
8047 /* Peer structure lookup. */
8048 peer = peer_lookup (bgp, &su);
8049 if (! peer)
8050 {
8051 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8052 return NULL;
8053 }
8054
8055 return peer;
8056}
8057
paul718e3742002-12-13 20:15:29 +00008058void
8059show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
8060 int in)
8061{
8062 struct bgp_table *table;
8063 struct bgp_adj_in *ain;
8064 struct bgp_adj_out *adj;
8065 unsigned long output_count;
8066 struct bgp_node *rn;
8067 int header1 = 1;
8068 struct bgp *bgp;
8069 int header2 = 1;
8070
paulbb46e942003-10-24 19:02:03 +00008071 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00008072
8073 if (! bgp)
8074 return;
8075
8076 table = bgp->rib[afi][safi];
8077
8078 output_count = 0;
8079
8080 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
8081 PEER_STATUS_DEFAULT_ORIGINATE))
8082 {
8083 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
8084 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
8085 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
8086
8087 vty_out (vty, "Originating default network 0.0.0.0%s%s",
8088 VTY_NEWLINE, VTY_NEWLINE);
8089 header1 = 0;
8090 }
8091
8092 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8093 if (in)
8094 {
8095 for (ain = rn->adj_in; ain; ain = ain->next)
8096 if (ain->peer == peer)
8097 {
8098 if (header1)
8099 {
8100 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
8101 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
8102 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
8103 header1 = 0;
8104 }
8105 if (header2)
8106 {
8107 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8108 header2 = 0;
8109 }
8110 if (ain->attr)
8111 {
8112 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
8113 output_count++;
8114 }
8115 }
8116 }
8117 else
8118 {
8119 for (adj = rn->adj_out; adj; adj = adj->next)
8120 if (adj->peer == peer)
8121 {
8122 if (header1)
8123 {
8124 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
8125 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
8126 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
8127 header1 = 0;
8128 }
8129 if (header2)
8130 {
8131 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8132 header2 = 0;
8133 }
8134 if (adj->attr)
8135 {
8136 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
8137 output_count++;
8138 }
8139 }
8140 }
8141
8142 if (output_count != 0)
8143 vty_out (vty, "%sTotal number of prefixes %ld%s",
8144 VTY_NEWLINE, output_count, VTY_NEWLINE);
8145}
8146
8147int
paulbb46e942003-10-24 19:02:03 +00008148peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
8149{
paul718e3742002-12-13 20:15:29 +00008150 if (! peer || ! peer->afc[afi][safi])
8151 {
8152 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8153 return CMD_WARNING;
8154 }
8155
8156 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8157 {
8158 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
8159 VTY_NEWLINE);
8160 return CMD_WARNING;
8161 }
8162
8163 show_adj_route (vty, peer, afi, safi, in);
8164
8165 return CMD_SUCCESS;
8166}
8167
8168DEFUN (show_ip_bgp_neighbor_advertised_route,
8169 show_ip_bgp_neighbor_advertised_route_cmd,
8170 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8171 SHOW_STR
8172 IP_STR
8173 BGP_STR
8174 "Detailed information on TCP and BGP neighbor connections\n"
8175 "Neighbor to display information about\n"
8176 "Neighbor to display information about\n"
8177 "Display the routes advertised to a BGP neighbor\n")
8178{
paulbb46e942003-10-24 19:02:03 +00008179 struct peer *peer;
8180
8181 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8182 if (! peer)
8183 return CMD_WARNING;
8184
8185 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008186}
8187
8188DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
8189 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
8190 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8191 SHOW_STR
8192 IP_STR
8193 BGP_STR
8194 "Address family\n"
8195 "Address Family modifier\n"
8196 "Address Family modifier\n"
8197 "Detailed information on TCP and BGP neighbor connections\n"
8198 "Neighbor to display information about\n"
8199 "Neighbor to display information about\n"
8200 "Display the routes advertised to a BGP neighbor\n")
8201{
paulbb46e942003-10-24 19:02:03 +00008202 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008203
paulbb46e942003-10-24 19:02:03 +00008204 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8205 if (! peer)
8206 return CMD_WARNING;
8207
8208 if (strncmp (argv[0], "m", 1) == 0)
8209 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
8210
8211 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008212}
8213
8214#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008215DEFUN (show_bgp_view_neighbor_advertised_route,
8216 show_bgp_view_neighbor_advertised_route_cmd,
8217 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8218 SHOW_STR
8219 BGP_STR
8220 "BGP view\n"
8221 "View name\n"
8222 "Detailed information on TCP and BGP neighbor connections\n"
8223 "Neighbor to display information about\n"
8224 "Neighbor to display information about\n"
8225 "Display the routes advertised to a BGP neighbor\n")
8226{
8227 struct peer *peer;
8228
8229 if (argc == 2)
8230 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8231 else
8232 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8233
8234 if (! peer)
8235 return CMD_WARNING;
8236
8237 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
8238}
8239
8240ALIAS (show_bgp_view_neighbor_advertised_route,
8241 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
8242 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8243 SHOW_STR
8244 BGP_STR
8245 "BGP view\n"
8246 "View name\n"
8247 "Address family\n"
8248 "Detailed information on TCP and BGP neighbor connections\n"
8249 "Neighbor to display information about\n"
8250 "Neighbor to display information about\n"
8251 "Display the routes advertised to a BGP neighbor\n")
8252
8253DEFUN (show_bgp_view_neighbor_received_routes,
8254 show_bgp_view_neighbor_received_routes_cmd,
8255 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
8256 SHOW_STR
8257 BGP_STR
8258 "BGP view\n"
8259 "View name\n"
8260 "Detailed information on TCP and BGP neighbor connections\n"
8261 "Neighbor to display information about\n"
8262 "Neighbor to display information about\n"
8263 "Display the received routes from neighbor\n")
8264{
8265 struct peer *peer;
8266
8267 if (argc == 2)
8268 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8269 else
8270 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8271
8272 if (! peer)
8273 return CMD_WARNING;
8274
8275 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
8276}
8277
8278ALIAS (show_bgp_view_neighbor_received_routes,
8279 show_bgp_view_ipv6_neighbor_received_routes_cmd,
8280 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8281 SHOW_STR
8282 BGP_STR
8283 "BGP view\n"
8284 "View name\n"
8285 "Address family\n"
8286 "Detailed information on TCP and BGP neighbor connections\n"
8287 "Neighbor to display information about\n"
8288 "Neighbor to display information about\n"
8289 "Display the received routes from neighbor\n")
8290
8291ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008292 show_bgp_neighbor_advertised_route_cmd,
8293 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8294 SHOW_STR
8295 BGP_STR
8296 "Detailed information on TCP and BGP neighbor connections\n"
8297 "Neighbor to display information about\n"
8298 "Neighbor to display information about\n"
8299 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008300
8301ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008302 show_bgp_ipv6_neighbor_advertised_route_cmd,
8303 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8304 SHOW_STR
8305 BGP_STR
8306 "Address family\n"
8307 "Detailed information on TCP and BGP neighbor connections\n"
8308 "Neighbor to display information about\n"
8309 "Neighbor to display information about\n"
8310 "Display the routes advertised to a BGP neighbor\n")
8311
8312/* old command */
paulbb46e942003-10-24 19:02:03 +00008313ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008314 ipv6_bgp_neighbor_advertised_route_cmd,
8315 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8316 SHOW_STR
8317 IPV6_STR
8318 BGP_STR
8319 "Detailed information on TCP and BGP neighbor connections\n"
8320 "Neighbor to display information about\n"
8321 "Neighbor to display information about\n"
8322 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008323
paul718e3742002-12-13 20:15:29 +00008324/* old command */
8325DEFUN (ipv6_mbgp_neighbor_advertised_route,
8326 ipv6_mbgp_neighbor_advertised_route_cmd,
8327 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8328 SHOW_STR
8329 IPV6_STR
8330 MBGP_STR
8331 "Detailed information on TCP and BGP neighbor connections\n"
8332 "Neighbor to display information about\n"
8333 "Neighbor to display information about\n"
8334 "Display the routes advertised to a BGP neighbor\n")
8335{
paulbb46e942003-10-24 19:02:03 +00008336 struct peer *peer;
8337
8338 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8339 if (! peer)
8340 return CMD_WARNING;
8341
8342 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00008343}
8344#endif /* HAVE_IPV6 */
8345
8346DEFUN (show_ip_bgp_neighbor_received_routes,
8347 show_ip_bgp_neighbor_received_routes_cmd,
8348 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8349 SHOW_STR
8350 IP_STR
8351 BGP_STR
8352 "Detailed information on TCP and BGP neighbor connections\n"
8353 "Neighbor to display information about\n"
8354 "Neighbor to display information about\n"
8355 "Display the received routes from neighbor\n")
8356{
paulbb46e942003-10-24 19:02:03 +00008357 struct peer *peer;
8358
8359 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8360 if (! peer)
8361 return CMD_WARNING;
8362
8363 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008364}
8365
8366DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
8367 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
8368 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
8369 SHOW_STR
8370 IP_STR
8371 BGP_STR
8372 "Address family\n"
8373 "Address Family modifier\n"
8374 "Address Family modifier\n"
8375 "Detailed information on TCP and BGP neighbor connections\n"
8376 "Neighbor to display information about\n"
8377 "Neighbor to display information about\n"
8378 "Display the received routes from neighbor\n")
8379{
paulbb46e942003-10-24 19:02:03 +00008380 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008381
paulbb46e942003-10-24 19:02:03 +00008382 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8383 if (! peer)
8384 return CMD_WARNING;
8385
8386 if (strncmp (argv[0], "m", 1) == 0)
8387 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
8388
8389 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008390}
8391
8392DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
8393 show_ip_bgp_neighbor_received_prefix_filter_cmd,
8394 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8395 SHOW_STR
8396 IP_STR
8397 BGP_STR
8398 "Detailed information on TCP and BGP neighbor connections\n"
8399 "Neighbor to display information about\n"
8400 "Neighbor to display information about\n"
8401 "Display information received from a BGP neighbor\n"
8402 "Display the prefixlist filter\n")
8403{
8404 char name[BUFSIZ];
8405 union sockunion *su;
8406 struct peer *peer;
8407 int count;
8408
8409 su = sockunion_str2su (argv[0]);
8410 if (su == NULL)
8411 return CMD_WARNING;
8412
8413 peer = peer_lookup (NULL, su);
8414 if (! peer)
8415 return CMD_WARNING;
8416
8417 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8418 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8419 if (count)
8420 {
8421 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8422 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8423 }
8424
8425 return CMD_SUCCESS;
8426}
8427
8428DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
8429 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
8430 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8431 SHOW_STR
8432 IP_STR
8433 BGP_STR
8434 "Address family\n"
8435 "Address Family modifier\n"
8436 "Address Family modifier\n"
8437 "Detailed information on TCP and BGP neighbor connections\n"
8438 "Neighbor to display information about\n"
8439 "Neighbor to display information about\n"
8440 "Display information received from a BGP neighbor\n"
8441 "Display the prefixlist filter\n")
8442{
8443 char name[BUFSIZ];
8444 union sockunion *su;
8445 struct peer *peer;
8446 int count;
8447
8448 su = sockunion_str2su (argv[1]);
8449 if (su == NULL)
8450 return CMD_WARNING;
8451
8452 peer = peer_lookup (NULL, su);
8453 if (! peer)
8454 return CMD_WARNING;
8455
8456 if (strncmp (argv[0], "m", 1) == 0)
8457 {
8458 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
8459 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8460 if (count)
8461 {
8462 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
8463 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8464 }
8465 }
8466 else
8467 {
8468 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8469 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8470 if (count)
8471 {
8472 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8473 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8474 }
8475 }
8476
8477 return CMD_SUCCESS;
8478}
8479
8480
8481#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008482ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008483 show_bgp_neighbor_received_routes_cmd,
8484 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8485 SHOW_STR
8486 BGP_STR
8487 "Detailed information on TCP and BGP neighbor connections\n"
8488 "Neighbor to display information about\n"
8489 "Neighbor to display information about\n"
8490 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008491
paulbb46e942003-10-24 19:02:03 +00008492ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008493 show_bgp_ipv6_neighbor_received_routes_cmd,
8494 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8495 SHOW_STR
8496 BGP_STR
8497 "Address family\n"
8498 "Detailed information on TCP and BGP neighbor connections\n"
8499 "Neighbor to display information about\n"
8500 "Neighbor to display information about\n"
8501 "Display the received routes from neighbor\n")
8502
8503DEFUN (show_bgp_neighbor_received_prefix_filter,
8504 show_bgp_neighbor_received_prefix_filter_cmd,
8505 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8506 SHOW_STR
8507 BGP_STR
8508 "Detailed information on TCP and BGP neighbor connections\n"
8509 "Neighbor to display information about\n"
8510 "Neighbor to display information about\n"
8511 "Display information received from a BGP neighbor\n"
8512 "Display the prefixlist filter\n")
8513{
8514 char name[BUFSIZ];
8515 union sockunion *su;
8516 struct peer *peer;
8517 int count;
8518
8519 su = sockunion_str2su (argv[0]);
8520 if (su == NULL)
8521 return CMD_WARNING;
8522
8523 peer = peer_lookup (NULL, su);
8524 if (! peer)
8525 return CMD_WARNING;
8526
8527 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8528 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8529 if (count)
8530 {
8531 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8532 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8533 }
8534
8535 return CMD_SUCCESS;
8536}
8537
8538ALIAS (show_bgp_neighbor_received_prefix_filter,
8539 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
8540 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8541 SHOW_STR
8542 BGP_STR
8543 "Address family\n"
8544 "Detailed information on TCP and BGP neighbor connections\n"
8545 "Neighbor to display information about\n"
8546 "Neighbor to display information about\n"
8547 "Display information received from a BGP neighbor\n"
8548 "Display the prefixlist filter\n")
8549
8550/* old command */
paulbb46e942003-10-24 19:02:03 +00008551ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008552 ipv6_bgp_neighbor_received_routes_cmd,
8553 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8554 SHOW_STR
8555 IPV6_STR
8556 BGP_STR
8557 "Detailed information on TCP and BGP neighbor connections\n"
8558 "Neighbor to display information about\n"
8559 "Neighbor to display information about\n"
8560 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008561
8562/* old command */
8563DEFUN (ipv6_mbgp_neighbor_received_routes,
8564 ipv6_mbgp_neighbor_received_routes_cmd,
8565 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8566 SHOW_STR
8567 IPV6_STR
8568 MBGP_STR
8569 "Detailed information on TCP and BGP neighbor connections\n"
8570 "Neighbor to display information about\n"
8571 "Neighbor to display information about\n"
8572 "Display the received routes from neighbor\n")
8573{
paulbb46e942003-10-24 19:02:03 +00008574 struct peer *peer;
8575
8576 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8577 if (! peer)
8578 return CMD_WARNING;
8579
8580 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00008581}
paulbb46e942003-10-24 19:02:03 +00008582
8583DEFUN (show_bgp_view_neighbor_received_prefix_filter,
8584 show_bgp_view_neighbor_received_prefix_filter_cmd,
8585 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8586 SHOW_STR
8587 BGP_STR
8588 "BGP view\n"
8589 "View name\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 information received from a BGP neighbor\n"
8594 "Display the prefixlist filter\n")
8595{
8596 char name[BUFSIZ];
8597 union sockunion *su;
8598 struct peer *peer;
8599 struct bgp *bgp;
8600 int count;
8601
8602 /* BGP structure lookup. */
8603 bgp = bgp_lookup_by_name (argv[0]);
8604 if (bgp == NULL)
8605 {
8606 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8607 return CMD_WARNING;
8608 }
8609
8610 su = sockunion_str2su (argv[1]);
8611 if (su == NULL)
8612 return CMD_WARNING;
8613
8614 peer = peer_lookup (bgp, su);
8615 if (! peer)
8616 return CMD_WARNING;
8617
8618 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8619 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8620 if (count)
8621 {
8622 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8623 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8624 }
8625
8626 return CMD_SUCCESS;
8627}
8628
8629ALIAS (show_bgp_view_neighbor_received_prefix_filter,
8630 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
8631 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8632 SHOW_STR
8633 BGP_STR
8634 "BGP view\n"
8635 "View name\n"
8636 "Address family\n"
8637 "Detailed information on TCP and BGP neighbor connections\n"
8638 "Neighbor to display information about\n"
8639 "Neighbor to display information about\n"
8640 "Display information received from a BGP neighbor\n"
8641 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00008642#endif /* HAVE_IPV6 */
8643
paul718e3742002-12-13 20:15:29 +00008644int
paulbb46e942003-10-24 19:02:03 +00008645bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008646 safi_t safi, enum bgp_show_type type)
8647{
paul718e3742002-12-13 20:15:29 +00008648 if (! peer || ! peer->afc[afi][safi])
8649 {
8650 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008651 return CMD_WARNING;
8652 }
8653
ajs5a646652004-11-05 01:25:55 +00008654 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +00008655}
8656
8657DEFUN (show_ip_bgp_neighbor_routes,
8658 show_ip_bgp_neighbor_routes_cmd,
8659 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
8660 SHOW_STR
8661 IP_STR
8662 BGP_STR
8663 "Detailed information on TCP and BGP neighbor connections\n"
8664 "Neighbor to display information about\n"
8665 "Neighbor to display information about\n"
8666 "Display routes learned from neighbor\n")
8667{
paulbb46e942003-10-24 19:02:03 +00008668 struct peer *peer;
8669
8670 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8671 if (! peer)
8672 return CMD_WARNING;
8673
8674 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008675 bgp_show_type_neighbor);
8676}
8677
8678DEFUN (show_ip_bgp_neighbor_flap,
8679 show_ip_bgp_neighbor_flap_cmd,
8680 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
8681 SHOW_STR
8682 IP_STR
8683 BGP_STR
8684 "Detailed information on TCP and BGP neighbor connections\n"
8685 "Neighbor to display information about\n"
8686 "Neighbor to display information about\n"
8687 "Display flap statistics of the routes learned from neighbor\n")
8688{
paulbb46e942003-10-24 19:02:03 +00008689 struct peer *peer;
8690
8691 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8692 if (! peer)
8693 return CMD_WARNING;
8694
8695 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008696 bgp_show_type_flap_neighbor);
8697}
8698
8699DEFUN (show_ip_bgp_neighbor_damp,
8700 show_ip_bgp_neighbor_damp_cmd,
8701 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
8702 SHOW_STR
8703 IP_STR
8704 BGP_STR
8705 "Detailed information on TCP and BGP neighbor connections\n"
8706 "Neighbor to display information about\n"
8707 "Neighbor to display information about\n"
8708 "Display the dampened routes received from neighbor\n")
8709{
paulbb46e942003-10-24 19:02:03 +00008710 struct peer *peer;
8711
8712 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8713 if (! peer)
8714 return CMD_WARNING;
8715
8716 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008717 bgp_show_type_damp_neighbor);
8718}
8719
8720DEFUN (show_ip_bgp_ipv4_neighbor_routes,
8721 show_ip_bgp_ipv4_neighbor_routes_cmd,
8722 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
8723 SHOW_STR
8724 IP_STR
8725 BGP_STR
8726 "Address family\n"
8727 "Address Family modifier\n"
8728 "Address Family modifier\n"
8729 "Detailed information on TCP and BGP neighbor connections\n"
8730 "Neighbor to display information about\n"
8731 "Neighbor to display information about\n"
8732 "Display routes learned from neighbor\n")
8733{
paulbb46e942003-10-24 19:02:03 +00008734 struct peer *peer;
8735
8736 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8737 if (! peer)
8738 return CMD_WARNING;
8739
paul718e3742002-12-13 20:15:29 +00008740 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00008741 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00008742 bgp_show_type_neighbor);
8743
paulbb46e942003-10-24 19:02:03 +00008744 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008745 bgp_show_type_neighbor);
8746}
paulbb46e942003-10-24 19:02:03 +00008747
paulfee0f4c2004-09-13 05:12:46 +00008748DEFUN (show_ip_bgp_view_rsclient,
8749 show_ip_bgp_view_rsclient_cmd,
8750 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
8751 SHOW_STR
8752 IP_STR
8753 BGP_STR
8754 "BGP view\n"
8755 "BGP view name\n"
8756 "Information about Route Server Client\n"
8757 NEIGHBOR_ADDR_STR)
8758{
8759 struct bgp_table *table;
8760 struct peer *peer;
8761
8762 if (argc == 2)
8763 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8764 else
8765 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8766
8767 if (! peer)
8768 return CMD_WARNING;
8769
8770 if (! peer->afc[AFI_IP][SAFI_UNICAST])
8771 {
8772 vty_out (vty, "%% Activate the neighbor for the address family first%s",
8773 VTY_NEWLINE);
8774 return CMD_WARNING;
8775 }
8776
8777 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
8778 PEER_FLAG_RSERVER_CLIENT))
8779 {
8780 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
8781 VTY_NEWLINE);
8782 return CMD_WARNING;
8783 }
8784
8785 table = peer->rib[AFI_IP][SAFI_UNICAST];
8786
ajs5a646652004-11-05 01:25:55 +00008787 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00008788}
8789
8790ALIAS (show_ip_bgp_view_rsclient,
8791 show_ip_bgp_rsclient_cmd,
8792 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
8793 SHOW_STR
8794 IP_STR
8795 BGP_STR
8796 "Information about Route Server Client\n"
8797 NEIGHBOR_ADDR_STR)
8798
8799DEFUN (show_ip_bgp_view_rsclient_route,
8800 show_ip_bgp_view_rsclient_route_cmd,
8801 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
8802 SHOW_STR
8803 IP_STR
8804 BGP_STR
8805 "BGP view\n"
8806 "BGP view name\n"
8807 "Information about Route Server Client\n"
8808 NEIGHBOR_ADDR_STR
8809 "Network in the BGP routing table to display\n")
8810{
8811 struct bgp *bgp;
8812 struct peer *peer;
8813
8814 /* BGP structure lookup. */
8815 if (argc == 3)
8816 {
8817 bgp = bgp_lookup_by_name (argv[0]);
8818 if (bgp == NULL)
8819 {
8820 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8821 return CMD_WARNING;
8822 }
8823 }
8824 else
8825 {
8826 bgp = bgp_get_default ();
8827 if (bgp == NULL)
8828 {
8829 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8830 return CMD_WARNING;
8831 }
8832 }
8833
8834 if (argc == 3)
8835 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8836 else
8837 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8838
8839 if (! peer)
8840 return CMD_WARNING;
8841
8842 if (! peer->afc[AFI_IP][SAFI_UNICAST])
8843 {
8844 vty_out (vty, "%% Activate the neighbor for the address family first%s",
8845 VTY_NEWLINE);
8846 return CMD_WARNING;
8847}
8848
8849 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
8850 PEER_FLAG_RSERVER_CLIENT))
8851 {
8852 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
8853 VTY_NEWLINE);
8854 return CMD_WARNING;
8855 }
8856
8857 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
8858 (argc == 3) ? argv[2] : argv[1],
8859 AFI_IP, SAFI_UNICAST, NULL, 0);
8860}
8861
8862ALIAS (show_ip_bgp_view_rsclient_route,
8863 show_ip_bgp_rsclient_route_cmd,
8864 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
8865 SHOW_STR
8866 IP_STR
8867 BGP_STR
8868 "Information about Route Server Client\n"
8869 NEIGHBOR_ADDR_STR
8870 "Network in the BGP routing table to display\n")
8871
8872DEFUN (show_ip_bgp_view_rsclient_prefix,
8873 show_ip_bgp_view_rsclient_prefix_cmd,
8874 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
8875 SHOW_STR
8876 IP_STR
8877 BGP_STR
8878 "BGP view\n"
8879 "BGP view name\n"
8880 "Information about Route Server Client\n"
8881 NEIGHBOR_ADDR_STR
8882 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8883{
8884 struct bgp *bgp;
8885 struct peer *peer;
8886
8887 /* BGP structure lookup. */
8888 if (argc == 3)
8889 {
8890 bgp = bgp_lookup_by_name (argv[0]);
8891 if (bgp == NULL)
8892 {
8893 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8894 return CMD_WARNING;
8895 }
8896 }
8897 else
8898 {
8899 bgp = bgp_get_default ();
8900 if (bgp == NULL)
8901 {
8902 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8903 return CMD_WARNING;
8904 }
8905 }
8906
8907 if (argc == 3)
8908 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8909 else
8910 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8911
8912 if (! peer)
8913 return CMD_WARNING;
8914
8915 if (! peer->afc[AFI_IP][SAFI_UNICAST])
8916 {
8917 vty_out (vty, "%% Activate the neighbor for the address family first%s",
8918 VTY_NEWLINE);
8919 return CMD_WARNING;
8920}
8921
8922 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
8923 PEER_FLAG_RSERVER_CLIENT))
8924{
8925 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
8926 VTY_NEWLINE);
8927 return CMD_WARNING;
8928 }
8929
8930 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
8931 (argc == 3) ? argv[2] : argv[1],
8932 AFI_IP, SAFI_UNICAST, NULL, 1);
8933}
8934
8935ALIAS (show_ip_bgp_view_rsclient_prefix,
8936 show_ip_bgp_rsclient_prefix_cmd,
8937 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
8938 SHOW_STR
8939 IP_STR
8940 BGP_STR
8941 "Information about Route Server Client\n"
8942 NEIGHBOR_ADDR_STR
8943 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8944
8945
paul718e3742002-12-13 20:15:29 +00008946#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008947DEFUN (show_bgp_view_neighbor_routes,
8948 show_bgp_view_neighbor_routes_cmd,
8949 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
8950 SHOW_STR
8951 BGP_STR
8952 "BGP view\n"
8953 "BGP view name\n"
8954 "Detailed information on TCP and BGP neighbor connections\n"
8955 "Neighbor to display information about\n"
8956 "Neighbor to display information about\n"
8957 "Display routes learned from neighbor\n")
8958{
8959 struct peer *peer;
8960
8961 if (argc == 2)
8962 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8963 else
8964 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8965
8966 if (! peer)
8967 return CMD_WARNING;
8968
8969 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
8970 bgp_show_type_neighbor);
8971}
8972
8973ALIAS (show_bgp_view_neighbor_routes,
8974 show_bgp_view_ipv6_neighbor_routes_cmd,
8975 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
8976 SHOW_STR
8977 BGP_STR
8978 "BGP view\n"
8979 "BGP view name\n"
8980 "Address family\n"
8981 "Detailed information on TCP and BGP neighbor connections\n"
8982 "Neighbor to display information about\n"
8983 "Neighbor to display information about\n"
8984 "Display routes learned from neighbor\n")
8985
8986DEFUN (show_bgp_view_neighbor_damp,
8987 show_bgp_view_neighbor_damp_cmd,
8988 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
8989 SHOW_STR
8990 BGP_STR
8991 "BGP view\n"
8992 "BGP view name\n"
8993 "Detailed information on TCP and BGP neighbor connections\n"
8994 "Neighbor to display information about\n"
8995 "Neighbor to display information about\n"
8996 "Display the dampened routes received from neighbor\n")
8997{
8998 struct peer *peer;
8999
9000 if (argc == 2)
9001 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9002 else
9003 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9004
9005 if (! peer)
9006 return CMD_WARNING;
9007
9008 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9009 bgp_show_type_damp_neighbor);
9010}
9011
9012ALIAS (show_bgp_view_neighbor_damp,
9013 show_bgp_view_ipv6_neighbor_damp_cmd,
9014 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9015 SHOW_STR
9016 BGP_STR
9017 "BGP view\n"
9018 "BGP view name\n"
9019 "Address family\n"
9020 "Detailed information on TCP and BGP neighbor connections\n"
9021 "Neighbor to display information about\n"
9022 "Neighbor to display information about\n"
9023 "Display the dampened routes received from neighbor\n")
9024
9025DEFUN (show_bgp_view_neighbor_flap,
9026 show_bgp_view_neighbor_flap_cmd,
9027 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9028 SHOW_STR
9029 BGP_STR
9030 "BGP view\n"
9031 "BGP view name\n"
9032 "Detailed information on TCP and BGP neighbor connections\n"
9033 "Neighbor to display information about\n"
9034 "Neighbor to display information about\n"
9035 "Display flap statistics of the routes learned from neighbor\n")
9036{
9037 struct peer *peer;
9038
9039 if (argc == 2)
9040 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9041 else
9042 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9043
9044 if (! peer)
9045 return CMD_WARNING;
9046
9047 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9048 bgp_show_type_flap_neighbor);
9049}
9050
9051ALIAS (show_bgp_view_neighbor_flap,
9052 show_bgp_view_ipv6_neighbor_flap_cmd,
9053 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9054 SHOW_STR
9055 BGP_STR
9056 "BGP view\n"
9057 "BGP view name\n"
9058 "Address family\n"
9059 "Detailed information on TCP and BGP neighbor connections\n"
9060 "Neighbor to display information about\n"
9061 "Neighbor to display information about\n"
9062 "Display flap statistics of the routes learned from neighbor\n")
9063
9064ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009065 show_bgp_neighbor_routes_cmd,
9066 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
9067 SHOW_STR
9068 BGP_STR
9069 "Detailed information on TCP and BGP neighbor connections\n"
9070 "Neighbor to display information about\n"
9071 "Neighbor to display information about\n"
9072 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009073
paulbb46e942003-10-24 19:02:03 +00009074
9075ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009076 show_bgp_ipv6_neighbor_routes_cmd,
9077 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9078 SHOW_STR
9079 BGP_STR
9080 "Address family\n"
9081 "Detailed information on TCP and BGP neighbor connections\n"
9082 "Neighbor to display information about\n"
9083 "Neighbor to display information about\n"
9084 "Display routes learned from neighbor\n")
9085
9086/* old command */
paulbb46e942003-10-24 19:02:03 +00009087ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009088 ipv6_bgp_neighbor_routes_cmd,
9089 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
9090 SHOW_STR
9091 IPV6_STR
9092 BGP_STR
9093 "Detailed information on TCP and BGP neighbor connections\n"
9094 "Neighbor to display information about\n"
9095 "Neighbor to display information about\n"
9096 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009097
9098/* old command */
9099DEFUN (ipv6_mbgp_neighbor_routes,
9100 ipv6_mbgp_neighbor_routes_cmd,
9101 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
9102 SHOW_STR
9103 IPV6_STR
9104 MBGP_STR
9105 "Detailed information on TCP and BGP neighbor connections\n"
9106 "Neighbor to display information about\n"
9107 "Neighbor to display information about\n"
9108 "Display routes learned from neighbor\n")
9109{
paulbb46e942003-10-24 19:02:03 +00009110 struct peer *peer;
9111
9112 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9113 if (! peer)
9114 return CMD_WARNING;
9115
9116 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009117 bgp_show_type_neighbor);
9118}
paulbb46e942003-10-24 19:02:03 +00009119
9120ALIAS (show_bgp_view_neighbor_flap,
9121 show_bgp_neighbor_flap_cmd,
9122 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9123 SHOW_STR
9124 BGP_STR
9125 "Detailed information on TCP and BGP neighbor connections\n"
9126 "Neighbor to display information about\n"
9127 "Neighbor to display information about\n"
9128 "Display flap statistics of the routes learned from neighbor\n")
9129
9130ALIAS (show_bgp_view_neighbor_flap,
9131 show_bgp_ipv6_neighbor_flap_cmd,
9132 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9133 SHOW_STR
9134 BGP_STR
9135 "Address family\n"
9136 "Detailed information on TCP and BGP neighbor connections\n"
9137 "Neighbor to display information about\n"
9138 "Neighbor to display information about\n"
9139 "Display flap statistics of the routes learned from neighbor\n")
9140
9141ALIAS (show_bgp_view_neighbor_damp,
9142 show_bgp_neighbor_damp_cmd,
9143 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9144 SHOW_STR
9145 BGP_STR
9146 "Detailed information on TCP and BGP neighbor connections\n"
9147 "Neighbor to display information about\n"
9148 "Neighbor to display information about\n"
9149 "Display the dampened routes received from neighbor\n")
9150
9151ALIAS (show_bgp_view_neighbor_damp,
9152 show_bgp_ipv6_neighbor_damp_cmd,
9153 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9154 SHOW_STR
9155 BGP_STR
9156 "Address family\n"
9157 "Detailed information on TCP and BGP neighbor connections\n"
9158 "Neighbor to display information about\n"
9159 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +00009160 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +00009161
9162DEFUN (show_bgp_view_rsclient,
9163 show_bgp_view_rsclient_cmd,
9164 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9165 SHOW_STR
9166 BGP_STR
9167 "BGP view\n"
9168 "BGP view name\n"
9169 "Information about Route Server Client\n"
9170 NEIGHBOR_ADDR_STR)
9171{
9172 struct bgp_table *table;
9173 struct peer *peer;
9174
9175 if (argc == 2)
9176 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9177 else
9178 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9179
9180 if (! peer)
9181 return CMD_WARNING;
9182
9183 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9184 {
9185 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9186 VTY_NEWLINE);
9187 return CMD_WARNING;
9188 }
9189
9190 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9191 PEER_FLAG_RSERVER_CLIENT))
9192 {
9193 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9194 VTY_NEWLINE);
9195 return CMD_WARNING;
9196 }
9197
9198 table = peer->rib[AFI_IP6][SAFI_UNICAST];
9199
ajs5a646652004-11-05 01:25:55 +00009200 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009201}
9202
9203ALIAS (show_bgp_view_rsclient,
9204 show_bgp_rsclient_cmd,
9205 "show bgp rsclient (A.B.C.D|X:X::X:X)",
9206 SHOW_STR
9207 BGP_STR
9208 "Information about Route Server Client\n"
9209 NEIGHBOR_ADDR_STR)
9210
9211DEFUN (show_bgp_view_rsclient_route,
9212 show_bgp_view_rsclient_route_cmd,
9213 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9214 SHOW_STR
9215 BGP_STR
9216 "BGP view\n"
9217 "BGP view name\n"
9218 "Information about Route Server Client\n"
9219 NEIGHBOR_ADDR_STR
9220 "Network in the BGP routing table to display\n")
9221{
9222 struct bgp *bgp;
9223 struct peer *peer;
9224
9225 /* BGP structure lookup. */
9226 if (argc == 3)
9227 {
9228 bgp = bgp_lookup_by_name (argv[0]);
9229 if (bgp == NULL)
9230 {
9231 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9232 return CMD_WARNING;
9233 }
9234 }
9235 else
9236 {
9237 bgp = bgp_get_default ();
9238 if (bgp == NULL)
9239 {
9240 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9241 return CMD_WARNING;
9242 }
9243 }
9244
9245 if (argc == 3)
9246 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9247 else
9248 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9249
9250 if (! peer)
9251 return CMD_WARNING;
9252
9253 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9254 {
9255 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9256 VTY_NEWLINE);
9257 return CMD_WARNING;
9258 }
9259
9260 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9261 PEER_FLAG_RSERVER_CLIENT))
9262 {
9263 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9264 VTY_NEWLINE);
9265 return CMD_WARNING;
9266 }
9267
9268 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9269 (argc == 3) ? argv[2] : argv[1],
9270 AFI_IP6, SAFI_UNICAST, NULL, 0);
9271}
9272
9273ALIAS (show_bgp_view_rsclient_route,
9274 show_bgp_rsclient_route_cmd,
9275 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9276 SHOW_STR
9277 BGP_STR
9278 "Information about Route Server Client\n"
9279 NEIGHBOR_ADDR_STR
9280 "Network in the BGP routing table to display\n")
9281
9282DEFUN (show_bgp_view_rsclient_prefix,
9283 show_bgp_view_rsclient_prefix_cmd,
9284 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9285 SHOW_STR
9286 BGP_STR
9287 "BGP view\n"
9288 "BGP view name\n"
9289 "Information about Route Server Client\n"
9290 NEIGHBOR_ADDR_STR
9291 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9292{
9293 struct bgp *bgp;
9294 struct peer *peer;
9295
9296 /* BGP structure lookup. */
9297 if (argc == 3)
9298 {
9299 bgp = bgp_lookup_by_name (argv[0]);
9300 if (bgp == NULL)
9301 {
9302 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9303 return CMD_WARNING;
9304 }
9305 }
9306 else
9307 {
9308 bgp = bgp_get_default ();
9309 if (bgp == NULL)
9310 {
9311 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9312 return CMD_WARNING;
9313 }
9314 }
9315
9316 if (argc == 3)
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 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9325 {
9326 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9327 VTY_NEWLINE);
9328 return CMD_WARNING;
9329 }
9330
9331 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9332 PEER_FLAG_RSERVER_CLIENT))
9333 {
9334 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9335 VTY_NEWLINE);
9336 return CMD_WARNING;
9337 }
9338
9339 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9340 (argc == 3) ? argv[2] : argv[1],
9341 AFI_IP6, SAFI_UNICAST, NULL, 1);
9342}
9343
9344ALIAS (show_bgp_view_rsclient_prefix,
9345 show_bgp_rsclient_prefix_cmd,
9346 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9347 SHOW_STR
9348 BGP_STR
9349 "Information about Route Server Client\n"
9350 NEIGHBOR_ADDR_STR
9351 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9352
paul718e3742002-12-13 20:15:29 +00009353#endif /* HAVE_IPV6 */
9354
9355struct bgp_table *bgp_distance_table;
9356
9357struct bgp_distance
9358{
9359 /* Distance value for the IP source prefix. */
9360 u_char distance;
9361
9362 /* Name of the access-list to be matched. */
9363 char *access_list;
9364};
9365
9366struct bgp_distance *
9367bgp_distance_new ()
9368{
9369 struct bgp_distance *new;
9370 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
9371 memset (new, 0, sizeof (struct bgp_distance));
9372 return new;
9373}
9374
9375void
9376bgp_distance_free (struct bgp_distance *bdistance)
9377{
9378 XFREE (MTYPE_BGP_DISTANCE, bdistance);
9379}
9380
9381int
paulfd79ac92004-10-13 05:06:08 +00009382bgp_distance_set (struct vty *vty, const char *distance_str,
9383 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009384{
9385 int ret;
9386 struct prefix_ipv4 p;
9387 u_char distance;
9388 struct bgp_node *rn;
9389 struct bgp_distance *bdistance;
9390
9391 ret = str2prefix_ipv4 (ip_str, &p);
9392 if (ret == 0)
9393 {
9394 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9395 return CMD_WARNING;
9396 }
9397
9398 distance = atoi (distance_str);
9399
9400 /* Get BGP distance node. */
9401 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
9402 if (rn->info)
9403 {
9404 bdistance = rn->info;
9405 bgp_unlock_node (rn);
9406 }
9407 else
9408 {
9409 bdistance = bgp_distance_new ();
9410 rn->info = bdistance;
9411 }
9412
9413 /* Set distance value. */
9414 bdistance->distance = distance;
9415
9416 /* Reset access-list configuration. */
9417 if (bdistance->access_list)
9418 {
9419 free (bdistance->access_list);
9420 bdistance->access_list = NULL;
9421 }
9422 if (access_list_str)
9423 bdistance->access_list = strdup (access_list_str);
9424
9425 return CMD_SUCCESS;
9426}
9427
9428int
paulfd79ac92004-10-13 05:06:08 +00009429bgp_distance_unset (struct vty *vty, const char *distance_str,
9430 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009431{
9432 int ret;
9433 struct prefix_ipv4 p;
9434 u_char distance;
9435 struct bgp_node *rn;
9436 struct bgp_distance *bdistance;
9437
9438 ret = str2prefix_ipv4 (ip_str, &p);
9439 if (ret == 0)
9440 {
9441 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9442 return CMD_WARNING;
9443 }
9444
9445 distance = atoi (distance_str);
9446
9447 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
9448 if (! rn)
9449 {
9450 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
9451 return CMD_WARNING;
9452 }
9453
9454 bdistance = rn->info;
9455
9456 if (bdistance->access_list)
9457 free (bdistance->access_list);
9458 bgp_distance_free (bdistance);
9459
9460 rn->info = NULL;
9461 bgp_unlock_node (rn);
9462 bgp_unlock_node (rn);
9463
9464 return CMD_SUCCESS;
9465}
9466
9467void
9468bgp_distance_reset ()
9469{
9470 struct bgp_node *rn;
9471 struct bgp_distance *bdistance;
9472
9473 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
9474 if ((bdistance = rn->info) != NULL)
9475 {
9476 if (bdistance->access_list)
9477 free (bdistance->access_list);
9478 bgp_distance_free (bdistance);
9479 rn->info = NULL;
9480 bgp_unlock_node (rn);
9481 }
9482}
9483
9484/* Apply BGP information to distance method. */
9485u_char
9486bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
9487{
9488 struct bgp_node *rn;
9489 struct prefix_ipv4 q;
9490 struct peer *peer;
9491 struct bgp_distance *bdistance;
9492 struct access_list *alist;
9493 struct bgp_static *bgp_static;
9494
9495 if (! bgp)
9496 return 0;
9497
9498 if (p->family != AF_INET)
9499 return 0;
9500
9501 peer = rinfo->peer;
9502
9503 if (peer->su.sa.sa_family != AF_INET)
9504 return 0;
9505
9506 memset (&q, 0, sizeof (struct prefix_ipv4));
9507 q.family = AF_INET;
9508 q.prefix = peer->su.sin.sin_addr;
9509 q.prefixlen = IPV4_MAX_BITLEN;
9510
9511 /* Check source address. */
9512 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
9513 if (rn)
9514 {
9515 bdistance = rn->info;
9516 bgp_unlock_node (rn);
9517
9518 if (bdistance->access_list)
9519 {
9520 alist = access_list_lookup (AFI_IP, bdistance->access_list);
9521 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
9522 return bdistance->distance;
9523 }
9524 else
9525 return bdistance->distance;
9526 }
9527
9528 /* Backdoor check. */
9529 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
9530 if (rn)
9531 {
9532 bgp_static = rn->info;
9533 bgp_unlock_node (rn);
9534
9535 if (bgp_static->backdoor)
9536 {
9537 if (bgp->distance_local)
9538 return bgp->distance_local;
9539 else
9540 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9541 }
9542 }
9543
9544 if (peer_sort (peer) == BGP_PEER_EBGP)
9545 {
9546 if (bgp->distance_ebgp)
9547 return bgp->distance_ebgp;
9548 return ZEBRA_EBGP_DISTANCE_DEFAULT;
9549 }
9550 else
9551 {
9552 if (bgp->distance_ibgp)
9553 return bgp->distance_ibgp;
9554 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9555 }
9556}
9557
9558DEFUN (bgp_distance,
9559 bgp_distance_cmd,
9560 "distance bgp <1-255> <1-255> <1-255>",
9561 "Define an administrative distance\n"
9562 "BGP distance\n"
9563 "Distance for routes external to the AS\n"
9564 "Distance for routes internal to the AS\n"
9565 "Distance for local routes\n")
9566{
9567 struct bgp *bgp;
9568
9569 bgp = vty->index;
9570
9571 bgp->distance_ebgp = atoi (argv[0]);
9572 bgp->distance_ibgp = atoi (argv[1]);
9573 bgp->distance_local = atoi (argv[2]);
9574 return CMD_SUCCESS;
9575}
9576
9577DEFUN (no_bgp_distance,
9578 no_bgp_distance_cmd,
9579 "no distance bgp <1-255> <1-255> <1-255>",
9580 NO_STR
9581 "Define an administrative distance\n"
9582 "BGP distance\n"
9583 "Distance for routes external to the AS\n"
9584 "Distance for routes internal to the AS\n"
9585 "Distance for local routes\n")
9586{
9587 struct bgp *bgp;
9588
9589 bgp = vty->index;
9590
9591 bgp->distance_ebgp= 0;
9592 bgp->distance_ibgp = 0;
9593 bgp->distance_local = 0;
9594 return CMD_SUCCESS;
9595}
9596
9597ALIAS (no_bgp_distance,
9598 no_bgp_distance2_cmd,
9599 "no distance bgp",
9600 NO_STR
9601 "Define an administrative distance\n"
9602 "BGP distance\n")
9603
9604DEFUN (bgp_distance_source,
9605 bgp_distance_source_cmd,
9606 "distance <1-255> A.B.C.D/M",
9607 "Define an administrative distance\n"
9608 "Administrative distance\n"
9609 "IP source prefix\n")
9610{
9611 bgp_distance_set (vty, argv[0], argv[1], NULL);
9612 return CMD_SUCCESS;
9613}
9614
9615DEFUN (no_bgp_distance_source,
9616 no_bgp_distance_source_cmd,
9617 "no distance <1-255> A.B.C.D/M",
9618 NO_STR
9619 "Define an administrative distance\n"
9620 "Administrative distance\n"
9621 "IP source prefix\n")
9622{
9623 bgp_distance_unset (vty, argv[0], argv[1], NULL);
9624 return CMD_SUCCESS;
9625}
9626
9627DEFUN (bgp_distance_source_access_list,
9628 bgp_distance_source_access_list_cmd,
9629 "distance <1-255> A.B.C.D/M WORD",
9630 "Define an administrative distance\n"
9631 "Administrative distance\n"
9632 "IP source prefix\n"
9633 "Access list name\n")
9634{
9635 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
9636 return CMD_SUCCESS;
9637}
9638
9639DEFUN (no_bgp_distance_source_access_list,
9640 no_bgp_distance_source_access_list_cmd,
9641 "no distance <1-255> A.B.C.D/M WORD",
9642 NO_STR
9643 "Define an administrative distance\n"
9644 "Administrative distance\n"
9645 "IP source prefix\n"
9646 "Access list name\n")
9647{
9648 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
9649 return CMD_SUCCESS;
9650}
9651
9652DEFUN (bgp_damp_set,
9653 bgp_damp_set_cmd,
9654 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
9655 "BGP Specific commands\n"
9656 "Enable route-flap dampening\n"
9657 "Half-life time for the penalty\n"
9658 "Value to start reusing a route\n"
9659 "Value to start suppressing a route\n"
9660 "Maximum duration to suppress a stable route\n")
9661{
9662 struct bgp *bgp;
9663 int half = DEFAULT_HALF_LIFE * 60;
9664 int reuse = DEFAULT_REUSE;
9665 int suppress = DEFAULT_SUPPRESS;
9666 int max = 4 * half;
9667
9668 if (argc == 4)
9669 {
9670 half = atoi (argv[0]) * 60;
9671 reuse = atoi (argv[1]);
9672 suppress = atoi (argv[2]);
9673 max = atoi (argv[3]) * 60;
9674 }
9675 else if (argc == 1)
9676 {
9677 half = atoi (argv[0]) * 60;
9678 max = 4 * half;
9679 }
9680
9681 bgp = vty->index;
9682 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
9683 half, reuse, suppress, max);
9684}
9685
9686ALIAS (bgp_damp_set,
9687 bgp_damp_set2_cmd,
9688 "bgp dampening <1-45>",
9689 "BGP Specific commands\n"
9690 "Enable route-flap dampening\n"
9691 "Half-life time for the penalty\n")
9692
9693ALIAS (bgp_damp_set,
9694 bgp_damp_set3_cmd,
9695 "bgp dampening",
9696 "BGP Specific commands\n"
9697 "Enable route-flap dampening\n")
9698
9699DEFUN (bgp_damp_unset,
9700 bgp_damp_unset_cmd,
9701 "no bgp dampening",
9702 NO_STR
9703 "BGP Specific commands\n"
9704 "Enable route-flap dampening\n")
9705{
9706 struct bgp *bgp;
9707
9708 bgp = vty->index;
9709 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
9710}
9711
9712ALIAS (bgp_damp_unset,
9713 bgp_damp_unset2_cmd,
9714 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
9715 NO_STR
9716 "BGP Specific commands\n"
9717 "Enable route-flap dampening\n"
9718 "Half-life time for the penalty\n"
9719 "Value to start reusing a route\n"
9720 "Value to start suppressing a route\n"
9721 "Maximum duration to suppress a stable route\n")
9722
9723DEFUN (show_ip_bgp_dampened_paths,
9724 show_ip_bgp_dampened_paths_cmd,
9725 "show ip bgp dampened-paths",
9726 SHOW_STR
9727 IP_STR
9728 BGP_STR
9729 "Display paths suppressed due to dampening\n")
9730{
ajs5a646652004-11-05 01:25:55 +00009731 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
9732 NULL);
paul718e3742002-12-13 20:15:29 +00009733}
9734
9735DEFUN (show_ip_bgp_flap_statistics,
9736 show_ip_bgp_flap_statistics_cmd,
9737 "show ip bgp flap-statistics",
9738 SHOW_STR
9739 IP_STR
9740 BGP_STR
9741 "Display flap statistics of routes\n")
9742{
ajs5a646652004-11-05 01:25:55 +00009743 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9744 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +00009745}
9746
9747/* Display specified route of BGP table. */
9748int
paulfd79ac92004-10-13 05:06:08 +00009749bgp_clear_damp_route (struct vty *vty, const char *view_name,
9750 const char *ip_str, afi_t afi, safi_t safi,
9751 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +00009752{
9753 int ret;
9754 struct prefix match;
9755 struct bgp_node *rn;
9756 struct bgp_node *rm;
9757 struct bgp_info *ri;
9758 struct bgp_info *ri_temp;
9759 struct bgp *bgp;
9760 struct bgp_table *table;
9761
9762 /* BGP structure lookup. */
9763 if (view_name)
9764 {
9765 bgp = bgp_lookup_by_name (view_name);
9766 if (bgp == NULL)
9767 {
9768 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9769 return CMD_WARNING;
9770 }
9771 }
9772 else
9773 {
9774 bgp = bgp_get_default ();
9775 if (bgp == NULL)
9776 {
9777 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
9778 return CMD_WARNING;
9779 }
9780 }
9781
9782 /* Check IP address argument. */
9783 ret = str2prefix (ip_str, &match);
9784 if (! ret)
9785 {
9786 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
9787 return CMD_WARNING;
9788 }
9789
9790 match.family = afi2family (afi);
9791
9792 if (safi == SAFI_MPLS_VPN)
9793 {
9794 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
9795 {
9796 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
9797 continue;
9798
9799 if ((table = rn->info) != NULL)
9800 if ((rm = bgp_node_match (table, &match)) != NULL)
9801 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
9802 {
9803 ri = rm->info;
9804 while (ri)
9805 {
9806 if (ri->damp_info)
9807 {
9808 ri_temp = ri->next;
9809 bgp_damp_info_free (ri->damp_info, 1);
9810 ri = ri_temp;
9811 }
9812 else
9813 ri = ri->next;
9814 }
9815 }
9816 }
9817 }
9818 else
9819 {
9820 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
9821 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
9822 {
9823 ri = rn->info;
9824 while (ri)
9825 {
9826 if (ri->damp_info)
9827 {
9828 ri_temp = ri->next;
9829 bgp_damp_info_free (ri->damp_info, 1);
9830 ri = ri_temp;
9831 }
9832 else
9833 ri = ri->next;
9834 }
9835 }
9836 }
9837
9838 return CMD_SUCCESS;
9839}
9840
9841DEFUN (clear_ip_bgp_dampening,
9842 clear_ip_bgp_dampening_cmd,
9843 "clear ip bgp dampening",
9844 CLEAR_STR
9845 IP_STR
9846 BGP_STR
9847 "Clear route flap dampening information\n")
9848{
9849 bgp_damp_info_clean ();
9850 return CMD_SUCCESS;
9851}
9852
9853DEFUN (clear_ip_bgp_dampening_prefix,
9854 clear_ip_bgp_dampening_prefix_cmd,
9855 "clear ip bgp dampening A.B.C.D/M",
9856 CLEAR_STR
9857 IP_STR
9858 BGP_STR
9859 "Clear route flap dampening information\n"
9860 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9861{
9862 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
9863 SAFI_UNICAST, NULL, 1);
9864}
9865
9866DEFUN (clear_ip_bgp_dampening_address,
9867 clear_ip_bgp_dampening_address_cmd,
9868 "clear ip bgp dampening A.B.C.D",
9869 CLEAR_STR
9870 IP_STR
9871 BGP_STR
9872 "Clear route flap dampening information\n"
9873 "Network to clear damping information\n")
9874{
9875 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
9876 SAFI_UNICAST, NULL, 0);
9877}
9878
9879DEFUN (clear_ip_bgp_dampening_address_mask,
9880 clear_ip_bgp_dampening_address_mask_cmd,
9881 "clear ip bgp dampening A.B.C.D A.B.C.D",
9882 CLEAR_STR
9883 IP_STR
9884 BGP_STR
9885 "Clear route flap dampening information\n"
9886 "Network to clear damping information\n"
9887 "Network mask\n")
9888{
9889 int ret;
9890 char prefix_str[BUFSIZ];
9891
9892 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
9893 if (! ret)
9894 {
9895 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
9896 return CMD_WARNING;
9897 }
9898
9899 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
9900 SAFI_UNICAST, NULL, 0);
9901}
9902
9903int
9904bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
9905 afi_t afi, safi_t safi, int *write)
9906{
9907 struct bgp_node *prn;
9908 struct bgp_node *rn;
9909 struct bgp_table *table;
9910 struct prefix *p;
9911 struct prefix_rd *prd;
9912 struct bgp_static *bgp_static;
9913 u_int32_t label;
9914 char buf[SU_ADDRSTRLEN];
9915 char rdbuf[RD_ADDRSTRLEN];
9916
9917 /* Network configuration. */
9918 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
9919 if ((table = prn->info) != NULL)
9920 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9921 if ((bgp_static = rn->info) != NULL)
9922 {
9923 p = &rn->p;
9924 prd = (struct prefix_rd *) &prn->p;
9925
9926 /* "address-family" display. */
9927 bgp_config_write_family_header (vty, afi, safi, write);
9928
9929 /* "network" configuration display. */
9930 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
9931 label = decode_label (bgp_static->tag);
9932
9933 vty_out (vty, " network %s/%d rd %s tag %d",
9934 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
9935 p->prefixlen,
9936 rdbuf, label);
9937 vty_out (vty, "%s", VTY_NEWLINE);
9938 }
9939 return 0;
9940}
9941
9942/* Configuration of static route announcement and aggregate
9943 information. */
9944int
9945bgp_config_write_network (struct vty *vty, struct bgp *bgp,
9946 afi_t afi, safi_t safi, int *write)
9947{
9948 struct bgp_node *rn;
9949 struct prefix *p;
9950 struct bgp_static *bgp_static;
9951 struct bgp_aggregate *bgp_aggregate;
9952 char buf[SU_ADDRSTRLEN];
9953
9954 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
9955 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
9956
9957 /* Network configuration. */
9958 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
9959 if ((bgp_static = rn->info) != NULL)
9960 {
9961 p = &rn->p;
9962
9963 /* "address-family" display. */
9964 bgp_config_write_family_header (vty, afi, safi, write);
9965
9966 /* "network" configuration display. */
9967 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
9968 {
9969 u_int32_t destination;
9970 struct in_addr netmask;
9971
9972 destination = ntohl (p->u.prefix4.s_addr);
9973 masklen2ip (p->prefixlen, &netmask);
9974 vty_out (vty, " network %s",
9975 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
9976
9977 if ((IN_CLASSC (destination) && p->prefixlen == 24)
9978 || (IN_CLASSB (destination) && p->prefixlen == 16)
9979 || (IN_CLASSA (destination) && p->prefixlen == 8)
9980 || p->u.prefix4.s_addr == 0)
9981 {
9982 /* Natural mask is not display. */
9983 }
9984 else
9985 vty_out (vty, " mask %s", inet_ntoa (netmask));
9986 }
9987 else
9988 {
9989 vty_out (vty, " network %s/%d",
9990 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
9991 p->prefixlen);
9992 }
9993
9994 if (bgp_static->rmap.name)
9995 vty_out (vty, " route-map %s", bgp_static->rmap.name);
9996 else if (bgp_static->backdoor)
9997 vty_out (vty, " backdoor");
9998
9999 vty_out (vty, "%s", VTY_NEWLINE);
10000 }
10001
10002 /* Aggregate-address configuration. */
10003 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
10004 if ((bgp_aggregate = rn->info) != NULL)
10005 {
10006 p = &rn->p;
10007
10008 /* "address-family" display. */
10009 bgp_config_write_family_header (vty, afi, safi, write);
10010
10011 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10012 {
10013 struct in_addr netmask;
10014
10015 masklen2ip (p->prefixlen, &netmask);
10016 vty_out (vty, " aggregate-address %s %s",
10017 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10018 inet_ntoa (netmask));
10019 }
10020 else
10021 {
10022 vty_out (vty, " aggregate-address %s/%d",
10023 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10024 p->prefixlen);
10025 }
10026
10027 if (bgp_aggregate->as_set)
10028 vty_out (vty, " as-set");
10029
10030 if (bgp_aggregate->summary_only)
10031 vty_out (vty, " summary-only");
10032
10033 vty_out (vty, "%s", VTY_NEWLINE);
10034 }
10035
10036 return 0;
10037}
10038
10039int
10040bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
10041{
10042 struct bgp_node *rn;
10043 struct bgp_distance *bdistance;
10044
10045 /* Distance configuration. */
10046 if (bgp->distance_ebgp
10047 && bgp->distance_ibgp
10048 && bgp->distance_local
10049 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
10050 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
10051 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
10052 vty_out (vty, " distance bgp %d %d %d%s",
10053 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
10054 VTY_NEWLINE);
10055
10056 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10057 if ((bdistance = rn->info) != NULL)
10058 {
10059 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
10060 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
10061 bdistance->access_list ? bdistance->access_list : "",
10062 VTY_NEWLINE);
10063 }
10064
10065 return 0;
10066}
10067
10068/* Allocate routing table structure and install commands. */
10069void
10070bgp_route_init ()
10071{
10072 /* Init BGP distance table. */
10073 bgp_distance_table = bgp_table_init ();
10074
10075 /* IPv4 BGP commands. */
10076 install_element (BGP_NODE, &bgp_network_cmd);
10077 install_element (BGP_NODE, &bgp_network_mask_cmd);
10078 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
10079 install_element (BGP_NODE, &bgp_network_route_map_cmd);
10080 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
10081 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
10082 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
10083 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
10084 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
10085 install_element (BGP_NODE, &no_bgp_network_cmd);
10086 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
10087 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
10088 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
10089 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
10090 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10091 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
10092 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
10093 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
10094
10095 install_element (BGP_NODE, &aggregate_address_cmd);
10096 install_element (BGP_NODE, &aggregate_address_mask_cmd);
10097 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
10098 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
10099 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
10100 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
10101 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
10102 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
10103 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
10104 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
10105 install_element (BGP_NODE, &no_aggregate_address_cmd);
10106 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
10107 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
10108 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
10109 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
10110 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
10111 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
10112 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
10113 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10114 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10115
10116 /* IPv4 unicast configuration. */
10117 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
10118 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
10119 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
10120 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
10121 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
10122 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
10123 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
10124 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
10125 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
10126 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
10127 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
10128 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10129 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
10130 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
10131 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
10132 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
10133 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
10134 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
10135 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
10136 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
10137 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
10138 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
10139 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
10140 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
10141 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
10142 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
10143 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
10144 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
10145 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
10146 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
10147 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10148 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10149
10150 /* IPv4 multicast configuration. */
10151 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
10152 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
10153 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
10154 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
10155 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
10156 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
10157 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
10158 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
10159 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
10160 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
10161 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
10162 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10163 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
10164 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
10165 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
10166 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
10167 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
10168 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
10169 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
10170 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
10171 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
10172 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
10173 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
10174 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
10175 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
10176 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
10177 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
10178 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
10179 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
10180 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
10181 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10182 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10183
10184 install_element (VIEW_NODE, &show_ip_bgp_cmd);
10185 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
10186 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
10187 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
10188 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10189 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10190 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
10191 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10192 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10193 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10194 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
10195 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
10196 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
10197 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
10198 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10199 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
10200 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10201 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
10202 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10203 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
10204 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10205 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
10206 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10207 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
10208 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10209 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
10210 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
10211 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
10212 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
10213 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
10214 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
10215 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
10216 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
10217 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
10218 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
10219 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
10220 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
10221 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10222 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10223 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10224 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10225 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
10226 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10227 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
10228 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10229 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
10230 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10231 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10232 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10233 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10234 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10235 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
10236 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10237 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10238 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10239 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
10240 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
10241 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
10242 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
10243 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10244 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
10245 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
10246 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10247 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10248 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
10249 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
10250 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010251 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
10252 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
10253 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10254 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
10255 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10256 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010257
10258 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
10259 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
10260 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
10261 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
10262 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10263 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10264 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
10265 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10266 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10267 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10268 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
10269 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
10270 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
10271 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
10272 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10273 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
10274 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10275 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
10276 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10277 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
10278 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10279 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
10280 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10281 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
10282 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10283 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
10284 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
10285 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
10286 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
10287 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
10288 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
10289 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
10290 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
10291 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
10292 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
10293 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
10294 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
10295 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10296 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10297 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10298 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10299 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
10300 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10301 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
10302 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10303 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
10304 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10305 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10306 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10307 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10308 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10309 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
10310 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10311 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10312 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10313 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
10314 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
10315 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
10316 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
10317 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10318 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
10319 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
10320 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10321 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10322 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
10323 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
10324 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010325 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
10326 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
10327 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10328 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
10329 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10330 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010331
10332 /* BGP dampening clear commands */
10333 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
10334 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
10335 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
10336 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
10337
10338#ifdef HAVE_IPV6
10339 /* New config IPv6 BGP commands. */
10340 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
10341 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
10342 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
10343 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
10344
10345 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
10346 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
10347 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
10348 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
10349
10350 /* Old config IPv6 BGP commands. */
10351 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
10352 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
10353
10354 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
10355 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
10356 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
10357 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
10358
10359 install_element (VIEW_NODE, &show_bgp_cmd);
10360 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
10361 install_element (VIEW_NODE, &show_bgp_route_cmd);
10362 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
10363 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
10364 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
10365 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
10366 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
10367 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
10368 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
10369 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
10370 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
10371 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
10372 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
10373 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
10374 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
10375 install_element (VIEW_NODE, &show_bgp_community_cmd);
10376 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
10377 install_element (VIEW_NODE, &show_bgp_community2_cmd);
10378 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
10379 install_element (VIEW_NODE, &show_bgp_community3_cmd);
10380 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
10381 install_element (VIEW_NODE, &show_bgp_community4_cmd);
10382 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
10383 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
10384 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
10385 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
10386 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
10387 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
10388 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
10389 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
10390 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
10391 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
10392 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
10393 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
10394 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10395 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
10396 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10397 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
10398 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10399 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
10400 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10401 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
10402 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10403 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10404 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010405 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
10406 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10407 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
10408 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010409 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
10410 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
10411 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010412 install_element (VIEW_NODE, &show_bgp_view_cmd);
10413 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
10414 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
10415 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
10416 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
10417 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
10418 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10419 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10420 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10421 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10422 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
10423 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10424 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10425 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10426 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
10427 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10428 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
10429 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010430 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
10431 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
10432 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010433
10434 install_element (ENABLE_NODE, &show_bgp_cmd);
10435 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
10436 install_element (ENABLE_NODE, &show_bgp_route_cmd);
10437 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
10438 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
10439 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
10440 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
10441 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
10442 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
10443 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
10444 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
10445 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
10446 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
10447 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
10448 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
10449 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
10450 install_element (ENABLE_NODE, &show_bgp_community_cmd);
10451 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
10452 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
10453 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
10454 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
10455 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
10456 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
10457 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
10458 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
10459 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
10460 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
10461 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
10462 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
10463 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
10464 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
10465 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
10466 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
10467 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
10468 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
10469 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10470 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
10471 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10472 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
10473 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10474 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
10475 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10476 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
10477 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10478 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10479 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010480 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
10481 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10482 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
10483 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010484 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
10485 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
10486 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010487 install_element (ENABLE_NODE, &show_bgp_view_cmd);
10488 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
10489 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
10490 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
10491 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
10492 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
10493 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10494 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10495 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10496 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10497 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
10498 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10499 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10500 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10501 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
10502 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10503 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
10504 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010505 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
10506 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
10507 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010508
10509 /* old command */
10510 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
10511 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
10512 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
10513 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
10514 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
10515 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
10516 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
10517 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
10518 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
10519 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
10520 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
10521 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
10522 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
10523 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
10524 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
10525 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
10526 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10527 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10528 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
10529 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
10530 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
10531 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
10532 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10533 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
10534 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
10535 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
10536 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
10537 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
10538 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
10539 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
10540 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10541 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10542 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10543 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
10544 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10545 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000010546
paul718e3742002-12-13 20:15:29 +000010547 /* old command */
10548 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
10549 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
10550 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
10551 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
10552 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
10553 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
10554 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
10555 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
10556 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
10557 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
10558 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
10559 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
10560 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
10561 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
10562 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
10563 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
10564 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10565 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10566 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
10567 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
10568 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
10569 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
10570 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10571 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
10572 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
10573 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
10574 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
10575 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
10576 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
10577 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
10578 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10579 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10580 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10581 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
10582 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10583 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
10584
10585 /* old command */
10586 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10587 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10588 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10589 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10590
10591 /* old command */
10592 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10593 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10594 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10595 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10596
10597 /* old command */
10598 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
10599 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
10600 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10601 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10602#endif /* HAVE_IPV6 */
10603
10604 install_element (BGP_NODE, &bgp_distance_cmd);
10605 install_element (BGP_NODE, &no_bgp_distance_cmd);
10606 install_element (BGP_NODE, &no_bgp_distance2_cmd);
10607 install_element (BGP_NODE, &bgp_distance_source_cmd);
10608 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
10609 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
10610 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
10611
10612 install_element (BGP_NODE, &bgp_damp_set_cmd);
10613 install_element (BGP_NODE, &bgp_damp_set2_cmd);
10614 install_element (BGP_NODE, &bgp_damp_set3_cmd);
10615 install_element (BGP_NODE, &bgp_damp_unset_cmd);
10616 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
10617 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
10618 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
10619 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
10620 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
10621 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
10622}