blob: dbd29cbf52e1aa593ea76e27c2e4ddba9f1219b2 [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
4683/* Calculate line number of output data. */
4684int
4685vty_calc_line (struct vty *vty, unsigned long length)
4686{
4687 return vty->width ? (((vty->obuf->length - length) / vty->width) + 1) : 1;
4688}
4689
4690enum bgp_display_type
4691{
4692 normal_list,
4693};
4694
4695/* called from terminal list command */
4696int
4697route_vty_out (struct vty *vty, struct prefix *p,
4698 struct bgp_info *binfo, int display, safi_t safi)
4699{
4700 struct attr *attr;
4701 unsigned long length = 0;
4702
4703 length = vty->obuf->length;
4704
4705 /* Route status display. */
4706 if (binfo->suppress)
4707 vty_out (vty, "s");
4708 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4709 vty_out (vty, "*");
4710 else
4711 vty_out (vty, " ");
4712
4713 /* Selected */
4714 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4715 vty_out (vty, "h");
4716 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4717 vty_out (vty, "d");
4718 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4719 vty_out (vty, ">");
4720 else
4721 vty_out (vty, " ");
4722
4723 /* Internal route. */
4724 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
4725 vty_out (vty, "i");
4726 else
4727 vty_out (vty, " ");
4728
4729 /* print prefix and mask */
4730 if (! display)
4731 route_vty_out_route (p, vty);
4732 else
4733 vty_out (vty, "%*s", 17, " ");
4734
4735 /* Print attribute */
4736 attr = binfo->attr;
4737 if (attr)
4738 {
4739 if (p->family == AF_INET)
4740 {
4741 if (safi == SAFI_MPLS_VPN)
4742 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
4743 else
4744 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
4745 }
4746#ifdef HAVE_IPV6
4747 else if (p->family == AF_INET6)
4748 {
4749 int len;
4750 char buf[BUFSIZ];
4751
4752 len = vty_out (vty, "%s",
4753 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
4754 len = 16 - len;
4755 if (len < 1)
4756 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
4757 else
4758 vty_out (vty, "%*s", len, " ");
4759 }
4760#endif /* HAVE_IPV6 */
4761
4762 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
4763 vty_out (vty, "%10d", attr->med);
4764 else
4765 vty_out (vty, " ");
4766
4767 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
4768 vty_out (vty, "%7d", attr->local_pref);
4769 else
4770 vty_out (vty, " ");
4771
4772 vty_out (vty, "%7u ",attr->weight);
4773
4774 /* Print aspath */
4775 if (attr->aspath)
4776 aspath_print_vty (vty, attr->aspath);
4777
4778 /* Print origin */
4779 if (strlen (attr->aspath->str) == 0)
4780 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4781 else
4782 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4783 }
4784 vty_out (vty, "%s", VTY_NEWLINE);
4785
4786 return vty_calc_line (vty, length);
4787}
4788
4789/* called from terminal list command */
4790void
4791route_vty_out_tmp (struct vty *vty, struct prefix *p,
4792 struct attr *attr, safi_t safi)
4793{
4794 /* Route status display. */
4795 vty_out (vty, "*");
4796 vty_out (vty, ">");
4797 vty_out (vty, " ");
4798
4799 /* print prefix and mask */
4800 route_vty_out_route (p, vty);
4801
4802 /* Print attribute */
4803 if (attr)
4804 {
4805 if (p->family == AF_INET)
4806 {
4807 if (safi == SAFI_MPLS_VPN)
4808 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
4809 else
4810 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
4811 }
4812#ifdef HAVE_IPV6
4813 else if (p->family == AF_INET6)
4814 {
4815 int len;
4816 char buf[BUFSIZ];
4817
4818 len = vty_out (vty, "%s",
4819 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
4820 len = 16 - len;
4821 if (len < 1)
4822 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
4823 else
4824 vty_out (vty, "%*s", len, " ");
4825 }
4826#endif /* HAVE_IPV6 */
4827
4828 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
4829 vty_out (vty, "%10d", attr->med);
4830 else
4831 vty_out (vty, " ");
4832
4833 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
4834 vty_out (vty, "%7d", attr->local_pref);
4835 else
4836 vty_out (vty, " ");
4837
4838 vty_out (vty, "%7d ",attr->weight);
4839
4840 /* Print aspath */
4841 if (attr->aspath)
4842 aspath_print_vty (vty, attr->aspath);
4843
4844 /* Print origin */
4845 if (strlen (attr->aspath->str) == 0)
4846 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4847 else
4848 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4849 }
4850
4851 vty_out (vty, "%s", VTY_NEWLINE);
4852}
4853
4854int
4855route_vty_out_tag (struct vty *vty, struct prefix *p,
4856 struct bgp_info *binfo, int display, safi_t safi)
4857{
4858 struct attr *attr;
4859 unsigned long length = 0;
4860 u_int32_t label = 0;
4861
4862 length = vty->obuf->length;
4863
4864 /* Route status display. */
4865 if (binfo->suppress)
4866 vty_out (vty, "s");
4867 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4868 vty_out (vty, "*");
4869 else
4870 vty_out (vty, " ");
4871
4872 /* Selected */
4873 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4874 vty_out (vty, "h");
4875 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4876 vty_out (vty, "d");
4877 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4878 vty_out (vty, ">");
4879 else
4880 vty_out (vty, " ");
4881
4882 /* Internal route. */
4883 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
4884 vty_out (vty, "i");
4885 else
4886 vty_out (vty, " ");
4887
4888 /* print prefix and mask */
4889 if (! display)
4890 route_vty_out_route (p, vty);
4891 else
4892 vty_out (vty, "%*s", 17, " ");
4893
4894 /* Print attribute */
4895 attr = binfo->attr;
4896 if (attr)
4897 {
4898 if (p->family == AF_INET)
4899 {
4900 if (safi == SAFI_MPLS_VPN)
4901 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
4902 else
4903 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
4904 }
4905#ifdef HAVE_IPV6
4906 else if (p->family == AF_INET6)
4907 {
4908 char buf[BUFSIZ];
4909 char buf1[BUFSIZ];
4910 if (attr->mp_nexthop_len == 16)
4911 vty_out (vty, "%s",
4912 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
4913 else if (attr->mp_nexthop_len == 32)
4914 vty_out (vty, "%s(%s)",
4915 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
4916 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
4917
4918 }
4919#endif /* HAVE_IPV6 */
4920 }
4921
4922 label = decode_label (binfo->tag);
4923
4924 vty_out (vty, "notag/%d", label);
4925
4926 vty_out (vty, "%s", VTY_NEWLINE);
4927
4928 return vty_calc_line (vty, length);
4929}
4930
4931/* dampening route */
4932int
4933damp_route_vty_out (struct vty *vty, struct prefix *p,
4934 struct bgp_info *binfo, int display, safi_t safi)
4935{
4936 struct attr *attr;
4937 unsigned long length = 0;
4938 int len;
4939
4940 length = vty->obuf->length;
4941
4942 /* Route status display. */
4943 if (binfo->suppress)
4944 vty_out (vty, "s");
4945 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4946 vty_out (vty, "*");
4947 else
4948 vty_out (vty, " ");
4949
4950 /* Selected */
4951 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4952 vty_out (vty, "h");
4953 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4954 vty_out (vty, "d");
4955 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4956 vty_out (vty, ">");
4957 else
4958 vty_out (vty, " ");
4959
4960 vty_out (vty, " ");
4961
4962 /* print prefix and mask */
4963 if (! display)
4964 route_vty_out_route (p, vty);
4965 else
4966 vty_out (vty, "%*s", 17, " ");
4967
4968 len = vty_out (vty, "%s", binfo->peer->host);
4969 len = 17 - len;
4970 if (len < 1)
4971 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
4972 else
4973 vty_out (vty, "%*s", len, " ");
4974
4975 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
4976
4977 /* Print attribute */
4978 attr = binfo->attr;
4979 if (attr)
4980 {
4981 /* Print aspath */
4982 if (attr->aspath)
4983 aspath_print_vty (vty, attr->aspath);
4984
4985 /* Print origin */
4986 if (strlen (attr->aspath->str) == 0)
4987 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4988 else
4989 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4990 }
4991 vty_out (vty, "%s", VTY_NEWLINE);
4992
4993 return vty_calc_line (vty, length);
4994}
4995
4996#define BGP_UPTIME_LEN 25
4997
4998/* flap route */
4999int
5000flap_route_vty_out (struct vty *vty, struct prefix *p,
5001 struct bgp_info *binfo, int display, safi_t safi)
5002{
5003 struct attr *attr;
5004 struct bgp_damp_info *bdi;
5005 unsigned long length = 0;
5006 char timebuf[BGP_UPTIME_LEN];
5007 int len;
5008
5009 length = vty->obuf->length;
5010 bdi = binfo->damp_info;
5011
5012 /* Route status display. */
5013 if (binfo->suppress)
5014 vty_out (vty, "s");
5015 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5016 vty_out (vty, "*");
5017 else
5018 vty_out (vty, " ");
5019
5020 /* Selected */
5021 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5022 vty_out (vty, "h");
5023 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5024 vty_out (vty, "d");
5025 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5026 vty_out (vty, ">");
5027 else
5028 vty_out (vty, " ");
5029
5030 vty_out (vty, " ");
5031
5032 /* print prefix and mask */
5033 if (! display)
5034 route_vty_out_route (p, vty);
5035 else
5036 vty_out (vty, "%*s", 17, " ");
5037
5038 len = vty_out (vty, "%s", binfo->peer->host);
5039 len = 16 - len;
5040 if (len < 1)
5041 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5042 else
5043 vty_out (vty, "%*s", len, " ");
5044
5045 len = vty_out (vty, "%d", bdi->flap);
5046 len = 5 - len;
5047 if (len < 1)
5048 vty_out (vty, " ");
5049 else
5050 vty_out (vty, "%*s ", len, " ");
5051
5052 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5053 timebuf, BGP_UPTIME_LEN));
5054
5055 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5056 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5057 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5058 else
5059 vty_out (vty, "%*s ", 8, " ");
5060
5061 /* Print attribute */
5062 attr = binfo->attr;
5063 if (attr)
5064 {
5065 /* Print aspath */
5066 if (attr->aspath)
5067 aspath_print_vty (vty, attr->aspath);
5068
5069 /* Print origin */
5070 if (strlen (attr->aspath->str) == 0)
5071 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5072 else
5073 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5074 }
5075 vty_out (vty, "%s", VTY_NEWLINE);
5076
5077 return vty_calc_line (vty, length);
5078}
5079
5080void
5081route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5082 struct bgp_info *binfo, afi_t afi, safi_t safi)
5083{
5084 char buf[INET6_ADDRSTRLEN];
5085 char buf1[BUFSIZ];
5086 struct attr *attr;
5087 int sockunion_vty_out (struct vty *, union sockunion *);
5088
5089 attr = binfo->attr;
5090
5091 if (attr)
5092 {
5093 /* Line1 display AS-path, Aggregator */
5094 if (attr->aspath)
5095 {
5096 vty_out (vty, " ");
5097 if (attr->aspath->length == 0)
5098 vty_out (vty, "Local");
5099 else
5100 aspath_print_vty (vty, attr->aspath);
5101 }
5102
5103 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR)
5104 || CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)
5105 || CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
5106 || CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)
5107 || CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5108 {
5109 vty_out (vty, ",");
5110
5111 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR))
5112 vty_out (vty, " (aggregated by %d %s)", attr->aggregator_as,
5113 inet_ntoa (attr->aggregator_addr));
5114 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5115 vty_out (vty, " (Received from a RR-client)");
5116 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5117 vty_out (vty, " (Received from a RS-client)");
5118 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5119 vty_out (vty, " (history entry)");
5120 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5121 vty_out (vty, " (suppressed due to dampening)");
5122 }
5123 vty_out (vty, "%s", VTY_NEWLINE);
5124
5125 /* Line2 display Next-hop, Neighbor, Router-id */
5126 if (p->family == AF_INET)
5127 {
5128 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5129 inet_ntoa (attr->mp_nexthop_global_in) :
5130 inet_ntoa (attr->nexthop));
5131 }
5132#ifdef HAVE_IPV6
5133 else
5134 {
5135 vty_out (vty, " %s",
5136 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5137 buf, INET6_ADDRSTRLEN));
5138 }
5139#endif /* HAVE_IPV6 */
5140
5141 if (binfo->peer == bgp->peer_self)
5142 {
5143 vty_out (vty, " from %s ",
5144 p->family == AF_INET ? "0.0.0.0" : "::");
5145 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5146 }
5147 else
5148 {
5149 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5150 vty_out (vty, " (inaccessible)");
5151 else if (binfo->igpmetric)
5152 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005153 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005154 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5155 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5156 else
5157 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5158 }
5159 vty_out (vty, "%s", VTY_NEWLINE);
5160
5161#ifdef HAVE_IPV6
5162 /* display nexthop local */
5163 if (attr->mp_nexthop_len == 32)
5164 {
5165 vty_out (vty, " (%s)%s",
5166 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5167 buf, INET6_ADDRSTRLEN),
5168 VTY_NEWLINE);
5169 }
5170#endif /* HAVE_IPV6 */
5171
5172 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5173 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5174
5175 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5176 vty_out (vty, ", metric %d", attr->med);
5177
5178 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5179 vty_out (vty, ", localpref %d", attr->local_pref);
5180 else
5181 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5182
5183 if (attr->weight != 0)
5184 vty_out (vty, ", weight %d", attr->weight);
5185
5186 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5187 vty_out (vty, ", valid");
5188
5189 if (binfo->peer != bgp->peer_self)
5190 {
5191 if (binfo->peer->as == binfo->peer->local_as)
5192 vty_out (vty, ", internal");
5193 else
5194 vty_out (vty, ", %s",
5195 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5196 }
5197 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5198 vty_out (vty, ", aggregated, local");
5199 else if (binfo->type != ZEBRA_ROUTE_BGP)
5200 vty_out (vty, ", sourced");
5201 else
5202 vty_out (vty, ", sourced, local");
5203
5204 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5205 vty_out (vty, ", atomic-aggregate");
5206
5207 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5208 vty_out (vty, ", best");
5209
5210 vty_out (vty, "%s", VTY_NEWLINE);
5211
5212 /* Line 4 display Community */
5213 if (attr->community)
5214 vty_out (vty, " Community: %s%s", attr->community->str,
5215 VTY_NEWLINE);
5216
5217 /* Line 5 display Extended-community */
5218 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5219 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5220 VTY_NEWLINE);
5221
5222 /* Line 6 display Originator, Cluster-id */
5223 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5224 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5225 {
5226 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5227 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5228
5229 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5230 {
5231 int i;
5232 vty_out (vty, ", Cluster list: ");
5233 for (i = 0; i < attr->cluster->length / 4; i++)
5234 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5235 }
5236 vty_out (vty, "%s", VTY_NEWLINE);
5237 }
5238
5239 if (binfo->damp_info)
5240 bgp_damp_info_vty (vty, binfo);
5241
5242 /* Line 7 display Uptime */
5243 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5244 }
5245 vty_out (vty, "%s", VTY_NEWLINE);
5246}
5247
5248#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5249#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5250#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5251
5252enum bgp_show_type
5253{
5254 bgp_show_type_normal,
5255 bgp_show_type_regexp,
5256 bgp_show_type_prefix_list,
5257 bgp_show_type_filter_list,
5258 bgp_show_type_route_map,
5259 bgp_show_type_neighbor,
5260 bgp_show_type_cidr_only,
5261 bgp_show_type_prefix_longer,
5262 bgp_show_type_community_all,
5263 bgp_show_type_community,
5264 bgp_show_type_community_exact,
5265 bgp_show_type_community_list,
5266 bgp_show_type_community_list_exact,
5267 bgp_show_type_flap_statistics,
5268 bgp_show_type_flap_address,
5269 bgp_show_type_flap_prefix,
5270 bgp_show_type_flap_cidr_only,
5271 bgp_show_type_flap_regexp,
5272 bgp_show_type_flap_filter_list,
5273 bgp_show_type_flap_prefix_list,
5274 bgp_show_type_flap_prefix_longer,
5275 bgp_show_type_flap_route_map,
5276 bgp_show_type_flap_neighbor,
5277 bgp_show_type_dampend_paths,
5278 bgp_show_type_damp_neighbor
5279};
5280
5281int
5282bgp_show_callback (struct vty *vty, int unlock)
5283{
5284 struct bgp_node *rn;
5285 struct bgp_info *ri;
5286 int count;
5287 int limit;
5288 int display;
5289
paul5228ad22004-06-04 17:58:18 +00005290 rn = (struct bgp_node *) vty->output_rn;
paul718e3742002-12-13 20:15:29 +00005291 count = 0;
5292 limit = ((vty->lines == 0)
5293 ? 10 : (vty->lines > 0
5294 ? vty->lines : vty->height - 2));
5295 limit = limit > 0 ? limit : 2;
5296
5297 /* Quit of display. */
5298 if (unlock && rn)
5299 {
5300 bgp_unlock_node (rn);
5301 if (vty->output_clean)
5302 (*vty->output_clean) (vty);
5303 vty->output_rn = NULL;
5304 vty->output_func = NULL;
5305 vty->output_clean = NULL;
5306 vty->output_arg = NULL;
5307 return 0;
5308 }
5309
5310 for (; rn; rn = bgp_route_next (rn))
5311 if (rn->info != NULL)
5312 {
5313 display = 0;
5314
5315 for (ri = rn->info; ri; ri = ri->next)
5316 {
5317 if (vty->output_type == bgp_show_type_flap_statistics
5318 || vty->output_type == bgp_show_type_flap_address
5319 || vty->output_type == bgp_show_type_flap_prefix
5320 || vty->output_type == bgp_show_type_flap_cidr_only
5321 || vty->output_type == bgp_show_type_flap_regexp
5322 || vty->output_type == bgp_show_type_flap_filter_list
5323 || vty->output_type == bgp_show_type_flap_prefix_list
5324 || vty->output_type == bgp_show_type_flap_prefix_longer
5325 || vty->output_type == bgp_show_type_flap_route_map
5326 || vty->output_type == bgp_show_type_flap_neighbor
5327 || vty->output_type == bgp_show_type_dampend_paths
5328 || vty->output_type == bgp_show_type_damp_neighbor)
5329 {
5330 if (! ri->damp_info)
5331 continue;
5332 }
5333 if (vty->output_type == bgp_show_type_regexp
5334 || vty->output_type == bgp_show_type_flap_regexp)
5335 {
5336 regex_t *regex = vty->output_arg;
5337
5338 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5339 continue;
5340 }
5341 if (vty->output_type == bgp_show_type_prefix_list
5342 || vty->output_type == bgp_show_type_flap_prefix_list)
5343 {
5344 struct prefix_list *plist = vty->output_arg;
5345
5346 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5347 continue;
5348 }
5349 if (vty->output_type == bgp_show_type_filter_list
5350 || vty->output_type == bgp_show_type_flap_filter_list)
5351 {
5352 struct as_list *as_list = vty->output_arg;
5353
5354 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5355 continue;
5356 }
5357 if (vty->output_type == bgp_show_type_route_map
5358 || vty->output_type == bgp_show_type_flap_route_map)
5359 {
5360 struct route_map *rmap = vty->output_arg;
5361 struct bgp_info binfo;
5362 struct attr dummy_attr;
5363 int ret;
5364
5365 dummy_attr = *ri->attr;
5366 binfo.peer = ri->peer;
5367 binfo.attr = &dummy_attr;
5368
5369 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5370
5371 if (ret == RMAP_DENYMATCH)
5372 continue;
5373 }
5374 if (vty->output_type == bgp_show_type_neighbor
5375 || vty->output_type == bgp_show_type_flap_neighbor
5376 || vty->output_type == bgp_show_type_damp_neighbor)
5377 {
5378 union sockunion *su = vty->output_arg;
5379
5380 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5381 continue;
5382 }
5383 if (vty->output_type == bgp_show_type_cidr_only
5384 || vty->output_type == bgp_show_type_flap_cidr_only)
5385 {
5386 u_int32_t destination;
5387
5388 destination = ntohl (rn->p.u.prefix4.s_addr);
5389 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5390 continue;
5391 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5392 continue;
5393 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5394 continue;
5395 }
5396 if (vty->output_type == bgp_show_type_prefix_longer
5397 || vty->output_type == bgp_show_type_flap_prefix_longer)
5398 {
5399 struct prefix *p = vty->output_arg;
5400
5401 if (! prefix_match (p, &rn->p))
5402 continue;
5403 }
5404 if (vty->output_type == bgp_show_type_community_all)
5405 {
5406 if (! ri->attr->community)
5407 continue;
5408 }
5409 if (vty->output_type == bgp_show_type_community)
5410 {
5411 struct community *com = vty->output_arg;
5412
5413 if (! ri->attr->community ||
5414 ! community_match (ri->attr->community, com))
5415 continue;
5416 }
5417 if (vty->output_type == bgp_show_type_community_exact)
5418 {
5419 struct community *com = vty->output_arg;
5420
5421 if (! ri->attr->community ||
5422 ! community_cmp (ri->attr->community, com))
5423 continue;
5424 }
5425 if (vty->output_type == bgp_show_type_community_list)
5426 {
5427 struct community_list *list = vty->output_arg;
5428
5429 if (! community_list_match (ri->attr->community, list))
5430 continue;
5431 }
5432 if (vty->output_type == bgp_show_type_community_list_exact)
5433 {
5434 struct community_list *list = vty->output_arg;
5435
5436 if (! community_list_exact_match (ri->attr->community, list))
5437 continue;
5438 }
5439 if (vty->output_type == bgp_show_type_flap_address
5440 || vty->output_type == bgp_show_type_flap_prefix)
5441 {
5442 struct prefix *p = vty->output_arg;
5443
5444 if (! prefix_match (&rn->p, p))
5445 continue;
5446
5447 if (vty->output_type == bgp_show_type_flap_prefix)
5448 if (p->prefixlen != rn->p.prefixlen)
5449 continue;
5450 }
5451 if (vty->output_type == bgp_show_type_dampend_paths
5452 || vty->output_type == bgp_show_type_damp_neighbor)
5453 {
5454 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5455 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5456 continue;
5457 }
5458
5459 if (vty->output_type == bgp_show_type_dampend_paths
5460 || vty->output_type == bgp_show_type_damp_neighbor)
5461 count += damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
5462 else if (vty->output_type == bgp_show_type_flap_statistics
5463 || vty->output_type == bgp_show_type_flap_address
5464 || vty->output_type == bgp_show_type_flap_prefix
5465 || vty->output_type == bgp_show_type_flap_cidr_only
5466 || vty->output_type == bgp_show_type_flap_regexp
5467 || vty->output_type == bgp_show_type_flap_filter_list
5468 || vty->output_type == bgp_show_type_flap_prefix_list
5469 || vty->output_type == bgp_show_type_flap_prefix_longer
5470 || vty->output_type == bgp_show_type_flap_route_map
5471 || vty->output_type == bgp_show_type_flap_neighbor)
5472 count += flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
5473 else
5474 count += route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
5475 display++;
5476 }
5477
5478 if (display)
5479 vty->output_count++;
5480
5481 /* Remember current pointer then suspend output. */
5482 if (count >= limit)
5483 {
5484 vty->status = VTY_CONTINUE;
paul5228ad22004-06-04 17:58:18 +00005485 vty->output_rn = (struct route_node *) bgp_route_next (rn);;
paul718e3742002-12-13 20:15:29 +00005486 vty->output_func = bgp_show_callback;
5487 return 0;
5488 }
5489 }
5490
5491 /* Total line display. */
5492 if (vty->output_count)
5493 vty_out (vty, "%sTotal number of prefixes %ld%s",
5494 VTY_NEWLINE, vty->output_count, VTY_NEWLINE);
5495
5496 if (vty->output_clean)
5497 (*vty->output_clean) (vty);
5498
5499 vty->status = VTY_CONTINUE;
5500 vty->output_rn = NULL;
5501 vty->output_func = NULL;
5502 vty->output_clean = NULL;
5503 vty->output_arg = NULL;
5504
5505 return 0;
5506}
5507
5508int
paulfee0f4c2004-09-13 05:12:46 +00005509bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
paul718e3742002-12-13 20:15:29 +00005510 enum bgp_show_type type)
5511{
paul718e3742002-12-13 20:15:29 +00005512 struct bgp_info *ri;
5513 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005514 int header = 1;
5515 int count;
5516 int limit;
5517 int display;
5518
5519 limit = ((vty->lines == 0)
5520 ? 10 : (vty->lines > 0
5521 ? vty->lines : vty->height - 2));
5522 limit = limit > 0 ? limit : 2;
5523
paul718e3742002-12-13 20:15:29 +00005524 count = 0;
5525
5526 /* This is first entry point, so reset total line. */
5527 vty->output_count = 0;
5528 vty->output_type = type;
5529
paul718e3742002-12-13 20:15:29 +00005530 /* Start processing of routes. */
5531 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5532 if (rn->info != NULL)
5533 {
5534 display = 0;
5535
5536 for (ri = rn->info; ri; ri = ri->next)
5537 {
5538 if (vty->output_type == bgp_show_type_flap_statistics
5539 || type == bgp_show_type_flap_address
5540 || type == bgp_show_type_flap_prefix
5541 || type == bgp_show_type_flap_cidr_only
5542 || type == bgp_show_type_flap_regexp
5543 || type == bgp_show_type_flap_filter_list
5544 || type == bgp_show_type_flap_prefix_list
5545 || type == bgp_show_type_flap_prefix_longer
5546 || type == bgp_show_type_flap_route_map
5547 || type == bgp_show_type_flap_neighbor
5548 || type == bgp_show_type_dampend_paths
5549 || type == bgp_show_type_damp_neighbor)
5550 {
5551 if (! ri->damp_info)
5552 continue;
5553 }
5554 if (type == bgp_show_type_regexp
5555 || type == bgp_show_type_flap_regexp)
5556 {
5557 regex_t *regex = vty->output_arg;
5558
5559 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5560 continue;
5561 }
5562 if (type == bgp_show_type_prefix_list
5563 || type == bgp_show_type_flap_prefix_list)
5564 {
5565 struct prefix_list *plist = vty->output_arg;
5566
5567 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5568 continue;
5569 }
5570 if (type == bgp_show_type_filter_list
5571 || type == bgp_show_type_flap_filter_list)
5572 {
5573 struct as_list *as_list = vty->output_arg;
5574
5575 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5576 continue;
5577 }
5578 if (type == bgp_show_type_route_map
5579 || type == bgp_show_type_flap_route_map)
5580 {
5581 struct route_map *rmap = vty->output_arg;
5582 struct bgp_info binfo;
5583 struct attr dummy_attr;
5584 int ret;
5585
5586 dummy_attr = *ri->attr;
5587 binfo.peer = ri->peer;
5588 binfo.attr = &dummy_attr;
5589
5590 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5591
5592 if (ret == RMAP_DENYMATCH)
5593 continue;
5594 }
5595 if (type == bgp_show_type_neighbor
5596 || type == bgp_show_type_flap_neighbor
5597 || type == bgp_show_type_damp_neighbor)
5598 {
5599 union sockunion *su = vty->output_arg;
5600
5601 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5602 continue;
5603 }
5604 if (type == bgp_show_type_cidr_only
5605 || type == bgp_show_type_flap_cidr_only)
5606 {
5607 u_int32_t destination;
5608
5609 destination = ntohl (rn->p.u.prefix4.s_addr);
5610 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5611 continue;
5612 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5613 continue;
5614 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5615 continue;
5616 }
5617 if (type == bgp_show_type_prefix_longer
5618 || type == bgp_show_type_flap_prefix_longer)
5619 {
5620 struct prefix *p = vty->output_arg;
5621
5622 if (! prefix_match (p, &rn->p))
5623 continue;
5624 }
5625 if (type == bgp_show_type_community_all)
5626 {
5627 if (! ri->attr->community)
5628 continue;
5629 }
5630 if (type == bgp_show_type_community)
5631 {
5632 struct community *com = vty->output_arg;
5633
5634 if (! ri->attr->community ||
5635 ! community_match (ri->attr->community, com))
5636 continue;
5637 }
5638 if (type == bgp_show_type_community_exact)
5639 {
5640 struct community *com = vty->output_arg;
5641
5642 if (! ri->attr->community ||
5643 ! community_cmp (ri->attr->community, com))
5644 continue;
5645 }
5646 if (type == bgp_show_type_community_list)
5647 {
5648 struct community_list *list = vty->output_arg;
5649
5650 if (! community_list_match (ri->attr->community, list))
5651 continue;
5652 }
5653 if (type == bgp_show_type_community_list_exact)
5654 {
5655 struct community_list *list = vty->output_arg;
5656
5657 if (! community_list_exact_match (ri->attr->community, list))
5658 continue;
5659 }
5660 if (type == bgp_show_type_flap_address
5661 || type == bgp_show_type_flap_prefix)
5662 {
5663 struct prefix *p = vty->output_arg;
5664
5665 if (! prefix_match (&rn->p, p))
5666 continue;
5667
5668 if (type == bgp_show_type_flap_prefix)
5669 if (p->prefixlen != rn->p.prefixlen)
5670 continue;
5671 }
5672 if (type == bgp_show_type_dampend_paths
5673 || type == bgp_show_type_damp_neighbor)
5674 {
5675 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5676 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5677 continue;
5678 }
5679
5680 if (header)
5681 {
paulfee0f4c2004-09-13 05:12:46 +00005682 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 +00005683 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
5684 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
5685 if (type == bgp_show_type_dampend_paths
5686 || type == bgp_show_type_damp_neighbor)
5687 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5688 else if (type == bgp_show_type_flap_statistics
5689 || type == bgp_show_type_flap_address
5690 || type == bgp_show_type_flap_prefix
5691 || type == bgp_show_type_flap_cidr_only
5692 || type == bgp_show_type_flap_regexp
5693 || type == bgp_show_type_flap_filter_list
5694 || type == bgp_show_type_flap_prefix_list
5695 || type == bgp_show_type_flap_prefix_longer
5696 || type == bgp_show_type_flap_route_map
5697 || type == bgp_show_type_flap_neighbor)
5698 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5699 else
5700 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
5701 count += 5;
5702 header = 0;
5703 }
5704
5705 if (type == bgp_show_type_dampend_paths
5706 || type == bgp_show_type_damp_neighbor)
5707 count += damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
5708 else if (type == bgp_show_type_flap_statistics
5709 || type == bgp_show_type_flap_address
5710 || type == bgp_show_type_flap_prefix
5711 || type == bgp_show_type_flap_cidr_only
5712 || type == bgp_show_type_flap_regexp
5713 || type == bgp_show_type_flap_filter_list
5714 || type == bgp_show_type_flap_prefix_list
5715 || type == bgp_show_type_flap_prefix_longer
5716 || type == bgp_show_type_flap_route_map
5717 || type == bgp_show_type_flap_neighbor)
5718 count += flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
5719 else
5720 count += route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
5721 display++;
5722 }
5723 if (display)
5724 vty->output_count++;
5725
5726 /* Remember current pointer then suspend output. */
5727 if (count >= limit && vty->type != VTY_SHELL_SERV)
5728 {
5729 vty->status = VTY_START;
paul5228ad22004-06-04 17:58:18 +00005730 vty->output_rn = (struct route_node *) bgp_route_next (rn);
paul718e3742002-12-13 20:15:29 +00005731 vty->output_func = bgp_show_callback;
5732 vty->output_type = type;
5733
5734 return CMD_SUCCESS;
5735 }
5736 }
5737
5738 /* No route is displayed */
5739 if (vty->output_count == 0)
5740 {
5741 if (type == bgp_show_type_normal)
5742 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5743 }
5744 else
5745 vty_out (vty, "%sTotal number of prefixes %ld%s",
5746 VTY_NEWLINE, vty->output_count, VTY_NEWLINE);
5747
5748 /* Clean up allocated resources. */
5749 if (vty->output_clean)
5750 (*vty->output_clean) (vty);
5751
5752 vty->status = VTY_START;
5753 vty->output_rn = NULL;
5754 vty->output_func = NULL;
5755 vty->output_clean = NULL;
5756 vty->output_arg = NULL;
5757
5758 return CMD_SUCCESS;
5759}
5760
paulfee0f4c2004-09-13 05:12:46 +00005761int
5762bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
5763 enum bgp_show_type type)
5764{
5765 struct bgp_table *table;
5766
5767 if (bgp == NULL) {
5768 bgp = bgp_get_default ();
5769 }
5770
5771 if (bgp == NULL)
5772 {
5773 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5774 return CMD_WARNING;
5775 }
5776
5777
5778 table = bgp->rib[afi][safi];
5779
5780 return bgp_show_table (vty, table, &bgp->router_id, type);
5781}
5782
paul718e3742002-12-13 20:15:29 +00005783/* Header of detailed BGP route information */
5784void
5785route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5786 struct bgp_node *rn,
5787 struct prefix_rd *prd, afi_t afi, safi_t safi)
5788{
5789 struct bgp_info *ri;
5790 struct prefix *p;
5791 struct peer *peer;
5792 struct listnode *nn;
5793 char buf1[INET6_ADDRSTRLEN];
5794 char buf2[INET6_ADDRSTRLEN];
5795 int count = 0;
5796 int best = 0;
5797 int suppress = 0;
5798 int no_export = 0;
5799 int no_advertise = 0;
5800 int local_as = 0;
5801 int first = 0;
5802
5803 p = &rn->p;
5804 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5805 (safi == SAFI_MPLS_VPN ?
5806 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5807 safi == SAFI_MPLS_VPN ? ":" : "",
5808 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5809 p->prefixlen, VTY_NEWLINE);
5810
5811 for (ri = rn->info; ri; ri = ri->next)
5812 {
5813 count++;
5814 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5815 {
5816 best = count;
5817 if (ri->suppress)
5818 suppress = 1;
5819 if (ri->attr->community != NULL)
5820 {
5821 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5822 no_advertise = 1;
5823 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5824 no_export = 1;
5825 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5826 local_as = 1;
5827 }
5828 }
5829 }
5830
5831 vty_out (vty, "Paths: (%d available", count);
5832 if (best)
5833 {
5834 vty_out (vty, ", best #%d", best);
5835 if (safi == SAFI_UNICAST)
5836 vty_out (vty, ", table Default-IP-Routing-Table");
5837 }
5838 else
5839 vty_out (vty, ", no best path");
5840 if (no_advertise)
5841 vty_out (vty, ", not advertised to any peer");
5842 else if (no_export)
5843 vty_out (vty, ", not advertised to EBGP peer");
5844 else if (local_as)
5845 vty_out (vty, ", not advertised outside local AS");
5846 if (suppress)
5847 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5848 vty_out (vty, ")%s", VTY_NEWLINE);
5849
5850 /* advertised peer */
5851 LIST_LOOP (bgp->peer, peer, nn)
5852 {
5853 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5854 {
5855 if (! first)
5856 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5857 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5858 first = 1;
5859 }
5860 }
5861 if (! first)
5862 vty_out (vty, " Not advertised to any peer");
5863 vty_out (vty, "%s", VTY_NEWLINE);
5864}
5865
5866/* Display specified route of BGP table. */
5867int
paulfee0f4c2004-09-13 05:12:46 +00005868bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00005869 struct bgp_table *rib, const char *ip_str,
5870 afi_t afi, safi_t safi, struct prefix_rd *prd,
5871 int prefix_check)
paul718e3742002-12-13 20:15:29 +00005872{
5873 int ret;
5874 int header;
5875 int display = 0;
5876 struct prefix match;
5877 struct bgp_node *rn;
5878 struct bgp_node *rm;
5879 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00005880 struct bgp_table *table;
5881
paul718e3742002-12-13 20:15:29 +00005882 /* Check IP address argument. */
5883 ret = str2prefix (ip_str, &match);
5884 if (! ret)
5885 {
5886 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5887 return CMD_WARNING;
5888 }
5889
5890 match.family = afi2family (afi);
5891
5892 if (safi == SAFI_MPLS_VPN)
5893 {
paulfee0f4c2004-09-13 05:12:46 +00005894 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00005895 {
5896 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5897 continue;
5898
5899 if ((table = rn->info) != NULL)
5900 {
5901 header = 1;
5902
5903 if ((rm = bgp_node_match (table, &match)) != NULL)
5904 {
5905 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5906 continue;
5907
5908 for (ri = rm->info; ri; ri = ri->next)
5909 {
5910 if (header)
5911 {
5912 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5913 AFI_IP, SAFI_MPLS_VPN);
5914
5915 header = 0;
5916 }
5917 display++;
5918 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5919 }
5920 }
5921 }
5922 }
5923 }
5924 else
5925 {
5926 header = 1;
5927
paulfee0f4c2004-09-13 05:12:46 +00005928 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00005929 {
5930 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5931 {
5932 for (ri = rn->info; ri; ri = ri->next)
5933 {
5934 if (header)
5935 {
5936 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
5937 header = 0;
5938 }
5939 display++;
5940 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
5941 }
5942 }
5943 }
5944 }
5945
5946 if (! display)
5947 {
5948 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5949 return CMD_WARNING;
5950 }
5951
5952 return CMD_SUCCESS;
5953}
5954
paulfee0f4c2004-09-13 05:12:46 +00005955/* Display specified route of Main RIB */
5956int
paulfd79ac92004-10-13 05:06:08 +00005957bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00005958 afi_t afi, safi_t safi, struct prefix_rd *prd,
5959 int prefix_check)
5960{
5961 struct bgp *bgp;
5962
5963 /* BGP structure lookup. */
5964 if (view_name)
5965 {
5966 bgp = bgp_lookup_by_name (view_name);
5967 if (bgp == NULL)
5968 {
5969 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
5970 return CMD_WARNING;
5971 }
5972 }
5973 else
5974 {
5975 bgp = bgp_get_default ();
5976 if (bgp == NULL)
5977 {
5978 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5979 return CMD_WARNING;
5980 }
5981 }
5982
5983 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
5984 afi, safi, prd, prefix_check);
5985}
5986
paul718e3742002-12-13 20:15:29 +00005987/* BGP route print out function. */
5988DEFUN (show_ip_bgp,
5989 show_ip_bgp_cmd,
5990 "show ip bgp",
5991 SHOW_STR
5992 IP_STR
5993 BGP_STR)
5994{
5995 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal);
5996}
5997
5998DEFUN (show_ip_bgp_ipv4,
5999 show_ip_bgp_ipv4_cmd,
6000 "show ip bgp ipv4 (unicast|multicast)",
6001 SHOW_STR
6002 IP_STR
6003 BGP_STR
6004 "Address family\n"
6005 "Address Family modifier\n"
6006 "Address Family modifier\n")
6007{
6008 if (strncmp (argv[0], "m", 1) == 0)
6009 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal);
6010
6011 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal);
6012}
6013
6014DEFUN (show_ip_bgp_route,
6015 show_ip_bgp_route_cmd,
6016 "show ip bgp A.B.C.D",
6017 SHOW_STR
6018 IP_STR
6019 BGP_STR
6020 "Network in the BGP routing table to display\n")
6021{
6022 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6023}
6024
6025DEFUN (show_ip_bgp_ipv4_route,
6026 show_ip_bgp_ipv4_route_cmd,
6027 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6028 SHOW_STR
6029 IP_STR
6030 BGP_STR
6031 "Address family\n"
6032 "Address Family modifier\n"
6033 "Address Family modifier\n"
6034 "Network in the BGP routing table to display\n")
6035{
6036 if (strncmp (argv[0], "m", 1) == 0)
6037 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6038
6039 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6040}
6041
6042DEFUN (show_ip_bgp_vpnv4_all_route,
6043 show_ip_bgp_vpnv4_all_route_cmd,
6044 "show ip bgp vpnv4 all A.B.C.D",
6045 SHOW_STR
6046 IP_STR
6047 BGP_STR
6048 "Display VPNv4 NLRI specific information\n"
6049 "Display information about all VPNv4 NLRIs\n"
6050 "Network in the BGP routing table to display\n")
6051{
6052 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6053}
6054
6055DEFUN (show_ip_bgp_vpnv4_rd_route,
6056 show_ip_bgp_vpnv4_rd_route_cmd,
6057 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6058 SHOW_STR
6059 IP_STR
6060 BGP_STR
6061 "Display VPNv4 NLRI specific information\n"
6062 "Display information for a route distinguisher\n"
6063 "VPN Route Distinguisher\n"
6064 "Network in the BGP routing table to display\n")
6065{
6066 int ret;
6067 struct prefix_rd prd;
6068
6069 ret = str2prefix_rd (argv[0], &prd);
6070 if (! ret)
6071 {
6072 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6073 return CMD_WARNING;
6074 }
6075 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6076}
6077
6078DEFUN (show_ip_bgp_prefix,
6079 show_ip_bgp_prefix_cmd,
6080 "show ip bgp A.B.C.D/M",
6081 SHOW_STR
6082 IP_STR
6083 BGP_STR
6084 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6085{
6086 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6087}
6088
6089DEFUN (show_ip_bgp_ipv4_prefix,
6090 show_ip_bgp_ipv4_prefix_cmd,
6091 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6092 SHOW_STR
6093 IP_STR
6094 BGP_STR
6095 "Address family\n"
6096 "Address Family modifier\n"
6097 "Address Family modifier\n"
6098 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6099{
6100 if (strncmp (argv[0], "m", 1) == 0)
6101 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6102
6103 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6104}
6105
6106DEFUN (show_ip_bgp_vpnv4_all_prefix,
6107 show_ip_bgp_vpnv4_all_prefix_cmd,
6108 "show ip bgp vpnv4 all A.B.C.D/M",
6109 SHOW_STR
6110 IP_STR
6111 BGP_STR
6112 "Display VPNv4 NLRI specific information\n"
6113 "Display information about all VPNv4 NLRIs\n"
6114 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6115{
6116 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6117}
6118
6119DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6120 show_ip_bgp_vpnv4_rd_prefix_cmd,
6121 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6122 SHOW_STR
6123 IP_STR
6124 BGP_STR
6125 "Display VPNv4 NLRI specific information\n"
6126 "Display information for a route distinguisher\n"
6127 "VPN Route Distinguisher\n"
6128 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6129{
6130 int ret;
6131 struct prefix_rd prd;
6132
6133 ret = str2prefix_rd (argv[0], &prd);
6134 if (! ret)
6135 {
6136 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6137 return CMD_WARNING;
6138 }
6139 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6140}
6141
6142DEFUN (show_ip_bgp_view,
6143 show_ip_bgp_view_cmd,
6144 "show ip bgp view WORD",
6145 SHOW_STR
6146 IP_STR
6147 BGP_STR
6148 "BGP view\n"
6149 "BGP view name\n")
6150{
paulbb46e942003-10-24 19:02:03 +00006151 struct bgp *bgp;
6152
6153 /* BGP structure lookup. */
6154 bgp = bgp_lookup_by_name (argv[0]);
6155 if (bgp == NULL)
6156 {
6157 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6158 return CMD_WARNING;
6159 }
6160
6161 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal);
paul718e3742002-12-13 20:15:29 +00006162}
6163
6164DEFUN (show_ip_bgp_view_route,
6165 show_ip_bgp_view_route_cmd,
6166 "show ip bgp view WORD A.B.C.D",
6167 SHOW_STR
6168 IP_STR
6169 BGP_STR
6170 "BGP view\n"
6171 "BGP view name\n"
6172 "Network in the BGP routing table to display\n")
6173{
6174 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6175}
6176
6177DEFUN (show_ip_bgp_view_prefix,
6178 show_ip_bgp_view_prefix_cmd,
6179 "show ip bgp view WORD A.B.C.D/M",
6180 SHOW_STR
6181 IP_STR
6182 BGP_STR
6183 "BGP view\n"
6184 "BGP view name\n"
6185 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6186{
6187 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6188}
6189
6190#ifdef HAVE_IPV6
6191DEFUN (show_bgp,
6192 show_bgp_cmd,
6193 "show bgp",
6194 SHOW_STR
6195 BGP_STR)
6196{
6197 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal);
6198}
6199
6200ALIAS (show_bgp,
6201 show_bgp_ipv6_cmd,
6202 "show bgp ipv6",
6203 SHOW_STR
6204 BGP_STR
6205 "Address family\n")
6206
6207/* old command */
6208DEFUN (show_ipv6_bgp,
6209 show_ipv6_bgp_cmd,
6210 "show ipv6 bgp",
6211 SHOW_STR
6212 IP_STR
6213 BGP_STR)
6214{
6215 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal);
6216}
6217
6218DEFUN (show_bgp_route,
6219 show_bgp_route_cmd,
6220 "show bgp X:X::X:X",
6221 SHOW_STR
6222 BGP_STR
6223 "Network in the BGP routing table to display\n")
6224{
6225 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6226}
6227
6228ALIAS (show_bgp_route,
6229 show_bgp_ipv6_route_cmd,
6230 "show bgp ipv6 X:X::X:X",
6231 SHOW_STR
6232 BGP_STR
6233 "Address family\n"
6234 "Network in the BGP routing table to display\n")
6235
6236/* old command */
6237DEFUN (show_ipv6_bgp_route,
6238 show_ipv6_bgp_route_cmd,
6239 "show ipv6 bgp X:X::X:X",
6240 SHOW_STR
6241 IP_STR
6242 BGP_STR
6243 "Network in the BGP routing table to display\n")
6244{
6245 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6246}
6247
6248DEFUN (show_bgp_prefix,
6249 show_bgp_prefix_cmd,
6250 "show bgp X:X::X:X/M",
6251 SHOW_STR
6252 BGP_STR
6253 "IPv6 prefix <network>/<length>\n")
6254{
6255 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6256}
6257
6258ALIAS (show_bgp_prefix,
6259 show_bgp_ipv6_prefix_cmd,
6260 "show bgp ipv6 X:X::X:X/M",
6261 SHOW_STR
6262 BGP_STR
6263 "Address family\n"
6264 "IPv6 prefix <network>/<length>\n")
6265
6266/* old command */
6267DEFUN (show_ipv6_bgp_prefix,
6268 show_ipv6_bgp_prefix_cmd,
6269 "show ipv6 bgp X:X::X:X/M",
6270 SHOW_STR
6271 IP_STR
6272 BGP_STR
6273 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6274{
6275 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6276}
6277
paulbb46e942003-10-24 19:02:03 +00006278DEFUN (show_bgp_view,
6279 show_bgp_view_cmd,
6280 "show bgp view WORD",
6281 SHOW_STR
6282 BGP_STR
6283 "BGP view\n"
6284 "View name\n")
6285{
6286 struct bgp *bgp;
6287
6288 /* BGP structure lookup. */
6289 bgp = bgp_lookup_by_name (argv[0]);
6290 if (bgp == NULL)
6291 {
6292 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6293 return CMD_WARNING;
6294 }
6295
6296 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal);
6297}
6298
6299ALIAS (show_bgp_view,
6300 show_bgp_view_ipv6_cmd,
6301 "show bgp view WORD ipv6",
6302 SHOW_STR
6303 BGP_STR
6304 "BGP view\n"
6305 "View name\n"
6306 "Address family\n")
6307
6308DEFUN (show_bgp_view_route,
6309 show_bgp_view_route_cmd,
6310 "show bgp view WORD X:X::X:X",
6311 SHOW_STR
6312 BGP_STR
6313 "BGP view\n"
6314 "View name\n"
6315 "Network in the BGP routing table to display\n")
6316{
6317 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6318}
6319
6320ALIAS (show_bgp_view_route,
6321 show_bgp_view_ipv6_route_cmd,
6322 "show bgp view WORD ipv6 X:X::X:X",
6323 SHOW_STR
6324 BGP_STR
6325 "BGP view\n"
6326 "View name\n"
6327 "Address family\n"
6328 "Network in the BGP routing table to display\n")
6329
6330DEFUN (show_bgp_view_prefix,
6331 show_bgp_view_prefix_cmd,
6332 "show bgp view WORD X:X::X:X/M",
6333 SHOW_STR
6334 BGP_STR
6335 "BGP view\n"
6336 "View name\n"
6337 "IPv6 prefix <network>/<length>\n")
6338{
6339 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6340}
6341
6342ALIAS (show_bgp_view_prefix,
6343 show_bgp_view_ipv6_prefix_cmd,
6344 "show bgp view WORD ipv6 X:X::X:X/M",
6345 SHOW_STR
6346 BGP_STR
6347 "BGP view\n"
6348 "View name\n"
6349 "Address family\n"
6350 "IPv6 prefix <network>/<length>\n")
6351
paul718e3742002-12-13 20:15:29 +00006352/* old command */
6353DEFUN (show_ipv6_mbgp,
6354 show_ipv6_mbgp_cmd,
6355 "show ipv6 mbgp",
6356 SHOW_STR
6357 IP_STR
6358 MBGP_STR)
6359{
6360 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal);
6361}
6362
6363/* old command */
6364DEFUN (show_ipv6_mbgp_route,
6365 show_ipv6_mbgp_route_cmd,
6366 "show ipv6 mbgp X:X::X:X",
6367 SHOW_STR
6368 IP_STR
6369 MBGP_STR
6370 "Network in the MBGP routing table to display\n")
6371{
6372 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6373}
6374
6375/* old command */
6376DEFUN (show_ipv6_mbgp_prefix,
6377 show_ipv6_mbgp_prefix_cmd,
6378 "show ipv6 mbgp X:X::X:X/M",
6379 SHOW_STR
6380 IP_STR
6381 MBGP_STR
6382 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6383{
6384 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6385}
6386#endif
6387
6388void
6389bgp_show_regexp_clean (struct vty *vty)
6390{
6391 bgp_regex_free (vty->output_arg);
6392}
6393
6394int
paulfd79ac92004-10-13 05:06:08 +00006395bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006396 safi_t safi, enum bgp_show_type type)
6397{
6398 int i;
6399 struct buffer *b;
6400 char *regstr;
6401 int first;
6402 regex_t *regex;
6403
6404 first = 0;
6405 b = buffer_new (1024);
6406 for (i = 0; i < argc; i++)
6407 {
6408 if (first)
6409 buffer_putc (b, ' ');
6410 else
6411 {
6412 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6413 continue;
6414 first = 1;
6415 }
6416
6417 buffer_putstr (b, argv[i]);
6418 }
6419 buffer_putc (b, '\0');
6420
6421 regstr = buffer_getstr (b);
6422 buffer_free (b);
6423
6424 regex = bgp_regcomp (regstr);
6425 if (! regex)
6426 {
6427 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6428 VTY_NEWLINE);
6429 return CMD_WARNING;
6430 }
6431
6432 vty->output_arg = regex;
6433 vty->output_clean = bgp_show_regexp_clean;
6434
6435 return bgp_show (vty, NULL, afi, safi, type);
6436}
6437
6438DEFUN (show_ip_bgp_regexp,
6439 show_ip_bgp_regexp_cmd,
6440 "show ip bgp regexp .LINE",
6441 SHOW_STR
6442 IP_STR
6443 BGP_STR
6444 "Display routes matching the AS path regular expression\n"
6445 "A regular-expression to match the BGP AS paths\n")
6446{
6447 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6448 bgp_show_type_regexp);
6449}
6450
6451DEFUN (show_ip_bgp_flap_regexp,
6452 show_ip_bgp_flap_regexp_cmd,
6453 "show ip bgp flap-statistics regexp .LINE",
6454 SHOW_STR
6455 IP_STR
6456 BGP_STR
6457 "Display flap statistics of routes\n"
6458 "Display routes matching the AS path regular expression\n"
6459 "A regular-expression to match the BGP AS paths\n")
6460{
6461 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6462 bgp_show_type_flap_regexp);
6463}
6464
6465DEFUN (show_ip_bgp_ipv4_regexp,
6466 show_ip_bgp_ipv4_regexp_cmd,
6467 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6468 SHOW_STR
6469 IP_STR
6470 BGP_STR
6471 "Address family\n"
6472 "Address Family modifier\n"
6473 "Address Family modifier\n"
6474 "Display routes matching the AS path regular expression\n"
6475 "A regular-expression to match the BGP AS paths\n")
6476{
6477 if (strncmp (argv[0], "m", 1) == 0)
6478 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6479 bgp_show_type_regexp);
6480
6481 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6482 bgp_show_type_regexp);
6483}
6484
6485#ifdef HAVE_IPV6
6486DEFUN (show_bgp_regexp,
6487 show_bgp_regexp_cmd,
6488 "show bgp regexp .LINE",
6489 SHOW_STR
6490 BGP_STR
6491 "Display routes matching the AS path regular expression\n"
6492 "A regular-expression to match the BGP AS paths\n")
6493{
6494 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6495 bgp_show_type_regexp);
6496}
6497
6498ALIAS (show_bgp_regexp,
6499 show_bgp_ipv6_regexp_cmd,
6500 "show bgp ipv6 regexp .LINE",
6501 SHOW_STR
6502 BGP_STR
6503 "Address family\n"
6504 "Display routes matching the AS path regular expression\n"
6505 "A regular-expression to match the BGP AS paths\n")
6506
6507/* old command */
6508DEFUN (show_ipv6_bgp_regexp,
6509 show_ipv6_bgp_regexp_cmd,
6510 "show ipv6 bgp regexp .LINE",
6511 SHOW_STR
6512 IP_STR
6513 BGP_STR
6514 "Display routes matching the AS path regular expression\n"
6515 "A regular-expression to match the BGP AS paths\n")
6516{
6517 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6518 bgp_show_type_regexp);
6519}
6520
6521/* old command */
6522DEFUN (show_ipv6_mbgp_regexp,
6523 show_ipv6_mbgp_regexp_cmd,
6524 "show ipv6 mbgp regexp .LINE",
6525 SHOW_STR
6526 IP_STR
6527 BGP_STR
6528 "Display routes matching the AS path regular expression\n"
6529 "A regular-expression to match the MBGP AS paths\n")
6530{
6531 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6532 bgp_show_type_regexp);
6533}
6534#endif /* HAVE_IPV6 */
6535
6536int
paulfd79ac92004-10-13 05:06:08 +00006537bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006538 safi_t safi, enum bgp_show_type type)
6539{
6540 struct prefix_list *plist;
6541
6542 plist = prefix_list_lookup (afi, prefix_list_str);
6543 if (plist == NULL)
6544 {
6545 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6546 prefix_list_str, VTY_NEWLINE);
6547 return CMD_WARNING;
6548 }
6549
6550 vty->output_arg = plist;
6551
6552 return bgp_show (vty, NULL, afi, safi, type);
6553}
6554
6555DEFUN (show_ip_bgp_prefix_list,
6556 show_ip_bgp_prefix_list_cmd,
6557 "show ip bgp prefix-list WORD",
6558 SHOW_STR
6559 IP_STR
6560 BGP_STR
6561 "Display routes conforming to the prefix-list\n"
6562 "IP prefix-list name\n")
6563{
6564 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6565 bgp_show_type_prefix_list);
6566}
6567
6568DEFUN (show_ip_bgp_flap_prefix_list,
6569 show_ip_bgp_flap_prefix_list_cmd,
6570 "show ip bgp flap-statistics prefix-list WORD",
6571 SHOW_STR
6572 IP_STR
6573 BGP_STR
6574 "Display flap statistics of routes\n"
6575 "Display routes conforming to the prefix-list\n"
6576 "IP prefix-list name\n")
6577{
6578 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6579 bgp_show_type_flap_prefix_list);
6580}
6581
6582DEFUN (show_ip_bgp_ipv4_prefix_list,
6583 show_ip_bgp_ipv4_prefix_list_cmd,
6584 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6585 SHOW_STR
6586 IP_STR
6587 BGP_STR
6588 "Address family\n"
6589 "Address Family modifier\n"
6590 "Address Family modifier\n"
6591 "Display routes conforming to the prefix-list\n"
6592 "IP prefix-list name\n")
6593{
6594 if (strncmp (argv[0], "m", 1) == 0)
6595 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6596 bgp_show_type_prefix_list);
6597
6598 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6599 bgp_show_type_prefix_list);
6600}
6601
6602#ifdef HAVE_IPV6
6603DEFUN (show_bgp_prefix_list,
6604 show_bgp_prefix_list_cmd,
6605 "show bgp prefix-list WORD",
6606 SHOW_STR
6607 BGP_STR
6608 "Display routes conforming to the prefix-list\n"
6609 "IPv6 prefix-list name\n")
6610{
6611 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6612 bgp_show_type_prefix_list);
6613}
6614
6615ALIAS (show_bgp_prefix_list,
6616 show_bgp_ipv6_prefix_list_cmd,
6617 "show bgp ipv6 prefix-list WORD",
6618 SHOW_STR
6619 BGP_STR
6620 "Address family\n"
6621 "Display routes conforming to the prefix-list\n"
6622 "IPv6 prefix-list name\n")
6623
6624/* old command */
6625DEFUN (show_ipv6_bgp_prefix_list,
6626 show_ipv6_bgp_prefix_list_cmd,
6627 "show ipv6 bgp prefix-list WORD",
6628 SHOW_STR
6629 IPV6_STR
6630 BGP_STR
6631 "Display routes matching the prefix-list\n"
6632 "IPv6 prefix-list name\n")
6633{
6634 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6635 bgp_show_type_prefix_list);
6636}
6637
6638/* old command */
6639DEFUN (show_ipv6_mbgp_prefix_list,
6640 show_ipv6_mbgp_prefix_list_cmd,
6641 "show ipv6 mbgp prefix-list WORD",
6642 SHOW_STR
6643 IPV6_STR
6644 MBGP_STR
6645 "Display routes matching the prefix-list\n"
6646 "IPv6 prefix-list name\n")
6647{
6648 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6649 bgp_show_type_prefix_list);
6650}
6651#endif /* HAVE_IPV6 */
6652
6653int
paulfd79ac92004-10-13 05:06:08 +00006654bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006655 safi_t safi, enum bgp_show_type type)
6656{
6657 struct as_list *as_list;
6658
6659 as_list = as_list_lookup (filter);
6660 if (as_list == NULL)
6661 {
6662 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6663 return CMD_WARNING;
6664 }
6665
6666 vty->output_arg = as_list;
6667
6668 return bgp_show (vty, NULL, afi, safi, type);
6669}
6670
6671DEFUN (show_ip_bgp_filter_list,
6672 show_ip_bgp_filter_list_cmd,
6673 "show ip bgp filter-list WORD",
6674 SHOW_STR
6675 IP_STR
6676 BGP_STR
6677 "Display routes conforming to the filter-list\n"
6678 "Regular expression access list name\n")
6679{
6680 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6681 bgp_show_type_filter_list);
6682}
6683
6684DEFUN (show_ip_bgp_flap_filter_list,
6685 show_ip_bgp_flap_filter_list_cmd,
6686 "show ip bgp flap-statistics filter-list WORD",
6687 SHOW_STR
6688 IP_STR
6689 BGP_STR
6690 "Display flap statistics of routes\n"
6691 "Display routes conforming to the filter-list\n"
6692 "Regular expression access list name\n")
6693{
6694 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6695 bgp_show_type_flap_filter_list);
6696}
6697
6698DEFUN (show_ip_bgp_ipv4_filter_list,
6699 show_ip_bgp_ipv4_filter_list_cmd,
6700 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6701 SHOW_STR
6702 IP_STR
6703 BGP_STR
6704 "Address family\n"
6705 "Address Family modifier\n"
6706 "Address Family modifier\n"
6707 "Display routes conforming to the filter-list\n"
6708 "Regular expression access list name\n")
6709{
6710 if (strncmp (argv[0], "m", 1) == 0)
6711 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6712 bgp_show_type_filter_list);
6713
6714 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6715 bgp_show_type_filter_list);
6716}
6717
6718#ifdef HAVE_IPV6
6719DEFUN (show_bgp_filter_list,
6720 show_bgp_filter_list_cmd,
6721 "show bgp filter-list WORD",
6722 SHOW_STR
6723 BGP_STR
6724 "Display routes conforming to the filter-list\n"
6725 "Regular expression access list name\n")
6726{
6727 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6728 bgp_show_type_filter_list);
6729}
6730
6731ALIAS (show_bgp_filter_list,
6732 show_bgp_ipv6_filter_list_cmd,
6733 "show bgp ipv6 filter-list WORD",
6734 SHOW_STR
6735 BGP_STR
6736 "Address family\n"
6737 "Display routes conforming to the filter-list\n"
6738 "Regular expression access list name\n")
6739
6740/* old command */
6741DEFUN (show_ipv6_bgp_filter_list,
6742 show_ipv6_bgp_filter_list_cmd,
6743 "show ipv6 bgp filter-list WORD",
6744 SHOW_STR
6745 IPV6_STR
6746 BGP_STR
6747 "Display routes conforming to the filter-list\n"
6748 "Regular expression access list name\n")
6749{
6750 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6751 bgp_show_type_filter_list);
6752}
6753
6754/* old command */
6755DEFUN (show_ipv6_mbgp_filter_list,
6756 show_ipv6_mbgp_filter_list_cmd,
6757 "show ipv6 mbgp filter-list WORD",
6758 SHOW_STR
6759 IPV6_STR
6760 MBGP_STR
6761 "Display routes conforming to the filter-list\n"
6762 "Regular expression access list name\n")
6763{
6764 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6765 bgp_show_type_filter_list);
6766}
6767#endif /* HAVE_IPV6 */
6768
6769int
paulfd79ac92004-10-13 05:06:08 +00006770bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006771 safi_t safi, enum bgp_show_type type)
6772{
6773 struct route_map *rmap;
6774
6775 rmap = route_map_lookup_by_name (rmap_str);
6776 if (! rmap)
6777 {
6778 vty_out (vty, "%% %s is not a valid route-map name%s",
6779 rmap_str, VTY_NEWLINE);
6780 return CMD_WARNING;
6781 }
6782
6783 vty->output_arg = rmap;
6784
6785 return bgp_show (vty, NULL, afi, safi, type);
6786}
6787
6788DEFUN (show_ip_bgp_route_map,
6789 show_ip_bgp_route_map_cmd,
6790 "show ip bgp route-map WORD",
6791 SHOW_STR
6792 IP_STR
6793 BGP_STR
6794 "Display routes matching the route-map\n"
6795 "A route-map to match on\n")
6796{
6797 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6798 bgp_show_type_route_map);
6799}
6800
6801DEFUN (show_ip_bgp_flap_route_map,
6802 show_ip_bgp_flap_route_map_cmd,
6803 "show ip bgp flap-statistics route-map WORD",
6804 SHOW_STR
6805 IP_STR
6806 BGP_STR
6807 "Display flap statistics of routes\n"
6808 "Display routes matching the route-map\n"
6809 "A route-map to match on\n")
6810{
6811 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6812 bgp_show_type_flap_route_map);
6813}
6814
6815DEFUN (show_ip_bgp_ipv4_route_map,
6816 show_ip_bgp_ipv4_route_map_cmd,
6817 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6818 SHOW_STR
6819 IP_STR
6820 BGP_STR
6821 "Address family\n"
6822 "Address Family modifier\n"
6823 "Address Family modifier\n"
6824 "Display routes matching the route-map\n"
6825 "A route-map to match on\n")
6826{
6827 if (strncmp (argv[0], "m", 1) == 0)
6828 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6829 bgp_show_type_route_map);
6830
6831 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6832 bgp_show_type_route_map);
6833}
6834
6835DEFUN (show_bgp_route_map,
6836 show_bgp_route_map_cmd,
6837 "show bgp route-map WORD",
6838 SHOW_STR
6839 BGP_STR
6840 "Display routes matching the route-map\n"
6841 "A route-map to match on\n")
6842{
6843 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6844 bgp_show_type_route_map);
6845}
6846
6847ALIAS (show_bgp_route_map,
6848 show_bgp_ipv6_route_map_cmd,
6849 "show bgp ipv6 route-map WORD",
6850 SHOW_STR
6851 BGP_STR
6852 "Address family\n"
6853 "Display routes matching the route-map\n"
6854 "A route-map to match on\n")
6855
6856DEFUN (show_ip_bgp_cidr_only,
6857 show_ip_bgp_cidr_only_cmd,
6858 "show ip bgp cidr-only",
6859 SHOW_STR
6860 IP_STR
6861 BGP_STR
6862 "Display only routes with non-natural netmasks\n")
6863{
6864 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
6865 bgp_show_type_cidr_only);
6866}
6867
6868DEFUN (show_ip_bgp_flap_cidr_only,
6869 show_ip_bgp_flap_cidr_only_cmd,
6870 "show ip bgp flap-statistics cidr-only",
6871 SHOW_STR
6872 IP_STR
6873 BGP_STR
6874 "Display flap statistics of routes\n"
6875 "Display only routes with non-natural netmasks\n")
6876{
6877 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
6878 bgp_show_type_flap_cidr_only);
6879}
6880
6881DEFUN (show_ip_bgp_ipv4_cidr_only,
6882 show_ip_bgp_ipv4_cidr_only_cmd,
6883 "show ip bgp ipv4 (unicast|multicast) cidr-only",
6884 SHOW_STR
6885 IP_STR
6886 BGP_STR
6887 "Address family\n"
6888 "Address Family modifier\n"
6889 "Address Family modifier\n"
6890 "Display only routes with non-natural netmasks\n")
6891{
6892 if (strncmp (argv[0], "m", 1) == 0)
6893 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
6894 bgp_show_type_cidr_only);
6895
6896 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
6897 bgp_show_type_cidr_only);
6898}
6899
6900DEFUN (show_ip_bgp_community_all,
6901 show_ip_bgp_community_all_cmd,
6902 "show ip bgp community",
6903 SHOW_STR
6904 IP_STR
6905 BGP_STR
6906 "Display routes matching the communities\n")
6907{
6908 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
6909 bgp_show_type_community_all);
6910}
6911
6912DEFUN (show_ip_bgp_ipv4_community_all,
6913 show_ip_bgp_ipv4_community_all_cmd,
6914 "show ip bgp ipv4 (unicast|multicast) community",
6915 SHOW_STR
6916 IP_STR
6917 BGP_STR
6918 "Address family\n"
6919 "Address Family modifier\n"
6920 "Address Family modifier\n"
6921 "Display routes matching the communities\n")
6922{
6923 if (strncmp (argv[0], "m", 1) == 0)
6924 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
6925 bgp_show_type_community_all);
6926
6927 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
6928 bgp_show_type_community_all);
6929}
6930
6931#ifdef HAVE_IPV6
6932DEFUN (show_bgp_community_all,
6933 show_bgp_community_all_cmd,
6934 "show bgp community",
6935 SHOW_STR
6936 BGP_STR
6937 "Display routes matching the communities\n")
6938{
6939 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
6940 bgp_show_type_community_all);
6941}
6942
6943ALIAS (show_bgp_community_all,
6944 show_bgp_ipv6_community_all_cmd,
6945 "show bgp ipv6 community",
6946 SHOW_STR
6947 BGP_STR
6948 "Address family\n"
6949 "Display routes matching the communities\n")
6950
6951/* old command */
6952DEFUN (show_ipv6_bgp_community_all,
6953 show_ipv6_bgp_community_all_cmd,
6954 "show ipv6 bgp community",
6955 SHOW_STR
6956 IPV6_STR
6957 BGP_STR
6958 "Display routes matching the communities\n")
6959{
6960 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
6961 bgp_show_type_community_all);
6962}
6963
6964/* old command */
6965DEFUN (show_ipv6_mbgp_community_all,
6966 show_ipv6_mbgp_community_all_cmd,
6967 "show ipv6 mbgp community",
6968 SHOW_STR
6969 IPV6_STR
6970 MBGP_STR
6971 "Display routes matching the communities\n")
6972{
6973 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
6974 bgp_show_type_community_all);
6975}
6976#endif /* HAVE_IPV6 */
6977
6978int
paulfd79ac92004-10-13 05:06:08 +00006979bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
6980 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00006981{
6982 struct community *com;
6983 struct buffer *b;
6984 int i;
6985 char *str;
6986 int first = 0;
6987
6988 b = buffer_new (1024);
6989 for (i = 0; i < argc; i++)
6990 {
6991 if (first)
6992 buffer_putc (b, ' ');
6993 else
6994 {
6995 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6996 continue;
6997 first = 1;
6998 }
6999
7000 buffer_putstr (b, argv[i]);
7001 }
7002 buffer_putc (b, '\0');
7003
7004 str = buffer_getstr (b);
7005 buffer_free (b);
7006
7007 com = community_str2com (str);
7008 free (str);
7009 if (! com)
7010 {
7011 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7012 return CMD_WARNING;
7013 }
7014
7015 vty->output_arg = com;
7016
7017 if (exact)
7018 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_exact);
7019
7020 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community);
7021}
7022
7023DEFUN (show_ip_bgp_community,
7024 show_ip_bgp_community_cmd,
7025 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7026 SHOW_STR
7027 IP_STR
7028 BGP_STR
7029 "Display routes matching the communities\n"
7030 "community number\n"
7031 "Do not send outside local AS (well-known community)\n"
7032 "Do not advertise to any peer (well-known community)\n"
7033 "Do not export to next AS (well-known community)\n")
7034{
7035 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7036}
7037
7038ALIAS (show_ip_bgp_community,
7039 show_ip_bgp_community2_cmd,
7040 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7041 SHOW_STR
7042 IP_STR
7043 BGP_STR
7044 "Display routes matching the communities\n"
7045 "community number\n"
7046 "Do not send outside local AS (well-known community)\n"
7047 "Do not advertise to any peer (well-known community)\n"
7048 "Do not export to next AS (well-known community)\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
7054ALIAS (show_ip_bgp_community,
7055 show_ip_bgp_community3_cmd,
7056 "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)",
7057 SHOW_STR
7058 IP_STR
7059 BGP_STR
7060 "Display routes matching the communities\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 "community number\n"
7066 "Do not send outside local AS (well-known community)\n"
7067 "Do not advertise to any peer (well-known community)\n"
7068 "Do not export to next AS (well-known community)\n"
7069 "community number\n"
7070 "Do not send outside local AS (well-known community)\n"
7071 "Do not advertise to any peer (well-known community)\n"
7072 "Do not export to next AS (well-known community)\n")
7073
7074ALIAS (show_ip_bgp_community,
7075 show_ip_bgp_community4_cmd,
7076 "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)",
7077 SHOW_STR
7078 IP_STR
7079 BGP_STR
7080 "Display routes matching the communities\n"
7081 "community number\n"
7082 "Do not send outside local AS (well-known community)\n"
7083 "Do not advertise to any peer (well-known community)\n"
7084 "Do not export to next AS (well-known community)\n"
7085 "community number\n"
7086 "Do not send outside local AS (well-known community)\n"
7087 "Do not advertise to any peer (well-known community)\n"
7088 "Do not export to next AS (well-known community)\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 "community number\n"
7094 "Do not send outside local AS (well-known community)\n"
7095 "Do not advertise to any peer (well-known community)\n"
7096 "Do not export to next AS (well-known community)\n")
7097
7098DEFUN (show_ip_bgp_ipv4_community,
7099 show_ip_bgp_ipv4_community_cmd,
7100 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7101 SHOW_STR
7102 IP_STR
7103 BGP_STR
7104 "Address family\n"
7105 "Address Family modifier\n"
7106 "Address Family modifier\n"
7107 "Display routes matching the communities\n"
7108 "community number\n"
7109 "Do not send outside local AS (well-known community)\n"
7110 "Do not advertise to any peer (well-known community)\n"
7111 "Do not export to next AS (well-known community)\n")
7112{
7113 if (strncmp (argv[0], "m", 1) == 0)
7114 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7115
7116 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7117}
7118
7119ALIAS (show_ip_bgp_ipv4_community,
7120 show_ip_bgp_ipv4_community2_cmd,
7121 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7122 SHOW_STR
7123 IP_STR
7124 BGP_STR
7125 "Address family\n"
7126 "Address Family modifier\n"
7127 "Address Family modifier\n"
7128 "Display routes matching the communities\n"
7129 "community number\n"
7130 "Do not send outside local AS (well-known community)\n"
7131 "Do not advertise to any peer (well-known community)\n"
7132 "Do not export to next AS (well-known community)\n"
7133 "community number\n"
7134 "Do not send outside local AS (well-known community)\n"
7135 "Do not advertise to any peer (well-known community)\n"
7136 "Do not export to next AS (well-known community)\n")
7137
7138ALIAS (show_ip_bgp_ipv4_community,
7139 show_ip_bgp_ipv4_community3_cmd,
7140 "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)",
7141 SHOW_STR
7142 IP_STR
7143 BGP_STR
7144 "Address family\n"
7145 "Address Family modifier\n"
7146 "Address Family modifier\n"
7147 "Display routes matching the communities\n"
7148 "community number\n"
7149 "Do not send outside local AS (well-known community)\n"
7150 "Do not advertise to any peer (well-known community)\n"
7151 "Do not export to next AS (well-known community)\n"
7152 "community number\n"
7153 "Do not send outside local AS (well-known community)\n"
7154 "Do not advertise to any peer (well-known community)\n"
7155 "Do not export to next AS (well-known community)\n"
7156 "community number\n"
7157 "Do not send outside local AS (well-known community)\n"
7158 "Do not advertise to any peer (well-known community)\n"
7159 "Do not export to next AS (well-known community)\n")
7160
7161ALIAS (show_ip_bgp_ipv4_community,
7162 show_ip_bgp_ipv4_community4_cmd,
7163 "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)",
7164 SHOW_STR
7165 IP_STR
7166 BGP_STR
7167 "Address family\n"
7168 "Address Family modifier\n"
7169 "Address Family modifier\n"
7170 "Display routes matching the communities\n"
7171 "community number\n"
7172 "Do not send outside local AS (well-known community)\n"
7173 "Do not advertise to any peer (well-known community)\n"
7174 "Do not export to next AS (well-known community)\n"
7175 "community number\n"
7176 "Do not send outside local AS (well-known community)\n"
7177 "Do not advertise to any peer (well-known community)\n"
7178 "Do not export to next AS (well-known community)\n"
7179 "community number\n"
7180 "Do not send outside local AS (well-known community)\n"
7181 "Do not advertise to any peer (well-known community)\n"
7182 "Do not export to next AS (well-known community)\n"
7183 "community number\n"
7184 "Do not send outside local AS (well-known community)\n"
7185 "Do not advertise to any peer (well-known community)\n"
7186 "Do not export to next AS (well-known community)\n")
7187
7188DEFUN (show_ip_bgp_community_exact,
7189 show_ip_bgp_community_exact_cmd,
7190 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7191 SHOW_STR
7192 IP_STR
7193 BGP_STR
7194 "Display routes matching the communities\n"
7195 "community number\n"
7196 "Do not send outside local AS (well-known community)\n"
7197 "Do not advertise to any peer (well-known community)\n"
7198 "Do not export to next AS (well-known community)\n"
7199 "Exact match of the communities")
7200{
7201 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7202}
7203
7204ALIAS (show_ip_bgp_community_exact,
7205 show_ip_bgp_community2_exact_cmd,
7206 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7207 SHOW_STR
7208 IP_STR
7209 BGP_STR
7210 "Display routes matching the communities\n"
7211 "community number\n"
7212 "Do not send outside local AS (well-known community)\n"
7213 "Do not advertise to any peer (well-known community)\n"
7214 "Do not export to next AS (well-known community)\n"
7215 "community number\n"
7216 "Do not send outside local AS (well-known community)\n"
7217 "Do not advertise to any peer (well-known community)\n"
7218 "Do not export to next AS (well-known community)\n"
7219 "Exact match of the communities")
7220
7221ALIAS (show_ip_bgp_community_exact,
7222 show_ip_bgp_community3_exact_cmd,
7223 "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",
7224 SHOW_STR
7225 IP_STR
7226 BGP_STR
7227 "Display routes matching the communities\n"
7228 "community number\n"
7229 "Do not send outside local AS (well-known community)\n"
7230 "Do not advertise to any peer (well-known community)\n"
7231 "Do not export to next AS (well-known community)\n"
7232 "community number\n"
7233 "Do not send outside local AS (well-known community)\n"
7234 "Do not advertise to any peer (well-known community)\n"
7235 "Do not export to next AS (well-known community)\n"
7236 "community number\n"
7237 "Do not send outside local AS (well-known community)\n"
7238 "Do not advertise to any peer (well-known community)\n"
7239 "Do not export to next AS (well-known community)\n"
7240 "Exact match of the communities")
7241
7242ALIAS (show_ip_bgp_community_exact,
7243 show_ip_bgp_community4_exact_cmd,
7244 "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",
7245 SHOW_STR
7246 IP_STR
7247 BGP_STR
7248 "Display routes matching the communities\n"
7249 "community number\n"
7250 "Do not send outside local AS (well-known community)\n"
7251 "Do not advertise to any peer (well-known community)\n"
7252 "Do not export to next AS (well-known community)\n"
7253 "community number\n"
7254 "Do not send outside local AS (well-known community)\n"
7255 "Do not advertise to any peer (well-known community)\n"
7256 "Do not export to next AS (well-known community)\n"
7257 "community number\n"
7258 "Do not send outside local AS (well-known community)\n"
7259 "Do not advertise to any peer (well-known community)\n"
7260 "Do not export to next AS (well-known community)\n"
7261 "community number\n"
7262 "Do not send outside local AS (well-known community)\n"
7263 "Do not advertise to any peer (well-known community)\n"
7264 "Do not export to next AS (well-known community)\n"
7265 "Exact match of the communities")
7266
7267DEFUN (show_ip_bgp_ipv4_community_exact,
7268 show_ip_bgp_ipv4_community_exact_cmd,
7269 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7270 SHOW_STR
7271 IP_STR
7272 BGP_STR
7273 "Address family\n"
7274 "Address Family modifier\n"
7275 "Address Family modifier\n"
7276 "Display routes matching the communities\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 "Exact match of the communities")
7282{
7283 if (strncmp (argv[0], "m", 1) == 0)
7284 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7285
7286 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7287}
7288
7289ALIAS (show_ip_bgp_ipv4_community_exact,
7290 show_ip_bgp_ipv4_community2_exact_cmd,
7291 "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",
7292 SHOW_STR
7293 IP_STR
7294 BGP_STR
7295 "Address family\n"
7296 "Address Family modifier\n"
7297 "Address Family modifier\n"
7298 "Display routes matching the communities\n"
7299 "community number\n"
7300 "Do not send outside local AS (well-known community)\n"
7301 "Do not advertise to any peer (well-known community)\n"
7302 "Do not export to next AS (well-known community)\n"
7303 "community number\n"
7304 "Do not send outside local AS (well-known community)\n"
7305 "Do not advertise to any peer (well-known community)\n"
7306 "Do not export to next AS (well-known community)\n"
7307 "Exact match of the communities")
7308
7309ALIAS (show_ip_bgp_ipv4_community_exact,
7310 show_ip_bgp_ipv4_community3_exact_cmd,
7311 "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",
7312 SHOW_STR
7313 IP_STR
7314 BGP_STR
7315 "Address family\n"
7316 "Address Family modifier\n"
7317 "Address Family modifier\n"
7318 "Display routes matching the communities\n"
7319 "community number\n"
7320 "Do not send outside local AS (well-known community)\n"
7321 "Do not advertise to any peer (well-known community)\n"
7322 "Do not export to next AS (well-known community)\n"
7323 "community number\n"
7324 "Do not send outside local AS (well-known community)\n"
7325 "Do not advertise to any peer (well-known community)\n"
7326 "Do not export to next AS (well-known community)\n"
7327 "community number\n"
7328 "Do not send outside local AS (well-known community)\n"
7329 "Do not advertise to any peer (well-known community)\n"
7330 "Do not export to next AS (well-known community)\n"
7331 "Exact match of the communities")
7332
7333ALIAS (show_ip_bgp_ipv4_community_exact,
7334 show_ip_bgp_ipv4_community4_exact_cmd,
7335 "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",
7336 SHOW_STR
7337 IP_STR
7338 BGP_STR
7339 "Address family\n"
7340 "Address Family modifier\n"
7341 "Address Family modifier\n"
7342 "Display routes matching the communities\n"
7343 "community number\n"
7344 "Do not send outside local AS (well-known community)\n"
7345 "Do not advertise to any peer (well-known community)\n"
7346 "Do not export to next AS (well-known community)\n"
7347 "community number\n"
7348 "Do not send outside local AS (well-known community)\n"
7349 "Do not advertise to any peer (well-known community)\n"
7350 "Do not export to next AS (well-known community)\n"
7351 "community number\n"
7352 "Do not send outside local AS (well-known community)\n"
7353 "Do not advertise to any peer (well-known community)\n"
7354 "Do not export to next AS (well-known community)\n"
7355 "community number\n"
7356 "Do not send outside local AS (well-known community)\n"
7357 "Do not advertise to any peer (well-known community)\n"
7358 "Do not export to next AS (well-known community)\n"
7359 "Exact match of the communities")
7360
7361#ifdef HAVE_IPV6
7362DEFUN (show_bgp_community,
7363 show_bgp_community_cmd,
7364 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7365 SHOW_STR
7366 BGP_STR
7367 "Display routes matching the communities\n"
7368 "community number\n"
7369 "Do not send outside local AS (well-known community)\n"
7370 "Do not advertise to any peer (well-known community)\n"
7371 "Do not export to next AS (well-known community)\n")
7372{
7373 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7374}
7375
7376ALIAS (show_bgp_community,
7377 show_bgp_ipv6_community_cmd,
7378 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7379 SHOW_STR
7380 BGP_STR
7381 "Address family\n"
7382 "Display routes matching the communities\n"
7383 "community number\n"
7384 "Do not send outside local AS (well-known community)\n"
7385 "Do not advertise to any peer (well-known community)\n"
7386 "Do not export to next AS (well-known community)\n")
7387
7388ALIAS (show_bgp_community,
7389 show_bgp_community2_cmd,
7390 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7391 SHOW_STR
7392 BGP_STR
7393 "Display routes matching the communities\n"
7394 "community number\n"
7395 "Do not send outside local AS (well-known community)\n"
7396 "Do not advertise to any peer (well-known community)\n"
7397 "Do not export to next AS (well-known community)\n"
7398 "community number\n"
7399 "Do not send outside local AS (well-known community)\n"
7400 "Do not advertise to any peer (well-known community)\n"
7401 "Do not export to next AS (well-known community)\n")
7402
7403ALIAS (show_bgp_community,
7404 show_bgp_ipv6_community2_cmd,
7405 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7406 SHOW_STR
7407 BGP_STR
7408 "Address family\n"
7409 "Display routes matching the communities\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 "community number\n"
7415 "Do not send outside local AS (well-known community)\n"
7416 "Do not advertise to any peer (well-known community)\n"
7417 "Do not export to next AS (well-known community)\n")
7418
7419ALIAS (show_bgp_community,
7420 show_bgp_community3_cmd,
7421 "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)",
7422 SHOW_STR
7423 BGP_STR
7424 "Display routes matching the communities\n"
7425 "community number\n"
7426 "Do not send outside local AS (well-known community)\n"
7427 "Do not advertise to any peer (well-known community)\n"
7428 "Do not export to next AS (well-known community)\n"
7429 "community number\n"
7430 "Do not send outside local AS (well-known community)\n"
7431 "Do not advertise to any peer (well-known community)\n"
7432 "Do not export to next AS (well-known community)\n"
7433 "community number\n"
7434 "Do not send outside local AS (well-known community)\n"
7435 "Do not advertise to any peer (well-known community)\n"
7436 "Do not export to next AS (well-known community)\n")
7437
7438ALIAS (show_bgp_community,
7439 show_bgp_ipv6_community3_cmd,
7440 "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)",
7441 SHOW_STR
7442 BGP_STR
7443 "Address family\n"
7444 "Display routes matching the communities\n"
7445 "community number\n"
7446 "Do not send outside local AS (well-known community)\n"
7447 "Do not advertise to any peer (well-known community)\n"
7448 "Do not export to next AS (well-known community)\n"
7449 "community number\n"
7450 "Do not send outside local AS (well-known community)\n"
7451 "Do not advertise to any peer (well-known community)\n"
7452 "Do not export to next AS (well-known community)\n"
7453 "community number\n"
7454 "Do not send outside local AS (well-known community)\n"
7455 "Do not advertise to any peer (well-known community)\n"
7456 "Do not export to next AS (well-known community)\n")
7457
7458ALIAS (show_bgp_community,
7459 show_bgp_community4_cmd,
7460 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7461 SHOW_STR
7462 BGP_STR
7463 "Display routes matching the communities\n"
7464 "community number\n"
7465 "Do not send outside local AS (well-known community)\n"
7466 "Do not advertise to any peer (well-known community)\n"
7467 "Do not export to next AS (well-known community)\n"
7468 "community number\n"
7469 "Do not send outside local AS (well-known community)\n"
7470 "Do not advertise to any peer (well-known community)\n"
7471 "Do not export to next AS (well-known community)\n"
7472 "community number\n"
7473 "Do not send outside local AS (well-known community)\n"
7474 "Do not advertise to any peer (well-known community)\n"
7475 "Do not export to next AS (well-known community)\n"
7476 "community number\n"
7477 "Do not send outside local AS (well-known community)\n"
7478 "Do not advertise to any peer (well-known community)\n"
7479 "Do not export to next AS (well-known community)\n")
7480
7481ALIAS (show_bgp_community,
7482 show_bgp_ipv6_community4_cmd,
7483 "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)",
7484 SHOW_STR
7485 BGP_STR
7486 "Address family\n"
7487 "Display routes matching the communities\n"
7488 "community number\n"
7489 "Do not send outside local AS (well-known community)\n"
7490 "Do not advertise to any peer (well-known community)\n"
7491 "Do not export to next AS (well-known community)\n"
7492 "community number\n"
7493 "Do not send outside local AS (well-known community)\n"
7494 "Do not advertise to any peer (well-known community)\n"
7495 "Do not export to next AS (well-known community)\n"
7496 "community number\n"
7497 "Do not send outside local AS (well-known community)\n"
7498 "Do not advertise to any peer (well-known community)\n"
7499 "Do not export to next AS (well-known community)\n"
7500 "community number\n"
7501 "Do not send outside local AS (well-known community)\n"
7502 "Do not advertise to any peer (well-known community)\n"
7503 "Do not export to next AS (well-known community)\n")
7504
7505/* old command */
7506DEFUN (show_ipv6_bgp_community,
7507 show_ipv6_bgp_community_cmd,
7508 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7509 SHOW_STR
7510 IPV6_STR
7511 BGP_STR
7512 "Display routes matching the communities\n"
7513 "community number\n"
7514 "Do not send outside local AS (well-known community)\n"
7515 "Do not advertise to any peer (well-known community)\n"
7516 "Do not export to next AS (well-known community)\n")
7517{
7518 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7519}
7520
7521/* old command */
7522ALIAS (show_ipv6_bgp_community,
7523 show_ipv6_bgp_community2_cmd,
7524 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7525 SHOW_STR
7526 IPV6_STR
7527 BGP_STR
7528 "Display routes matching the communities\n"
7529 "community number\n"
7530 "Do not send outside local AS (well-known community)\n"
7531 "Do not advertise to any peer (well-known community)\n"
7532 "Do not export to next AS (well-known community)\n"
7533 "community number\n"
7534 "Do not send outside local AS (well-known community)\n"
7535 "Do not advertise to any peer (well-known community)\n"
7536 "Do not export to next AS (well-known community)\n")
7537
7538/* old command */
7539ALIAS (show_ipv6_bgp_community,
7540 show_ipv6_bgp_community3_cmd,
7541 "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)",
7542 SHOW_STR
7543 IPV6_STR
7544 BGP_STR
7545 "Display routes matching the communities\n"
7546 "community number\n"
7547 "Do not send outside local AS (well-known community)\n"
7548 "Do not advertise to any peer (well-known community)\n"
7549 "Do not export to next AS (well-known community)\n"
7550 "community number\n"
7551 "Do not send outside local AS (well-known community)\n"
7552 "Do not advertise to any peer (well-known community)\n"
7553 "Do not export to next AS (well-known community)\n"
7554 "community number\n"
7555 "Do not send outside local AS (well-known community)\n"
7556 "Do not advertise to any peer (well-known community)\n"
7557 "Do not export to next AS (well-known community)\n")
7558
7559/* old command */
7560ALIAS (show_ipv6_bgp_community,
7561 show_ipv6_bgp_community4_cmd,
7562 "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)",
7563 SHOW_STR
7564 IPV6_STR
7565 BGP_STR
7566 "Display routes matching the communities\n"
7567 "community number\n"
7568 "Do not send outside local AS (well-known community)\n"
7569 "Do not advertise to any peer (well-known community)\n"
7570 "Do not export to next AS (well-known community)\n"
7571 "community number\n"
7572 "Do not send outside local AS (well-known community)\n"
7573 "Do not advertise to any peer (well-known community)\n"
7574 "Do not export to next AS (well-known community)\n"
7575 "community number\n"
7576 "Do not send outside local AS (well-known community)\n"
7577 "Do not advertise to any peer (well-known community)\n"
7578 "Do not export to next AS (well-known community)\n"
7579 "community number\n"
7580 "Do not send outside local AS (well-known community)\n"
7581 "Do not advertise to any peer (well-known community)\n"
7582 "Do not export to next AS (well-known community)\n")
7583
7584DEFUN (show_bgp_community_exact,
7585 show_bgp_community_exact_cmd,
7586 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7587 SHOW_STR
7588 BGP_STR
7589 "Display routes matching the communities\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 "Exact match of the communities")
7595{
7596 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7597}
7598
7599ALIAS (show_bgp_community_exact,
7600 show_bgp_ipv6_community_exact_cmd,
7601 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7602 SHOW_STR
7603 BGP_STR
7604 "Address family\n"
7605 "Display routes matching the communities\n"
7606 "community number\n"
7607 "Do not send outside local AS (well-known community)\n"
7608 "Do not advertise to any peer (well-known community)\n"
7609 "Do not export to next AS (well-known community)\n"
7610 "Exact match of the communities")
7611
7612ALIAS (show_bgp_community_exact,
7613 show_bgp_community2_exact_cmd,
7614 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7615 SHOW_STR
7616 BGP_STR
7617 "Display routes matching the communities\n"
7618 "community number\n"
7619 "Do not send outside local AS (well-known community)\n"
7620 "Do not advertise to any peer (well-known community)\n"
7621 "Do not export to next AS (well-known community)\n"
7622 "community number\n"
7623 "Do not send outside local AS (well-known community)\n"
7624 "Do not advertise to any peer (well-known community)\n"
7625 "Do not export to next AS (well-known community)\n"
7626 "Exact match of the communities")
7627
7628ALIAS (show_bgp_community_exact,
7629 show_bgp_ipv6_community2_exact_cmd,
7630 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7631 SHOW_STR
7632 BGP_STR
7633 "Address family\n"
7634 "Display routes matching the communities\n"
7635 "community number\n"
7636 "Do not send outside local AS (well-known community)\n"
7637 "Do not advertise to any peer (well-known community)\n"
7638 "Do not export to next AS (well-known community)\n"
7639 "community number\n"
7640 "Do not send outside local AS (well-known community)\n"
7641 "Do not advertise to any peer (well-known community)\n"
7642 "Do not export to next AS (well-known community)\n"
7643 "Exact match of the communities")
7644
7645ALIAS (show_bgp_community_exact,
7646 show_bgp_community3_exact_cmd,
7647 "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",
7648 SHOW_STR
7649 BGP_STR
7650 "Display routes matching the communities\n"
7651 "community number\n"
7652 "Do not send outside local AS (well-known community)\n"
7653 "Do not advertise to any peer (well-known community)\n"
7654 "Do not export to next AS (well-known community)\n"
7655 "community number\n"
7656 "Do not send outside local AS (well-known community)\n"
7657 "Do not advertise to any peer (well-known community)\n"
7658 "Do not export to next AS (well-known community)\n"
7659 "community number\n"
7660 "Do not send outside local AS (well-known community)\n"
7661 "Do not advertise to any peer (well-known community)\n"
7662 "Do not export to next AS (well-known community)\n"
7663 "Exact match of the communities")
7664
7665ALIAS (show_bgp_community_exact,
7666 show_bgp_ipv6_community3_exact_cmd,
7667 "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",
7668 SHOW_STR
7669 BGP_STR
7670 "Address family\n"
7671 "Display routes matching the communities\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
7686ALIAS (show_bgp_community_exact,
7687 show_bgp_community4_exact_cmd,
7688 "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",
7689 SHOW_STR
7690 BGP_STR
7691 "Display routes matching the communities\n"
7692 "community number\n"
7693 "Do not send outside local AS (well-known community)\n"
7694 "Do not advertise to any peer (well-known community)\n"
7695 "Do not export to next AS (well-known community)\n"
7696 "community number\n"
7697 "Do not send outside local AS (well-known community)\n"
7698 "Do not advertise to any peer (well-known community)\n"
7699 "Do not export to next AS (well-known community)\n"
7700 "community number\n"
7701 "Do not send outside local AS (well-known community)\n"
7702 "Do not advertise to any peer (well-known community)\n"
7703 "Do not export to next AS (well-known community)\n"
7704 "community number\n"
7705 "Do not send outside local AS (well-known community)\n"
7706 "Do not advertise to any peer (well-known community)\n"
7707 "Do not export to next AS (well-known community)\n"
7708 "Exact match of the communities")
7709
7710ALIAS (show_bgp_community_exact,
7711 show_bgp_ipv6_community4_exact_cmd,
7712 "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",
7713 SHOW_STR
7714 BGP_STR
7715 "Address family\n"
7716 "Display routes matching the communities\n"
7717 "community number\n"
7718 "Do not send outside local AS (well-known community)\n"
7719 "Do not advertise to any peer (well-known community)\n"
7720 "Do not export to next AS (well-known community)\n"
7721 "community number\n"
7722 "Do not send outside local AS (well-known community)\n"
7723 "Do not advertise to any peer (well-known community)\n"
7724 "Do not export to next AS (well-known community)\n"
7725 "community number\n"
7726 "Do not send outside local AS (well-known community)\n"
7727 "Do not advertise to any peer (well-known community)\n"
7728 "Do not export to next AS (well-known community)\n"
7729 "community number\n"
7730 "Do not send outside local AS (well-known community)\n"
7731 "Do not advertise to any peer (well-known community)\n"
7732 "Do not export to next AS (well-known community)\n"
7733 "Exact match of the communities")
7734
7735/* old command */
7736DEFUN (show_ipv6_bgp_community_exact,
7737 show_ipv6_bgp_community_exact_cmd,
7738 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7739 SHOW_STR
7740 IPV6_STR
7741 BGP_STR
7742 "Display routes matching the communities\n"
7743 "community number\n"
7744 "Do not send outside local AS (well-known community)\n"
7745 "Do not advertise to any peer (well-known community)\n"
7746 "Do not export to next AS (well-known community)\n"
7747 "Exact match of the communities")
7748{
7749 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7750}
7751
7752/* old command */
7753ALIAS (show_ipv6_bgp_community_exact,
7754 show_ipv6_bgp_community2_exact_cmd,
7755 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7756 SHOW_STR
7757 IPV6_STR
7758 BGP_STR
7759 "Display routes matching the communities\n"
7760 "community number\n"
7761 "Do not send outside local AS (well-known community)\n"
7762 "Do not advertise to any peer (well-known community)\n"
7763 "Do not export to next AS (well-known community)\n"
7764 "community number\n"
7765 "Do not send outside local AS (well-known community)\n"
7766 "Do not advertise to any peer (well-known community)\n"
7767 "Do not export to next AS (well-known community)\n"
7768 "Exact match of the communities")
7769
7770/* old command */
7771ALIAS (show_ipv6_bgp_community_exact,
7772 show_ipv6_bgp_community3_exact_cmd,
7773 "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",
7774 SHOW_STR
7775 IPV6_STR
7776 BGP_STR
7777 "Display routes matching the communities\n"
7778 "community number\n"
7779 "Do not send outside local AS (well-known community)\n"
7780 "Do not advertise to any peer (well-known community)\n"
7781 "Do not export to next AS (well-known community)\n"
7782 "community number\n"
7783 "Do not send outside local AS (well-known community)\n"
7784 "Do not advertise to any peer (well-known community)\n"
7785 "Do not export to next AS (well-known community)\n"
7786 "community number\n"
7787 "Do not send outside local AS (well-known community)\n"
7788 "Do not advertise to any peer (well-known community)\n"
7789 "Do not export to next AS (well-known community)\n"
7790 "Exact match of the communities")
7791
7792/* old command */
7793ALIAS (show_ipv6_bgp_community_exact,
7794 show_ipv6_bgp_community4_exact_cmd,
7795 "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",
7796 SHOW_STR
7797 IPV6_STR
7798 BGP_STR
7799 "Display routes matching the communities\n"
7800 "community number\n"
7801 "Do not send outside local AS (well-known community)\n"
7802 "Do not advertise to any peer (well-known community)\n"
7803 "Do not export to next AS (well-known community)\n"
7804 "community number\n"
7805 "Do not send outside local AS (well-known community)\n"
7806 "Do not advertise to any peer (well-known community)\n"
7807 "Do not export to next AS (well-known community)\n"
7808 "community number\n"
7809 "Do not send outside local AS (well-known community)\n"
7810 "Do not advertise to any peer (well-known community)\n"
7811 "Do not export to next AS (well-known community)\n"
7812 "community number\n"
7813 "Do not send outside local AS (well-known community)\n"
7814 "Do not advertise to any peer (well-known community)\n"
7815 "Do not export to next AS (well-known community)\n"
7816 "Exact match of the communities")
7817
7818/* old command */
7819DEFUN (show_ipv6_mbgp_community,
7820 show_ipv6_mbgp_community_cmd,
7821 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7822 SHOW_STR
7823 IPV6_STR
7824 MBGP_STR
7825 "Display routes matching the communities\n"
7826 "community number\n"
7827 "Do not send outside local AS (well-known community)\n"
7828 "Do not advertise to any peer (well-known community)\n"
7829 "Do not export to next AS (well-known community)\n")
7830{
7831 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7832}
7833
7834/* old command */
7835ALIAS (show_ipv6_mbgp_community,
7836 show_ipv6_mbgp_community2_cmd,
7837 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7838 SHOW_STR
7839 IPV6_STR
7840 MBGP_STR
7841 "Display routes matching the communities\n"
7842 "community number\n"
7843 "Do not send outside local AS (well-known community)\n"
7844 "Do not advertise to any peer (well-known community)\n"
7845 "Do not export to next AS (well-known community)\n"
7846 "community number\n"
7847 "Do not send outside local AS (well-known community)\n"
7848 "Do not advertise to any peer (well-known community)\n"
7849 "Do not export to next AS (well-known community)\n")
7850
7851/* old command */
7852ALIAS (show_ipv6_mbgp_community,
7853 show_ipv6_mbgp_community3_cmd,
7854 "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)",
7855 SHOW_STR
7856 IPV6_STR
7857 MBGP_STR
7858 "Display routes matching the communities\n"
7859 "community number\n"
7860 "Do not send outside local AS (well-known community)\n"
7861 "Do not advertise to any peer (well-known community)\n"
7862 "Do not export to next AS (well-known community)\n"
7863 "community number\n"
7864 "Do not send outside local AS (well-known community)\n"
7865 "Do not advertise to any peer (well-known community)\n"
7866 "Do not export to next AS (well-known community)\n"
7867 "community number\n"
7868 "Do not send outside local AS (well-known community)\n"
7869 "Do not advertise to any peer (well-known community)\n"
7870 "Do not export to next AS (well-known community)\n")
7871
7872/* old command */
7873ALIAS (show_ipv6_mbgp_community,
7874 show_ipv6_mbgp_community4_cmd,
7875 "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)",
7876 SHOW_STR
7877 IPV6_STR
7878 MBGP_STR
7879 "Display routes matching the communities\n"
7880 "community number\n"
7881 "Do not send outside local AS (well-known community)\n"
7882 "Do not advertise to any peer (well-known community)\n"
7883 "Do not export to next AS (well-known community)\n"
7884 "community number\n"
7885 "Do not send outside local AS (well-known community)\n"
7886 "Do not advertise to any peer (well-known community)\n"
7887 "Do not export to next AS (well-known community)\n"
7888 "community number\n"
7889 "Do not send outside local AS (well-known community)\n"
7890 "Do not advertise to any peer (well-known community)\n"
7891 "Do not export to next AS (well-known community)\n"
7892 "community number\n"
7893 "Do not send outside local AS (well-known community)\n"
7894 "Do not advertise to any peer (well-known community)\n"
7895 "Do not export to next AS (well-known community)\n")
7896
7897/* old command */
7898DEFUN (show_ipv6_mbgp_community_exact,
7899 show_ipv6_mbgp_community_exact_cmd,
7900 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7901 SHOW_STR
7902 IPV6_STR
7903 MBGP_STR
7904 "Display routes matching the communities\n"
7905 "community number\n"
7906 "Do not send outside local AS (well-known community)\n"
7907 "Do not advertise to any peer (well-known community)\n"
7908 "Do not export to next AS (well-known community)\n"
7909 "Exact match of the communities")
7910{
7911 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7912}
7913
7914/* old command */
7915ALIAS (show_ipv6_mbgp_community_exact,
7916 show_ipv6_mbgp_community2_exact_cmd,
7917 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7918 SHOW_STR
7919 IPV6_STR
7920 MBGP_STR
7921 "Display routes matching the communities\n"
7922 "community number\n"
7923 "Do not send outside local AS (well-known community)\n"
7924 "Do not advertise to any peer (well-known community)\n"
7925 "Do not export to next AS (well-known community)\n"
7926 "community number\n"
7927 "Do not send outside local AS (well-known community)\n"
7928 "Do not advertise to any peer (well-known community)\n"
7929 "Do not export to next AS (well-known community)\n"
7930 "Exact match of the communities")
7931
7932/* old command */
7933ALIAS (show_ipv6_mbgp_community_exact,
7934 show_ipv6_mbgp_community3_exact_cmd,
7935 "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",
7936 SHOW_STR
7937 IPV6_STR
7938 MBGP_STR
7939 "Display routes matching the communities\n"
7940 "community number\n"
7941 "Do not send outside local AS (well-known community)\n"
7942 "Do not advertise to any peer (well-known community)\n"
7943 "Do not export to next AS (well-known community)\n"
7944 "community number\n"
7945 "Do not send outside local AS (well-known community)\n"
7946 "Do not advertise to any peer (well-known community)\n"
7947 "Do not export to next AS (well-known community)\n"
7948 "community number\n"
7949 "Do not send outside local AS (well-known community)\n"
7950 "Do not advertise to any peer (well-known community)\n"
7951 "Do not export to next AS (well-known community)\n"
7952 "Exact match of the communities")
7953
7954/* old command */
7955ALIAS (show_ipv6_mbgp_community_exact,
7956 show_ipv6_mbgp_community4_exact_cmd,
7957 "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",
7958 SHOW_STR
7959 IPV6_STR
7960 MBGP_STR
7961 "Display routes matching the communities\n"
7962 "community number\n"
7963 "Do not send outside local AS (well-known community)\n"
7964 "Do not advertise to any peer (well-known community)\n"
7965 "Do not export to next AS (well-known community)\n"
7966 "community number\n"
7967 "Do not send outside local AS (well-known community)\n"
7968 "Do not advertise to any peer (well-known community)\n"
7969 "Do not export to next AS (well-known community)\n"
7970 "community number\n"
7971 "Do not send outside local AS (well-known community)\n"
7972 "Do not advertise to any peer (well-known community)\n"
7973 "Do not export to next AS (well-known community)\n"
7974 "community number\n"
7975 "Do not send outside local AS (well-known community)\n"
7976 "Do not advertise to any peer (well-known community)\n"
7977 "Do not export to next AS (well-known community)\n"
7978 "Exact match of the communities")
7979#endif /* HAVE_IPV6 */
7980
7981int
paulfd79ac92004-10-13 05:06:08 +00007982bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00007983 u_int16_t afi, u_char safi)
7984{
7985 struct community_list *list;
7986
7987 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_AUTO);
7988 if (list == NULL)
7989 {
7990 vty_out (vty, "%% %s is not a valid community-list name%s", com,
7991 VTY_NEWLINE);
7992 return CMD_WARNING;
7993 }
7994
7995 vty->output_arg = list;
7996
7997 if (exact)
7998 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_list_exact);
7999
8000 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_list);
8001}
8002
8003DEFUN (show_ip_bgp_community_list,
8004 show_ip_bgp_community_list_cmd,
8005 "show ip bgp community-list WORD",
8006 SHOW_STR
8007 IP_STR
8008 BGP_STR
8009 "Display routes matching the community-list\n"
8010 "community-list name\n")
8011{
8012 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8013}
8014
8015DEFUN (show_ip_bgp_ipv4_community_list,
8016 show_ip_bgp_ipv4_community_list_cmd,
8017 "show ip bgp ipv4 (unicast|multicast) community-list WORD",
8018 SHOW_STR
8019 IP_STR
8020 BGP_STR
8021 "Address family\n"
8022 "Address Family modifier\n"
8023 "Address Family modifier\n"
8024 "Display routes matching the community-list\n"
8025 "community-list name\n")
8026{
8027 if (strncmp (argv[0], "m", 1) == 0)
8028 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8029
8030 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8031}
8032
8033DEFUN (show_ip_bgp_community_list_exact,
8034 show_ip_bgp_community_list_exact_cmd,
8035 "show ip bgp community-list WORD exact-match",
8036 SHOW_STR
8037 IP_STR
8038 BGP_STR
8039 "Display routes matching the community-list\n"
8040 "community-list name\n"
8041 "Exact match of the communities\n")
8042{
8043 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8044}
8045
8046DEFUN (show_ip_bgp_ipv4_community_list_exact,
8047 show_ip_bgp_ipv4_community_list_exact_cmd,
8048 "show ip bgp ipv4 (unicast|multicast) community-list WORD exact-match",
8049 SHOW_STR
8050 IP_STR
8051 BGP_STR
8052 "Address family\n"
8053 "Address Family modifier\n"
8054 "Address Family modifier\n"
8055 "Display routes matching the community-list\n"
8056 "community-list name\n"
8057 "Exact match of the communities\n")
8058{
8059 if (strncmp (argv[0], "m", 1) == 0)
8060 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8061
8062 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8063}
8064
8065#ifdef HAVE_IPV6
8066DEFUN (show_bgp_community_list,
8067 show_bgp_community_list_cmd,
8068 "show bgp community-list WORD",
8069 SHOW_STR
8070 BGP_STR
8071 "Display routes matching the community-list\n"
8072 "community-list name\n")
8073{
8074 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8075}
8076
8077ALIAS (show_bgp_community_list,
8078 show_bgp_ipv6_community_list_cmd,
8079 "show bgp ipv6 community-list WORD",
8080 SHOW_STR
8081 BGP_STR
8082 "Address family\n"
8083 "Display routes matching the community-list\n"
8084 "community-list name\n")
8085
8086/* old command */
8087DEFUN (show_ipv6_bgp_community_list,
8088 show_ipv6_bgp_community_list_cmd,
8089 "show ipv6 bgp community-list WORD",
8090 SHOW_STR
8091 IPV6_STR
8092 BGP_STR
8093 "Display routes matching the community-list\n"
8094 "community-list name\n")
8095{
8096 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8097}
8098
8099/* old command */
8100DEFUN (show_ipv6_mbgp_community_list,
8101 show_ipv6_mbgp_community_list_cmd,
8102 "show ipv6 mbgp community-list WORD",
8103 SHOW_STR
8104 IPV6_STR
8105 MBGP_STR
8106 "Display routes matching the community-list\n"
8107 "community-list name\n")
8108{
8109 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8110}
8111
8112DEFUN (show_bgp_community_list_exact,
8113 show_bgp_community_list_exact_cmd,
8114 "show bgp community-list WORD exact-match",
8115 SHOW_STR
8116 BGP_STR
8117 "Display routes matching the community-list\n"
8118 "community-list name\n"
8119 "Exact match of the communities\n")
8120{
8121 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8122}
8123
8124ALIAS (show_bgp_community_list_exact,
8125 show_bgp_ipv6_community_list_exact_cmd,
8126 "show bgp ipv6 community-list WORD exact-match",
8127 SHOW_STR
8128 BGP_STR
8129 "Address family\n"
8130 "Display routes matching the community-list\n"
8131 "community-list name\n"
8132 "Exact match of the communities\n")
8133
8134/* old command */
8135DEFUN (show_ipv6_bgp_community_list_exact,
8136 show_ipv6_bgp_community_list_exact_cmd,
8137 "show ipv6 bgp community-list WORD exact-match",
8138 SHOW_STR
8139 IPV6_STR
8140 BGP_STR
8141 "Display routes matching the community-list\n"
8142 "community-list name\n"
8143 "Exact match of the communities\n")
8144{
8145 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8146}
8147
8148/* old command */
8149DEFUN (show_ipv6_mbgp_community_list_exact,
8150 show_ipv6_mbgp_community_list_exact_cmd,
8151 "show ipv6 mbgp community-list WORD exact-match",
8152 SHOW_STR
8153 IPV6_STR
8154 MBGP_STR
8155 "Display routes matching the community-list\n"
8156 "community-list name\n"
8157 "Exact match of the communities\n")
8158{
8159 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8160}
8161#endif /* HAVE_IPV6 */
8162
8163void
8164bgp_show_prefix_longer_clean (struct vty *vty)
8165{
8166 struct prefix *p;
8167
8168 p = vty->output_arg;
8169 prefix_free (p);
8170}
8171
8172int
paulfd79ac92004-10-13 05:06:08 +00008173bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008174 safi_t safi, enum bgp_show_type type)
8175{
8176 int ret;
8177 struct prefix *p;
8178
8179 p = prefix_new();
8180
8181 ret = str2prefix (prefix, p);
8182 if (! ret)
8183 {
8184 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8185 return CMD_WARNING;
8186 }
8187
8188 vty->output_arg = p;
8189 vty->output_clean = bgp_show_prefix_longer_clean;
8190
8191 return bgp_show (vty, NULL, afi, safi, type);
8192}
8193
8194DEFUN (show_ip_bgp_prefix_longer,
8195 show_ip_bgp_prefix_longer_cmd,
8196 "show ip bgp A.B.C.D/M longer-prefixes",
8197 SHOW_STR
8198 IP_STR
8199 BGP_STR
8200 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8201 "Display route and more specific routes\n")
8202{
8203 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8204 bgp_show_type_prefix_longer);
8205}
8206
8207DEFUN (show_ip_bgp_flap_prefix_longer,
8208 show_ip_bgp_flap_prefix_longer_cmd,
8209 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8210 SHOW_STR
8211 IP_STR
8212 BGP_STR
8213 "Display flap statistics of routes\n"
8214 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8215 "Display route and more specific routes\n")
8216{
8217 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8218 bgp_show_type_flap_prefix_longer);
8219}
8220
8221DEFUN (show_ip_bgp_ipv4_prefix_longer,
8222 show_ip_bgp_ipv4_prefix_longer_cmd,
8223 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8224 SHOW_STR
8225 IP_STR
8226 BGP_STR
8227 "Address family\n"
8228 "Address Family modifier\n"
8229 "Address Family modifier\n"
8230 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8231 "Display route and more specific routes\n")
8232{
8233 if (strncmp (argv[0], "m", 1) == 0)
8234 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8235 bgp_show_type_prefix_longer);
8236
8237 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8238 bgp_show_type_prefix_longer);
8239}
8240
8241DEFUN (show_ip_bgp_flap_address,
8242 show_ip_bgp_flap_address_cmd,
8243 "show ip bgp flap-statistics A.B.C.D",
8244 SHOW_STR
8245 IP_STR
8246 BGP_STR
8247 "Display flap statistics of routes\n"
8248 "Network in the BGP routing table to display\n")
8249{
8250 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8251 bgp_show_type_flap_address);
8252}
8253
8254DEFUN (show_ip_bgp_flap_prefix,
8255 show_ip_bgp_flap_prefix_cmd,
8256 "show ip bgp flap-statistics A.B.C.D/M",
8257 SHOW_STR
8258 IP_STR
8259 BGP_STR
8260 "Display flap statistics of routes\n"
8261 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8262{
8263 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8264 bgp_show_type_flap_prefix);
8265}
8266#ifdef HAVE_IPV6
8267DEFUN (show_bgp_prefix_longer,
8268 show_bgp_prefix_longer_cmd,
8269 "show bgp X:X::X:X/M longer-prefixes",
8270 SHOW_STR
8271 BGP_STR
8272 "IPv6 prefix <network>/<length>\n"
8273 "Display route and more specific routes\n")
8274{
8275 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8276 bgp_show_type_prefix_longer);
8277}
8278
8279ALIAS (show_bgp_prefix_longer,
8280 show_bgp_ipv6_prefix_longer_cmd,
8281 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8282 SHOW_STR
8283 BGP_STR
8284 "Address family\n"
8285 "IPv6 prefix <network>/<length>\n"
8286 "Display route and more specific routes\n")
8287
8288/* old command */
8289DEFUN (show_ipv6_bgp_prefix_longer,
8290 show_ipv6_bgp_prefix_longer_cmd,
8291 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8292 SHOW_STR
8293 IPV6_STR
8294 BGP_STR
8295 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8296 "Display route and more specific routes\n")
8297{
8298 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8299 bgp_show_type_prefix_longer);
8300}
8301
8302/* old command */
8303DEFUN (show_ipv6_mbgp_prefix_longer,
8304 show_ipv6_mbgp_prefix_longer_cmd,
8305 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8306 SHOW_STR
8307 IPV6_STR
8308 MBGP_STR
8309 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8310 "Display route and more specific routes\n")
8311{
8312 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8313 bgp_show_type_prefix_longer);
8314}
8315#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008316
8317struct peer *
paulfd79ac92004-10-13 05:06:08 +00008318peer_lookup_in_view (struct vty *vty, const char *view_name,
8319 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008320{
8321 int ret;
8322 struct bgp *bgp;
8323 struct peer *peer;
8324 union sockunion su;
8325
8326 /* BGP structure lookup. */
8327 if (view_name)
8328 {
8329 bgp = bgp_lookup_by_name (view_name);
8330 if (! bgp)
8331 {
8332 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8333 return NULL;
8334 }
8335 }
paul5228ad22004-06-04 17:58:18 +00008336 else
paulbb46e942003-10-24 19:02:03 +00008337 {
8338 bgp = bgp_get_default ();
8339 if (! bgp)
8340 {
8341 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8342 return NULL;
8343 }
8344 }
8345
8346 /* Get peer sockunion. */
8347 ret = str2sockunion (ip_str, &su);
8348 if (ret < 0)
8349 {
8350 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8351 return NULL;
8352 }
8353
8354 /* Peer structure lookup. */
8355 peer = peer_lookup (bgp, &su);
8356 if (! peer)
8357 {
8358 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8359 return NULL;
8360 }
8361
8362 return peer;
8363}
8364
paul718e3742002-12-13 20:15:29 +00008365void
8366show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
8367 int in)
8368{
8369 struct bgp_table *table;
8370 struct bgp_adj_in *ain;
8371 struct bgp_adj_out *adj;
8372 unsigned long output_count;
8373 struct bgp_node *rn;
8374 int header1 = 1;
8375 struct bgp *bgp;
8376 int header2 = 1;
8377
paulbb46e942003-10-24 19:02:03 +00008378 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00008379
8380 if (! bgp)
8381 return;
8382
8383 table = bgp->rib[afi][safi];
8384
8385 output_count = 0;
8386
8387 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
8388 PEER_STATUS_DEFAULT_ORIGINATE))
8389 {
8390 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
8391 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
8392 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
8393
8394 vty_out (vty, "Originating default network 0.0.0.0%s%s",
8395 VTY_NEWLINE, VTY_NEWLINE);
8396 header1 = 0;
8397 }
8398
8399 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8400 if (in)
8401 {
8402 for (ain = rn->adj_in; ain; ain = ain->next)
8403 if (ain->peer == peer)
8404 {
8405 if (header1)
8406 {
8407 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
8408 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
8409 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
8410 header1 = 0;
8411 }
8412 if (header2)
8413 {
8414 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8415 header2 = 0;
8416 }
8417 if (ain->attr)
8418 {
8419 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
8420 output_count++;
8421 }
8422 }
8423 }
8424 else
8425 {
8426 for (adj = rn->adj_out; adj; adj = adj->next)
8427 if (adj->peer == peer)
8428 {
8429 if (header1)
8430 {
8431 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
8432 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
8433 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
8434 header1 = 0;
8435 }
8436 if (header2)
8437 {
8438 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8439 header2 = 0;
8440 }
8441 if (adj->attr)
8442 {
8443 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
8444 output_count++;
8445 }
8446 }
8447 }
8448
8449 if (output_count != 0)
8450 vty_out (vty, "%sTotal number of prefixes %ld%s",
8451 VTY_NEWLINE, output_count, VTY_NEWLINE);
8452}
8453
8454int
paulbb46e942003-10-24 19:02:03 +00008455peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
8456{
paul718e3742002-12-13 20:15:29 +00008457 if (! peer || ! peer->afc[afi][safi])
8458 {
8459 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8460 return CMD_WARNING;
8461 }
8462
8463 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8464 {
8465 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
8466 VTY_NEWLINE);
8467 return CMD_WARNING;
8468 }
8469
8470 show_adj_route (vty, peer, afi, safi, in);
8471
8472 return CMD_SUCCESS;
8473}
8474
8475DEFUN (show_ip_bgp_neighbor_advertised_route,
8476 show_ip_bgp_neighbor_advertised_route_cmd,
8477 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8478 SHOW_STR
8479 IP_STR
8480 BGP_STR
8481 "Detailed information on TCP and BGP neighbor connections\n"
8482 "Neighbor to display information about\n"
8483 "Neighbor to display information about\n"
8484 "Display the routes advertised to a BGP neighbor\n")
8485{
paulbb46e942003-10-24 19:02:03 +00008486 struct peer *peer;
8487
8488 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8489 if (! peer)
8490 return CMD_WARNING;
8491
8492 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008493}
8494
8495DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
8496 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
8497 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8498 SHOW_STR
8499 IP_STR
8500 BGP_STR
8501 "Address family\n"
8502 "Address Family modifier\n"
8503 "Address Family modifier\n"
8504 "Detailed information on TCP and BGP neighbor connections\n"
8505 "Neighbor to display information about\n"
8506 "Neighbor to display information about\n"
8507 "Display the routes advertised to a BGP neighbor\n")
8508{
paulbb46e942003-10-24 19:02:03 +00008509 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008510
paulbb46e942003-10-24 19:02:03 +00008511 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8512 if (! peer)
8513 return CMD_WARNING;
8514
8515 if (strncmp (argv[0], "m", 1) == 0)
8516 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
8517
8518 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008519}
8520
8521#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008522DEFUN (show_bgp_view_neighbor_advertised_route,
8523 show_bgp_view_neighbor_advertised_route_cmd,
8524 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8525 SHOW_STR
8526 BGP_STR
8527 "BGP view\n"
8528 "View name\n"
8529 "Detailed information on TCP and BGP neighbor connections\n"
8530 "Neighbor to display information about\n"
8531 "Neighbor to display information about\n"
8532 "Display the routes advertised to a BGP neighbor\n")
8533{
8534 struct peer *peer;
8535
8536 if (argc == 2)
8537 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8538 else
8539 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8540
8541 if (! peer)
8542 return CMD_WARNING;
8543
8544 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
8545}
8546
8547ALIAS (show_bgp_view_neighbor_advertised_route,
8548 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
8549 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8550 SHOW_STR
8551 BGP_STR
8552 "BGP view\n"
8553 "View name\n"
8554 "Address family\n"
8555 "Detailed information on TCP and BGP neighbor connections\n"
8556 "Neighbor to display information about\n"
8557 "Neighbor to display information about\n"
8558 "Display the routes advertised to a BGP neighbor\n")
8559
8560DEFUN (show_bgp_view_neighbor_received_routes,
8561 show_bgp_view_neighbor_received_routes_cmd,
8562 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
8563 SHOW_STR
8564 BGP_STR
8565 "BGP view\n"
8566 "View name\n"
8567 "Detailed information on TCP and BGP neighbor connections\n"
8568 "Neighbor to display information about\n"
8569 "Neighbor to display information about\n"
8570 "Display the received routes from neighbor\n")
8571{
8572 struct peer *peer;
8573
8574 if (argc == 2)
8575 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8576 else
8577 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8578
8579 if (! peer)
8580 return CMD_WARNING;
8581
8582 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
8583}
8584
8585ALIAS (show_bgp_view_neighbor_received_routes,
8586 show_bgp_view_ipv6_neighbor_received_routes_cmd,
8587 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8588 SHOW_STR
8589 BGP_STR
8590 "BGP view\n"
8591 "View name\n"
8592 "Address family\n"
8593 "Detailed information on TCP and BGP neighbor connections\n"
8594 "Neighbor to display information about\n"
8595 "Neighbor to display information about\n"
8596 "Display the received routes from neighbor\n")
8597
8598ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008599 show_bgp_neighbor_advertised_route_cmd,
8600 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8601 SHOW_STR
8602 BGP_STR
8603 "Detailed information on TCP and BGP neighbor connections\n"
8604 "Neighbor to display information about\n"
8605 "Neighbor to display information about\n"
8606 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008607
8608ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008609 show_bgp_ipv6_neighbor_advertised_route_cmd,
8610 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8611 SHOW_STR
8612 BGP_STR
8613 "Address family\n"
8614 "Detailed information on TCP and BGP neighbor connections\n"
8615 "Neighbor to display information about\n"
8616 "Neighbor to display information about\n"
8617 "Display the routes advertised to a BGP neighbor\n")
8618
8619/* old command */
paulbb46e942003-10-24 19:02:03 +00008620ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008621 ipv6_bgp_neighbor_advertised_route_cmd,
8622 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8623 SHOW_STR
8624 IPV6_STR
8625 BGP_STR
8626 "Detailed information on TCP and BGP neighbor connections\n"
8627 "Neighbor to display information about\n"
8628 "Neighbor to display information about\n"
8629 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008630
paul718e3742002-12-13 20:15:29 +00008631/* old command */
8632DEFUN (ipv6_mbgp_neighbor_advertised_route,
8633 ipv6_mbgp_neighbor_advertised_route_cmd,
8634 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8635 SHOW_STR
8636 IPV6_STR
8637 MBGP_STR
8638 "Detailed information on TCP and BGP neighbor connections\n"
8639 "Neighbor to display information about\n"
8640 "Neighbor to display information about\n"
8641 "Display the routes advertised to a BGP neighbor\n")
8642{
paulbb46e942003-10-24 19:02:03 +00008643 struct peer *peer;
8644
8645 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8646 if (! peer)
8647 return CMD_WARNING;
8648
8649 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00008650}
8651#endif /* HAVE_IPV6 */
8652
8653DEFUN (show_ip_bgp_neighbor_received_routes,
8654 show_ip_bgp_neighbor_received_routes_cmd,
8655 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8656 SHOW_STR
8657 IP_STR
8658 BGP_STR
8659 "Detailed information on TCP and BGP neighbor connections\n"
8660 "Neighbor to display information about\n"
8661 "Neighbor to display information about\n"
8662 "Display the received routes from neighbor\n")
8663{
paulbb46e942003-10-24 19:02:03 +00008664 struct peer *peer;
8665
8666 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8667 if (! peer)
8668 return CMD_WARNING;
8669
8670 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008671}
8672
8673DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
8674 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
8675 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
8676 SHOW_STR
8677 IP_STR
8678 BGP_STR
8679 "Address family\n"
8680 "Address Family modifier\n"
8681 "Address Family modifier\n"
8682 "Detailed information on TCP and BGP neighbor connections\n"
8683 "Neighbor to display information about\n"
8684 "Neighbor to display information about\n"
8685 "Display the received routes from neighbor\n")
8686{
paulbb46e942003-10-24 19:02:03 +00008687 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008688
paulbb46e942003-10-24 19:02:03 +00008689 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8690 if (! peer)
8691 return CMD_WARNING;
8692
8693 if (strncmp (argv[0], "m", 1) == 0)
8694 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
8695
8696 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008697}
8698
8699DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
8700 show_ip_bgp_neighbor_received_prefix_filter_cmd,
8701 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
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 information received from a BGP neighbor\n"
8709 "Display the prefixlist filter\n")
8710{
8711 char name[BUFSIZ];
8712 union sockunion *su;
8713 struct peer *peer;
8714 int count;
8715
8716 su = sockunion_str2su (argv[0]);
8717 if (su == NULL)
8718 return CMD_WARNING;
8719
8720 peer = peer_lookup (NULL, su);
8721 if (! peer)
8722 return CMD_WARNING;
8723
8724 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8725 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8726 if (count)
8727 {
8728 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8729 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8730 }
8731
8732 return CMD_SUCCESS;
8733}
8734
8735DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
8736 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
8737 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8738 SHOW_STR
8739 IP_STR
8740 BGP_STR
8741 "Address family\n"
8742 "Address Family modifier\n"
8743 "Address Family modifier\n"
8744 "Detailed information on TCP and BGP neighbor connections\n"
8745 "Neighbor to display information about\n"
8746 "Neighbor to display information about\n"
8747 "Display information received from a BGP neighbor\n"
8748 "Display the prefixlist filter\n")
8749{
8750 char name[BUFSIZ];
8751 union sockunion *su;
8752 struct peer *peer;
8753 int count;
8754
8755 su = sockunion_str2su (argv[1]);
8756 if (su == NULL)
8757 return CMD_WARNING;
8758
8759 peer = peer_lookup (NULL, su);
8760 if (! peer)
8761 return CMD_WARNING;
8762
8763 if (strncmp (argv[0], "m", 1) == 0)
8764 {
8765 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
8766 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8767 if (count)
8768 {
8769 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
8770 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8771 }
8772 }
8773 else
8774 {
8775 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8776 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8777 if (count)
8778 {
8779 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8780 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8781 }
8782 }
8783
8784 return CMD_SUCCESS;
8785}
8786
8787
8788#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008789ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008790 show_bgp_neighbor_received_routes_cmd,
8791 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8792 SHOW_STR
8793 BGP_STR
8794 "Detailed information on TCP and BGP neighbor connections\n"
8795 "Neighbor to display information about\n"
8796 "Neighbor to display information about\n"
8797 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008798
paulbb46e942003-10-24 19:02:03 +00008799ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008800 show_bgp_ipv6_neighbor_received_routes_cmd,
8801 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8802 SHOW_STR
8803 BGP_STR
8804 "Address family\n"
8805 "Detailed information on TCP and BGP neighbor connections\n"
8806 "Neighbor to display information about\n"
8807 "Neighbor to display information about\n"
8808 "Display the received routes from neighbor\n")
8809
8810DEFUN (show_bgp_neighbor_received_prefix_filter,
8811 show_bgp_neighbor_received_prefix_filter_cmd,
8812 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8813 SHOW_STR
8814 BGP_STR
8815 "Detailed information on TCP and BGP neighbor connections\n"
8816 "Neighbor to display information about\n"
8817 "Neighbor to display information about\n"
8818 "Display information received from a BGP neighbor\n"
8819 "Display the prefixlist filter\n")
8820{
8821 char name[BUFSIZ];
8822 union sockunion *su;
8823 struct peer *peer;
8824 int count;
8825
8826 su = sockunion_str2su (argv[0]);
8827 if (su == NULL)
8828 return CMD_WARNING;
8829
8830 peer = peer_lookup (NULL, su);
8831 if (! peer)
8832 return CMD_WARNING;
8833
8834 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8835 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8836 if (count)
8837 {
8838 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8839 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8840 }
8841
8842 return CMD_SUCCESS;
8843}
8844
8845ALIAS (show_bgp_neighbor_received_prefix_filter,
8846 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
8847 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8848 SHOW_STR
8849 BGP_STR
8850 "Address family\n"
8851 "Detailed information on TCP and BGP neighbor connections\n"
8852 "Neighbor to display information about\n"
8853 "Neighbor to display information about\n"
8854 "Display information received from a BGP neighbor\n"
8855 "Display the prefixlist filter\n")
8856
8857/* old command */
paulbb46e942003-10-24 19:02:03 +00008858ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008859 ipv6_bgp_neighbor_received_routes_cmd,
8860 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8861 SHOW_STR
8862 IPV6_STR
8863 BGP_STR
8864 "Detailed information on TCP and BGP neighbor connections\n"
8865 "Neighbor to display information about\n"
8866 "Neighbor to display information about\n"
8867 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008868
8869/* old command */
8870DEFUN (ipv6_mbgp_neighbor_received_routes,
8871 ipv6_mbgp_neighbor_received_routes_cmd,
8872 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8873 SHOW_STR
8874 IPV6_STR
8875 MBGP_STR
8876 "Detailed information on TCP and BGP neighbor connections\n"
8877 "Neighbor to display information about\n"
8878 "Neighbor to display information about\n"
8879 "Display the received routes from neighbor\n")
8880{
paulbb46e942003-10-24 19:02:03 +00008881 struct peer *peer;
8882
8883 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8884 if (! peer)
8885 return CMD_WARNING;
8886
8887 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00008888}
paulbb46e942003-10-24 19:02:03 +00008889
8890DEFUN (show_bgp_view_neighbor_received_prefix_filter,
8891 show_bgp_view_neighbor_received_prefix_filter_cmd,
8892 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8893 SHOW_STR
8894 BGP_STR
8895 "BGP view\n"
8896 "View name\n"
8897 "Detailed information on TCP and BGP neighbor connections\n"
8898 "Neighbor to display information about\n"
8899 "Neighbor to display information about\n"
8900 "Display information received from a BGP neighbor\n"
8901 "Display the prefixlist filter\n")
8902{
8903 char name[BUFSIZ];
8904 union sockunion *su;
8905 struct peer *peer;
8906 struct bgp *bgp;
8907 int count;
8908
8909 /* BGP structure lookup. */
8910 bgp = bgp_lookup_by_name (argv[0]);
8911 if (bgp == NULL)
8912 {
8913 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8914 return CMD_WARNING;
8915 }
8916
8917 su = sockunion_str2su (argv[1]);
8918 if (su == NULL)
8919 return CMD_WARNING;
8920
8921 peer = peer_lookup (bgp, su);
8922 if (! peer)
8923 return CMD_WARNING;
8924
8925 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8926 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8927 if (count)
8928 {
8929 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8930 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8931 }
8932
8933 return CMD_SUCCESS;
8934}
8935
8936ALIAS (show_bgp_view_neighbor_received_prefix_filter,
8937 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
8938 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8939 SHOW_STR
8940 BGP_STR
8941 "BGP view\n"
8942 "View name\n"
8943 "Address family\n"
8944 "Detailed information on TCP and BGP neighbor connections\n"
8945 "Neighbor to display information about\n"
8946 "Neighbor to display information about\n"
8947 "Display information received from a BGP neighbor\n"
8948 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00008949#endif /* HAVE_IPV6 */
8950
8951void
8952bgp_show_neighbor_route_clean (struct vty *vty)
8953{
8954 union sockunion *su;
8955
8956 su = vty->output_arg;
8957 XFREE (MTYPE_SOCKUNION, su);
8958}
8959
8960int
paulbb46e942003-10-24 19:02:03 +00008961bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008962 safi_t safi, enum bgp_show_type type)
8963{
paul718e3742002-12-13 20:15:29 +00008964 if (! peer || ! peer->afc[afi][safi])
8965 {
8966 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008967 return CMD_WARNING;
8968 }
8969
paulbb46e942003-10-24 19:02:03 +00008970 vty->output_arg = sockunion_dup (&peer->su);
paul718e3742002-12-13 20:15:29 +00008971 vty->output_clean = bgp_show_neighbor_route_clean;
8972
paulbb46e942003-10-24 19:02:03 +00008973 return bgp_show (vty, peer->bgp, afi, safi, type);
paul718e3742002-12-13 20:15:29 +00008974}
8975
8976DEFUN (show_ip_bgp_neighbor_routes,
8977 show_ip_bgp_neighbor_routes_cmd,
8978 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
8979 SHOW_STR
8980 IP_STR
8981 BGP_STR
8982 "Detailed information on TCP and BGP neighbor connections\n"
8983 "Neighbor to display information about\n"
8984 "Neighbor to display information about\n"
8985 "Display routes learned from neighbor\n")
8986{
paulbb46e942003-10-24 19:02:03 +00008987 struct peer *peer;
8988
8989 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8990 if (! peer)
8991 return CMD_WARNING;
8992
8993 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008994 bgp_show_type_neighbor);
8995}
8996
8997DEFUN (show_ip_bgp_neighbor_flap,
8998 show_ip_bgp_neighbor_flap_cmd,
8999 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9000 SHOW_STR
9001 IP_STR
9002 BGP_STR
9003 "Detailed information on TCP and BGP neighbor connections\n"
9004 "Neighbor to display information about\n"
9005 "Neighbor to display information about\n"
9006 "Display flap statistics of the routes learned from neighbor\n")
9007{
paulbb46e942003-10-24 19:02:03 +00009008 struct peer *peer;
9009
9010 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9011 if (! peer)
9012 return CMD_WARNING;
9013
9014 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009015 bgp_show_type_flap_neighbor);
9016}
9017
9018DEFUN (show_ip_bgp_neighbor_damp,
9019 show_ip_bgp_neighbor_damp_cmd,
9020 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9021 SHOW_STR
9022 IP_STR
9023 BGP_STR
9024 "Detailed information on TCP and BGP neighbor connections\n"
9025 "Neighbor to display information about\n"
9026 "Neighbor to display information about\n"
9027 "Display the dampened routes received from neighbor\n")
9028{
paulbb46e942003-10-24 19:02:03 +00009029 struct peer *peer;
9030
9031 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9032 if (! peer)
9033 return CMD_WARNING;
9034
9035 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009036 bgp_show_type_damp_neighbor);
9037}
9038
9039DEFUN (show_ip_bgp_ipv4_neighbor_routes,
9040 show_ip_bgp_ipv4_neighbor_routes_cmd,
9041 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
9042 SHOW_STR
9043 IP_STR
9044 BGP_STR
9045 "Address family\n"
9046 "Address Family modifier\n"
9047 "Address Family modifier\n"
9048 "Detailed information on TCP and BGP neighbor connections\n"
9049 "Neighbor to display information about\n"
9050 "Neighbor to display information about\n"
9051 "Display routes learned from neighbor\n")
9052{
paulbb46e942003-10-24 19:02:03 +00009053 struct peer *peer;
9054
9055 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9056 if (! peer)
9057 return CMD_WARNING;
9058
paul718e3742002-12-13 20:15:29 +00009059 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00009060 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009061 bgp_show_type_neighbor);
9062
paulbb46e942003-10-24 19:02:03 +00009063 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00009064 bgp_show_type_neighbor);
9065}
paulbb46e942003-10-24 19:02:03 +00009066
paulfee0f4c2004-09-13 05:12:46 +00009067DEFUN (show_ip_bgp_view_rsclient,
9068 show_ip_bgp_view_rsclient_cmd,
9069 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9070 SHOW_STR
9071 IP_STR
9072 BGP_STR
9073 "BGP view\n"
9074 "BGP view name\n"
9075 "Information about Route Server Client\n"
9076 NEIGHBOR_ADDR_STR)
9077{
9078 struct bgp_table *table;
9079 struct peer *peer;
9080
9081 if (argc == 2)
9082 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9083 else
9084 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9085
9086 if (! peer)
9087 return CMD_WARNING;
9088
9089 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9090 {
9091 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9092 VTY_NEWLINE);
9093 return CMD_WARNING;
9094 }
9095
9096 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9097 PEER_FLAG_RSERVER_CLIENT))
9098 {
9099 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9100 VTY_NEWLINE);
9101 return CMD_WARNING;
9102 }
9103
9104 table = peer->rib[AFI_IP][SAFI_UNICAST];
9105
9106 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal);
9107}
9108
9109ALIAS (show_ip_bgp_view_rsclient,
9110 show_ip_bgp_rsclient_cmd,
9111 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
9112 SHOW_STR
9113 IP_STR
9114 BGP_STR
9115 "Information about Route Server Client\n"
9116 NEIGHBOR_ADDR_STR)
9117
9118DEFUN (show_ip_bgp_view_rsclient_route,
9119 show_ip_bgp_view_rsclient_route_cmd,
9120 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9121 SHOW_STR
9122 IP_STR
9123 BGP_STR
9124 "BGP view\n"
9125 "BGP view name\n"
9126 "Information about Route Server Client\n"
9127 NEIGHBOR_ADDR_STR
9128 "Network in the BGP routing table to display\n")
9129{
9130 struct bgp *bgp;
9131 struct peer *peer;
9132
9133 /* BGP structure lookup. */
9134 if (argc == 3)
9135 {
9136 bgp = bgp_lookup_by_name (argv[0]);
9137 if (bgp == NULL)
9138 {
9139 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9140 return CMD_WARNING;
9141 }
9142 }
9143 else
9144 {
9145 bgp = bgp_get_default ();
9146 if (bgp == NULL)
9147 {
9148 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9149 return CMD_WARNING;
9150 }
9151 }
9152
9153 if (argc == 3)
9154 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9155 else
9156 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9157
9158 if (! peer)
9159 return CMD_WARNING;
9160
9161 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9162 {
9163 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9164 VTY_NEWLINE);
9165 return CMD_WARNING;
9166}
9167
9168 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9169 PEER_FLAG_RSERVER_CLIENT))
9170 {
9171 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9172 VTY_NEWLINE);
9173 return CMD_WARNING;
9174 }
9175
9176 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9177 (argc == 3) ? argv[2] : argv[1],
9178 AFI_IP, SAFI_UNICAST, NULL, 0);
9179}
9180
9181ALIAS (show_ip_bgp_view_rsclient_route,
9182 show_ip_bgp_rsclient_route_cmd,
9183 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
9184 SHOW_STR
9185 IP_STR
9186 BGP_STR
9187 "Information about Route Server Client\n"
9188 NEIGHBOR_ADDR_STR
9189 "Network in the BGP routing table to display\n")
9190
9191DEFUN (show_ip_bgp_view_rsclient_prefix,
9192 show_ip_bgp_view_rsclient_prefix_cmd,
9193 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9194 SHOW_STR
9195 IP_STR
9196 BGP_STR
9197 "BGP view\n"
9198 "BGP view name\n"
9199 "Information about Route Server Client\n"
9200 NEIGHBOR_ADDR_STR
9201 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9202{
9203 struct bgp *bgp;
9204 struct peer *peer;
9205
9206 /* BGP structure lookup. */
9207 if (argc == 3)
9208 {
9209 bgp = bgp_lookup_by_name (argv[0]);
9210 if (bgp == NULL)
9211 {
9212 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9213 return CMD_WARNING;
9214 }
9215 }
9216 else
9217 {
9218 bgp = bgp_get_default ();
9219 if (bgp == NULL)
9220 {
9221 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9222 return CMD_WARNING;
9223 }
9224 }
9225
9226 if (argc == 3)
9227 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9228 else
9229 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9230
9231 if (! peer)
9232 return CMD_WARNING;
9233
9234 if (! peer->afc[AFI_IP][SAFI_UNICAST])
9235 {
9236 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9237 VTY_NEWLINE);
9238 return CMD_WARNING;
9239}
9240
9241 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
9242 PEER_FLAG_RSERVER_CLIENT))
9243{
9244 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9245 VTY_NEWLINE);
9246 return CMD_WARNING;
9247 }
9248
9249 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
9250 (argc == 3) ? argv[2] : argv[1],
9251 AFI_IP, SAFI_UNICAST, NULL, 1);
9252}
9253
9254ALIAS (show_ip_bgp_view_rsclient_prefix,
9255 show_ip_bgp_rsclient_prefix_cmd,
9256 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
9257 SHOW_STR
9258 IP_STR
9259 BGP_STR
9260 "Information about Route Server Client\n"
9261 NEIGHBOR_ADDR_STR
9262 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9263
9264
paul718e3742002-12-13 20:15:29 +00009265#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009266DEFUN (show_bgp_view_neighbor_routes,
9267 show_bgp_view_neighbor_routes_cmd,
9268 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
9269 SHOW_STR
9270 BGP_STR
9271 "BGP view\n"
9272 "BGP view name\n"
9273 "Detailed information on TCP and BGP neighbor connections\n"
9274 "Neighbor to display information about\n"
9275 "Neighbor to display information about\n"
9276 "Display routes learned from neighbor\n")
9277{
9278 struct peer *peer;
9279
9280 if (argc == 2)
9281 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9282 else
9283 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9284
9285 if (! peer)
9286 return CMD_WARNING;
9287
9288 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9289 bgp_show_type_neighbor);
9290}
9291
9292ALIAS (show_bgp_view_neighbor_routes,
9293 show_bgp_view_ipv6_neighbor_routes_cmd,
9294 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9295 SHOW_STR
9296 BGP_STR
9297 "BGP view\n"
9298 "BGP view name\n"
9299 "Address family\n"
9300 "Detailed information on TCP and BGP neighbor connections\n"
9301 "Neighbor to display information about\n"
9302 "Neighbor to display information about\n"
9303 "Display routes learned from neighbor\n")
9304
9305DEFUN (show_bgp_view_neighbor_damp,
9306 show_bgp_view_neighbor_damp_cmd,
9307 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9308 SHOW_STR
9309 BGP_STR
9310 "BGP view\n"
9311 "BGP view name\n"
9312 "Detailed information on TCP and BGP neighbor connections\n"
9313 "Neighbor to display information about\n"
9314 "Neighbor to display information about\n"
9315 "Display the dampened routes received from neighbor\n")
9316{
9317 struct peer *peer;
9318
9319 if (argc == 2)
9320 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9321 else
9322 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9323
9324 if (! peer)
9325 return CMD_WARNING;
9326
9327 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9328 bgp_show_type_damp_neighbor);
9329}
9330
9331ALIAS (show_bgp_view_neighbor_damp,
9332 show_bgp_view_ipv6_neighbor_damp_cmd,
9333 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9334 SHOW_STR
9335 BGP_STR
9336 "BGP view\n"
9337 "BGP view name\n"
9338 "Address family\n"
9339 "Detailed information on TCP and BGP neighbor connections\n"
9340 "Neighbor to display information about\n"
9341 "Neighbor to display information about\n"
9342 "Display the dampened routes received from neighbor\n")
9343
9344DEFUN (show_bgp_view_neighbor_flap,
9345 show_bgp_view_neighbor_flap_cmd,
9346 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9347 SHOW_STR
9348 BGP_STR
9349 "BGP view\n"
9350 "BGP view name\n"
9351 "Detailed information on TCP and BGP neighbor connections\n"
9352 "Neighbor to display information about\n"
9353 "Neighbor to display information about\n"
9354 "Display flap statistics of the routes learned from neighbor\n")
9355{
9356 struct peer *peer;
9357
9358 if (argc == 2)
9359 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9360 else
9361 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9362
9363 if (! peer)
9364 return CMD_WARNING;
9365
9366 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9367 bgp_show_type_flap_neighbor);
9368}
9369
9370ALIAS (show_bgp_view_neighbor_flap,
9371 show_bgp_view_ipv6_neighbor_flap_cmd,
9372 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9373 SHOW_STR
9374 BGP_STR
9375 "BGP view\n"
9376 "BGP view name\n"
9377 "Address family\n"
9378 "Detailed information on TCP and BGP neighbor connections\n"
9379 "Neighbor to display information about\n"
9380 "Neighbor to display information about\n"
9381 "Display flap statistics of the routes learned from neighbor\n")
9382
9383ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009384 show_bgp_neighbor_routes_cmd,
9385 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
9386 SHOW_STR
9387 BGP_STR
9388 "Detailed information on TCP and BGP neighbor connections\n"
9389 "Neighbor to display information about\n"
9390 "Neighbor to display information about\n"
9391 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009392
paulbb46e942003-10-24 19:02:03 +00009393
9394ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009395 show_bgp_ipv6_neighbor_routes_cmd,
9396 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9397 SHOW_STR
9398 BGP_STR
9399 "Address family\n"
9400 "Detailed information on TCP and BGP neighbor connections\n"
9401 "Neighbor to display information about\n"
9402 "Neighbor to display information about\n"
9403 "Display routes learned from neighbor\n")
9404
9405/* old command */
paulbb46e942003-10-24 19:02:03 +00009406ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009407 ipv6_bgp_neighbor_routes_cmd,
9408 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
9409 SHOW_STR
9410 IPV6_STR
9411 BGP_STR
9412 "Detailed information on TCP and BGP neighbor connections\n"
9413 "Neighbor to display information about\n"
9414 "Neighbor to display information about\n"
9415 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009416
9417/* old command */
9418DEFUN (ipv6_mbgp_neighbor_routes,
9419 ipv6_mbgp_neighbor_routes_cmd,
9420 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
9421 SHOW_STR
9422 IPV6_STR
9423 MBGP_STR
9424 "Detailed information on TCP and BGP neighbor connections\n"
9425 "Neighbor to display information about\n"
9426 "Neighbor to display information about\n"
9427 "Display routes learned from neighbor\n")
9428{
paulbb46e942003-10-24 19:02:03 +00009429 struct peer *peer;
9430
9431 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9432 if (! peer)
9433 return CMD_WARNING;
9434
9435 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009436 bgp_show_type_neighbor);
9437}
paulbb46e942003-10-24 19:02:03 +00009438
9439ALIAS (show_bgp_view_neighbor_flap,
9440 show_bgp_neighbor_flap_cmd,
9441 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9442 SHOW_STR
9443 BGP_STR
9444 "Detailed information on TCP and BGP neighbor connections\n"
9445 "Neighbor to display information about\n"
9446 "Neighbor to display information about\n"
9447 "Display flap statistics of the routes learned from neighbor\n")
9448
9449ALIAS (show_bgp_view_neighbor_flap,
9450 show_bgp_ipv6_neighbor_flap_cmd,
9451 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9452 SHOW_STR
9453 BGP_STR
9454 "Address family\n"
9455 "Detailed information on TCP and BGP neighbor connections\n"
9456 "Neighbor to display information about\n"
9457 "Neighbor to display information about\n"
9458 "Display flap statistics of the routes learned from neighbor\n")
9459
9460ALIAS (show_bgp_view_neighbor_damp,
9461 show_bgp_neighbor_damp_cmd,
9462 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9463 SHOW_STR
9464 BGP_STR
9465 "Detailed information on TCP and BGP neighbor connections\n"
9466 "Neighbor to display information about\n"
9467 "Neighbor to display information about\n"
9468 "Display the dampened routes received from neighbor\n")
9469
9470ALIAS (show_bgp_view_neighbor_damp,
9471 show_bgp_ipv6_neighbor_damp_cmd,
9472 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9473 SHOW_STR
9474 BGP_STR
9475 "Address family\n"
9476 "Detailed information on TCP and BGP neighbor connections\n"
9477 "Neighbor to display information about\n"
9478 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +00009479 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +00009480
9481DEFUN (show_bgp_view_rsclient,
9482 show_bgp_view_rsclient_cmd,
9483 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9484 SHOW_STR
9485 BGP_STR
9486 "BGP view\n"
9487 "BGP view name\n"
9488 "Information about Route Server Client\n"
9489 NEIGHBOR_ADDR_STR)
9490{
9491 struct bgp_table *table;
9492 struct peer *peer;
9493
9494 if (argc == 2)
9495 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9496 else
9497 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9498
9499 if (! peer)
9500 return CMD_WARNING;
9501
9502 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9503 {
9504 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9505 VTY_NEWLINE);
9506 return CMD_WARNING;
9507 }
9508
9509 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9510 PEER_FLAG_RSERVER_CLIENT))
9511 {
9512 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9513 VTY_NEWLINE);
9514 return CMD_WARNING;
9515 }
9516
9517 table = peer->rib[AFI_IP6][SAFI_UNICAST];
9518
9519 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal);
9520}
9521
9522ALIAS (show_bgp_view_rsclient,
9523 show_bgp_rsclient_cmd,
9524 "show bgp rsclient (A.B.C.D|X:X::X:X)",
9525 SHOW_STR
9526 BGP_STR
9527 "Information about Route Server Client\n"
9528 NEIGHBOR_ADDR_STR)
9529
9530DEFUN (show_bgp_view_rsclient_route,
9531 show_bgp_view_rsclient_route_cmd,
9532 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9533 SHOW_STR
9534 BGP_STR
9535 "BGP view\n"
9536 "BGP view name\n"
9537 "Information about Route Server Client\n"
9538 NEIGHBOR_ADDR_STR
9539 "Network in the BGP routing table to display\n")
9540{
9541 struct bgp *bgp;
9542 struct peer *peer;
9543
9544 /* BGP structure lookup. */
9545 if (argc == 3)
9546 {
9547 bgp = bgp_lookup_by_name (argv[0]);
9548 if (bgp == NULL)
9549 {
9550 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9551 return CMD_WARNING;
9552 }
9553 }
9554 else
9555 {
9556 bgp = bgp_get_default ();
9557 if (bgp == NULL)
9558 {
9559 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9560 return CMD_WARNING;
9561 }
9562 }
9563
9564 if (argc == 3)
9565 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9566 else
9567 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9568
9569 if (! peer)
9570 return CMD_WARNING;
9571
9572 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9573 {
9574 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9575 VTY_NEWLINE);
9576 return CMD_WARNING;
9577 }
9578
9579 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9580 PEER_FLAG_RSERVER_CLIENT))
9581 {
9582 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9583 VTY_NEWLINE);
9584 return CMD_WARNING;
9585 }
9586
9587 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9588 (argc == 3) ? argv[2] : argv[1],
9589 AFI_IP6, SAFI_UNICAST, NULL, 0);
9590}
9591
9592ALIAS (show_bgp_view_rsclient_route,
9593 show_bgp_rsclient_route_cmd,
9594 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9595 SHOW_STR
9596 BGP_STR
9597 "Information about Route Server Client\n"
9598 NEIGHBOR_ADDR_STR
9599 "Network in the BGP routing table to display\n")
9600
9601DEFUN (show_bgp_view_rsclient_prefix,
9602 show_bgp_view_rsclient_prefix_cmd,
9603 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9604 SHOW_STR
9605 BGP_STR
9606 "BGP view\n"
9607 "BGP view name\n"
9608 "Information about Route Server Client\n"
9609 NEIGHBOR_ADDR_STR
9610 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9611{
9612 struct bgp *bgp;
9613 struct peer *peer;
9614
9615 /* BGP structure lookup. */
9616 if (argc == 3)
9617 {
9618 bgp = bgp_lookup_by_name (argv[0]);
9619 if (bgp == NULL)
9620 {
9621 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9622 return CMD_WARNING;
9623 }
9624 }
9625 else
9626 {
9627 bgp = bgp_get_default ();
9628 if (bgp == NULL)
9629 {
9630 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9631 return CMD_WARNING;
9632 }
9633 }
9634
9635 if (argc == 3)
9636 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9637 else
9638 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9639
9640 if (! peer)
9641 return CMD_WARNING;
9642
9643 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9644 {
9645 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9646 VTY_NEWLINE);
9647 return CMD_WARNING;
9648 }
9649
9650 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9651 PEER_FLAG_RSERVER_CLIENT))
9652 {
9653 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9654 VTY_NEWLINE);
9655 return CMD_WARNING;
9656 }
9657
9658 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9659 (argc == 3) ? argv[2] : argv[1],
9660 AFI_IP6, SAFI_UNICAST, NULL, 1);
9661}
9662
9663ALIAS (show_bgp_view_rsclient_prefix,
9664 show_bgp_rsclient_prefix_cmd,
9665 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9666 SHOW_STR
9667 BGP_STR
9668 "Information about Route Server Client\n"
9669 NEIGHBOR_ADDR_STR
9670 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9671
paul718e3742002-12-13 20:15:29 +00009672#endif /* HAVE_IPV6 */
9673
9674struct bgp_table *bgp_distance_table;
9675
9676struct bgp_distance
9677{
9678 /* Distance value for the IP source prefix. */
9679 u_char distance;
9680
9681 /* Name of the access-list to be matched. */
9682 char *access_list;
9683};
9684
9685struct bgp_distance *
9686bgp_distance_new ()
9687{
9688 struct bgp_distance *new;
9689 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
9690 memset (new, 0, sizeof (struct bgp_distance));
9691 return new;
9692}
9693
9694void
9695bgp_distance_free (struct bgp_distance *bdistance)
9696{
9697 XFREE (MTYPE_BGP_DISTANCE, bdistance);
9698}
9699
9700int
paulfd79ac92004-10-13 05:06:08 +00009701bgp_distance_set (struct vty *vty, const char *distance_str,
9702 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009703{
9704 int ret;
9705 struct prefix_ipv4 p;
9706 u_char distance;
9707 struct bgp_node *rn;
9708 struct bgp_distance *bdistance;
9709
9710 ret = str2prefix_ipv4 (ip_str, &p);
9711 if (ret == 0)
9712 {
9713 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9714 return CMD_WARNING;
9715 }
9716
9717 distance = atoi (distance_str);
9718
9719 /* Get BGP distance node. */
9720 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
9721 if (rn->info)
9722 {
9723 bdistance = rn->info;
9724 bgp_unlock_node (rn);
9725 }
9726 else
9727 {
9728 bdistance = bgp_distance_new ();
9729 rn->info = bdistance;
9730 }
9731
9732 /* Set distance value. */
9733 bdistance->distance = distance;
9734
9735 /* Reset access-list configuration. */
9736 if (bdistance->access_list)
9737 {
9738 free (bdistance->access_list);
9739 bdistance->access_list = NULL;
9740 }
9741 if (access_list_str)
9742 bdistance->access_list = strdup (access_list_str);
9743
9744 return CMD_SUCCESS;
9745}
9746
9747int
paulfd79ac92004-10-13 05:06:08 +00009748bgp_distance_unset (struct vty *vty, const char *distance_str,
9749 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009750{
9751 int ret;
9752 struct prefix_ipv4 p;
9753 u_char distance;
9754 struct bgp_node *rn;
9755 struct bgp_distance *bdistance;
9756
9757 ret = str2prefix_ipv4 (ip_str, &p);
9758 if (ret == 0)
9759 {
9760 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9761 return CMD_WARNING;
9762 }
9763
9764 distance = atoi (distance_str);
9765
9766 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
9767 if (! rn)
9768 {
9769 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
9770 return CMD_WARNING;
9771 }
9772
9773 bdistance = rn->info;
9774
9775 if (bdistance->access_list)
9776 free (bdistance->access_list);
9777 bgp_distance_free (bdistance);
9778
9779 rn->info = NULL;
9780 bgp_unlock_node (rn);
9781 bgp_unlock_node (rn);
9782
9783 return CMD_SUCCESS;
9784}
9785
9786void
9787bgp_distance_reset ()
9788{
9789 struct bgp_node *rn;
9790 struct bgp_distance *bdistance;
9791
9792 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
9793 if ((bdistance = rn->info) != NULL)
9794 {
9795 if (bdistance->access_list)
9796 free (bdistance->access_list);
9797 bgp_distance_free (bdistance);
9798 rn->info = NULL;
9799 bgp_unlock_node (rn);
9800 }
9801}
9802
9803/* Apply BGP information to distance method. */
9804u_char
9805bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
9806{
9807 struct bgp_node *rn;
9808 struct prefix_ipv4 q;
9809 struct peer *peer;
9810 struct bgp_distance *bdistance;
9811 struct access_list *alist;
9812 struct bgp_static *bgp_static;
9813
9814 if (! bgp)
9815 return 0;
9816
9817 if (p->family != AF_INET)
9818 return 0;
9819
9820 peer = rinfo->peer;
9821
9822 if (peer->su.sa.sa_family != AF_INET)
9823 return 0;
9824
9825 memset (&q, 0, sizeof (struct prefix_ipv4));
9826 q.family = AF_INET;
9827 q.prefix = peer->su.sin.sin_addr;
9828 q.prefixlen = IPV4_MAX_BITLEN;
9829
9830 /* Check source address. */
9831 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
9832 if (rn)
9833 {
9834 bdistance = rn->info;
9835 bgp_unlock_node (rn);
9836
9837 if (bdistance->access_list)
9838 {
9839 alist = access_list_lookup (AFI_IP, bdistance->access_list);
9840 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
9841 return bdistance->distance;
9842 }
9843 else
9844 return bdistance->distance;
9845 }
9846
9847 /* Backdoor check. */
9848 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
9849 if (rn)
9850 {
9851 bgp_static = rn->info;
9852 bgp_unlock_node (rn);
9853
9854 if (bgp_static->backdoor)
9855 {
9856 if (bgp->distance_local)
9857 return bgp->distance_local;
9858 else
9859 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9860 }
9861 }
9862
9863 if (peer_sort (peer) == BGP_PEER_EBGP)
9864 {
9865 if (bgp->distance_ebgp)
9866 return bgp->distance_ebgp;
9867 return ZEBRA_EBGP_DISTANCE_DEFAULT;
9868 }
9869 else
9870 {
9871 if (bgp->distance_ibgp)
9872 return bgp->distance_ibgp;
9873 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9874 }
9875}
9876
9877DEFUN (bgp_distance,
9878 bgp_distance_cmd,
9879 "distance bgp <1-255> <1-255> <1-255>",
9880 "Define an administrative distance\n"
9881 "BGP distance\n"
9882 "Distance for routes external to the AS\n"
9883 "Distance for routes internal to the AS\n"
9884 "Distance for local routes\n")
9885{
9886 struct bgp *bgp;
9887
9888 bgp = vty->index;
9889
9890 bgp->distance_ebgp = atoi (argv[0]);
9891 bgp->distance_ibgp = atoi (argv[1]);
9892 bgp->distance_local = atoi (argv[2]);
9893 return CMD_SUCCESS;
9894}
9895
9896DEFUN (no_bgp_distance,
9897 no_bgp_distance_cmd,
9898 "no distance bgp <1-255> <1-255> <1-255>",
9899 NO_STR
9900 "Define an administrative distance\n"
9901 "BGP distance\n"
9902 "Distance for routes external to the AS\n"
9903 "Distance for routes internal to the AS\n"
9904 "Distance for local routes\n")
9905{
9906 struct bgp *bgp;
9907
9908 bgp = vty->index;
9909
9910 bgp->distance_ebgp= 0;
9911 bgp->distance_ibgp = 0;
9912 bgp->distance_local = 0;
9913 return CMD_SUCCESS;
9914}
9915
9916ALIAS (no_bgp_distance,
9917 no_bgp_distance2_cmd,
9918 "no distance bgp",
9919 NO_STR
9920 "Define an administrative distance\n"
9921 "BGP distance\n")
9922
9923DEFUN (bgp_distance_source,
9924 bgp_distance_source_cmd,
9925 "distance <1-255> A.B.C.D/M",
9926 "Define an administrative distance\n"
9927 "Administrative distance\n"
9928 "IP source prefix\n")
9929{
9930 bgp_distance_set (vty, argv[0], argv[1], NULL);
9931 return CMD_SUCCESS;
9932}
9933
9934DEFUN (no_bgp_distance_source,
9935 no_bgp_distance_source_cmd,
9936 "no distance <1-255> A.B.C.D/M",
9937 NO_STR
9938 "Define an administrative distance\n"
9939 "Administrative distance\n"
9940 "IP source prefix\n")
9941{
9942 bgp_distance_unset (vty, argv[0], argv[1], NULL);
9943 return CMD_SUCCESS;
9944}
9945
9946DEFUN (bgp_distance_source_access_list,
9947 bgp_distance_source_access_list_cmd,
9948 "distance <1-255> A.B.C.D/M WORD",
9949 "Define an administrative distance\n"
9950 "Administrative distance\n"
9951 "IP source prefix\n"
9952 "Access list name\n")
9953{
9954 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
9955 return CMD_SUCCESS;
9956}
9957
9958DEFUN (no_bgp_distance_source_access_list,
9959 no_bgp_distance_source_access_list_cmd,
9960 "no distance <1-255> A.B.C.D/M WORD",
9961 NO_STR
9962 "Define an administrative distance\n"
9963 "Administrative distance\n"
9964 "IP source prefix\n"
9965 "Access list name\n")
9966{
9967 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
9968 return CMD_SUCCESS;
9969}
9970
9971DEFUN (bgp_damp_set,
9972 bgp_damp_set_cmd,
9973 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
9974 "BGP Specific commands\n"
9975 "Enable route-flap dampening\n"
9976 "Half-life time for the penalty\n"
9977 "Value to start reusing a route\n"
9978 "Value to start suppressing a route\n"
9979 "Maximum duration to suppress a stable route\n")
9980{
9981 struct bgp *bgp;
9982 int half = DEFAULT_HALF_LIFE * 60;
9983 int reuse = DEFAULT_REUSE;
9984 int suppress = DEFAULT_SUPPRESS;
9985 int max = 4 * half;
9986
9987 if (argc == 4)
9988 {
9989 half = atoi (argv[0]) * 60;
9990 reuse = atoi (argv[1]);
9991 suppress = atoi (argv[2]);
9992 max = atoi (argv[3]) * 60;
9993 }
9994 else if (argc == 1)
9995 {
9996 half = atoi (argv[0]) * 60;
9997 max = 4 * half;
9998 }
9999
10000 bgp = vty->index;
10001 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
10002 half, reuse, suppress, max);
10003}
10004
10005ALIAS (bgp_damp_set,
10006 bgp_damp_set2_cmd,
10007 "bgp dampening <1-45>",
10008 "BGP Specific commands\n"
10009 "Enable route-flap dampening\n"
10010 "Half-life time for the penalty\n")
10011
10012ALIAS (bgp_damp_set,
10013 bgp_damp_set3_cmd,
10014 "bgp dampening",
10015 "BGP Specific commands\n"
10016 "Enable route-flap dampening\n")
10017
10018DEFUN (bgp_damp_unset,
10019 bgp_damp_unset_cmd,
10020 "no bgp dampening",
10021 NO_STR
10022 "BGP Specific commands\n"
10023 "Enable route-flap dampening\n")
10024{
10025 struct bgp *bgp;
10026
10027 bgp = vty->index;
10028 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
10029}
10030
10031ALIAS (bgp_damp_unset,
10032 bgp_damp_unset2_cmd,
10033 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
10034 NO_STR
10035 "BGP Specific commands\n"
10036 "Enable route-flap dampening\n"
10037 "Half-life time for the penalty\n"
10038 "Value to start reusing a route\n"
10039 "Value to start suppressing a route\n"
10040 "Maximum duration to suppress a stable route\n")
10041
10042DEFUN (show_ip_bgp_dampened_paths,
10043 show_ip_bgp_dampened_paths_cmd,
10044 "show ip bgp dampened-paths",
10045 SHOW_STR
10046 IP_STR
10047 BGP_STR
10048 "Display paths suppressed due to dampening\n")
10049{
10050 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths);
10051}
10052
10053DEFUN (show_ip_bgp_flap_statistics,
10054 show_ip_bgp_flap_statistics_cmd,
10055 "show ip bgp flap-statistics",
10056 SHOW_STR
10057 IP_STR
10058 BGP_STR
10059 "Display flap statistics of routes\n")
10060{
10061 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_flap_statistics);
10062}
10063
10064/* Display specified route of BGP table. */
10065int
paulfd79ac92004-10-13 05:06:08 +000010066bgp_clear_damp_route (struct vty *vty, const char *view_name,
10067 const char *ip_str, afi_t afi, safi_t safi,
10068 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000010069{
10070 int ret;
10071 struct prefix match;
10072 struct bgp_node *rn;
10073 struct bgp_node *rm;
10074 struct bgp_info *ri;
10075 struct bgp_info *ri_temp;
10076 struct bgp *bgp;
10077 struct bgp_table *table;
10078
10079 /* BGP structure lookup. */
10080 if (view_name)
10081 {
10082 bgp = bgp_lookup_by_name (view_name);
10083 if (bgp == NULL)
10084 {
10085 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
10086 return CMD_WARNING;
10087 }
10088 }
10089 else
10090 {
10091 bgp = bgp_get_default ();
10092 if (bgp == NULL)
10093 {
10094 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
10095 return CMD_WARNING;
10096 }
10097 }
10098
10099 /* Check IP address argument. */
10100 ret = str2prefix (ip_str, &match);
10101 if (! ret)
10102 {
10103 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
10104 return CMD_WARNING;
10105 }
10106
10107 match.family = afi2family (afi);
10108
10109 if (safi == SAFI_MPLS_VPN)
10110 {
10111 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
10112 {
10113 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
10114 continue;
10115
10116 if ((table = rn->info) != NULL)
10117 if ((rm = bgp_node_match (table, &match)) != NULL)
10118 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
10119 {
10120 ri = rm->info;
10121 while (ri)
10122 {
10123 if (ri->damp_info)
10124 {
10125 ri_temp = ri->next;
10126 bgp_damp_info_free (ri->damp_info, 1);
10127 ri = ri_temp;
10128 }
10129 else
10130 ri = ri->next;
10131 }
10132 }
10133 }
10134 }
10135 else
10136 {
10137 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
10138 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
10139 {
10140 ri = rn->info;
10141 while (ri)
10142 {
10143 if (ri->damp_info)
10144 {
10145 ri_temp = ri->next;
10146 bgp_damp_info_free (ri->damp_info, 1);
10147 ri = ri_temp;
10148 }
10149 else
10150 ri = ri->next;
10151 }
10152 }
10153 }
10154
10155 return CMD_SUCCESS;
10156}
10157
10158DEFUN (clear_ip_bgp_dampening,
10159 clear_ip_bgp_dampening_cmd,
10160 "clear ip bgp dampening",
10161 CLEAR_STR
10162 IP_STR
10163 BGP_STR
10164 "Clear route flap dampening information\n")
10165{
10166 bgp_damp_info_clean ();
10167 return CMD_SUCCESS;
10168}
10169
10170DEFUN (clear_ip_bgp_dampening_prefix,
10171 clear_ip_bgp_dampening_prefix_cmd,
10172 "clear ip bgp dampening A.B.C.D/M",
10173 CLEAR_STR
10174 IP_STR
10175 BGP_STR
10176 "Clear route flap dampening information\n"
10177 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10178{
10179 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10180 SAFI_UNICAST, NULL, 1);
10181}
10182
10183DEFUN (clear_ip_bgp_dampening_address,
10184 clear_ip_bgp_dampening_address_cmd,
10185 "clear ip bgp dampening A.B.C.D",
10186 CLEAR_STR
10187 IP_STR
10188 BGP_STR
10189 "Clear route flap dampening information\n"
10190 "Network to clear damping information\n")
10191{
10192 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
10193 SAFI_UNICAST, NULL, 0);
10194}
10195
10196DEFUN (clear_ip_bgp_dampening_address_mask,
10197 clear_ip_bgp_dampening_address_mask_cmd,
10198 "clear ip bgp dampening A.B.C.D A.B.C.D",
10199 CLEAR_STR
10200 IP_STR
10201 BGP_STR
10202 "Clear route flap dampening information\n"
10203 "Network to clear damping information\n"
10204 "Network mask\n")
10205{
10206 int ret;
10207 char prefix_str[BUFSIZ];
10208
10209 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
10210 if (! ret)
10211 {
10212 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
10213 return CMD_WARNING;
10214 }
10215
10216 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
10217 SAFI_UNICAST, NULL, 0);
10218}
10219
10220int
10221bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
10222 afi_t afi, safi_t safi, int *write)
10223{
10224 struct bgp_node *prn;
10225 struct bgp_node *rn;
10226 struct bgp_table *table;
10227 struct prefix *p;
10228 struct prefix_rd *prd;
10229 struct bgp_static *bgp_static;
10230 u_int32_t label;
10231 char buf[SU_ADDRSTRLEN];
10232 char rdbuf[RD_ADDRSTRLEN];
10233
10234 /* Network configuration. */
10235 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
10236 if ((table = prn->info) != NULL)
10237 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10238 if ((bgp_static = rn->info) != NULL)
10239 {
10240 p = &rn->p;
10241 prd = (struct prefix_rd *) &prn->p;
10242
10243 /* "address-family" display. */
10244 bgp_config_write_family_header (vty, afi, safi, write);
10245
10246 /* "network" configuration display. */
10247 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
10248 label = decode_label (bgp_static->tag);
10249
10250 vty_out (vty, " network %s/%d rd %s tag %d",
10251 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10252 p->prefixlen,
10253 rdbuf, label);
10254 vty_out (vty, "%s", VTY_NEWLINE);
10255 }
10256 return 0;
10257}
10258
10259/* Configuration of static route announcement and aggregate
10260 information. */
10261int
10262bgp_config_write_network (struct vty *vty, struct bgp *bgp,
10263 afi_t afi, safi_t safi, int *write)
10264{
10265 struct bgp_node *rn;
10266 struct prefix *p;
10267 struct bgp_static *bgp_static;
10268 struct bgp_aggregate *bgp_aggregate;
10269 char buf[SU_ADDRSTRLEN];
10270
10271 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
10272 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
10273
10274 /* Network configuration. */
10275 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
10276 if ((bgp_static = rn->info) != NULL)
10277 {
10278 p = &rn->p;
10279
10280 /* "address-family" display. */
10281 bgp_config_write_family_header (vty, afi, safi, write);
10282
10283 /* "network" configuration display. */
10284 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10285 {
10286 u_int32_t destination;
10287 struct in_addr netmask;
10288
10289 destination = ntohl (p->u.prefix4.s_addr);
10290 masklen2ip (p->prefixlen, &netmask);
10291 vty_out (vty, " network %s",
10292 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
10293
10294 if ((IN_CLASSC (destination) && p->prefixlen == 24)
10295 || (IN_CLASSB (destination) && p->prefixlen == 16)
10296 || (IN_CLASSA (destination) && p->prefixlen == 8)
10297 || p->u.prefix4.s_addr == 0)
10298 {
10299 /* Natural mask is not display. */
10300 }
10301 else
10302 vty_out (vty, " mask %s", inet_ntoa (netmask));
10303 }
10304 else
10305 {
10306 vty_out (vty, " network %s/%d",
10307 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10308 p->prefixlen);
10309 }
10310
10311 if (bgp_static->rmap.name)
10312 vty_out (vty, " route-map %s", bgp_static->rmap.name);
10313 else if (bgp_static->backdoor)
10314 vty_out (vty, " backdoor");
10315
10316 vty_out (vty, "%s", VTY_NEWLINE);
10317 }
10318
10319 /* Aggregate-address configuration. */
10320 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
10321 if ((bgp_aggregate = rn->info) != NULL)
10322 {
10323 p = &rn->p;
10324
10325 /* "address-family" display. */
10326 bgp_config_write_family_header (vty, afi, safi, write);
10327
10328 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10329 {
10330 struct in_addr netmask;
10331
10332 masklen2ip (p->prefixlen, &netmask);
10333 vty_out (vty, " aggregate-address %s %s",
10334 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10335 inet_ntoa (netmask));
10336 }
10337 else
10338 {
10339 vty_out (vty, " aggregate-address %s/%d",
10340 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10341 p->prefixlen);
10342 }
10343
10344 if (bgp_aggregate->as_set)
10345 vty_out (vty, " as-set");
10346
10347 if (bgp_aggregate->summary_only)
10348 vty_out (vty, " summary-only");
10349
10350 vty_out (vty, "%s", VTY_NEWLINE);
10351 }
10352
10353 return 0;
10354}
10355
10356int
10357bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
10358{
10359 struct bgp_node *rn;
10360 struct bgp_distance *bdistance;
10361
10362 /* Distance configuration. */
10363 if (bgp->distance_ebgp
10364 && bgp->distance_ibgp
10365 && bgp->distance_local
10366 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
10367 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
10368 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
10369 vty_out (vty, " distance bgp %d %d %d%s",
10370 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
10371 VTY_NEWLINE);
10372
10373 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10374 if ((bdistance = rn->info) != NULL)
10375 {
10376 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
10377 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
10378 bdistance->access_list ? bdistance->access_list : "",
10379 VTY_NEWLINE);
10380 }
10381
10382 return 0;
10383}
10384
10385/* Allocate routing table structure and install commands. */
10386void
10387bgp_route_init ()
10388{
10389 /* Init BGP distance table. */
10390 bgp_distance_table = bgp_table_init ();
10391
10392 /* IPv4 BGP commands. */
10393 install_element (BGP_NODE, &bgp_network_cmd);
10394 install_element (BGP_NODE, &bgp_network_mask_cmd);
10395 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
10396 install_element (BGP_NODE, &bgp_network_route_map_cmd);
10397 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
10398 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
10399 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
10400 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
10401 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
10402 install_element (BGP_NODE, &no_bgp_network_cmd);
10403 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
10404 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
10405 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
10406 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
10407 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10408 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
10409 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
10410 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
10411
10412 install_element (BGP_NODE, &aggregate_address_cmd);
10413 install_element (BGP_NODE, &aggregate_address_mask_cmd);
10414 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
10415 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
10416 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
10417 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
10418 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
10419 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
10420 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
10421 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
10422 install_element (BGP_NODE, &no_aggregate_address_cmd);
10423 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
10424 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
10425 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
10426 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
10427 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
10428 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
10429 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
10430 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10431 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10432
10433 /* IPv4 unicast configuration. */
10434 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
10435 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
10436 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
10437 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
10438 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
10439 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
10440 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
10441 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
10442 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
10443 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
10444 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
10445 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10446 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
10447 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
10448 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
10449 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
10450 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
10451 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
10452 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
10453 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
10454 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
10455 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
10456 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
10457 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
10458 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
10459 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
10460 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
10461 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
10462 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
10463 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
10464 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10465 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10466
10467 /* IPv4 multicast configuration. */
10468 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
10469 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
10470 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
10471 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
10472 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
10473 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
10474 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
10475 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
10476 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
10477 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
10478 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
10479 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10480 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
10481 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
10482 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
10483 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
10484 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
10485 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
10486 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
10487 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
10488 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
10489 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
10490 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
10491 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
10492 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
10493 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
10494 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
10495 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
10496 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
10497 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
10498 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10499 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10500
10501 install_element (VIEW_NODE, &show_ip_bgp_cmd);
10502 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
10503 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
10504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
10505 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10506 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10507 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
10508 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10509 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10510 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10511 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
10512 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
10513 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
10514 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
10515 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10516 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
10517 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10518 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
10519 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10520 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
10521 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10522 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
10523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10524 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
10525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10526 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
10527 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
10528 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
10529 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
10530 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
10531 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
10532 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
10533 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
10534 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
10535 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
10536 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
10537 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
10538 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10539 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10540 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10541 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10542 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
10543 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10544 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
10545 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10546 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
10547 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10548 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10549 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10550 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10551 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10552 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
10553 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10554 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10555 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10556 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
10557 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
10558 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
10559 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
10560 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10561 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
10562 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
10563 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10564 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10565 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
10566 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
10567 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010568 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
10569 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
10570 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10571 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
10572 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10573 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010574
10575 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
10576 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
10577 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
10578 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
10579 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10580 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10581 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
10582 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10583 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10584 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10585 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
10586 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
10587 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
10588 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
10589 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10590 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
10591 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10592 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
10593 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10594 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
10595 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10596 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
10597 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10598 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
10599 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10600 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
10601 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
10602 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
10603 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
10604 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
10605 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
10606 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
10607 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
10608 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
10609 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
10610 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
10611 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
10612 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10613 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10614 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10615 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10616 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
10617 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10618 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
10619 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10620 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
10621 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10622 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10623 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10624 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10625 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10626 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
10627 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10628 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10629 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10630 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
10631 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
10632 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
10633 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
10634 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10635 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
10636 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
10637 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10638 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10639 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
10640 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
10641 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010642 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
10643 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
10644 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10645 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
10646 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10647 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010648
10649 /* BGP dampening clear commands */
10650 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
10651 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
10652 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
10653 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
10654
10655#ifdef HAVE_IPV6
10656 /* New config IPv6 BGP commands. */
10657 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
10658 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
10659 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
10660 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
10661
10662 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
10663 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
10664 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
10665 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
10666
10667 /* Old config IPv6 BGP commands. */
10668 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
10669 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
10670
10671 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
10672 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
10673 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
10674 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
10675
10676 install_element (VIEW_NODE, &show_bgp_cmd);
10677 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
10678 install_element (VIEW_NODE, &show_bgp_route_cmd);
10679 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
10680 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
10681 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
10682 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
10683 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
10684 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
10685 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
10686 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
10687 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
10688 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
10689 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
10690 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
10691 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
10692 install_element (VIEW_NODE, &show_bgp_community_cmd);
10693 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
10694 install_element (VIEW_NODE, &show_bgp_community2_cmd);
10695 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
10696 install_element (VIEW_NODE, &show_bgp_community3_cmd);
10697 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
10698 install_element (VIEW_NODE, &show_bgp_community4_cmd);
10699 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
10700 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
10701 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
10702 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
10703 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
10704 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
10705 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
10706 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
10707 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
10708 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
10709 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
10710 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
10711 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10712 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
10713 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10714 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
10715 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10716 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
10717 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10718 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
10719 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10720 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10721 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010722 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
10723 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10724 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
10725 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010726 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
10727 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
10728 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010729 install_element (VIEW_NODE, &show_bgp_view_cmd);
10730 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
10731 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
10732 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
10733 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
10734 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
10735 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10736 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10737 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10738 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10739 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
10740 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10741 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10742 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10743 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
10744 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10745 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
10746 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010747 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
10748 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
10749 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010750
10751 install_element (ENABLE_NODE, &show_bgp_cmd);
10752 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
10753 install_element (ENABLE_NODE, &show_bgp_route_cmd);
10754 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
10755 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
10756 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
10757 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
10758 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
10759 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
10760 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
10761 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
10762 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
10763 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
10764 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
10765 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
10766 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
10767 install_element (ENABLE_NODE, &show_bgp_community_cmd);
10768 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
10769 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
10770 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
10771 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
10772 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
10773 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
10774 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
10775 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
10776 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
10777 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
10778 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
10779 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
10780 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
10781 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
10782 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
10783 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
10784 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
10785 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
10786 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10787 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
10788 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10789 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
10790 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10791 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
10792 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10793 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
10794 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10795 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10796 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010797 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
10798 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10799 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
10800 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010801 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
10802 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
10803 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010804 install_element (ENABLE_NODE, &show_bgp_view_cmd);
10805 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
10806 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
10807 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
10808 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
10809 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
10810 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10811 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10812 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10813 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10814 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
10815 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10816 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10817 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10818 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
10819 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10820 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
10821 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010822 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
10823 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
10824 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010825
10826 /* old command */
10827 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
10828 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
10829 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
10830 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
10831 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
10832 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
10833 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
10834 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
10835 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
10836 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
10837 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
10838 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
10839 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
10840 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
10841 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
10842 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
10843 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10844 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10845 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
10846 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
10847 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
10848 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
10849 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10850 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
10851 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
10852 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
10853 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
10854 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
10855 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
10856 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
10857 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10858 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10859 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10860 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
10861 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10862 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000010863
paul718e3742002-12-13 20:15:29 +000010864 /* old command */
10865 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
10866 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
10867 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
10868 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
10869 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
10870 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
10871 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
10872 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
10873 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
10874 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
10875 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
10876 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
10877 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
10878 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
10879 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
10880 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
10881 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10882 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10883 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
10884 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
10885 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
10886 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
10887 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10888 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
10889 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
10890 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
10891 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
10892 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
10893 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
10894 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
10895 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10896 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10897 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10898 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
10899 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10900 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
10901
10902 /* old command */
10903 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10904 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10905 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10906 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10907
10908 /* old command */
10909 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10910 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10911 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10912 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10913
10914 /* old command */
10915 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
10916 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
10917 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10918 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10919#endif /* HAVE_IPV6 */
10920
10921 install_element (BGP_NODE, &bgp_distance_cmd);
10922 install_element (BGP_NODE, &no_bgp_distance_cmd);
10923 install_element (BGP_NODE, &no_bgp_distance2_cmd);
10924 install_element (BGP_NODE, &bgp_distance_source_cmd);
10925 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
10926 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
10927 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
10928
10929 install_element (BGP_NODE, &bgp_damp_set_cmd);
10930 install_element (BGP_NODE, &bgp_damp_set2_cmd);
10931 install_element (BGP_NODE, &bgp_damp_set3_cmd);
10932 install_element (BGP_NODE, &bgp_damp_unset_cmd);
10933 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
10934 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
10935 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
10936 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
10937 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
10938 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
10939}