blob: 16fcc89f7b12a5a6b8a821d40cb606fad70c2535 [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))
ajsd2c1f162004-12-08 21:10:20 +0000599 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000600 "%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))
ajsd2c1f162004-12-08 21:10:20 +0000622 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000623 "%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))
ajsd2c1f162004-12-08 21:10:20 +0000635 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000636 "%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))
ajsd2c1f162004-12-08 21:10:20 +0000648 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000649 "%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))
ajsd2c1f162004-12-08 21:10:20 +0000875 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000876 "%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))
ajsd2c1f162004-12-08 21:10:20 +0000898 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000899 "%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))
ajsd2c1f162004-12-08 21:10:20 +0000911 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +0000912 "%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))
ajsd2c1f162004-12-08 21:10:20 +00001482 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001483 "%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))
ajsd2c1f162004-12-08 21:10:20 +00001496 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001497 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 {
ajsd2c1f162004-12-08 21:10:20 +00001524 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001525 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))
ajsd2c1f162004-12-08 21:10:20 +00001556 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001557 "%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))
ajsd2c1f162004-12-08 21:10:20 +00001593 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001594 "%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))
ajsd2c1f162004-12-08 21:10:20 +00001727 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00001728 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))
ajsd2c1f162004-12-08 21:10:20 +00001743 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00001744 "%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))
ajsd2c1f162004-12-08 21:10:20 +00001757 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00001758 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 {
ajsd2c1f162004-12-08 21:10:20 +00001826 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00001827 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))
ajsd2c1f162004-12-08 21:10:20 +00001882 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00001883 "%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))
ajsd2c1f162004-12-08 21:10:20 +00001945 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00001946 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))
ajsd2c1f162004-12-08 21:10:20 +00001968 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00001969 "%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
paul718e3742002-12-13 20:15:29 +00002251 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002252 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002253 else
2254 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2255 rn = bgp_route_next (rn))
2256 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002257 bgp_clear_route_table (peer, afi, safi, table, NULL);
2258
2259 LIST_LOOP (peer->bgp->rsclient, rsclient, nn)
2260 {
2261 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2262 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2263 }
paul718e3742002-12-13 20:15:29 +00002264}
2265
2266void
2267bgp_clear_route_all (struct peer *peer)
2268{
2269 afi_t afi;
2270 safi_t safi;
2271
2272 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2273 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2274 bgp_clear_route (peer, afi, safi);
2275}
2276
2277void
2278bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2279{
2280 struct bgp_table *table;
2281 struct bgp_node *rn;
2282 struct bgp_adj_in *ain;
2283
2284 table = peer->bgp->rib[afi][safi];
2285
2286 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2287 for (ain = rn->adj_in; ain ; ain = ain->next)
2288 if (ain->peer == peer)
2289 {
2290 bgp_adj_in_remove (rn, ain);
2291 bgp_unlock_node (rn);
2292 break;
2293 }
2294}
2295
2296/* Delete all kernel routes. */
2297void
paul545acaf2004-04-20 15:13:15 +00002298bgp_cleanup_routes ()
paul718e3742002-12-13 20:15:29 +00002299{
2300 struct bgp *bgp;
2301 struct listnode *nn;
2302 struct bgp_node *rn;
2303 struct bgp_table *table;
2304 struct bgp_info *ri;
2305
2306 LIST_LOOP (bm->bgp, bgp, nn)
2307 {
2308 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2309
2310 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2311 for (ri = rn->info; ri; ri = ri->next)
2312 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2313 && ri->type == ZEBRA_ROUTE_BGP
2314 && ri->sub_type == BGP_ROUTE_NORMAL)
2315 bgp_zebra_withdraw (&rn->p, ri);
2316
2317 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2318
2319 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2320 for (ri = rn->info; ri; ri = ri->next)
2321 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2322 && ri->type == ZEBRA_ROUTE_BGP
2323 && ri->sub_type == BGP_ROUTE_NORMAL)
2324 bgp_zebra_withdraw (&rn->p, ri);
2325 }
2326}
2327
2328void
2329bgp_reset ()
2330{
2331 vty_reset ();
2332 bgp_zclient_reset ();
2333 access_list_reset ();
2334 prefix_list_reset ();
2335}
2336
2337/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2338 value. */
2339int
2340bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2341{
2342 u_char *pnt;
2343 u_char *lim;
2344 struct prefix p;
2345 int psize;
2346 int ret;
2347
2348 /* Check peer status. */
2349 if (peer->status != Established)
2350 return 0;
2351
2352 pnt = packet->nlri;
2353 lim = pnt + packet->length;
2354
2355 for (; pnt < lim; pnt += psize)
2356 {
2357 /* Clear prefix structure. */
2358 memset (&p, 0, sizeof (struct prefix));
2359
2360 /* Fetch prefix length. */
2361 p.prefixlen = *pnt++;
2362 p.family = afi2family (packet->afi);
2363
2364 /* Already checked in nlri_sanity_check(). We do double check
2365 here. */
2366 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2367 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2368 return -1;
2369
2370 /* Packet size overflow check. */
2371 psize = PSIZE (p.prefixlen);
2372
2373 /* When packet overflow occur return immediately. */
2374 if (pnt + psize > lim)
2375 return -1;
2376
2377 /* Fetch prefix from NLRI packet. */
2378 memcpy (&p.u.prefix, pnt, psize);
2379
2380 /* Check address. */
2381 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
2382 {
2383 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
2384 {
paulf5ba3872004-07-09 12:11:31 +00002385 /*
2386 * From draft-ietf-idr-bgp4-22, Section 6.3:
2387 * If a BGP router receives an UPDATE message with a
2388 * semantically incorrect NLRI field, in which a prefix is
2389 * semantically incorrect (eg. an unexpected multicast IP
2390 * address), it should ignore the prefix.
2391 */
paul718e3742002-12-13 20:15:29 +00002392 zlog (peer->log, LOG_ERR,
2393 "IPv4 unicast NLRI is multicast address %s",
2394 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00002395
paul718e3742002-12-13 20:15:29 +00002396 return -1;
2397 }
2398 }
2399
2400#ifdef HAVE_IPV6
2401 /* Check address. */
2402 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
2403 {
2404 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2405 {
2406 char buf[BUFSIZ];
2407
2408 zlog (peer->log, LOG_WARNING,
2409 "IPv6 link-local NLRI received %s ignore this NLRI",
2410 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
2411
2412 continue;
2413 }
2414 }
2415#endif /* HAVE_IPV6 */
2416
2417 /* Normal process. */
2418 if (attr)
2419 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
2420 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
2421 else
2422 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
2423 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2424
2425 /* Address family configuration mismatch or maximum-prefix count
2426 overflow. */
2427 if (ret < 0)
2428 return -1;
2429 }
2430
2431 /* Packet length consistency check. */
2432 if (pnt != lim)
2433 return -1;
2434
2435 return 0;
2436}
2437
2438/* NLRI encode syntax check routine. */
2439int
2440bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
2441 bgp_size_t length)
2442{
2443 u_char *end;
2444 u_char prefixlen;
2445 int psize;
2446
2447 end = pnt + length;
2448
2449 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
2450 syntactic validity. If the field is syntactically incorrect,
2451 then the Error Subcode is set to Invalid Network Field. */
2452
2453 while (pnt < end)
2454 {
2455 prefixlen = *pnt++;
2456
2457 /* Prefix length check. */
2458 if ((afi == AFI_IP && prefixlen > 32)
2459 || (afi == AFI_IP6 && prefixlen > 128))
2460 {
2461 plog_err (peer->log,
2462 "%s [Error] Update packet error (wrong prefix length %d)",
2463 peer->host, prefixlen);
2464 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2465 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2466 return -1;
2467 }
2468
2469 /* Packet size overflow check. */
2470 psize = PSIZE (prefixlen);
2471
2472 if (pnt + psize > end)
2473 {
2474 plog_err (peer->log,
2475 "%s [Error] Update packet error"
2476 " (prefix data overflow prefix size is %d)",
2477 peer->host, psize);
2478 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2479 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2480 return -1;
2481 }
2482
2483 pnt += psize;
2484 }
2485
2486 /* Packet length consistency check. */
2487 if (pnt != end)
2488 {
2489 plog_err (peer->log,
2490 "%s [Error] Update packet error"
2491 " (prefix length mismatch with total length)",
2492 peer->host);
2493 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
2494 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
2495 return -1;
2496 }
2497 return 0;
2498}
2499
2500struct bgp_static *
2501bgp_static_new ()
2502{
2503 struct bgp_static *new;
2504 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
2505 memset (new, 0, sizeof (struct bgp_static));
2506 return new;
2507}
2508
2509void
2510bgp_static_free (struct bgp_static *bgp_static)
2511{
2512 if (bgp_static->rmap.name)
2513 free (bgp_static->rmap.name);
2514 XFREE (MTYPE_BGP_STATIC, bgp_static);
2515}
2516
2517void
paulfee0f4c2004-09-13 05:12:46 +00002518bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
2519 struct prefix *p, afi_t afi, safi_t safi)
2520{
2521 struct bgp_node *rn;
2522 struct bgp_info *ri;
2523
2524 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2525
2526 /* Check selected route and self inserted route. */
2527 for (ri = rn->info; ri; ri = ri->next)
2528 if (ri->peer == bgp->peer_self
2529 && ri->type == ZEBRA_ROUTE_BGP
2530 && ri->sub_type == BGP_ROUTE_STATIC)
2531 break;
2532
2533 /* Withdraw static BGP route from routing table. */
2534 if (ri)
2535 {
2536 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2537 bgp_process (bgp, rn, afi, safi);
2538 bgp_info_delete (rn, ri);
2539 bgp_info_free (ri);
2540 bgp_unlock_node (rn);
2541 }
2542
2543 /* Unlock bgp_node_lookup. */
2544 bgp_unlock_node (rn);
2545}
2546
2547void
2548bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
2549 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
2550{
2551 struct bgp_node *rn;
2552 struct bgp_info *ri;
2553 struct bgp_info *new;
2554 struct bgp_info info;
2555 struct attr new_attr;
2556 struct attr *attr_new;
2557 struct attr attr;
2558 struct bgp *bgp;
2559 int ret;
2560 char buf[SU_ADDRSTRLEN];
2561
2562 bgp = rsclient->bgp;
2563
2564 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
2565
2566 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2567 if (bgp_static)
2568 {
2569 attr.nexthop = bgp_static->igpnexthop;
2570 attr.med = bgp_static->igpmetric;
2571 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
2572 }
2573
2574 new_attr = attr;
2575
2576 /* Apply network route-map for export to this rsclient. */
2577 if (bgp_static->rmap.name)
2578 {
2579 info.peer = rsclient;
2580 info.attr = &new_attr;
2581
2582 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
2583 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
2584
2585 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
2586
2587 rsclient->rmap_type = 0;
2588
2589 if (ret == RMAP_DENYMATCH)
2590 {
2591 /* Free uninterned attribute. */
2592 bgp_attr_flush (&new_attr);
2593
2594 /* Unintern original. */
2595 aspath_unintern (attr.aspath);
2596 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2597
2598 return;
2599 }
2600 attr_new = bgp_attr_intern (&new_attr);
2601 }
2602 else
2603 attr_new = bgp_attr_intern (&attr);
2604
2605 new_attr = *attr_new;
2606
2607 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
2608
2609 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) == RMAP_DENY)
2610{
2611 /* This BGP update is filtered. Log the reason then update BGP entry. */
2612 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002613 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002614 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
2615 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2616 p->prefixlen, rsclient->host);
2617
2618 bgp->peer_self->rmap_type = 0;
2619
2620 bgp_attr_unintern (attr_new);
2621 aspath_unintern (attr.aspath);
2622
2623 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
2624
2625 return;
2626 }
2627
2628 bgp->peer_self->rmap_type = 0;
2629
2630 bgp_attr_unintern (attr_new);
2631 attr_new = bgp_attr_intern (&new_attr);
2632
2633 for (ri = rn->info; ri; ri = ri->next)
2634 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
2635 && ri->sub_type == BGP_ROUTE_STATIC)
2636 break;
2637
2638 if (ri)
2639 {
2640 if (attrhash_cmp (ri->attr, attr_new))
2641 {
2642 bgp_unlock_node (rn);
2643 bgp_attr_unintern (attr_new);
2644 aspath_unintern (attr.aspath);
2645 return;
2646 }
2647 else
2648 {
2649 /* The attribute is changed. */
2650 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
2651
2652 /* Rewrite BGP route information. */
2653 bgp_attr_unintern (ri->attr);
2654 ri->attr = attr_new;
2655 ri->uptime = time (NULL);
2656
2657 /* Process change. */
2658 bgp_process (bgp, rn, afi, safi);
2659 bgp_unlock_node (rn);
2660 aspath_unintern (attr.aspath);
2661 return;
2662 }
2663}
2664
2665 /* Make new BGP info. */
2666 new = bgp_info_new ();
2667 new->type = ZEBRA_ROUTE_BGP;
2668 new->sub_type = BGP_ROUTE_STATIC;
2669 new->peer = bgp->peer_self;
2670 SET_FLAG (new->flags, BGP_INFO_VALID);
2671 new->attr = attr_new;
2672 new->uptime = time (NULL);
2673
2674 /* Register new BGP information. */
2675 bgp_info_add (rn, new);
2676
2677 /* Process change. */
2678 bgp_process (bgp, rn, afi, safi);
2679
2680 /* Unintern original. */
2681 aspath_unintern (attr.aspath);
2682}
2683
2684void
2685bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00002686 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
2687{
2688 struct bgp_node *rn;
2689 struct bgp_info *ri;
2690 struct bgp_info *new;
2691 struct bgp_info info;
2692 struct attr attr;
paul286e1e72003-08-08 00:24:31 +00002693 struct attr attr_tmp;
paul718e3742002-12-13 20:15:29 +00002694 struct attr *attr_new;
2695 int ret;
2696
paulfee0f4c2004-09-13 05:12:46 +00002697 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00002698
2699 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2700 if (bgp_static)
2701 {
2702 attr.nexthop = bgp_static->igpnexthop;
2703 attr.med = bgp_static->igpmetric;
2704 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
2705 }
2706
2707 /* Apply route-map. */
2708 if (bgp_static->rmap.name)
2709 {
paul286e1e72003-08-08 00:24:31 +00002710 attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00002711 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00002712 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00002713
paulfee0f4c2004-09-13 05:12:46 +00002714 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
2715
paul718e3742002-12-13 20:15:29 +00002716 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00002717
paulfee0f4c2004-09-13 05:12:46 +00002718 bgp->peer_self->rmap_type = 0;
2719
paul718e3742002-12-13 20:15:29 +00002720 if (ret == RMAP_DENYMATCH)
2721 {
2722 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00002723 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00002724
2725 /* Unintern original. */
2726 aspath_unintern (attr.aspath);
2727 bgp_static_withdraw (bgp, p, afi, safi);
2728 return;
2729 }
paul286e1e72003-08-08 00:24:31 +00002730 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00002731 }
paul286e1e72003-08-08 00:24:31 +00002732 else
2733 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00002734
2735 for (ri = rn->info; ri; ri = ri->next)
2736 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
2737 && ri->sub_type == BGP_ROUTE_STATIC)
2738 break;
2739
2740 if (ri)
2741 {
2742 if (attrhash_cmp (ri->attr, attr_new))
2743 {
2744 bgp_unlock_node (rn);
2745 bgp_attr_unintern (attr_new);
2746 aspath_unintern (attr.aspath);
2747 return;
2748 }
2749 else
2750 {
2751 /* The attribute is changed. */
2752 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
2753
2754 /* Rewrite BGP route information. */
2755 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2756 bgp_attr_unintern (ri->attr);
2757 ri->attr = attr_new;
2758 ri->uptime = time (NULL);
2759
2760 /* Process change. */
2761 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2762 bgp_process (bgp, rn, afi, safi);
2763 bgp_unlock_node (rn);
2764 aspath_unintern (attr.aspath);
2765 return;
2766 }
2767 }
2768
2769 /* Make new BGP info. */
2770 new = bgp_info_new ();
2771 new->type = ZEBRA_ROUTE_BGP;
2772 new->sub_type = BGP_ROUTE_STATIC;
2773 new->peer = bgp->peer_self;
2774 SET_FLAG (new->flags, BGP_INFO_VALID);
2775 new->attr = attr_new;
2776 new->uptime = time (NULL);
2777
2778 /* Aggregate address increment. */
2779 bgp_aggregate_increment (bgp, p, new, afi, safi);
2780
2781 /* Register new BGP information. */
2782 bgp_info_add (rn, new);
2783
2784 /* Process change. */
2785 bgp_process (bgp, rn, afi, safi);
2786
2787 /* Unintern original. */
2788 aspath_unintern (attr.aspath);
2789}
2790
2791void
paulfee0f4c2004-09-13 05:12:46 +00002792bgp_static_update (struct bgp *bgp, struct prefix *p,
2793 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
2794{
2795 struct peer *rsclient;
2796 struct listnode *nn;
2797
2798 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
2799
2800 LIST_LOOP(bgp->rsclient, rsclient, nn)
2801 {
2802 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
2803 }
2804}
2805
2806void
paul718e3742002-12-13 20:15:29 +00002807bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
2808 u_char safi, struct prefix_rd *prd, u_char *tag)
2809{
2810 struct bgp_node *rn;
2811 struct bgp_info *new;
2812
paulfee0f4c2004-09-13 05:12:46 +00002813 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002814
2815 /* Make new BGP info. */
2816 new = bgp_info_new ();
2817 new->type = ZEBRA_ROUTE_BGP;
2818 new->sub_type = BGP_ROUTE_STATIC;
2819 new->peer = bgp->peer_self;
2820 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
2821 SET_FLAG (new->flags, BGP_INFO_VALID);
2822 new->uptime = time (NULL);
2823 memcpy (new->tag, tag, 3);
2824
2825 /* Aggregate address increment. */
2826 bgp_aggregate_increment (bgp, p, (struct bgp_info *) new, afi, safi);
2827
2828 /* Register new BGP information. */
2829 bgp_info_add (rn, (struct bgp_info *) new);
2830
2831 /* Process change. */
2832 bgp_process (bgp, rn, afi, safi);
2833}
2834
2835void
2836bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
2837 safi_t safi)
2838{
2839 struct bgp_node *rn;
2840 struct bgp_info *ri;
2841
paulfee0f4c2004-09-13 05:12:46 +00002842 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00002843
2844 /* Check selected route and self inserted route. */
2845 for (ri = rn->info; ri; ri = ri->next)
2846 if (ri->peer == bgp->peer_self
2847 && ri->type == ZEBRA_ROUTE_BGP
2848 && ri->sub_type == BGP_ROUTE_STATIC)
2849 break;
2850
2851 /* Withdraw static BGP route from routing table. */
2852 if (ri)
2853 {
2854 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2855 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2856 bgp_process (bgp, rn, afi, safi);
2857 bgp_info_delete (rn, ri);
2858 bgp_info_free (ri);
2859 bgp_unlock_node (rn);
2860 }
2861
2862 /* Unlock bgp_node_lookup. */
2863 bgp_unlock_node (rn);
2864}
2865
2866void
paulfee0f4c2004-09-13 05:12:46 +00002867bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2868{
2869 struct bgp_static *bgp_static;
2870 struct bgp *bgp;
2871 struct bgp_node *rn;
2872 struct prefix *p;
2873
2874 bgp = rsclient->bgp;
2875
2876 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
2877 if ((bgp_static = rn->info) != NULL)
2878 {
2879 p = &rn->p;
2880
2881 bgp_static_update_rsclient (rsclient, p, bgp_static,
2882 afi, safi);
2883 }
2884}
2885
2886void
paul718e3742002-12-13 20:15:29 +00002887bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
2888 u_char safi, struct prefix_rd *prd, u_char *tag)
2889{
2890 struct bgp_node *rn;
2891 struct bgp_info *ri;
2892
paulfee0f4c2004-09-13 05:12:46 +00002893 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002894
2895 /* Check selected route and self inserted route. */
2896 for (ri = rn->info; ri; ri = ri->next)
2897 if (ri->peer == bgp->peer_self
2898 && ri->type == ZEBRA_ROUTE_BGP
2899 && ri->sub_type == BGP_ROUTE_STATIC)
2900 break;
2901
2902 /* Withdraw static BGP route from routing table. */
2903 if (ri)
2904 {
2905 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2906 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2907 bgp_process (bgp, rn, afi, safi);
2908 bgp_info_delete (rn, ri);
2909 bgp_info_free (ri);
2910 bgp_unlock_node (rn);
2911 }
2912
2913 /* Unlock bgp_node_lookup. */
2914 bgp_unlock_node (rn);
2915}
2916
2917/* Configure static BGP network. When user don't run zebra, static
2918 route should be installed as valid. */
2919int
paulfd79ac92004-10-13 05:06:08 +00002920bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
2921 u_int16_t afi, u_char safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00002922{
2923 int ret;
2924 struct prefix p;
2925 struct bgp_static *bgp_static;
2926 struct bgp_node *rn;
2927 int need_update = 0;
2928
2929 /* Convert IP prefix string to struct prefix. */
2930 ret = str2prefix (ip_str, &p);
2931 if (! ret)
2932 {
2933 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2934 return CMD_WARNING;
2935 }
2936#ifdef HAVE_IPV6
2937 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2938 {
2939 vty_out (vty, "%% Malformed prefix (link-local address)%s",
2940 VTY_NEWLINE);
2941 return CMD_WARNING;
2942 }
2943#endif /* HAVE_IPV6 */
2944
2945 apply_mask (&p);
2946
2947 /* Set BGP static route configuration. */
2948 rn = bgp_node_get (bgp->route[afi][safi], &p);
2949
2950 if (rn->info)
2951 {
2952 /* Configuration change. */
2953 bgp_static = rn->info;
2954
2955 /* Check previous routes are installed into BGP. */
2956 if (! bgp_static->backdoor && bgp_static->valid)
2957 need_update = 1;
2958
2959 bgp_static->backdoor = backdoor;
2960 if (rmap)
2961 {
2962 if (bgp_static->rmap.name)
2963 free (bgp_static->rmap.name);
2964 bgp_static->rmap.name = strdup (rmap);
2965 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
2966 }
2967 else
2968 {
2969 if (bgp_static->rmap.name)
2970 free (bgp_static->rmap.name);
2971 bgp_static->rmap.name = NULL;
2972 bgp_static->rmap.map = NULL;
2973 bgp_static->valid = 0;
2974 }
2975 bgp_unlock_node (rn);
2976 }
2977 else
2978 {
2979 /* New configuration. */
2980 bgp_static = bgp_static_new ();
2981 bgp_static->backdoor = backdoor;
2982 bgp_static->valid = 0;
2983 bgp_static->igpmetric = 0;
2984 bgp_static->igpnexthop.s_addr = 0;
2985 if (rmap)
2986 {
2987 if (bgp_static->rmap.name)
2988 free (bgp_static->rmap.name);
2989 bgp_static->rmap.name = strdup (rmap);
2990 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
2991 }
2992 rn->info = bgp_static;
2993 }
2994
2995 /* If BGP scan is not enabled, we should install this route here. */
2996 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
2997 {
2998 bgp_static->valid = 1;
2999
3000 if (need_update)
3001 bgp_static_withdraw (bgp, &p, afi, safi);
3002
3003 if (! bgp_static->backdoor)
3004 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3005 }
3006
3007 return CMD_SUCCESS;
3008}
3009
3010/* Configure static BGP network. */
3011int
paulfd79ac92004-10-13 05:06:08 +00003012bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003013 u_int16_t afi, u_char safi)
3014{
3015 int ret;
3016 struct prefix p;
3017 struct bgp_static *bgp_static;
3018 struct bgp_node *rn;
3019
3020 /* Convert IP prefix string to struct prefix. */
3021 ret = str2prefix (ip_str, &p);
3022 if (! ret)
3023 {
3024 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3025 return CMD_WARNING;
3026 }
3027#ifdef HAVE_IPV6
3028 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3029 {
3030 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3031 VTY_NEWLINE);
3032 return CMD_WARNING;
3033 }
3034#endif /* HAVE_IPV6 */
3035
3036 apply_mask (&p);
3037
3038 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3039 if (! rn)
3040 {
3041 vty_out (vty, "%% Can't find specified static route configuration.%s",
3042 VTY_NEWLINE);
3043 return CMD_WARNING;
3044 }
3045
3046 bgp_static = rn->info;
3047
3048 /* Update BGP RIB. */
3049 if (! bgp_static->backdoor)
3050 bgp_static_withdraw (bgp, &p, afi, safi);
3051
3052 /* Clear configuration. */
3053 bgp_static_free (bgp_static);
3054 rn->info = NULL;
3055 bgp_unlock_node (rn);
3056 bgp_unlock_node (rn);
3057
3058 return CMD_SUCCESS;
3059}
3060
3061/* Called from bgp_delete(). Delete all static routes from the BGP
3062 instance. */
3063void
3064bgp_static_delete (struct bgp *bgp)
3065{
3066 afi_t afi;
3067 safi_t safi;
3068 struct bgp_node *rn;
3069 struct bgp_node *rm;
3070 struct bgp_table *table;
3071 struct bgp_static *bgp_static;
3072
3073 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3074 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3075 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3076 if (rn->info != NULL)
3077 {
3078 if (safi == SAFI_MPLS_VPN)
3079 {
3080 table = rn->info;
3081
3082 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3083 {
3084 bgp_static = rn->info;
3085 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3086 AFI_IP, SAFI_MPLS_VPN,
3087 (struct prefix_rd *)&rn->p,
3088 bgp_static->tag);
3089 bgp_static_free (bgp_static);
3090 rn->info = NULL;
3091 bgp_unlock_node (rn);
3092 }
3093 }
3094 else
3095 {
3096 bgp_static = rn->info;
3097 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3098 bgp_static_free (bgp_static);
3099 rn->info = NULL;
3100 bgp_unlock_node (rn);
3101 }
3102 }
3103}
3104
3105int
paulfd79ac92004-10-13 05:06:08 +00003106bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3107 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003108{
3109 int ret;
3110 struct prefix p;
3111 struct prefix_rd prd;
3112 struct bgp *bgp;
3113 struct bgp_node *prn;
3114 struct bgp_node *rn;
3115 struct bgp_table *table;
3116 struct bgp_static *bgp_static;
3117 u_char tag[3];
3118
3119 bgp = vty->index;
3120
3121 ret = str2prefix (ip_str, &p);
3122 if (! ret)
3123 {
3124 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3125 return CMD_WARNING;
3126 }
3127 apply_mask (&p);
3128
3129 ret = str2prefix_rd (rd_str, &prd);
3130 if (! ret)
3131 {
3132 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3133 return CMD_WARNING;
3134 }
3135
3136 ret = str2tag (tag_str, tag);
3137 if (! ret)
3138 {
3139 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3140 return CMD_WARNING;
3141 }
3142
3143 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3144 (struct prefix *)&prd);
3145 if (prn->info == NULL)
3146 prn->info = bgp_table_init ();
3147 else
3148 bgp_unlock_node (prn);
3149 table = prn->info;
3150
3151 rn = bgp_node_get (table, &p);
3152
3153 if (rn->info)
3154 {
3155 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3156 bgp_unlock_node (rn);
3157 }
3158 else
3159 {
3160 /* New configuration. */
3161 bgp_static = bgp_static_new ();
3162 bgp_static->valid = 1;
3163 memcpy (bgp_static->tag, tag, 3);
3164 rn->info = bgp_static;
3165
3166 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3167 }
3168
3169 return CMD_SUCCESS;
3170}
3171
3172/* Configure static BGP network. */
3173int
paulfd79ac92004-10-13 05:06:08 +00003174bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3175 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003176{
3177 int ret;
3178 struct bgp *bgp;
3179 struct prefix p;
3180 struct prefix_rd prd;
3181 struct bgp_node *prn;
3182 struct bgp_node *rn;
3183 struct bgp_table *table;
3184 struct bgp_static *bgp_static;
3185 u_char tag[3];
3186
3187 bgp = vty->index;
3188
3189 /* Convert IP prefix string to struct prefix. */
3190 ret = str2prefix (ip_str, &p);
3191 if (! ret)
3192 {
3193 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3194 return CMD_WARNING;
3195 }
3196 apply_mask (&p);
3197
3198 ret = str2prefix_rd (rd_str, &prd);
3199 if (! ret)
3200 {
3201 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3202 return CMD_WARNING;
3203 }
3204
3205 ret = str2tag (tag_str, tag);
3206 if (! ret)
3207 {
3208 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3209 return CMD_WARNING;
3210 }
3211
3212 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3213 (struct prefix *)&prd);
3214 if (prn->info == NULL)
3215 prn->info = bgp_table_init ();
3216 else
3217 bgp_unlock_node (prn);
3218 table = prn->info;
3219
3220 rn = bgp_node_lookup (table, &p);
3221
3222 if (rn)
3223 {
3224 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3225
3226 bgp_static = rn->info;
3227 bgp_static_free (bgp_static);
3228 rn->info = NULL;
3229 bgp_unlock_node (rn);
3230 bgp_unlock_node (rn);
3231 }
3232 else
3233 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3234
3235 return CMD_SUCCESS;
3236}
3237
3238DEFUN (bgp_network,
3239 bgp_network_cmd,
3240 "network A.B.C.D/M",
3241 "Specify a network to announce via BGP\n"
3242 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3243{
3244 return bgp_static_set (vty, vty->index, argv[0],
3245 AFI_IP, bgp_node_safi (vty), NULL, 0);
3246}
3247
3248DEFUN (bgp_network_route_map,
3249 bgp_network_route_map_cmd,
3250 "network A.B.C.D/M route-map WORD",
3251 "Specify a network to announce via BGP\n"
3252 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3253 "Route-map to modify the attributes\n"
3254 "Name of the route map\n")
3255{
3256 return bgp_static_set (vty, vty->index, argv[0],
3257 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3258}
3259
3260DEFUN (bgp_network_backdoor,
3261 bgp_network_backdoor_cmd,
3262 "network A.B.C.D/M backdoor",
3263 "Specify a network to announce via BGP\n"
3264 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3265 "Specify a BGP backdoor route\n")
3266{
3267 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
3268}
3269
3270DEFUN (bgp_network_mask,
3271 bgp_network_mask_cmd,
3272 "network A.B.C.D mask A.B.C.D",
3273 "Specify a network to announce via BGP\n"
3274 "Network number\n"
3275 "Network mask\n"
3276 "Network mask\n")
3277{
3278 int ret;
3279 char prefix_str[BUFSIZ];
3280
3281 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3282 if (! ret)
3283 {
3284 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3285 return CMD_WARNING;
3286 }
3287
3288 return bgp_static_set (vty, vty->index, prefix_str,
3289 AFI_IP, bgp_node_safi (vty), NULL, 0);
3290}
3291
3292DEFUN (bgp_network_mask_route_map,
3293 bgp_network_mask_route_map_cmd,
3294 "network A.B.C.D mask A.B.C.D route-map WORD",
3295 "Specify a network to announce via BGP\n"
3296 "Network number\n"
3297 "Network mask\n"
3298 "Network mask\n"
3299 "Route-map to modify the attributes\n"
3300 "Name of the route map\n")
3301{
3302 int ret;
3303 char prefix_str[BUFSIZ];
3304
3305 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3306 if (! ret)
3307 {
3308 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3309 return CMD_WARNING;
3310 }
3311
3312 return bgp_static_set (vty, vty->index, prefix_str,
3313 AFI_IP, bgp_node_safi (vty), argv[2], 0);
3314}
3315
3316DEFUN (bgp_network_mask_backdoor,
3317 bgp_network_mask_backdoor_cmd,
3318 "network A.B.C.D mask A.B.C.D backdoor",
3319 "Specify a network to announce via BGP\n"
3320 "Network number\n"
3321 "Network mask\n"
3322 "Network mask\n"
3323 "Specify a BGP backdoor route\n")
3324{
3325 int ret;
3326 char prefix_str[BUFSIZ];
3327
3328 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3329 if (! ret)
3330 {
3331 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3332 return CMD_WARNING;
3333 }
3334
3335 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3336}
3337
3338DEFUN (bgp_network_mask_natural,
3339 bgp_network_mask_natural_cmd,
3340 "network A.B.C.D",
3341 "Specify a network to announce via BGP\n"
3342 "Network number\n")
3343{
3344 int ret;
3345 char prefix_str[BUFSIZ];
3346
3347 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3348 if (! ret)
3349 {
3350 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3351 return CMD_WARNING;
3352 }
3353
3354 return bgp_static_set (vty, vty->index, prefix_str,
3355 AFI_IP, bgp_node_safi (vty), NULL, 0);
3356}
3357
3358DEFUN (bgp_network_mask_natural_route_map,
3359 bgp_network_mask_natural_route_map_cmd,
3360 "network A.B.C.D route-map WORD",
3361 "Specify a network to announce via BGP\n"
3362 "Network number\n"
3363 "Route-map to modify the attributes\n"
3364 "Name of the route map\n")
3365{
3366 int ret;
3367 char prefix_str[BUFSIZ];
3368
3369 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3370 if (! ret)
3371 {
3372 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3373 return CMD_WARNING;
3374 }
3375
3376 return bgp_static_set (vty, vty->index, prefix_str,
3377 AFI_IP, bgp_node_safi (vty), argv[1], 0);
3378}
3379
3380DEFUN (bgp_network_mask_natural_backdoor,
3381 bgp_network_mask_natural_backdoor_cmd,
3382 "network A.B.C.D backdoor",
3383 "Specify a network to announce via BGP\n"
3384 "Network number\n"
3385 "Specify a BGP backdoor route\n")
3386{
3387 int ret;
3388 char prefix_str[BUFSIZ];
3389
3390 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3391 if (! ret)
3392 {
3393 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3394 return CMD_WARNING;
3395 }
3396
3397 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
3398}
3399
3400DEFUN (no_bgp_network,
3401 no_bgp_network_cmd,
3402 "no network A.B.C.D/M",
3403 NO_STR
3404 "Specify a network to announce via BGP\n"
3405 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3406{
3407 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
3408 bgp_node_safi (vty));
3409}
3410
3411ALIAS (no_bgp_network,
3412 no_bgp_network_route_map_cmd,
3413 "no network A.B.C.D/M route-map WORD",
3414 NO_STR
3415 "Specify a network to announce via BGP\n"
3416 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3417 "Route-map to modify the attributes\n"
3418 "Name of the route map\n")
3419
3420ALIAS (no_bgp_network,
3421 no_bgp_network_backdoor_cmd,
3422 "no network A.B.C.D/M backdoor",
3423 NO_STR
3424 "Specify a network to announce via BGP\n"
3425 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3426 "Specify a BGP backdoor route\n")
3427
3428DEFUN (no_bgp_network_mask,
3429 no_bgp_network_mask_cmd,
3430 "no network A.B.C.D mask A.B.C.D",
3431 NO_STR
3432 "Specify a network to announce via BGP\n"
3433 "Network number\n"
3434 "Network mask\n"
3435 "Network mask\n")
3436{
3437 int ret;
3438 char prefix_str[BUFSIZ];
3439
3440 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3441 if (! ret)
3442 {
3443 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3444 return CMD_WARNING;
3445 }
3446
3447 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3448 bgp_node_safi (vty));
3449}
3450
3451ALIAS (no_bgp_network_mask,
3452 no_bgp_network_mask_route_map_cmd,
3453 "no network A.B.C.D mask A.B.C.D route-map WORD",
3454 NO_STR
3455 "Specify a network to announce via BGP\n"
3456 "Network number\n"
3457 "Network mask\n"
3458 "Network mask\n"
3459 "Route-map to modify the attributes\n"
3460 "Name of the route map\n")
3461
3462ALIAS (no_bgp_network_mask,
3463 no_bgp_network_mask_backdoor_cmd,
3464 "no network A.B.C.D mask A.B.C.D backdoor",
3465 NO_STR
3466 "Specify a network to announce via BGP\n"
3467 "Network number\n"
3468 "Network mask\n"
3469 "Network mask\n"
3470 "Specify a BGP backdoor route\n")
3471
3472DEFUN (no_bgp_network_mask_natural,
3473 no_bgp_network_mask_natural_cmd,
3474 "no network A.B.C.D",
3475 NO_STR
3476 "Specify a network to announce via BGP\n"
3477 "Network number\n")
3478{
3479 int ret;
3480 char prefix_str[BUFSIZ];
3481
3482 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
3483 if (! ret)
3484 {
3485 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3486 return CMD_WARNING;
3487 }
3488
3489 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
3490 bgp_node_safi (vty));
3491}
3492
3493ALIAS (no_bgp_network_mask_natural,
3494 no_bgp_network_mask_natural_route_map_cmd,
3495 "no network A.B.C.D route-map WORD",
3496 NO_STR
3497 "Specify a network to announce via BGP\n"
3498 "Network number\n"
3499 "Route-map to modify the attributes\n"
3500 "Name of the route map\n")
3501
3502ALIAS (no_bgp_network_mask_natural,
3503 no_bgp_network_mask_natural_backdoor_cmd,
3504 "no network A.B.C.D backdoor",
3505 NO_STR
3506 "Specify a network to announce via BGP\n"
3507 "Network number\n"
3508 "Specify a BGP backdoor route\n")
3509
3510#ifdef HAVE_IPV6
3511DEFUN (ipv6_bgp_network,
3512 ipv6_bgp_network_cmd,
3513 "network X:X::X:X/M",
3514 "Specify a network to announce via BGP\n"
3515 "IPv6 prefix <network>/<length>\n")
3516{
3517 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
3518}
3519
3520DEFUN (ipv6_bgp_network_route_map,
3521 ipv6_bgp_network_route_map_cmd,
3522 "network X:X::X:X/M route-map WORD",
3523 "Specify a network to announce via BGP\n"
3524 "IPv6 prefix <network>/<length>\n"
3525 "Route-map to modify the attributes\n"
3526 "Name of the route map\n")
3527{
3528 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
3529 bgp_node_safi (vty), argv[1], 0);
3530}
3531
3532DEFUN (no_ipv6_bgp_network,
3533 no_ipv6_bgp_network_cmd,
3534 "no network X:X::X:X/M",
3535 NO_STR
3536 "Specify a network to announce via BGP\n"
3537 "IPv6 prefix <network>/<length>\n")
3538{
3539 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
3540}
3541
3542ALIAS (no_ipv6_bgp_network,
3543 no_ipv6_bgp_network_route_map_cmd,
3544 "no network X:X::X:X/M route-map WORD",
3545 NO_STR
3546 "Specify a network to announce via BGP\n"
3547 "IPv6 prefix <network>/<length>\n"
3548 "Route-map to modify the attributes\n"
3549 "Name of the route map\n")
3550
3551ALIAS (ipv6_bgp_network,
3552 old_ipv6_bgp_network_cmd,
3553 "ipv6 bgp network X:X::X:X/M",
3554 IPV6_STR
3555 BGP_STR
3556 "Specify a network to announce via BGP\n"
3557 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3558
3559ALIAS (no_ipv6_bgp_network,
3560 old_no_ipv6_bgp_network_cmd,
3561 "no ipv6 bgp network X:X::X:X/M",
3562 NO_STR
3563 IPV6_STR
3564 BGP_STR
3565 "Specify a network to announce via BGP\n"
3566 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
3567#endif /* HAVE_IPV6 */
3568
3569/* Aggreagete address:
3570
3571 advertise-map Set condition to advertise attribute
3572 as-set Generate AS set path information
3573 attribute-map Set attributes of aggregate
3574 route-map Set parameters of aggregate
3575 summary-only Filter more specific routes from updates
3576 suppress-map Conditionally filter more specific routes from updates
3577 <cr>
3578 */
3579struct bgp_aggregate
3580{
3581 /* Summary-only flag. */
3582 u_char summary_only;
3583
3584 /* AS set generation. */
3585 u_char as_set;
3586
3587 /* Route-map for aggregated route. */
3588 struct route_map *map;
3589
3590 /* Suppress-count. */
3591 unsigned long count;
3592
3593 /* SAFI configuration. */
3594 safi_t safi;
3595};
3596
3597struct bgp_aggregate *
3598bgp_aggregate_new ()
3599{
3600 struct bgp_aggregate *new;
3601 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
3602 memset (new, 0, sizeof (struct bgp_aggregate));
3603 return new;
3604}
3605
3606void
3607bgp_aggregate_free (struct bgp_aggregate *aggregate)
3608{
3609 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
3610}
3611
3612void
3613bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
3614 afi_t afi, safi_t safi, struct bgp_info *del,
3615 struct bgp_aggregate *aggregate)
3616{
3617 struct bgp_table *table;
3618 struct bgp_node *top;
3619 struct bgp_node *rn;
3620 u_char origin;
3621 struct aspath *aspath = NULL;
3622 struct aspath *asmerge = NULL;
3623 struct community *community = NULL;
3624 struct community *commerge = NULL;
3625 struct in_addr nexthop;
3626 u_int32_t med = 0;
3627 struct bgp_info *ri;
3628 struct bgp_info *new;
3629 int first = 1;
3630 unsigned long match = 0;
3631
3632 /* Record adding route's nexthop and med. */
3633 if (rinew)
3634 {
3635 nexthop = rinew->attr->nexthop;
3636 med = rinew->attr->med;
3637 }
3638
3639 /* ORIGIN attribute: If at least one route among routes that are
3640 aggregated has ORIGIN with the value INCOMPLETE, then the
3641 aggregated route must have the ORIGIN attribute with the value
3642 INCOMPLETE. Otherwise, if at least one route among routes that
3643 are aggregated has ORIGIN with the value EGP, then the aggregated
3644 route must have the origin attribute with the value EGP. In all
3645 other case the value of the ORIGIN attribute of the aggregated
3646 route is INTERNAL. */
3647 origin = BGP_ORIGIN_IGP;
3648
3649 table = bgp->rib[afi][safi];
3650
3651 top = bgp_node_get (table, p);
3652 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
3653 if (rn->p.prefixlen > p->prefixlen)
3654 {
3655 match = 0;
3656
3657 for (ri = rn->info; ri; ri = ri->next)
3658 {
3659 if (BGP_INFO_HOLDDOWN (ri))
3660 continue;
3661
3662 if (del && ri == del)
3663 continue;
3664
3665 if (! rinew && first)
3666 {
3667 nexthop = ri->attr->nexthop;
3668 med = ri->attr->med;
3669 first = 0;
3670 }
3671
3672#ifdef AGGREGATE_NEXTHOP_CHECK
3673 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
3674 || ri->attr->med != med)
3675 {
3676 if (aspath)
3677 aspath_free (aspath);
3678 if (community)
3679 community_free (community);
3680 bgp_unlock_node (rn);
3681 bgp_unlock_node (top);
3682 return;
3683 }
3684#endif /* AGGREGATE_NEXTHOP_CHECK */
3685
3686 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
3687 {
3688 if (aggregate->summary_only)
3689 {
3690 ri->suppress++;
3691 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3692 match++;
3693 }
3694
3695 aggregate->count++;
3696
3697 if (aggregate->as_set)
3698 {
3699 if (origin < ri->attr->origin)
3700 origin = ri->attr->origin;
3701
3702 if (aspath)
3703 {
3704 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
3705 aspath_free (aspath);
3706 aspath = asmerge;
3707 }
3708 else
3709 aspath = aspath_dup (ri->attr->aspath);
3710
3711 if (ri->attr->community)
3712 {
3713 if (community)
3714 {
3715 commerge = community_merge (community,
3716 ri->attr->community);
3717 community = community_uniq_sort (commerge);
3718 community_free (commerge);
3719 }
3720 else
3721 community = community_dup (ri->attr->community);
3722 }
3723 }
3724 }
3725 }
3726 if (match)
3727 bgp_process (bgp, rn, afi, safi);
3728 }
3729 bgp_unlock_node (top);
3730
3731 if (rinew)
3732 {
3733 aggregate->count++;
3734
3735 if (aggregate->summary_only)
3736 rinew->suppress++;
3737
3738 if (aggregate->as_set)
3739 {
3740 if (origin < rinew->attr->origin)
3741 origin = rinew->attr->origin;
3742
3743 if (aspath)
3744 {
3745 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
3746 aspath_free (aspath);
3747 aspath = asmerge;
3748 }
3749 else
3750 aspath = aspath_dup (rinew->attr->aspath);
3751
3752 if (rinew->attr->community)
3753 {
3754 if (community)
3755 {
3756 commerge = community_merge (community,
3757 rinew->attr->community);
3758 community = community_uniq_sort (commerge);
3759 community_free (commerge);
3760 }
3761 else
3762 community = community_dup (rinew->attr->community);
3763 }
3764 }
3765 }
3766
3767 if (aggregate->count > 0)
3768 {
3769 rn = bgp_node_get (table, p);
3770 new = bgp_info_new ();
3771 new->type = ZEBRA_ROUTE_BGP;
3772 new->sub_type = BGP_ROUTE_AGGREGATE;
3773 new->peer = bgp->peer_self;
3774 SET_FLAG (new->flags, BGP_INFO_VALID);
3775 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
3776 new->uptime = time (NULL);
3777
3778 bgp_info_add (rn, new);
3779 bgp_process (bgp, rn, afi, safi);
3780 }
3781 else
3782 {
3783 if (aspath)
3784 aspath_free (aspath);
3785 if (community)
3786 community_free (community);
3787 }
3788}
3789
3790void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
3791 struct bgp_aggregate *);
3792
3793void
3794bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
3795 struct bgp_info *ri, afi_t afi, safi_t safi)
3796{
3797 struct bgp_node *child;
3798 struct bgp_node *rn;
3799 struct bgp_aggregate *aggregate;
3800
3801 /* MPLS-VPN aggregation is not yet supported. */
3802 if (safi == SAFI_MPLS_VPN)
3803 return;
3804
3805 if (p->prefixlen == 0)
3806 return;
3807
3808 if (BGP_INFO_HOLDDOWN (ri))
3809 return;
3810
3811 child = bgp_node_get (bgp->aggregate[afi][safi], p);
3812
3813 /* Aggregate address configuration check. */
3814 for (rn = child; rn; rn = rn->parent)
3815 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
3816 {
3817 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00003818 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00003819 }
3820 bgp_unlock_node (child);
3821}
3822
3823void
3824bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
3825 struct bgp_info *del, afi_t afi, safi_t safi)
3826{
3827 struct bgp_node *child;
3828 struct bgp_node *rn;
3829 struct bgp_aggregate *aggregate;
3830
3831 /* MPLS-VPN aggregation is not yet supported. */
3832 if (safi == SAFI_MPLS_VPN)
3833 return;
3834
3835 if (p->prefixlen == 0)
3836 return;
3837
3838 child = bgp_node_get (bgp->aggregate[afi][safi], p);
3839
3840 /* Aggregate address configuration check. */
3841 for (rn = child; rn; rn = rn->parent)
3842 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
3843 {
3844 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00003845 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00003846 }
3847 bgp_unlock_node (child);
3848}
3849
3850void
3851bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
3852 struct bgp_aggregate *aggregate)
3853{
3854 struct bgp_table *table;
3855 struct bgp_node *top;
3856 struct bgp_node *rn;
3857 struct bgp_info *new;
3858 struct bgp_info *ri;
3859 unsigned long match;
3860 u_char origin = BGP_ORIGIN_IGP;
3861 struct aspath *aspath = NULL;
3862 struct aspath *asmerge = NULL;
3863 struct community *community = NULL;
3864 struct community *commerge = NULL;
3865
3866 table = bgp->rib[afi][safi];
3867
3868 /* Sanity check. */
3869 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
3870 return;
3871 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
3872 return;
3873
3874 /* If routes exists below this node, generate aggregate routes. */
3875 top = bgp_node_get (table, p);
3876 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
3877 if (rn->p.prefixlen > p->prefixlen)
3878 {
3879 match = 0;
3880
3881 for (ri = rn->info; ri; ri = ri->next)
3882 {
3883 if (BGP_INFO_HOLDDOWN (ri))
3884 continue;
3885
3886 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
3887 {
3888 /* summary-only aggregate route suppress aggregated
3889 route announcement. */
3890 if (aggregate->summary_only)
3891 {
3892 ri->suppress++;
3893 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3894 match++;
3895 }
3896 /* as-set aggregate route generate origin, as path,
3897 community aggregation. */
3898 if (aggregate->as_set)
3899 {
3900 if (origin < ri->attr->origin)
3901 origin = ri->attr->origin;
3902
3903 if (aspath)
3904 {
3905 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
3906 aspath_free (aspath);
3907 aspath = asmerge;
3908 }
3909 else
3910 aspath = aspath_dup (ri->attr->aspath);
3911
3912 if (ri->attr->community)
3913 {
3914 if (community)
3915 {
3916 commerge = community_merge (community,
3917 ri->attr->community);
3918 community = community_uniq_sort (commerge);
3919 community_free (commerge);
3920 }
3921 else
3922 community = community_dup (ri->attr->community);
3923 }
3924 }
3925 aggregate->count++;
3926 }
3927 }
3928
3929 /* If this node is suppressed, process the change. */
3930 if (match)
3931 bgp_process (bgp, rn, afi, safi);
3932 }
3933 bgp_unlock_node (top);
3934
3935 /* Add aggregate route to BGP table. */
3936 if (aggregate->count)
3937 {
3938 rn = bgp_node_get (table, p);
3939
3940 new = bgp_info_new ();
3941 new->type = ZEBRA_ROUTE_BGP;
3942 new->sub_type = BGP_ROUTE_AGGREGATE;
3943 new->peer = bgp->peer_self;
3944 SET_FLAG (new->flags, BGP_INFO_VALID);
3945 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
3946 new->uptime = time (NULL);
3947
3948 bgp_info_add (rn, new);
3949
3950 /* Process change. */
3951 bgp_process (bgp, rn, afi, safi);
3952 }
3953}
3954
3955void
3956bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
3957 safi_t safi, struct bgp_aggregate *aggregate)
3958{
3959 struct bgp_table *table;
3960 struct bgp_node *top;
3961 struct bgp_node *rn;
3962 struct bgp_info *ri;
3963 unsigned long match;
3964
3965 table = bgp->rib[afi][safi];
3966
3967 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
3968 return;
3969 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
3970 return;
3971
3972 /* If routes exists below this node, generate aggregate routes. */
3973 top = bgp_node_get (table, p);
3974 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
3975 if (rn->p.prefixlen > p->prefixlen)
3976 {
3977 match = 0;
3978
3979 for (ri = rn->info; ri; ri = ri->next)
3980 {
3981 if (BGP_INFO_HOLDDOWN (ri))
3982 continue;
3983
3984 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
3985 {
3986 if (aggregate->summary_only)
3987 {
3988 ri->suppress--;
3989
3990 if (ri->suppress == 0)
3991 {
3992 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3993 match++;
3994 }
3995 }
3996 aggregate->count--;
3997 }
3998 }
3999
4000 /* If this node is suppressed, process the change. */
4001 if (match)
4002 bgp_process (bgp, rn, afi, safi);
4003 }
4004 bgp_unlock_node (top);
4005
4006 /* Delete aggregate route from BGP table. */
4007 rn = bgp_node_get (table, p);
4008
4009 for (ri = rn->info; ri; ri = ri->next)
4010 if (ri->peer == bgp->peer_self
4011 && ri->type == ZEBRA_ROUTE_BGP
4012 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4013 break;
4014
4015 /* Withdraw static BGP route from routing table. */
4016 if (ri)
4017 {
4018 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4019 bgp_process (bgp, rn, afi, safi);
4020 bgp_info_delete (rn, ri);
4021 bgp_info_free (ri);
4022 bgp_unlock_node (rn);
4023 }
4024
4025 /* Unlock bgp_node_lookup. */
4026 bgp_unlock_node (rn);
4027}
4028
4029/* Aggregate route attribute. */
4030#define AGGREGATE_SUMMARY_ONLY 1
4031#define AGGREGATE_AS_SET 1
4032
4033int
paulfd79ac92004-10-13 05:06:08 +00004034bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4035 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004036 u_char summary_only, u_char as_set)
4037{
4038 int ret;
4039 struct prefix p;
4040 struct bgp_node *rn;
4041 struct bgp *bgp;
4042 struct bgp_aggregate *aggregate;
4043
4044 /* Convert string to prefix structure. */
4045 ret = str2prefix (prefix_str, &p);
4046 if (!ret)
4047 {
4048 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4049 return CMD_WARNING;
4050 }
4051 apply_mask (&p);
4052
4053 /* Get BGP structure. */
4054 bgp = vty->index;
4055
4056 /* Old configuration check. */
4057 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4058
4059 if (rn->info)
4060 {
4061 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4062 bgp_unlock_node (rn);
4063 return CMD_WARNING;
4064 }
4065
4066 /* Make aggregate address structure. */
4067 aggregate = bgp_aggregate_new ();
4068 aggregate->summary_only = summary_only;
4069 aggregate->as_set = as_set;
4070 aggregate->safi = safi;
4071 rn->info = aggregate;
4072
4073 /* Aggregate address insert into BGP routing table. */
4074 if (safi & SAFI_UNICAST)
4075 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4076 if (safi & SAFI_MULTICAST)
4077 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4078
4079 return CMD_SUCCESS;
4080}
4081
4082int
paulfd79ac92004-10-13 05:06:08 +00004083bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4084 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004085{
4086 int ret;
4087 struct prefix p;
4088 struct bgp_node *rn;
4089 struct bgp *bgp;
4090 struct bgp_aggregate *aggregate;
4091
4092 /* Convert string to prefix structure. */
4093 ret = str2prefix (prefix_str, &p);
4094 if (!ret)
4095 {
4096 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4097 return CMD_WARNING;
4098 }
4099 apply_mask (&p);
4100
4101 /* Get BGP structure. */
4102 bgp = vty->index;
4103
4104 /* Old configuration check. */
4105 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4106 if (! rn)
4107 {
4108 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4109 VTY_NEWLINE);
4110 return CMD_WARNING;
4111 }
4112
4113 aggregate = rn->info;
4114 if (aggregate->safi & SAFI_UNICAST)
4115 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4116 if (aggregate->safi & SAFI_MULTICAST)
4117 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4118
4119 /* Unlock aggregate address configuration. */
4120 rn->info = NULL;
4121 bgp_aggregate_free (aggregate);
4122 bgp_unlock_node (rn);
4123 bgp_unlock_node (rn);
4124
4125 return CMD_SUCCESS;
4126}
4127
4128DEFUN (aggregate_address,
4129 aggregate_address_cmd,
4130 "aggregate-address A.B.C.D/M",
4131 "Configure BGP aggregate entries\n"
4132 "Aggregate prefix\n")
4133{
4134 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4135}
4136
4137DEFUN (aggregate_address_mask,
4138 aggregate_address_mask_cmd,
4139 "aggregate-address A.B.C.D A.B.C.D",
4140 "Configure BGP aggregate entries\n"
4141 "Aggregate address\n"
4142 "Aggregate mask\n")
4143{
4144 int ret;
4145 char prefix_str[BUFSIZ];
4146
4147 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4148
4149 if (! ret)
4150 {
4151 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4152 return CMD_WARNING;
4153 }
4154
4155 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4156 0, 0);
4157}
4158
4159DEFUN (aggregate_address_summary_only,
4160 aggregate_address_summary_only_cmd,
4161 "aggregate-address A.B.C.D/M summary-only",
4162 "Configure BGP aggregate entries\n"
4163 "Aggregate prefix\n"
4164 "Filter more specific routes from updates\n")
4165{
4166 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4167 AGGREGATE_SUMMARY_ONLY, 0);
4168}
4169
4170DEFUN (aggregate_address_mask_summary_only,
4171 aggregate_address_mask_summary_only_cmd,
4172 "aggregate-address A.B.C.D A.B.C.D summary-only",
4173 "Configure BGP aggregate entries\n"
4174 "Aggregate address\n"
4175 "Aggregate mask\n"
4176 "Filter more specific routes from updates\n")
4177{
4178 int ret;
4179 char prefix_str[BUFSIZ];
4180
4181 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4182
4183 if (! ret)
4184 {
4185 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4186 return CMD_WARNING;
4187 }
4188
4189 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4190 AGGREGATE_SUMMARY_ONLY, 0);
4191}
4192
4193DEFUN (aggregate_address_as_set,
4194 aggregate_address_as_set_cmd,
4195 "aggregate-address A.B.C.D/M as-set",
4196 "Configure BGP aggregate entries\n"
4197 "Aggregate prefix\n"
4198 "Generate AS set path information\n")
4199{
4200 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4201 0, AGGREGATE_AS_SET);
4202}
4203
4204DEFUN (aggregate_address_mask_as_set,
4205 aggregate_address_mask_as_set_cmd,
4206 "aggregate-address A.B.C.D A.B.C.D as-set",
4207 "Configure BGP aggregate entries\n"
4208 "Aggregate address\n"
4209 "Aggregate mask\n"
4210 "Generate AS set path information\n")
4211{
4212 int ret;
4213 char prefix_str[BUFSIZ];
4214
4215 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4216
4217 if (! ret)
4218 {
4219 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4220 return CMD_WARNING;
4221 }
4222
4223 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4224 0, AGGREGATE_AS_SET);
4225}
4226
4227
4228DEFUN (aggregate_address_as_set_summary,
4229 aggregate_address_as_set_summary_cmd,
4230 "aggregate-address A.B.C.D/M as-set summary-only",
4231 "Configure BGP aggregate entries\n"
4232 "Aggregate prefix\n"
4233 "Generate AS set path information\n"
4234 "Filter more specific routes from updates\n")
4235{
4236 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4237 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4238}
4239
4240ALIAS (aggregate_address_as_set_summary,
4241 aggregate_address_summary_as_set_cmd,
4242 "aggregate-address A.B.C.D/M summary-only as-set",
4243 "Configure BGP aggregate entries\n"
4244 "Aggregate prefix\n"
4245 "Filter more specific routes from updates\n"
4246 "Generate AS set path information\n")
4247
4248DEFUN (aggregate_address_mask_as_set_summary,
4249 aggregate_address_mask_as_set_summary_cmd,
4250 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4251 "Configure BGP aggregate entries\n"
4252 "Aggregate address\n"
4253 "Aggregate mask\n"
4254 "Generate AS set path information\n"
4255 "Filter more specific routes from updates\n")
4256{
4257 int ret;
4258 char prefix_str[BUFSIZ];
4259
4260 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4261
4262 if (! ret)
4263 {
4264 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4265 return CMD_WARNING;
4266 }
4267
4268 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4269 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
4270}
4271
4272ALIAS (aggregate_address_mask_as_set_summary,
4273 aggregate_address_mask_summary_as_set_cmd,
4274 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4275 "Configure BGP aggregate entries\n"
4276 "Aggregate address\n"
4277 "Aggregate mask\n"
4278 "Filter more specific routes from updates\n"
4279 "Generate AS set path information\n")
4280
4281DEFUN (no_aggregate_address,
4282 no_aggregate_address_cmd,
4283 "no aggregate-address A.B.C.D/M",
4284 NO_STR
4285 "Configure BGP aggregate entries\n"
4286 "Aggregate prefix\n")
4287{
4288 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
4289}
4290
4291ALIAS (no_aggregate_address,
4292 no_aggregate_address_summary_only_cmd,
4293 "no aggregate-address A.B.C.D/M summary-only",
4294 NO_STR
4295 "Configure BGP aggregate entries\n"
4296 "Aggregate prefix\n"
4297 "Filter more specific routes from updates\n")
4298
4299ALIAS (no_aggregate_address,
4300 no_aggregate_address_as_set_cmd,
4301 "no aggregate-address A.B.C.D/M as-set",
4302 NO_STR
4303 "Configure BGP aggregate entries\n"
4304 "Aggregate prefix\n"
4305 "Generate AS set path information\n")
4306
4307ALIAS (no_aggregate_address,
4308 no_aggregate_address_as_set_summary_cmd,
4309 "no aggregate-address A.B.C.D/M as-set summary-only",
4310 NO_STR
4311 "Configure BGP aggregate entries\n"
4312 "Aggregate prefix\n"
4313 "Generate AS set path information\n"
4314 "Filter more specific routes from updates\n")
4315
4316ALIAS (no_aggregate_address,
4317 no_aggregate_address_summary_as_set_cmd,
4318 "no aggregate-address A.B.C.D/M summary-only as-set",
4319 NO_STR
4320 "Configure BGP aggregate entries\n"
4321 "Aggregate prefix\n"
4322 "Filter more specific routes from updates\n"
4323 "Generate AS set path information\n")
4324
4325DEFUN (no_aggregate_address_mask,
4326 no_aggregate_address_mask_cmd,
4327 "no aggregate-address A.B.C.D A.B.C.D",
4328 NO_STR
4329 "Configure BGP aggregate entries\n"
4330 "Aggregate address\n"
4331 "Aggregate mask\n")
4332{
4333 int ret;
4334 char prefix_str[BUFSIZ];
4335
4336 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4337
4338 if (! ret)
4339 {
4340 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4341 return CMD_WARNING;
4342 }
4343
4344 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
4345}
4346
4347ALIAS (no_aggregate_address_mask,
4348 no_aggregate_address_mask_summary_only_cmd,
4349 "no aggregate-address A.B.C.D A.B.C.D summary-only",
4350 NO_STR
4351 "Configure BGP aggregate entries\n"
4352 "Aggregate address\n"
4353 "Aggregate mask\n"
4354 "Filter more specific routes from updates\n")
4355
4356ALIAS (no_aggregate_address_mask,
4357 no_aggregate_address_mask_as_set_cmd,
4358 "no aggregate-address A.B.C.D A.B.C.D as-set",
4359 NO_STR
4360 "Configure BGP aggregate entries\n"
4361 "Aggregate address\n"
4362 "Aggregate mask\n"
4363 "Generate AS set path information\n")
4364
4365ALIAS (no_aggregate_address_mask,
4366 no_aggregate_address_mask_as_set_summary_cmd,
4367 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
4368 NO_STR
4369 "Configure BGP aggregate entries\n"
4370 "Aggregate address\n"
4371 "Aggregate mask\n"
4372 "Generate AS set path information\n"
4373 "Filter more specific routes from updates\n")
4374
4375ALIAS (no_aggregate_address_mask,
4376 no_aggregate_address_mask_summary_as_set_cmd,
4377 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
4378 NO_STR
4379 "Configure BGP aggregate entries\n"
4380 "Aggregate address\n"
4381 "Aggregate mask\n"
4382 "Filter more specific routes from updates\n"
4383 "Generate AS set path information\n")
4384
4385#ifdef HAVE_IPV6
4386DEFUN (ipv6_aggregate_address,
4387 ipv6_aggregate_address_cmd,
4388 "aggregate-address X:X::X:X/M",
4389 "Configure BGP aggregate entries\n"
4390 "Aggregate prefix\n")
4391{
4392 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
4393}
4394
4395DEFUN (ipv6_aggregate_address_summary_only,
4396 ipv6_aggregate_address_summary_only_cmd,
4397 "aggregate-address X:X::X:X/M summary-only",
4398 "Configure BGP aggregate entries\n"
4399 "Aggregate prefix\n"
4400 "Filter more specific routes from updates\n")
4401{
4402 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
4403 AGGREGATE_SUMMARY_ONLY, 0);
4404}
4405
4406DEFUN (no_ipv6_aggregate_address,
4407 no_ipv6_aggregate_address_cmd,
4408 "no aggregate-address X:X::X:X/M",
4409 NO_STR
4410 "Configure BGP aggregate entries\n"
4411 "Aggregate prefix\n")
4412{
4413 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4414}
4415
4416DEFUN (no_ipv6_aggregate_address_summary_only,
4417 no_ipv6_aggregate_address_summary_only_cmd,
4418 "no aggregate-address X:X::X:X/M summary-only",
4419 NO_STR
4420 "Configure BGP aggregate entries\n"
4421 "Aggregate prefix\n"
4422 "Filter more specific routes from updates\n")
4423{
4424 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
4425}
4426
4427ALIAS (ipv6_aggregate_address,
4428 old_ipv6_aggregate_address_cmd,
4429 "ipv6 bgp aggregate-address X:X::X:X/M",
4430 IPV6_STR
4431 BGP_STR
4432 "Configure BGP aggregate entries\n"
4433 "Aggregate prefix\n")
4434
4435ALIAS (ipv6_aggregate_address_summary_only,
4436 old_ipv6_aggregate_address_summary_only_cmd,
4437 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4438 IPV6_STR
4439 BGP_STR
4440 "Configure BGP aggregate entries\n"
4441 "Aggregate prefix\n"
4442 "Filter more specific routes from updates\n")
4443
4444ALIAS (no_ipv6_aggregate_address,
4445 old_no_ipv6_aggregate_address_cmd,
4446 "no ipv6 bgp aggregate-address X:X::X:X/M",
4447 NO_STR
4448 IPV6_STR
4449 BGP_STR
4450 "Configure BGP aggregate entries\n"
4451 "Aggregate prefix\n")
4452
4453ALIAS (no_ipv6_aggregate_address_summary_only,
4454 old_no_ipv6_aggregate_address_summary_only_cmd,
4455 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
4456 NO_STR
4457 IPV6_STR
4458 BGP_STR
4459 "Configure BGP aggregate entries\n"
4460 "Aggregate prefix\n"
4461 "Filter more specific routes from updates\n")
4462#endif /* HAVE_IPV6 */
4463
4464/* Redistribute route treatment. */
4465void
4466bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
4467 u_int32_t metric, u_char type)
4468{
4469 struct bgp *bgp;
4470 struct listnode *nn;
4471 struct bgp_info *new;
4472 struct bgp_info *bi;
4473 struct bgp_info info;
4474 struct bgp_node *bn;
4475 struct attr attr;
4476 struct attr attr_new;
4477 struct attr *new_attr;
4478 afi_t afi;
4479 int ret;
4480
4481 /* Make default attribute. */
4482 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
4483 if (nexthop)
4484 attr.nexthop = *nexthop;
4485
4486 attr.med = metric;
4487 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
4488
4489 LIST_LOOP (bm->bgp, bgp, nn)
4490 {
4491 afi = family2afi (p->family);
4492
4493 if (bgp->redist[afi][type])
4494 {
4495 /* Copy attribute for modification. */
4496 attr_new = attr;
4497
4498 if (bgp->redist_metric_flag[afi][type])
4499 attr_new.med = bgp->redist_metric[afi][type];
4500
4501 /* Apply route-map. */
4502 if (bgp->rmap[afi][type].map)
4503 {
4504 info.peer = bgp->peer_self;
4505 info.attr = &attr_new;
4506
paulfee0f4c2004-09-13 05:12:46 +00004507 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
4508
paul718e3742002-12-13 20:15:29 +00004509 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
4510 &info);
paulfee0f4c2004-09-13 05:12:46 +00004511
4512 bgp->peer_self->rmap_type = 0;
4513
paul718e3742002-12-13 20:15:29 +00004514 if (ret == RMAP_DENYMATCH)
4515 {
4516 /* Free uninterned attribute. */
4517 bgp_attr_flush (&attr_new);
4518
4519 /* Unintern original. */
4520 aspath_unintern (attr.aspath);
4521 bgp_redistribute_delete (p, type);
4522 return;
4523 }
4524 }
4525
paulfee0f4c2004-09-13 05:12:46 +00004526 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004527 new_attr = bgp_attr_intern (&attr_new);
4528
4529 for (bi = bn->info; bi; bi = bi->next)
4530 if (bi->peer == bgp->peer_self
4531 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
4532 break;
4533
4534 if (bi)
4535 {
4536 if (attrhash_cmp (bi->attr, new_attr))
4537 {
4538 bgp_attr_unintern (new_attr);
4539 aspath_unintern (attr.aspath);
4540 bgp_unlock_node (bn);
4541 return;
4542 }
4543 else
4544 {
4545 /* The attribute is changed. */
4546 SET_FLAG (bi->flags, BGP_INFO_ATTR_CHANGED);
4547
4548 /* Rewrite BGP route information. */
4549 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
4550 bgp_attr_unintern (bi->attr);
4551 bi->attr = new_attr;
4552 bi->uptime = time (NULL);
4553
4554 /* Process change. */
4555 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
4556 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4557 bgp_unlock_node (bn);
4558 aspath_unintern (attr.aspath);
4559 return;
4560 }
4561 }
4562
4563 new = bgp_info_new ();
4564 new->type = type;
4565 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
4566 new->peer = bgp->peer_self;
4567 SET_FLAG (new->flags, BGP_INFO_VALID);
4568 new->attr = new_attr;
4569 new->uptime = time (NULL);
4570
4571 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
4572 bgp_info_add (bn, new);
4573 bgp_process (bgp, bn, afi, SAFI_UNICAST);
4574 }
4575 }
4576
4577 /* Unintern original. */
4578 aspath_unintern (attr.aspath);
4579}
4580
4581void
4582bgp_redistribute_delete (struct prefix *p, u_char type)
4583{
4584 struct bgp *bgp;
4585 struct listnode *nn;
4586 afi_t afi;
4587 struct bgp_node *rn;
4588 struct bgp_info *ri;
4589
4590 LIST_LOOP (bm->bgp, bgp, nn)
4591 {
4592 afi = family2afi (p->family);
4593
4594 if (bgp->redist[afi][type])
4595 {
paulfee0f4c2004-09-13 05:12:46 +00004596 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00004597
4598 for (ri = rn->info; ri; ri = ri->next)
4599 if (ri->peer == bgp->peer_self
4600 && ri->type == type)
4601 break;
4602
4603 if (ri)
4604 {
4605 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
4606 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4607 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4608 bgp_info_delete (rn, ri);
4609 bgp_info_free (ri);
4610 bgp_unlock_node (rn);
4611 }
4612 bgp_unlock_node (rn);
4613 }
4614 }
4615}
4616
4617/* Withdraw specified route type's route. */
4618void
4619bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
4620{
4621 struct bgp_node *rn;
4622 struct bgp_info *ri;
4623 struct bgp_table *table;
4624
4625 table = bgp->rib[afi][SAFI_UNICAST];
4626
4627 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4628 {
4629 for (ri = rn->info; ri; ri = ri->next)
4630 if (ri->peer == bgp->peer_self
4631 && ri->type == type)
4632 break;
4633
4634 if (ri)
4635 {
4636 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
4637 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
4638 bgp_process (bgp, rn, afi, SAFI_UNICAST);
4639 bgp_info_delete (rn, ri);
4640 bgp_info_free (ri);
4641 bgp_unlock_node (rn);
4642 }
4643 }
4644}
4645
4646/* Static function to display route. */
4647void
4648route_vty_out_route (struct prefix *p, struct vty *vty)
4649{
4650 int len;
4651 u_int32_t destination;
4652 char buf[BUFSIZ];
4653
4654 if (p->family == AF_INET)
4655 {
4656 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
4657 destination = ntohl (p->u.prefix4.s_addr);
4658
4659 if ((IN_CLASSC (destination) && p->prefixlen == 24)
4660 || (IN_CLASSB (destination) && p->prefixlen == 16)
4661 || (IN_CLASSA (destination) && p->prefixlen == 8)
4662 || p->u.prefix4.s_addr == 0)
4663 {
4664 /* When mask is natural, mask is not displayed. */
4665 }
4666 else
4667 len += vty_out (vty, "/%d", p->prefixlen);
4668 }
4669 else
4670 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
4671 p->prefixlen);
4672
4673 len = 17 - len;
4674 if (len < 1)
4675 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
4676 else
4677 vty_out (vty, "%*s", len, " ");
4678}
4679
paul718e3742002-12-13 20:15:29 +00004680enum bgp_display_type
4681{
4682 normal_list,
4683};
4684
4685/* called from terminal list command */
ajs5a646652004-11-05 01:25:55 +00004686void
paul718e3742002-12-13 20:15:29 +00004687route_vty_out (struct vty *vty, struct prefix *p,
4688 struct bgp_info *binfo, int display, safi_t safi)
4689{
4690 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00004691
4692 /* Route status display. */
4693 if (binfo->suppress)
4694 vty_out (vty, "s");
4695 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4696 vty_out (vty, "*");
4697 else
4698 vty_out (vty, " ");
4699
4700 /* Selected */
4701 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4702 vty_out (vty, "h");
4703 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4704 vty_out (vty, "d");
4705 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4706 vty_out (vty, ">");
4707 else
4708 vty_out (vty, " ");
4709
4710 /* Internal route. */
4711 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
4712 vty_out (vty, "i");
4713 else
4714 vty_out (vty, " ");
4715
4716 /* print prefix and mask */
4717 if (! display)
4718 route_vty_out_route (p, vty);
4719 else
4720 vty_out (vty, "%*s", 17, " ");
4721
4722 /* Print attribute */
4723 attr = binfo->attr;
4724 if (attr)
4725 {
4726 if (p->family == AF_INET)
4727 {
4728 if (safi == SAFI_MPLS_VPN)
4729 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
4730 else
4731 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
4732 }
4733#ifdef HAVE_IPV6
4734 else if (p->family == AF_INET6)
4735 {
4736 int len;
4737 char buf[BUFSIZ];
4738
4739 len = vty_out (vty, "%s",
4740 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
4741 len = 16 - len;
4742 if (len < 1)
4743 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
4744 else
4745 vty_out (vty, "%*s", len, " ");
4746 }
4747#endif /* HAVE_IPV6 */
4748
4749 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
4750 vty_out (vty, "%10d", attr->med);
4751 else
4752 vty_out (vty, " ");
4753
4754 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
4755 vty_out (vty, "%7d", attr->local_pref);
4756 else
4757 vty_out (vty, " ");
4758
4759 vty_out (vty, "%7u ",attr->weight);
4760
4761 /* Print aspath */
4762 if (attr->aspath)
4763 aspath_print_vty (vty, attr->aspath);
4764
4765 /* Print origin */
4766 if (strlen (attr->aspath->str) == 0)
4767 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4768 else
4769 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4770 }
4771 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00004772}
4773
4774/* called from terminal list command */
4775void
4776route_vty_out_tmp (struct vty *vty, struct prefix *p,
4777 struct attr *attr, safi_t safi)
4778{
4779 /* Route status display. */
4780 vty_out (vty, "*");
4781 vty_out (vty, ">");
4782 vty_out (vty, " ");
4783
4784 /* print prefix and mask */
4785 route_vty_out_route (p, vty);
4786
4787 /* Print attribute */
4788 if (attr)
4789 {
4790 if (p->family == AF_INET)
4791 {
4792 if (safi == SAFI_MPLS_VPN)
4793 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
4794 else
4795 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
4796 }
4797#ifdef HAVE_IPV6
4798 else if (p->family == AF_INET6)
4799 {
4800 int len;
4801 char buf[BUFSIZ];
4802
4803 len = vty_out (vty, "%s",
4804 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
4805 len = 16 - len;
4806 if (len < 1)
4807 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
4808 else
4809 vty_out (vty, "%*s", len, " ");
4810 }
4811#endif /* HAVE_IPV6 */
4812
4813 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
4814 vty_out (vty, "%10d", attr->med);
4815 else
4816 vty_out (vty, " ");
4817
4818 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
4819 vty_out (vty, "%7d", attr->local_pref);
4820 else
4821 vty_out (vty, " ");
4822
4823 vty_out (vty, "%7d ",attr->weight);
4824
4825 /* Print aspath */
4826 if (attr->aspath)
4827 aspath_print_vty (vty, attr->aspath);
4828
4829 /* Print origin */
4830 if (strlen (attr->aspath->str) == 0)
4831 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4832 else
4833 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4834 }
4835
4836 vty_out (vty, "%s", VTY_NEWLINE);
4837}
4838
ajs5a646652004-11-05 01:25:55 +00004839void
paul718e3742002-12-13 20:15:29 +00004840route_vty_out_tag (struct vty *vty, struct prefix *p,
4841 struct bgp_info *binfo, int display, safi_t safi)
4842{
4843 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00004844 u_int32_t label = 0;
4845
paul718e3742002-12-13 20:15:29 +00004846 /* Route status display. */
4847 if (binfo->suppress)
4848 vty_out (vty, "s");
4849 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4850 vty_out (vty, "*");
4851 else
4852 vty_out (vty, " ");
4853
4854 /* Selected */
4855 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4856 vty_out (vty, "h");
4857 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4858 vty_out (vty, "d");
4859 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4860 vty_out (vty, ">");
4861 else
4862 vty_out (vty, " ");
4863
4864 /* Internal route. */
4865 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
4866 vty_out (vty, "i");
4867 else
4868 vty_out (vty, " ");
4869
4870 /* print prefix and mask */
4871 if (! display)
4872 route_vty_out_route (p, vty);
4873 else
4874 vty_out (vty, "%*s", 17, " ");
4875
4876 /* Print attribute */
4877 attr = binfo->attr;
4878 if (attr)
4879 {
4880 if (p->family == AF_INET)
4881 {
4882 if (safi == SAFI_MPLS_VPN)
4883 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
4884 else
4885 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
4886 }
4887#ifdef HAVE_IPV6
4888 else if (p->family == AF_INET6)
4889 {
4890 char buf[BUFSIZ];
4891 char buf1[BUFSIZ];
4892 if (attr->mp_nexthop_len == 16)
4893 vty_out (vty, "%s",
4894 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
4895 else if (attr->mp_nexthop_len == 32)
4896 vty_out (vty, "%s(%s)",
4897 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
4898 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
4899
4900 }
4901#endif /* HAVE_IPV6 */
4902 }
4903
4904 label = decode_label (binfo->tag);
4905
4906 vty_out (vty, "notag/%d", label);
4907
4908 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00004909}
4910
4911/* dampening route */
ajs5a646652004-11-05 01:25:55 +00004912static void
paul718e3742002-12-13 20:15:29 +00004913damp_route_vty_out (struct vty *vty, struct prefix *p,
4914 struct bgp_info *binfo, int display, safi_t safi)
4915{
4916 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00004917 int len;
4918
paul718e3742002-12-13 20:15:29 +00004919 /* Route status display. */
4920 if (binfo->suppress)
4921 vty_out (vty, "s");
4922 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4923 vty_out (vty, "*");
4924 else
4925 vty_out (vty, " ");
4926
4927 /* Selected */
4928 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4929 vty_out (vty, "h");
4930 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4931 vty_out (vty, "d");
4932 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4933 vty_out (vty, ">");
4934 else
4935 vty_out (vty, " ");
4936
4937 vty_out (vty, " ");
4938
4939 /* print prefix and mask */
4940 if (! display)
4941 route_vty_out_route (p, vty);
4942 else
4943 vty_out (vty, "%*s", 17, " ");
4944
4945 len = vty_out (vty, "%s", binfo->peer->host);
4946 len = 17 - len;
4947 if (len < 1)
4948 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
4949 else
4950 vty_out (vty, "%*s", len, " ");
4951
4952 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
4953
4954 /* Print attribute */
4955 attr = binfo->attr;
4956 if (attr)
4957 {
4958 /* Print aspath */
4959 if (attr->aspath)
4960 aspath_print_vty (vty, attr->aspath);
4961
4962 /* Print origin */
4963 if (strlen (attr->aspath->str) == 0)
4964 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4965 else
4966 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4967 }
4968 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00004969}
4970
4971#define BGP_UPTIME_LEN 25
4972
4973/* flap route */
ajs5a646652004-11-05 01:25:55 +00004974static void
paul718e3742002-12-13 20:15:29 +00004975flap_route_vty_out (struct vty *vty, struct prefix *p,
4976 struct bgp_info *binfo, int display, safi_t safi)
4977{
4978 struct attr *attr;
4979 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00004980 char timebuf[BGP_UPTIME_LEN];
4981 int len;
4982
paul718e3742002-12-13 20:15:29 +00004983 bdi = binfo->damp_info;
4984
4985 /* Route status display. */
4986 if (binfo->suppress)
4987 vty_out (vty, "s");
4988 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4989 vty_out (vty, "*");
4990 else
4991 vty_out (vty, " ");
4992
4993 /* Selected */
4994 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4995 vty_out (vty, "h");
4996 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4997 vty_out (vty, "d");
4998 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4999 vty_out (vty, ">");
5000 else
5001 vty_out (vty, " ");
5002
5003 vty_out (vty, " ");
5004
5005 /* print prefix and mask */
5006 if (! display)
5007 route_vty_out_route (p, vty);
5008 else
5009 vty_out (vty, "%*s", 17, " ");
5010
5011 len = vty_out (vty, "%s", binfo->peer->host);
5012 len = 16 - len;
5013 if (len < 1)
5014 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5015 else
5016 vty_out (vty, "%*s", len, " ");
5017
5018 len = vty_out (vty, "%d", bdi->flap);
5019 len = 5 - len;
5020 if (len < 1)
5021 vty_out (vty, " ");
5022 else
5023 vty_out (vty, "%*s ", len, " ");
5024
5025 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5026 timebuf, BGP_UPTIME_LEN));
5027
5028 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5029 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5030 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5031 else
5032 vty_out (vty, "%*s ", 8, " ");
5033
5034 /* Print attribute */
5035 attr = binfo->attr;
5036 if (attr)
5037 {
5038 /* Print aspath */
5039 if (attr->aspath)
5040 aspath_print_vty (vty, attr->aspath);
5041
5042 /* Print origin */
5043 if (strlen (attr->aspath->str) == 0)
5044 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
5045 else
5046 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
5047 }
5048 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005049}
5050
5051void
5052route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5053 struct bgp_info *binfo, afi_t afi, safi_t safi)
5054{
5055 char buf[INET6_ADDRSTRLEN];
5056 char buf1[BUFSIZ];
5057 struct attr *attr;
5058 int sockunion_vty_out (struct vty *, union sockunion *);
5059
5060 attr = binfo->attr;
5061
5062 if (attr)
5063 {
5064 /* Line1 display AS-path, Aggregator */
5065 if (attr->aspath)
5066 {
5067 vty_out (vty, " ");
5068 if (attr->aspath->length == 0)
5069 vty_out (vty, "Local");
5070 else
5071 aspath_print_vty (vty, attr->aspath);
5072 }
5073
5074 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR)
5075 || CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)
5076 || CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
5077 || CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)
5078 || CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5079 {
5080 vty_out (vty, ",");
5081
5082 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR))
5083 vty_out (vty, " (aggregated by %d %s)", attr->aggregator_as,
5084 inet_ntoa (attr->aggregator_addr));
5085 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5086 vty_out (vty, " (Received from a RR-client)");
5087 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5088 vty_out (vty, " (Received from a RS-client)");
5089 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5090 vty_out (vty, " (history entry)");
5091 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5092 vty_out (vty, " (suppressed due to dampening)");
5093 }
5094 vty_out (vty, "%s", VTY_NEWLINE);
5095
5096 /* Line2 display Next-hop, Neighbor, Router-id */
5097 if (p->family == AF_INET)
5098 {
5099 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
5100 inet_ntoa (attr->mp_nexthop_global_in) :
5101 inet_ntoa (attr->nexthop));
5102 }
5103#ifdef HAVE_IPV6
5104 else
5105 {
5106 vty_out (vty, " %s",
5107 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
5108 buf, INET6_ADDRSTRLEN));
5109 }
5110#endif /* HAVE_IPV6 */
5111
5112 if (binfo->peer == bgp->peer_self)
5113 {
5114 vty_out (vty, " from %s ",
5115 p->family == AF_INET ? "0.0.0.0" : "::");
5116 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5117 }
5118 else
5119 {
5120 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5121 vty_out (vty, " (inaccessible)");
5122 else if (binfo->igpmetric)
5123 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00005124 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005125 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5126 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
5127 else
5128 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5129 }
5130 vty_out (vty, "%s", VTY_NEWLINE);
5131
5132#ifdef HAVE_IPV6
5133 /* display nexthop local */
5134 if (attr->mp_nexthop_len == 32)
5135 {
5136 vty_out (vty, " (%s)%s",
5137 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
5138 buf, INET6_ADDRSTRLEN),
5139 VTY_NEWLINE);
5140 }
5141#endif /* HAVE_IPV6 */
5142
5143 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5144 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5145
5146 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
5147 vty_out (vty, ", metric %d", attr->med);
5148
5149 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
5150 vty_out (vty, ", localpref %d", attr->local_pref);
5151 else
5152 vty_out (vty, ", localpref %d", bgp->default_local_pref);
5153
5154 if (attr->weight != 0)
5155 vty_out (vty, ", weight %d", attr->weight);
5156
5157 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5158 vty_out (vty, ", valid");
5159
5160 if (binfo->peer != bgp->peer_self)
5161 {
5162 if (binfo->peer->as == binfo->peer->local_as)
5163 vty_out (vty, ", internal");
5164 else
5165 vty_out (vty, ", %s",
5166 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5167 }
5168 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5169 vty_out (vty, ", aggregated, local");
5170 else if (binfo->type != ZEBRA_ROUTE_BGP)
5171 vty_out (vty, ", sourced");
5172 else
5173 vty_out (vty, ", sourced, local");
5174
5175 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5176 vty_out (vty, ", atomic-aggregate");
5177
5178 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5179 vty_out (vty, ", best");
5180
5181 vty_out (vty, "%s", VTY_NEWLINE);
5182
5183 /* Line 4 display Community */
5184 if (attr->community)
5185 vty_out (vty, " Community: %s%s", attr->community->str,
5186 VTY_NEWLINE);
5187
5188 /* Line 5 display Extended-community */
5189 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
5190 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
5191 VTY_NEWLINE);
5192
5193 /* Line 6 display Originator, Cluster-id */
5194 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5195 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5196 {
5197 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
5198 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
5199
5200 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5201 {
5202 int i;
5203 vty_out (vty, ", Cluster list: ");
5204 for (i = 0; i < attr->cluster->length / 4; i++)
5205 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
5206 }
5207 vty_out (vty, "%s", VTY_NEWLINE);
5208 }
5209
5210 if (binfo->damp_info)
5211 bgp_damp_info_vty (vty, binfo);
5212
5213 /* Line 7 display Uptime */
5214 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
5215 }
5216 vty_out (vty, "%s", VTY_NEWLINE);
5217}
5218
5219#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5220#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5221#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5222
5223enum bgp_show_type
5224{
5225 bgp_show_type_normal,
5226 bgp_show_type_regexp,
5227 bgp_show_type_prefix_list,
5228 bgp_show_type_filter_list,
5229 bgp_show_type_route_map,
5230 bgp_show_type_neighbor,
5231 bgp_show_type_cidr_only,
5232 bgp_show_type_prefix_longer,
5233 bgp_show_type_community_all,
5234 bgp_show_type_community,
5235 bgp_show_type_community_exact,
5236 bgp_show_type_community_list,
5237 bgp_show_type_community_list_exact,
5238 bgp_show_type_flap_statistics,
5239 bgp_show_type_flap_address,
5240 bgp_show_type_flap_prefix,
5241 bgp_show_type_flap_cidr_only,
5242 bgp_show_type_flap_regexp,
5243 bgp_show_type_flap_filter_list,
5244 bgp_show_type_flap_prefix_list,
5245 bgp_show_type_flap_prefix_longer,
5246 bgp_show_type_flap_route_map,
5247 bgp_show_type_flap_neighbor,
5248 bgp_show_type_dampend_paths,
5249 bgp_show_type_damp_neighbor
5250};
5251
ajs5a646652004-11-05 01:25:55 +00005252static int
paulfee0f4c2004-09-13 05:12:46 +00005253bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00005254 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00005255{
paul718e3742002-12-13 20:15:29 +00005256 struct bgp_info *ri;
5257 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00005258 int header = 1;
paul718e3742002-12-13 20:15:29 +00005259 int display;
ajs5a646652004-11-05 01:25:55 +00005260 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00005261
5262 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00005263 output_count = 0;
paul718e3742002-12-13 20:15:29 +00005264
paul718e3742002-12-13 20:15:29 +00005265 /* Start processing of routes. */
5266 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5267 if (rn->info != NULL)
5268 {
5269 display = 0;
5270
5271 for (ri = rn->info; ri; ri = ri->next)
5272 {
ajs5a646652004-11-05 01:25:55 +00005273 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00005274 || type == bgp_show_type_flap_address
5275 || type == bgp_show_type_flap_prefix
5276 || type == bgp_show_type_flap_cidr_only
5277 || type == bgp_show_type_flap_regexp
5278 || type == bgp_show_type_flap_filter_list
5279 || type == bgp_show_type_flap_prefix_list
5280 || type == bgp_show_type_flap_prefix_longer
5281 || type == bgp_show_type_flap_route_map
5282 || type == bgp_show_type_flap_neighbor
5283 || type == bgp_show_type_dampend_paths
5284 || type == bgp_show_type_damp_neighbor)
5285 {
5286 if (! ri->damp_info)
5287 continue;
5288 }
5289 if (type == bgp_show_type_regexp
5290 || type == bgp_show_type_flap_regexp)
5291 {
ajs5a646652004-11-05 01:25:55 +00005292 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00005293
5294 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
5295 continue;
5296 }
5297 if (type == bgp_show_type_prefix_list
5298 || type == bgp_show_type_flap_prefix_list)
5299 {
ajs5a646652004-11-05 01:25:55 +00005300 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00005301
5302 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
5303 continue;
5304 }
5305 if (type == bgp_show_type_filter_list
5306 || type == bgp_show_type_flap_filter_list)
5307 {
ajs5a646652004-11-05 01:25:55 +00005308 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00005309
5310 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
5311 continue;
5312 }
5313 if (type == bgp_show_type_route_map
5314 || type == bgp_show_type_flap_route_map)
5315 {
ajs5a646652004-11-05 01:25:55 +00005316 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00005317 struct bgp_info binfo;
5318 struct attr dummy_attr;
5319 int ret;
5320
5321 dummy_attr = *ri->attr;
5322 binfo.peer = ri->peer;
5323 binfo.attr = &dummy_attr;
5324
5325 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
5326
5327 if (ret == RMAP_DENYMATCH)
5328 continue;
5329 }
5330 if (type == bgp_show_type_neighbor
5331 || type == bgp_show_type_flap_neighbor
5332 || type == bgp_show_type_damp_neighbor)
5333 {
ajs5a646652004-11-05 01:25:55 +00005334 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00005335
5336 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
5337 continue;
5338 }
5339 if (type == bgp_show_type_cidr_only
5340 || type == bgp_show_type_flap_cidr_only)
5341 {
5342 u_int32_t destination;
5343
5344 destination = ntohl (rn->p.u.prefix4.s_addr);
5345 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
5346 continue;
5347 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
5348 continue;
5349 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
5350 continue;
5351 }
5352 if (type == bgp_show_type_prefix_longer
5353 || type == bgp_show_type_flap_prefix_longer)
5354 {
ajs5a646652004-11-05 01:25:55 +00005355 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005356
5357 if (! prefix_match (p, &rn->p))
5358 continue;
5359 }
5360 if (type == bgp_show_type_community_all)
5361 {
5362 if (! ri->attr->community)
5363 continue;
5364 }
5365 if (type == bgp_show_type_community)
5366 {
ajs5a646652004-11-05 01:25:55 +00005367 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005368
5369 if (! ri->attr->community ||
5370 ! community_match (ri->attr->community, com))
5371 continue;
5372 }
5373 if (type == bgp_show_type_community_exact)
5374 {
ajs5a646652004-11-05 01:25:55 +00005375 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00005376
5377 if (! ri->attr->community ||
5378 ! community_cmp (ri->attr->community, com))
5379 continue;
5380 }
5381 if (type == bgp_show_type_community_list)
5382 {
ajs5a646652004-11-05 01:25:55 +00005383 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005384
5385 if (! community_list_match (ri->attr->community, list))
5386 continue;
5387 }
5388 if (type == bgp_show_type_community_list_exact)
5389 {
ajs5a646652004-11-05 01:25:55 +00005390 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00005391
5392 if (! community_list_exact_match (ri->attr->community, list))
5393 continue;
5394 }
5395 if (type == bgp_show_type_flap_address
5396 || type == bgp_show_type_flap_prefix)
5397 {
ajs5a646652004-11-05 01:25:55 +00005398 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00005399
5400 if (! prefix_match (&rn->p, p))
5401 continue;
5402
5403 if (type == bgp_show_type_flap_prefix)
5404 if (p->prefixlen != rn->p.prefixlen)
5405 continue;
5406 }
5407 if (type == bgp_show_type_dampend_paths
5408 || type == bgp_show_type_damp_neighbor)
5409 {
5410 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
5411 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
5412 continue;
5413 }
5414
5415 if (header)
5416 {
paulfee0f4c2004-09-13 05:12:46 +00005417 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 +00005418 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
5419 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
5420 if (type == bgp_show_type_dampend_paths
5421 || type == bgp_show_type_damp_neighbor)
5422 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
5423 else if (type == bgp_show_type_flap_statistics
5424 || type == bgp_show_type_flap_address
5425 || type == bgp_show_type_flap_prefix
5426 || type == bgp_show_type_flap_cidr_only
5427 || type == bgp_show_type_flap_regexp
5428 || type == bgp_show_type_flap_filter_list
5429 || type == bgp_show_type_flap_prefix_list
5430 || type == bgp_show_type_flap_prefix_longer
5431 || type == bgp_show_type_flap_route_map
5432 || type == bgp_show_type_flap_neighbor)
5433 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
5434 else
5435 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005436 header = 0;
5437 }
5438
5439 if (type == bgp_show_type_dampend_paths
5440 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00005441 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005442 else if (type == bgp_show_type_flap_statistics
5443 || type == bgp_show_type_flap_address
5444 || type == bgp_show_type_flap_prefix
5445 || type == bgp_show_type_flap_cidr_only
5446 || type == bgp_show_type_flap_regexp
5447 || type == bgp_show_type_flap_filter_list
5448 || type == bgp_show_type_flap_prefix_list
5449 || type == bgp_show_type_flap_prefix_longer
5450 || type == bgp_show_type_flap_route_map
5451 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00005452 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005453 else
ajs5a646652004-11-05 01:25:55 +00005454 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005455 display++;
5456 }
5457 if (display)
ajs5a646652004-11-05 01:25:55 +00005458 output_count++;
paul718e3742002-12-13 20:15:29 +00005459 }
5460
5461 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00005462 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00005463 {
5464 if (type == bgp_show_type_normal)
5465 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
5466 }
5467 else
5468 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00005469 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005470
5471 return CMD_SUCCESS;
5472}
5473
ajs5a646652004-11-05 01:25:55 +00005474static int
paulfee0f4c2004-09-13 05:12:46 +00005475bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00005476 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00005477{
5478 struct bgp_table *table;
5479
5480 if (bgp == NULL) {
5481 bgp = bgp_get_default ();
5482 }
5483
5484 if (bgp == NULL)
5485 {
5486 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5487 return CMD_WARNING;
5488 }
5489
5490
5491 table = bgp->rib[afi][safi];
5492
ajs5a646652004-11-05 01:25:55 +00005493 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00005494}
5495
paul718e3742002-12-13 20:15:29 +00005496/* Header of detailed BGP route information */
5497void
5498route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
5499 struct bgp_node *rn,
5500 struct prefix_rd *prd, afi_t afi, safi_t safi)
5501{
5502 struct bgp_info *ri;
5503 struct prefix *p;
5504 struct peer *peer;
5505 struct listnode *nn;
5506 char buf1[INET6_ADDRSTRLEN];
5507 char buf2[INET6_ADDRSTRLEN];
5508 int count = 0;
5509 int best = 0;
5510 int suppress = 0;
5511 int no_export = 0;
5512 int no_advertise = 0;
5513 int local_as = 0;
5514 int first = 0;
5515
5516 p = &rn->p;
5517 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
5518 (safi == SAFI_MPLS_VPN ?
5519 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
5520 safi == SAFI_MPLS_VPN ? ":" : "",
5521 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
5522 p->prefixlen, VTY_NEWLINE);
5523
5524 for (ri = rn->info; ri; ri = ri->next)
5525 {
5526 count++;
5527 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
5528 {
5529 best = count;
5530 if (ri->suppress)
5531 suppress = 1;
5532 if (ri->attr->community != NULL)
5533 {
5534 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
5535 no_advertise = 1;
5536 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
5537 no_export = 1;
5538 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
5539 local_as = 1;
5540 }
5541 }
5542 }
5543
5544 vty_out (vty, "Paths: (%d available", count);
5545 if (best)
5546 {
5547 vty_out (vty, ", best #%d", best);
5548 if (safi == SAFI_UNICAST)
5549 vty_out (vty, ", table Default-IP-Routing-Table");
5550 }
5551 else
5552 vty_out (vty, ", no best path");
5553 if (no_advertise)
5554 vty_out (vty, ", not advertised to any peer");
5555 else if (no_export)
5556 vty_out (vty, ", not advertised to EBGP peer");
5557 else if (local_as)
5558 vty_out (vty, ", not advertised outside local AS");
5559 if (suppress)
5560 vty_out (vty, ", Advertisements suppressed by an aggregate.");
5561 vty_out (vty, ")%s", VTY_NEWLINE);
5562
5563 /* advertised peer */
5564 LIST_LOOP (bgp->peer, peer, nn)
5565 {
5566 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
5567 {
5568 if (! first)
5569 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
5570 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
5571 first = 1;
5572 }
5573 }
5574 if (! first)
5575 vty_out (vty, " Not advertised to any peer");
5576 vty_out (vty, "%s", VTY_NEWLINE);
5577}
5578
5579/* Display specified route of BGP table. */
5580int
paulfee0f4c2004-09-13 05:12:46 +00005581bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00005582 struct bgp_table *rib, const char *ip_str,
5583 afi_t afi, safi_t safi, struct prefix_rd *prd,
5584 int prefix_check)
paul718e3742002-12-13 20:15:29 +00005585{
5586 int ret;
5587 int header;
5588 int display = 0;
5589 struct prefix match;
5590 struct bgp_node *rn;
5591 struct bgp_node *rm;
5592 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00005593 struct bgp_table *table;
5594
paul718e3742002-12-13 20:15:29 +00005595 /* Check IP address argument. */
5596 ret = str2prefix (ip_str, &match);
5597 if (! ret)
5598 {
5599 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
5600 return CMD_WARNING;
5601 }
5602
5603 match.family = afi2family (afi);
5604
5605 if (safi == SAFI_MPLS_VPN)
5606 {
paulfee0f4c2004-09-13 05:12:46 +00005607 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00005608 {
5609 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
5610 continue;
5611
5612 if ((table = rn->info) != NULL)
5613 {
5614 header = 1;
5615
5616 if ((rm = bgp_node_match (table, &match)) != NULL)
5617 {
5618 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5619 continue;
5620
5621 for (ri = rm->info; ri; ri = ri->next)
5622 {
5623 if (header)
5624 {
5625 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5626 AFI_IP, SAFI_MPLS_VPN);
5627
5628 header = 0;
5629 }
5630 display++;
5631 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5632 }
5633 }
5634 }
5635 }
5636 }
5637 else
5638 {
5639 header = 1;
5640
paulfee0f4c2004-09-13 05:12:46 +00005641 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00005642 {
5643 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5644 {
5645 for (ri = rn->info; ri; ri = ri->next)
5646 {
5647 if (header)
5648 {
5649 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
5650 header = 0;
5651 }
5652 display++;
5653 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
5654 }
5655 }
5656 }
5657 }
5658
5659 if (! display)
5660 {
5661 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5662 return CMD_WARNING;
5663 }
5664
5665 return CMD_SUCCESS;
5666}
5667
paulfee0f4c2004-09-13 05:12:46 +00005668/* Display specified route of Main RIB */
5669int
paulfd79ac92004-10-13 05:06:08 +00005670bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00005671 afi_t afi, safi_t safi, struct prefix_rd *prd,
5672 int prefix_check)
5673{
5674 struct bgp *bgp;
5675
5676 /* BGP structure lookup. */
5677 if (view_name)
5678 {
5679 bgp = bgp_lookup_by_name (view_name);
5680 if (bgp == NULL)
5681 {
5682 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
5683 return CMD_WARNING;
5684 }
5685 }
5686 else
5687 {
5688 bgp = bgp_get_default ();
5689 if (bgp == NULL)
5690 {
5691 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
5692 return CMD_WARNING;
5693 }
5694 }
5695
5696 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
5697 afi, safi, prd, prefix_check);
5698}
5699
paul718e3742002-12-13 20:15:29 +00005700/* BGP route print out function. */
5701DEFUN (show_ip_bgp,
5702 show_ip_bgp_cmd,
5703 "show ip bgp",
5704 SHOW_STR
5705 IP_STR
5706 BGP_STR)
5707{
ajs5a646652004-11-05 01:25:55 +00005708 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00005709}
5710
5711DEFUN (show_ip_bgp_ipv4,
5712 show_ip_bgp_ipv4_cmd,
5713 "show ip bgp ipv4 (unicast|multicast)",
5714 SHOW_STR
5715 IP_STR
5716 BGP_STR
5717 "Address family\n"
5718 "Address Family modifier\n"
5719 "Address Family modifier\n")
5720{
5721 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00005722 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
5723 NULL);
paul718e3742002-12-13 20:15:29 +00005724
ajs5a646652004-11-05 01:25:55 +00005725 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00005726}
5727
5728DEFUN (show_ip_bgp_route,
5729 show_ip_bgp_route_cmd,
5730 "show ip bgp A.B.C.D",
5731 SHOW_STR
5732 IP_STR
5733 BGP_STR
5734 "Network in the BGP routing table to display\n")
5735{
5736 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
5737}
5738
5739DEFUN (show_ip_bgp_ipv4_route,
5740 show_ip_bgp_ipv4_route_cmd,
5741 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
5742 SHOW_STR
5743 IP_STR
5744 BGP_STR
5745 "Address family\n"
5746 "Address Family modifier\n"
5747 "Address Family modifier\n"
5748 "Network in the BGP routing table to display\n")
5749{
5750 if (strncmp (argv[0], "m", 1) == 0)
5751 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
5752
5753 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
5754}
5755
5756DEFUN (show_ip_bgp_vpnv4_all_route,
5757 show_ip_bgp_vpnv4_all_route_cmd,
5758 "show ip bgp vpnv4 all A.B.C.D",
5759 SHOW_STR
5760 IP_STR
5761 BGP_STR
5762 "Display VPNv4 NLRI specific information\n"
5763 "Display information about all VPNv4 NLRIs\n"
5764 "Network in the BGP routing table to display\n")
5765{
5766 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
5767}
5768
5769DEFUN (show_ip_bgp_vpnv4_rd_route,
5770 show_ip_bgp_vpnv4_rd_route_cmd,
5771 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
5772 SHOW_STR
5773 IP_STR
5774 BGP_STR
5775 "Display VPNv4 NLRI specific information\n"
5776 "Display information for a route distinguisher\n"
5777 "VPN Route Distinguisher\n"
5778 "Network in the BGP routing table to display\n")
5779{
5780 int ret;
5781 struct prefix_rd prd;
5782
5783 ret = str2prefix_rd (argv[0], &prd);
5784 if (! ret)
5785 {
5786 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
5787 return CMD_WARNING;
5788 }
5789 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
5790}
5791
5792DEFUN (show_ip_bgp_prefix,
5793 show_ip_bgp_prefix_cmd,
5794 "show ip bgp A.B.C.D/M",
5795 SHOW_STR
5796 IP_STR
5797 BGP_STR
5798 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5799{
5800 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
5801}
5802
5803DEFUN (show_ip_bgp_ipv4_prefix,
5804 show_ip_bgp_ipv4_prefix_cmd,
5805 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
5806 SHOW_STR
5807 IP_STR
5808 BGP_STR
5809 "Address family\n"
5810 "Address Family modifier\n"
5811 "Address Family modifier\n"
5812 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5813{
5814 if (strncmp (argv[0], "m", 1) == 0)
5815 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
5816
5817 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
5818}
5819
5820DEFUN (show_ip_bgp_vpnv4_all_prefix,
5821 show_ip_bgp_vpnv4_all_prefix_cmd,
5822 "show ip bgp vpnv4 all A.B.C.D/M",
5823 SHOW_STR
5824 IP_STR
5825 BGP_STR
5826 "Display VPNv4 NLRI specific information\n"
5827 "Display information about all VPNv4 NLRIs\n"
5828 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5829{
5830 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
5831}
5832
5833DEFUN (show_ip_bgp_vpnv4_rd_prefix,
5834 show_ip_bgp_vpnv4_rd_prefix_cmd,
5835 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
5836 SHOW_STR
5837 IP_STR
5838 BGP_STR
5839 "Display VPNv4 NLRI specific information\n"
5840 "Display information for a route distinguisher\n"
5841 "VPN Route Distinguisher\n"
5842 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5843{
5844 int ret;
5845 struct prefix_rd prd;
5846
5847 ret = str2prefix_rd (argv[0], &prd);
5848 if (! ret)
5849 {
5850 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
5851 return CMD_WARNING;
5852 }
5853 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
5854}
5855
5856DEFUN (show_ip_bgp_view,
5857 show_ip_bgp_view_cmd,
5858 "show ip bgp view WORD",
5859 SHOW_STR
5860 IP_STR
5861 BGP_STR
5862 "BGP view\n"
5863 "BGP view name\n")
5864{
paulbb46e942003-10-24 19:02:03 +00005865 struct bgp *bgp;
5866
5867 /* BGP structure lookup. */
5868 bgp = bgp_lookup_by_name (argv[0]);
5869 if (bgp == NULL)
5870 {
5871 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
5872 return CMD_WARNING;
5873 }
5874
ajs5a646652004-11-05 01:25:55 +00005875 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00005876}
5877
5878DEFUN (show_ip_bgp_view_route,
5879 show_ip_bgp_view_route_cmd,
5880 "show ip bgp view WORD A.B.C.D",
5881 SHOW_STR
5882 IP_STR
5883 BGP_STR
5884 "BGP view\n"
5885 "BGP view name\n"
5886 "Network in the BGP routing table to display\n")
5887{
5888 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
5889}
5890
5891DEFUN (show_ip_bgp_view_prefix,
5892 show_ip_bgp_view_prefix_cmd,
5893 "show ip bgp view WORD A.B.C.D/M",
5894 SHOW_STR
5895 IP_STR
5896 BGP_STR
5897 "BGP view\n"
5898 "BGP view name\n"
5899 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5900{
5901 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
5902}
5903
5904#ifdef HAVE_IPV6
5905DEFUN (show_bgp,
5906 show_bgp_cmd,
5907 "show bgp",
5908 SHOW_STR
5909 BGP_STR)
5910{
ajs5a646652004-11-05 01:25:55 +00005911 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
5912 NULL);
paul718e3742002-12-13 20:15:29 +00005913}
5914
5915ALIAS (show_bgp,
5916 show_bgp_ipv6_cmd,
5917 "show bgp ipv6",
5918 SHOW_STR
5919 BGP_STR
5920 "Address family\n")
5921
5922/* old command */
5923DEFUN (show_ipv6_bgp,
5924 show_ipv6_bgp_cmd,
5925 "show ipv6 bgp",
5926 SHOW_STR
5927 IP_STR
5928 BGP_STR)
5929{
ajs5a646652004-11-05 01:25:55 +00005930 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
5931 NULL);
paul718e3742002-12-13 20:15:29 +00005932}
5933
5934DEFUN (show_bgp_route,
5935 show_bgp_route_cmd,
5936 "show bgp X:X::X:X",
5937 SHOW_STR
5938 BGP_STR
5939 "Network in the BGP routing table to display\n")
5940{
5941 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
5942}
5943
5944ALIAS (show_bgp_route,
5945 show_bgp_ipv6_route_cmd,
5946 "show bgp ipv6 X:X::X:X",
5947 SHOW_STR
5948 BGP_STR
5949 "Address family\n"
5950 "Network in the BGP routing table to display\n")
5951
5952/* old command */
5953DEFUN (show_ipv6_bgp_route,
5954 show_ipv6_bgp_route_cmd,
5955 "show ipv6 bgp X:X::X:X",
5956 SHOW_STR
5957 IP_STR
5958 BGP_STR
5959 "Network in the BGP routing table to display\n")
5960{
5961 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
5962}
5963
5964DEFUN (show_bgp_prefix,
5965 show_bgp_prefix_cmd,
5966 "show bgp X:X::X:X/M",
5967 SHOW_STR
5968 BGP_STR
5969 "IPv6 prefix <network>/<length>\n")
5970{
5971 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
5972}
5973
5974ALIAS (show_bgp_prefix,
5975 show_bgp_ipv6_prefix_cmd,
5976 "show bgp ipv6 X:X::X:X/M",
5977 SHOW_STR
5978 BGP_STR
5979 "Address family\n"
5980 "IPv6 prefix <network>/<length>\n")
5981
5982/* old command */
5983DEFUN (show_ipv6_bgp_prefix,
5984 show_ipv6_bgp_prefix_cmd,
5985 "show ipv6 bgp X:X::X:X/M",
5986 SHOW_STR
5987 IP_STR
5988 BGP_STR
5989 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5990{
5991 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
5992}
5993
paulbb46e942003-10-24 19:02:03 +00005994DEFUN (show_bgp_view,
5995 show_bgp_view_cmd,
5996 "show bgp view WORD",
5997 SHOW_STR
5998 BGP_STR
5999 "BGP view\n"
6000 "View name\n")
6001{
6002 struct bgp *bgp;
6003
6004 /* BGP structure lookup. */
6005 bgp = bgp_lookup_by_name (argv[0]);
6006 if (bgp == NULL)
6007 {
6008 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6009 return CMD_WARNING;
6010 }
6011
ajs5a646652004-11-05 01:25:55 +00006012 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006013}
6014
6015ALIAS (show_bgp_view,
6016 show_bgp_view_ipv6_cmd,
6017 "show bgp view WORD ipv6",
6018 SHOW_STR
6019 BGP_STR
6020 "BGP view\n"
6021 "View name\n"
6022 "Address family\n")
6023
6024DEFUN (show_bgp_view_route,
6025 show_bgp_view_route_cmd,
6026 "show bgp view WORD X:X::X:X",
6027 SHOW_STR
6028 BGP_STR
6029 "BGP view\n"
6030 "View name\n"
6031 "Network in the BGP routing table to display\n")
6032{
6033 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6034}
6035
6036ALIAS (show_bgp_view_route,
6037 show_bgp_view_ipv6_route_cmd,
6038 "show bgp view WORD ipv6 X:X::X:X",
6039 SHOW_STR
6040 BGP_STR
6041 "BGP view\n"
6042 "View name\n"
6043 "Address family\n"
6044 "Network in the BGP routing table to display\n")
6045
6046DEFUN (show_bgp_view_prefix,
6047 show_bgp_view_prefix_cmd,
6048 "show bgp view WORD X:X::X:X/M",
6049 SHOW_STR
6050 BGP_STR
6051 "BGP view\n"
6052 "View name\n"
6053 "IPv6 prefix <network>/<length>\n")
6054{
6055 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6056}
6057
6058ALIAS (show_bgp_view_prefix,
6059 show_bgp_view_ipv6_prefix_cmd,
6060 "show bgp view WORD ipv6 X:X::X:X/M",
6061 SHOW_STR
6062 BGP_STR
6063 "BGP view\n"
6064 "View name\n"
6065 "Address family\n"
6066 "IPv6 prefix <network>/<length>\n")
6067
paul718e3742002-12-13 20:15:29 +00006068/* old command */
6069DEFUN (show_ipv6_mbgp,
6070 show_ipv6_mbgp_cmd,
6071 "show ipv6 mbgp",
6072 SHOW_STR
6073 IP_STR
6074 MBGP_STR)
6075{
ajs5a646652004-11-05 01:25:55 +00006076 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6077 NULL);
paul718e3742002-12-13 20:15:29 +00006078}
6079
6080/* old command */
6081DEFUN (show_ipv6_mbgp_route,
6082 show_ipv6_mbgp_route_cmd,
6083 "show ipv6 mbgp X:X::X:X",
6084 SHOW_STR
6085 IP_STR
6086 MBGP_STR
6087 "Network in the MBGP routing table to display\n")
6088{
6089 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6090}
6091
6092/* old command */
6093DEFUN (show_ipv6_mbgp_prefix,
6094 show_ipv6_mbgp_prefix_cmd,
6095 "show ipv6 mbgp X:X::X:X/M",
6096 SHOW_STR
6097 IP_STR
6098 MBGP_STR
6099 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6100{
6101 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6102}
6103#endif
6104
paul718e3742002-12-13 20:15:29 +00006105
6106int
paulfd79ac92004-10-13 05:06:08 +00006107bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006108 safi_t safi, enum bgp_show_type type)
6109{
6110 int i;
6111 struct buffer *b;
6112 char *regstr;
6113 int first;
6114 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006115 int rc;
paul718e3742002-12-13 20:15:29 +00006116
6117 first = 0;
6118 b = buffer_new (1024);
6119 for (i = 0; i < argc; i++)
6120 {
6121 if (first)
6122 buffer_putc (b, ' ');
6123 else
6124 {
6125 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6126 continue;
6127 first = 1;
6128 }
6129
6130 buffer_putstr (b, argv[i]);
6131 }
6132 buffer_putc (b, '\0');
6133
6134 regstr = buffer_getstr (b);
6135 buffer_free (b);
6136
6137 regex = bgp_regcomp (regstr);
6138 if (! regex)
6139 {
6140 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6141 VTY_NEWLINE);
6142 return CMD_WARNING;
6143 }
6144
ajs5a646652004-11-05 01:25:55 +00006145 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6146 bgp_regex_free (regex);
6147 return rc;
paul718e3742002-12-13 20:15:29 +00006148}
6149
6150DEFUN (show_ip_bgp_regexp,
6151 show_ip_bgp_regexp_cmd,
6152 "show ip bgp regexp .LINE",
6153 SHOW_STR
6154 IP_STR
6155 BGP_STR
6156 "Display routes matching the AS path regular expression\n"
6157 "A regular-expression to match the BGP AS paths\n")
6158{
6159 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6160 bgp_show_type_regexp);
6161}
6162
6163DEFUN (show_ip_bgp_flap_regexp,
6164 show_ip_bgp_flap_regexp_cmd,
6165 "show ip bgp flap-statistics regexp .LINE",
6166 SHOW_STR
6167 IP_STR
6168 BGP_STR
6169 "Display flap statistics of routes\n"
6170 "Display routes matching the AS path regular expression\n"
6171 "A regular-expression to match the BGP AS paths\n")
6172{
6173 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6174 bgp_show_type_flap_regexp);
6175}
6176
6177DEFUN (show_ip_bgp_ipv4_regexp,
6178 show_ip_bgp_ipv4_regexp_cmd,
6179 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6180 SHOW_STR
6181 IP_STR
6182 BGP_STR
6183 "Address family\n"
6184 "Address Family modifier\n"
6185 "Address Family modifier\n"
6186 "Display routes matching the AS path regular expression\n"
6187 "A regular-expression to match the BGP AS paths\n")
6188{
6189 if (strncmp (argv[0], "m", 1) == 0)
6190 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6191 bgp_show_type_regexp);
6192
6193 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6194 bgp_show_type_regexp);
6195}
6196
6197#ifdef HAVE_IPV6
6198DEFUN (show_bgp_regexp,
6199 show_bgp_regexp_cmd,
6200 "show bgp regexp .LINE",
6201 SHOW_STR
6202 BGP_STR
6203 "Display routes matching the AS path regular expression\n"
6204 "A regular-expression to match the BGP AS paths\n")
6205{
6206 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6207 bgp_show_type_regexp);
6208}
6209
6210ALIAS (show_bgp_regexp,
6211 show_bgp_ipv6_regexp_cmd,
6212 "show bgp ipv6 regexp .LINE",
6213 SHOW_STR
6214 BGP_STR
6215 "Address family\n"
6216 "Display routes matching the AS path regular expression\n"
6217 "A regular-expression to match the BGP AS paths\n")
6218
6219/* old command */
6220DEFUN (show_ipv6_bgp_regexp,
6221 show_ipv6_bgp_regexp_cmd,
6222 "show ipv6 bgp regexp .LINE",
6223 SHOW_STR
6224 IP_STR
6225 BGP_STR
6226 "Display routes matching the AS path regular expression\n"
6227 "A regular-expression to match the BGP AS paths\n")
6228{
6229 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6230 bgp_show_type_regexp);
6231}
6232
6233/* old command */
6234DEFUN (show_ipv6_mbgp_regexp,
6235 show_ipv6_mbgp_regexp_cmd,
6236 "show ipv6 mbgp regexp .LINE",
6237 SHOW_STR
6238 IP_STR
6239 BGP_STR
6240 "Display routes matching the AS path regular expression\n"
6241 "A regular-expression to match the MBGP AS paths\n")
6242{
6243 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
6244 bgp_show_type_regexp);
6245}
6246#endif /* HAVE_IPV6 */
6247
6248int
paulfd79ac92004-10-13 05:06:08 +00006249bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006250 safi_t safi, enum bgp_show_type type)
6251{
6252 struct prefix_list *plist;
6253
6254 plist = prefix_list_lookup (afi, prefix_list_str);
6255 if (plist == NULL)
6256 {
6257 vty_out (vty, "%% %s is not a valid prefix-list name%s",
6258 prefix_list_str, VTY_NEWLINE);
6259 return CMD_WARNING;
6260 }
6261
ajs5a646652004-11-05 01:25:55 +00006262 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00006263}
6264
6265DEFUN (show_ip_bgp_prefix_list,
6266 show_ip_bgp_prefix_list_cmd,
6267 "show ip bgp prefix-list WORD",
6268 SHOW_STR
6269 IP_STR
6270 BGP_STR
6271 "Display routes conforming to the prefix-list\n"
6272 "IP prefix-list name\n")
6273{
6274 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6275 bgp_show_type_prefix_list);
6276}
6277
6278DEFUN (show_ip_bgp_flap_prefix_list,
6279 show_ip_bgp_flap_prefix_list_cmd,
6280 "show ip bgp flap-statistics prefix-list WORD",
6281 SHOW_STR
6282 IP_STR
6283 BGP_STR
6284 "Display flap statistics of routes\n"
6285 "Display routes conforming to the prefix-list\n"
6286 "IP prefix-list name\n")
6287{
6288 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6289 bgp_show_type_flap_prefix_list);
6290}
6291
6292DEFUN (show_ip_bgp_ipv4_prefix_list,
6293 show_ip_bgp_ipv4_prefix_list_cmd,
6294 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
6295 SHOW_STR
6296 IP_STR
6297 BGP_STR
6298 "Address family\n"
6299 "Address Family modifier\n"
6300 "Address Family modifier\n"
6301 "Display routes conforming to the prefix-list\n"
6302 "IP prefix-list name\n")
6303{
6304 if (strncmp (argv[0], "m", 1) == 0)
6305 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6306 bgp_show_type_prefix_list);
6307
6308 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6309 bgp_show_type_prefix_list);
6310}
6311
6312#ifdef HAVE_IPV6
6313DEFUN (show_bgp_prefix_list,
6314 show_bgp_prefix_list_cmd,
6315 "show bgp prefix-list WORD",
6316 SHOW_STR
6317 BGP_STR
6318 "Display routes conforming to the prefix-list\n"
6319 "IPv6 prefix-list name\n")
6320{
6321 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6322 bgp_show_type_prefix_list);
6323}
6324
6325ALIAS (show_bgp_prefix_list,
6326 show_bgp_ipv6_prefix_list_cmd,
6327 "show bgp ipv6 prefix-list WORD",
6328 SHOW_STR
6329 BGP_STR
6330 "Address family\n"
6331 "Display routes conforming to the prefix-list\n"
6332 "IPv6 prefix-list name\n")
6333
6334/* old command */
6335DEFUN (show_ipv6_bgp_prefix_list,
6336 show_ipv6_bgp_prefix_list_cmd,
6337 "show ipv6 bgp prefix-list WORD",
6338 SHOW_STR
6339 IPV6_STR
6340 BGP_STR
6341 "Display routes matching the prefix-list\n"
6342 "IPv6 prefix-list name\n")
6343{
6344 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6345 bgp_show_type_prefix_list);
6346}
6347
6348/* old command */
6349DEFUN (show_ipv6_mbgp_prefix_list,
6350 show_ipv6_mbgp_prefix_list_cmd,
6351 "show ipv6 mbgp prefix-list WORD",
6352 SHOW_STR
6353 IPV6_STR
6354 MBGP_STR
6355 "Display routes matching the prefix-list\n"
6356 "IPv6 prefix-list name\n")
6357{
6358 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6359 bgp_show_type_prefix_list);
6360}
6361#endif /* HAVE_IPV6 */
6362
6363int
paulfd79ac92004-10-13 05:06:08 +00006364bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006365 safi_t safi, enum bgp_show_type type)
6366{
6367 struct as_list *as_list;
6368
6369 as_list = as_list_lookup (filter);
6370 if (as_list == NULL)
6371 {
6372 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
6373 return CMD_WARNING;
6374 }
6375
ajs5a646652004-11-05 01:25:55 +00006376 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00006377}
6378
6379DEFUN (show_ip_bgp_filter_list,
6380 show_ip_bgp_filter_list_cmd,
6381 "show ip bgp filter-list WORD",
6382 SHOW_STR
6383 IP_STR
6384 BGP_STR
6385 "Display routes conforming to the filter-list\n"
6386 "Regular expression access list name\n")
6387{
6388 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6389 bgp_show_type_filter_list);
6390}
6391
6392DEFUN (show_ip_bgp_flap_filter_list,
6393 show_ip_bgp_flap_filter_list_cmd,
6394 "show ip bgp flap-statistics filter-list WORD",
6395 SHOW_STR
6396 IP_STR
6397 BGP_STR
6398 "Display flap statistics of routes\n"
6399 "Display routes conforming to the filter-list\n"
6400 "Regular expression access list name\n")
6401{
6402 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
6403 bgp_show_type_flap_filter_list);
6404}
6405
6406DEFUN (show_ip_bgp_ipv4_filter_list,
6407 show_ip_bgp_ipv4_filter_list_cmd,
6408 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
6409 SHOW_STR
6410 IP_STR
6411 BGP_STR
6412 "Address family\n"
6413 "Address Family modifier\n"
6414 "Address Family modifier\n"
6415 "Display routes conforming to the filter-list\n"
6416 "Regular expression access list name\n")
6417{
6418 if (strncmp (argv[0], "m", 1) == 0)
6419 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6420 bgp_show_type_filter_list);
6421
6422 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
6423 bgp_show_type_filter_list);
6424}
6425
6426#ifdef HAVE_IPV6
6427DEFUN (show_bgp_filter_list,
6428 show_bgp_filter_list_cmd,
6429 "show bgp filter-list WORD",
6430 SHOW_STR
6431 BGP_STR
6432 "Display routes conforming to the filter-list\n"
6433 "Regular expression access list name\n")
6434{
6435 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6436 bgp_show_type_filter_list);
6437}
6438
6439ALIAS (show_bgp_filter_list,
6440 show_bgp_ipv6_filter_list_cmd,
6441 "show bgp ipv6 filter-list WORD",
6442 SHOW_STR
6443 BGP_STR
6444 "Address family\n"
6445 "Display routes conforming to the filter-list\n"
6446 "Regular expression access list name\n")
6447
6448/* old command */
6449DEFUN (show_ipv6_bgp_filter_list,
6450 show_ipv6_bgp_filter_list_cmd,
6451 "show ipv6 bgp filter-list WORD",
6452 SHOW_STR
6453 IPV6_STR
6454 BGP_STR
6455 "Display routes conforming to the filter-list\n"
6456 "Regular expression access list name\n")
6457{
6458 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6459 bgp_show_type_filter_list);
6460}
6461
6462/* old command */
6463DEFUN (show_ipv6_mbgp_filter_list,
6464 show_ipv6_mbgp_filter_list_cmd,
6465 "show ipv6 mbgp filter-list WORD",
6466 SHOW_STR
6467 IPV6_STR
6468 MBGP_STR
6469 "Display routes conforming to the filter-list\n"
6470 "Regular expression access list name\n")
6471{
6472 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
6473 bgp_show_type_filter_list);
6474}
6475#endif /* HAVE_IPV6 */
6476
6477int
paulfd79ac92004-10-13 05:06:08 +00006478bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006479 safi_t safi, enum bgp_show_type type)
6480{
6481 struct route_map *rmap;
6482
6483 rmap = route_map_lookup_by_name (rmap_str);
6484 if (! rmap)
6485 {
6486 vty_out (vty, "%% %s is not a valid route-map name%s",
6487 rmap_str, VTY_NEWLINE);
6488 return CMD_WARNING;
6489 }
6490
ajs5a646652004-11-05 01:25:55 +00006491 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00006492}
6493
6494DEFUN (show_ip_bgp_route_map,
6495 show_ip_bgp_route_map_cmd,
6496 "show ip bgp route-map WORD",
6497 SHOW_STR
6498 IP_STR
6499 BGP_STR
6500 "Display routes matching the route-map\n"
6501 "A route-map to match on\n")
6502{
6503 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6504 bgp_show_type_route_map);
6505}
6506
6507DEFUN (show_ip_bgp_flap_route_map,
6508 show_ip_bgp_flap_route_map_cmd,
6509 "show ip bgp flap-statistics route-map WORD",
6510 SHOW_STR
6511 IP_STR
6512 BGP_STR
6513 "Display flap statistics of routes\n"
6514 "Display routes matching the route-map\n"
6515 "A route-map to match on\n")
6516{
6517 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
6518 bgp_show_type_flap_route_map);
6519}
6520
6521DEFUN (show_ip_bgp_ipv4_route_map,
6522 show_ip_bgp_ipv4_route_map_cmd,
6523 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
6524 SHOW_STR
6525 IP_STR
6526 BGP_STR
6527 "Address family\n"
6528 "Address Family modifier\n"
6529 "Address Family modifier\n"
6530 "Display routes matching the route-map\n"
6531 "A route-map to match on\n")
6532{
6533 if (strncmp (argv[0], "m", 1) == 0)
6534 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
6535 bgp_show_type_route_map);
6536
6537 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
6538 bgp_show_type_route_map);
6539}
6540
6541DEFUN (show_bgp_route_map,
6542 show_bgp_route_map_cmd,
6543 "show bgp route-map WORD",
6544 SHOW_STR
6545 BGP_STR
6546 "Display routes matching the route-map\n"
6547 "A route-map to match on\n")
6548{
6549 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
6550 bgp_show_type_route_map);
6551}
6552
6553ALIAS (show_bgp_route_map,
6554 show_bgp_ipv6_route_map_cmd,
6555 "show bgp ipv6 route-map WORD",
6556 SHOW_STR
6557 BGP_STR
6558 "Address family\n"
6559 "Display routes matching the route-map\n"
6560 "A route-map to match on\n")
6561
6562DEFUN (show_ip_bgp_cidr_only,
6563 show_ip_bgp_cidr_only_cmd,
6564 "show ip bgp cidr-only",
6565 SHOW_STR
6566 IP_STR
6567 BGP_STR
6568 "Display only routes with non-natural netmasks\n")
6569{
6570 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006571 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006572}
6573
6574DEFUN (show_ip_bgp_flap_cidr_only,
6575 show_ip_bgp_flap_cidr_only_cmd,
6576 "show ip bgp flap-statistics cidr-only",
6577 SHOW_STR
6578 IP_STR
6579 BGP_STR
6580 "Display flap statistics of routes\n"
6581 "Display only routes with non-natural netmasks\n")
6582{
6583 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006584 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006585}
6586
6587DEFUN (show_ip_bgp_ipv4_cidr_only,
6588 show_ip_bgp_ipv4_cidr_only_cmd,
6589 "show ip bgp ipv4 (unicast|multicast) cidr-only",
6590 SHOW_STR
6591 IP_STR
6592 BGP_STR
6593 "Address family\n"
6594 "Address Family modifier\n"
6595 "Address Family modifier\n"
6596 "Display only routes with non-natural netmasks\n")
6597{
6598 if (strncmp (argv[0], "m", 1) == 0)
6599 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006600 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006601
6602 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006603 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00006604}
6605
6606DEFUN (show_ip_bgp_community_all,
6607 show_ip_bgp_community_all_cmd,
6608 "show ip bgp community",
6609 SHOW_STR
6610 IP_STR
6611 BGP_STR
6612 "Display routes matching the communities\n")
6613{
6614 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006615 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006616}
6617
6618DEFUN (show_ip_bgp_ipv4_community_all,
6619 show_ip_bgp_ipv4_community_all_cmd,
6620 "show ip bgp ipv4 (unicast|multicast) community",
6621 SHOW_STR
6622 IP_STR
6623 BGP_STR
6624 "Address family\n"
6625 "Address Family modifier\n"
6626 "Address Family modifier\n"
6627 "Display routes matching the communities\n")
6628{
6629 if (strncmp (argv[0], "m", 1) == 0)
6630 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006631 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006632
6633 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006634 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006635}
6636
6637#ifdef HAVE_IPV6
6638DEFUN (show_bgp_community_all,
6639 show_bgp_community_all_cmd,
6640 "show bgp community",
6641 SHOW_STR
6642 BGP_STR
6643 "Display routes matching the communities\n")
6644{
6645 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006646 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006647}
6648
6649ALIAS (show_bgp_community_all,
6650 show_bgp_ipv6_community_all_cmd,
6651 "show bgp ipv6 community",
6652 SHOW_STR
6653 BGP_STR
6654 "Address family\n"
6655 "Display routes matching the communities\n")
6656
6657/* old command */
6658DEFUN (show_ipv6_bgp_community_all,
6659 show_ipv6_bgp_community_all_cmd,
6660 "show ipv6 bgp community",
6661 SHOW_STR
6662 IPV6_STR
6663 BGP_STR
6664 "Display routes matching the communities\n")
6665{
6666 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00006667 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006668}
6669
6670/* old command */
6671DEFUN (show_ipv6_mbgp_community_all,
6672 show_ipv6_mbgp_community_all_cmd,
6673 "show ipv6 mbgp community",
6674 SHOW_STR
6675 IPV6_STR
6676 MBGP_STR
6677 "Display routes matching the communities\n")
6678{
6679 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00006680 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00006681}
6682#endif /* HAVE_IPV6 */
6683
6684int
paulfd79ac92004-10-13 05:06:08 +00006685bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
6686 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00006687{
6688 struct community *com;
6689 struct buffer *b;
6690 int i;
6691 char *str;
6692 int first = 0;
6693
6694 b = buffer_new (1024);
6695 for (i = 0; i < argc; i++)
6696 {
6697 if (first)
6698 buffer_putc (b, ' ');
6699 else
6700 {
6701 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6702 continue;
6703 first = 1;
6704 }
6705
6706 buffer_putstr (b, argv[i]);
6707 }
6708 buffer_putc (b, '\0');
6709
6710 str = buffer_getstr (b);
6711 buffer_free (b);
6712
6713 com = community_str2com (str);
6714 free (str);
6715 if (! com)
6716 {
6717 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
6718 return CMD_WARNING;
6719 }
6720
ajs5a646652004-11-05 01:25:55 +00006721 return bgp_show (vty, NULL, afi, safi,
6722 (exact ? bgp_show_type_community_exact :
6723 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00006724}
6725
6726DEFUN (show_ip_bgp_community,
6727 show_ip_bgp_community_cmd,
6728 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
6729 SHOW_STR
6730 IP_STR
6731 BGP_STR
6732 "Display routes matching the communities\n"
6733 "community number\n"
6734 "Do not send outside local AS (well-known community)\n"
6735 "Do not advertise to any peer (well-known community)\n"
6736 "Do not export to next AS (well-known community)\n")
6737{
6738 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
6739}
6740
6741ALIAS (show_ip_bgp_community,
6742 show_ip_bgp_community2_cmd,
6743 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6744 SHOW_STR
6745 IP_STR
6746 BGP_STR
6747 "Display routes matching the communities\n"
6748 "community number\n"
6749 "Do not send outside local AS (well-known community)\n"
6750 "Do not advertise to any peer (well-known community)\n"
6751 "Do not export to next AS (well-known community)\n"
6752 "community number\n"
6753 "Do not send outside local AS (well-known community)\n"
6754 "Do not advertise to any peer (well-known community)\n"
6755 "Do not export to next AS (well-known community)\n")
6756
6757ALIAS (show_ip_bgp_community,
6758 show_ip_bgp_community3_cmd,
6759 "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)",
6760 SHOW_STR
6761 IP_STR
6762 BGP_STR
6763 "Display routes matching the communities\n"
6764 "community number\n"
6765 "Do not send outside local AS (well-known community)\n"
6766 "Do not advertise to any peer (well-known community)\n"
6767 "Do not export to next AS (well-known community)\n"
6768 "community number\n"
6769 "Do not send outside local AS (well-known community)\n"
6770 "Do not advertise to any peer (well-known community)\n"
6771 "Do not export to next AS (well-known community)\n"
6772 "community number\n"
6773 "Do not send outside local AS (well-known community)\n"
6774 "Do not advertise to any peer (well-known community)\n"
6775 "Do not export to next AS (well-known community)\n")
6776
6777ALIAS (show_ip_bgp_community,
6778 show_ip_bgp_community4_cmd,
6779 "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)",
6780 SHOW_STR
6781 IP_STR
6782 BGP_STR
6783 "Display routes matching the communities\n"
6784 "community number\n"
6785 "Do not send outside local AS (well-known community)\n"
6786 "Do not advertise to any peer (well-known community)\n"
6787 "Do not export to next AS (well-known community)\n"
6788 "community number\n"
6789 "Do not send outside local AS (well-known community)\n"
6790 "Do not advertise to any peer (well-known community)\n"
6791 "Do not export to next AS (well-known community)\n"
6792 "community number\n"
6793 "Do not send outside local AS (well-known community)\n"
6794 "Do not advertise to any peer (well-known community)\n"
6795 "Do not export to next AS (well-known community)\n"
6796 "community number\n"
6797 "Do not send outside local AS (well-known community)\n"
6798 "Do not advertise to any peer (well-known community)\n"
6799 "Do not export to next AS (well-known community)\n")
6800
6801DEFUN (show_ip_bgp_ipv4_community,
6802 show_ip_bgp_ipv4_community_cmd,
6803 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
6804 SHOW_STR
6805 IP_STR
6806 BGP_STR
6807 "Address family\n"
6808 "Address Family modifier\n"
6809 "Address Family modifier\n"
6810 "Display routes matching the communities\n"
6811 "community number\n"
6812 "Do not send outside local AS (well-known community)\n"
6813 "Do not advertise to any peer (well-known community)\n"
6814 "Do not export to next AS (well-known community)\n")
6815{
6816 if (strncmp (argv[0], "m", 1) == 0)
6817 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
6818
6819 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
6820}
6821
6822ALIAS (show_ip_bgp_ipv4_community,
6823 show_ip_bgp_ipv4_community2_cmd,
6824 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6825 SHOW_STR
6826 IP_STR
6827 BGP_STR
6828 "Address family\n"
6829 "Address Family modifier\n"
6830 "Address Family modifier\n"
6831 "Display routes matching the communities\n"
6832 "community number\n"
6833 "Do not send outside local AS (well-known community)\n"
6834 "Do not advertise to any peer (well-known community)\n"
6835 "Do not export to next AS (well-known community)\n"
6836 "community number\n"
6837 "Do not send outside local AS (well-known community)\n"
6838 "Do not advertise to any peer (well-known community)\n"
6839 "Do not export to next AS (well-known community)\n")
6840
6841ALIAS (show_ip_bgp_ipv4_community,
6842 show_ip_bgp_ipv4_community3_cmd,
6843 "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)",
6844 SHOW_STR
6845 IP_STR
6846 BGP_STR
6847 "Address family\n"
6848 "Address Family modifier\n"
6849 "Address Family modifier\n"
6850 "Display routes matching the communities\n"
6851 "community number\n"
6852 "Do not send outside local AS (well-known community)\n"
6853 "Do not advertise to any peer (well-known community)\n"
6854 "Do not export to next AS (well-known community)\n"
6855 "community number\n"
6856 "Do not send outside local AS (well-known community)\n"
6857 "Do not advertise to any peer (well-known community)\n"
6858 "Do not export to next AS (well-known community)\n"
6859 "community number\n"
6860 "Do not send outside local AS (well-known community)\n"
6861 "Do not advertise to any peer (well-known community)\n"
6862 "Do not export to next AS (well-known community)\n")
6863
6864ALIAS (show_ip_bgp_ipv4_community,
6865 show_ip_bgp_ipv4_community4_cmd,
6866 "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)",
6867 SHOW_STR
6868 IP_STR
6869 BGP_STR
6870 "Address family\n"
6871 "Address Family modifier\n"
6872 "Address Family modifier\n"
6873 "Display routes matching the communities\n"
6874 "community number\n"
6875 "Do not send outside local AS (well-known community)\n"
6876 "Do not advertise to any peer (well-known community)\n"
6877 "Do not export to next AS (well-known community)\n"
6878 "community number\n"
6879 "Do not send outside local AS (well-known community)\n"
6880 "Do not advertise to any peer (well-known community)\n"
6881 "Do not export to next AS (well-known community)\n"
6882 "community number\n"
6883 "Do not send outside local AS (well-known community)\n"
6884 "Do not advertise to any peer (well-known community)\n"
6885 "Do not export to next AS (well-known community)\n"
6886 "community number\n"
6887 "Do not send outside local AS (well-known community)\n"
6888 "Do not advertise to any peer (well-known community)\n"
6889 "Do not export to next AS (well-known community)\n")
6890
6891DEFUN (show_ip_bgp_community_exact,
6892 show_ip_bgp_community_exact_cmd,
6893 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6894 SHOW_STR
6895 IP_STR
6896 BGP_STR
6897 "Display routes matching the communities\n"
6898 "community number\n"
6899 "Do not send outside local AS (well-known community)\n"
6900 "Do not advertise to any peer (well-known community)\n"
6901 "Do not export to next AS (well-known community)\n"
6902 "Exact match of the communities")
6903{
6904 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
6905}
6906
6907ALIAS (show_ip_bgp_community_exact,
6908 show_ip_bgp_community2_exact_cmd,
6909 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6910 SHOW_STR
6911 IP_STR
6912 BGP_STR
6913 "Display routes matching the communities\n"
6914 "community number\n"
6915 "Do not send outside local AS (well-known community)\n"
6916 "Do not advertise to any peer (well-known community)\n"
6917 "Do not export to next AS (well-known community)\n"
6918 "community number\n"
6919 "Do not send outside local AS (well-known community)\n"
6920 "Do not advertise to any peer (well-known community)\n"
6921 "Do not export to next AS (well-known community)\n"
6922 "Exact match of the communities")
6923
6924ALIAS (show_ip_bgp_community_exact,
6925 show_ip_bgp_community3_exact_cmd,
6926 "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",
6927 SHOW_STR
6928 IP_STR
6929 BGP_STR
6930 "Display routes matching the communities\n"
6931 "community number\n"
6932 "Do not send outside local AS (well-known community)\n"
6933 "Do not advertise to any peer (well-known community)\n"
6934 "Do not export to next AS (well-known community)\n"
6935 "community number\n"
6936 "Do not send outside local AS (well-known community)\n"
6937 "Do not advertise to any peer (well-known community)\n"
6938 "Do not export to next AS (well-known community)\n"
6939 "community number\n"
6940 "Do not send outside local AS (well-known community)\n"
6941 "Do not advertise to any peer (well-known community)\n"
6942 "Do not export to next AS (well-known community)\n"
6943 "Exact match of the communities")
6944
6945ALIAS (show_ip_bgp_community_exact,
6946 show_ip_bgp_community4_exact_cmd,
6947 "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",
6948 SHOW_STR
6949 IP_STR
6950 BGP_STR
6951 "Display routes matching the communities\n"
6952 "community number\n"
6953 "Do not send outside local AS (well-known community)\n"
6954 "Do not advertise to any peer (well-known community)\n"
6955 "Do not export to next AS (well-known community)\n"
6956 "community number\n"
6957 "Do not send outside local AS (well-known community)\n"
6958 "Do not advertise to any peer (well-known community)\n"
6959 "Do not export to next AS (well-known community)\n"
6960 "community number\n"
6961 "Do not send outside local AS (well-known community)\n"
6962 "Do not advertise to any peer (well-known community)\n"
6963 "Do not export to next AS (well-known community)\n"
6964 "community number\n"
6965 "Do not send outside local AS (well-known community)\n"
6966 "Do not advertise to any peer (well-known community)\n"
6967 "Do not export to next AS (well-known community)\n"
6968 "Exact match of the communities")
6969
6970DEFUN (show_ip_bgp_ipv4_community_exact,
6971 show_ip_bgp_ipv4_community_exact_cmd,
6972 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6973 SHOW_STR
6974 IP_STR
6975 BGP_STR
6976 "Address family\n"
6977 "Address Family modifier\n"
6978 "Address Family modifier\n"
6979 "Display routes matching the communities\n"
6980 "community number\n"
6981 "Do not send outside local AS (well-known community)\n"
6982 "Do not advertise to any peer (well-known community)\n"
6983 "Do not export to next AS (well-known community)\n"
6984 "Exact match of the communities")
6985{
6986 if (strncmp (argv[0], "m", 1) == 0)
6987 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
6988
6989 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
6990}
6991
6992ALIAS (show_ip_bgp_ipv4_community_exact,
6993 show_ip_bgp_ipv4_community2_exact_cmd,
6994 "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",
6995 SHOW_STR
6996 IP_STR
6997 BGP_STR
6998 "Address family\n"
6999 "Address Family modifier\n"
7000 "Address Family modifier\n"
7001 "Display routes matching the communities\n"
7002 "community number\n"
7003 "Do not send outside local AS (well-known community)\n"
7004 "Do not advertise to any peer (well-known community)\n"
7005 "Do not export to next AS (well-known community)\n"
7006 "community number\n"
7007 "Do not send outside local AS (well-known community)\n"
7008 "Do not advertise to any peer (well-known community)\n"
7009 "Do not export to next AS (well-known community)\n"
7010 "Exact match of the communities")
7011
7012ALIAS (show_ip_bgp_ipv4_community_exact,
7013 show_ip_bgp_ipv4_community3_exact_cmd,
7014 "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",
7015 SHOW_STR
7016 IP_STR
7017 BGP_STR
7018 "Address family\n"
7019 "Address Family modifier\n"
7020 "Address Family modifier\n"
7021 "Display routes matching the communities\n"
7022 "community number\n"
7023 "Do not send outside local AS (well-known community)\n"
7024 "Do not advertise to any peer (well-known community)\n"
7025 "Do not export to next AS (well-known community)\n"
7026 "community number\n"
7027 "Do not send outside local AS (well-known community)\n"
7028 "Do not advertise to any peer (well-known community)\n"
7029 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
7035
7036ALIAS (show_ip_bgp_ipv4_community_exact,
7037 show_ip_bgp_ipv4_community4_exact_cmd,
7038 "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",
7039 SHOW_STR
7040 IP_STR
7041 BGP_STR
7042 "Address family\n"
7043 "Address Family modifier\n"
7044 "Address Family modifier\n"
7045 "Display routes matching the communities\n"
7046 "community number\n"
7047 "Do not send outside local AS (well-known community)\n"
7048 "Do not advertise to any peer (well-known community)\n"
7049 "Do not export to next AS (well-known community)\n"
7050 "community number\n"
7051 "Do not send outside local AS (well-known community)\n"
7052 "Do not advertise to any peer (well-known community)\n"
7053 "Do not export to next AS (well-known community)\n"
7054 "community number\n"
7055 "Do not send outside local AS (well-known community)\n"
7056 "Do not advertise to any peer (well-known community)\n"
7057 "Do not export to next AS (well-known community)\n"
7058 "community number\n"
7059 "Do not send outside local AS (well-known community)\n"
7060 "Do not advertise to any peer (well-known community)\n"
7061 "Do not export to next AS (well-known community)\n"
7062 "Exact match of the communities")
7063
7064#ifdef HAVE_IPV6
7065DEFUN (show_bgp_community,
7066 show_bgp_community_cmd,
7067 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7068 SHOW_STR
7069 BGP_STR
7070 "Display routes matching the communities\n"
7071 "community number\n"
7072 "Do not send outside local AS (well-known community)\n"
7073 "Do not advertise to any peer (well-known community)\n"
7074 "Do not export to next AS (well-known community)\n")
7075{
7076 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7077}
7078
7079ALIAS (show_bgp_community,
7080 show_bgp_ipv6_community_cmd,
7081 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7082 SHOW_STR
7083 BGP_STR
7084 "Address family\n"
7085 "Display routes matching the communities\n"
7086 "community number\n"
7087 "Do not send outside local AS (well-known community)\n"
7088 "Do not advertise to any peer (well-known community)\n"
7089 "Do not export to next AS (well-known community)\n")
7090
7091ALIAS (show_bgp_community,
7092 show_bgp_community2_cmd,
7093 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7094 SHOW_STR
7095 BGP_STR
7096 "Display routes matching the communities\n"
7097 "community number\n"
7098 "Do not send outside local AS (well-known community)\n"
7099 "Do not advertise to any peer (well-known community)\n"
7100 "Do not export to next AS (well-known community)\n"
7101 "community number\n"
7102 "Do not send outside local AS (well-known community)\n"
7103 "Do not advertise to any peer (well-known community)\n"
7104 "Do not export to next AS (well-known community)\n")
7105
7106ALIAS (show_bgp_community,
7107 show_bgp_ipv6_community2_cmd,
7108 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7109 SHOW_STR
7110 BGP_STR
7111 "Address family\n"
7112 "Display routes matching the communities\n"
7113 "community number\n"
7114 "Do not send outside local AS (well-known community)\n"
7115 "Do not advertise to any peer (well-known community)\n"
7116 "Do not export to next AS (well-known community)\n"
7117 "community number\n"
7118 "Do not send outside local AS (well-known community)\n"
7119 "Do not advertise to any peer (well-known community)\n"
7120 "Do not export to next AS (well-known community)\n")
7121
7122ALIAS (show_bgp_community,
7123 show_bgp_community3_cmd,
7124 "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)",
7125 SHOW_STR
7126 BGP_STR
7127 "Display routes matching the communities\n"
7128 "community number\n"
7129 "Do not send outside local AS (well-known community)\n"
7130 "Do not advertise to any peer (well-known community)\n"
7131 "Do not export to next AS (well-known community)\n"
7132 "community number\n"
7133 "Do not send outside local AS (well-known community)\n"
7134 "Do not advertise to any peer (well-known community)\n"
7135 "Do not export to next AS (well-known community)\n"
7136 "community number\n"
7137 "Do not send outside local AS (well-known community)\n"
7138 "Do not advertise to any peer (well-known community)\n"
7139 "Do not export to next AS (well-known community)\n")
7140
7141ALIAS (show_bgp_community,
7142 show_bgp_ipv6_community3_cmd,
7143 "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)",
7144 SHOW_STR
7145 BGP_STR
7146 "Address family\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_bgp_community,
7162 show_bgp_community4_cmd,
7163 "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)",
7164 SHOW_STR
7165 BGP_STR
7166 "Display routes matching the communities\n"
7167 "community number\n"
7168 "Do not send outside local AS (well-known community)\n"
7169 "Do not advertise to any peer (well-known community)\n"
7170 "Do not export to next AS (well-known community)\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
7184ALIAS (show_bgp_community,
7185 show_bgp_ipv6_community4_cmd,
7186 "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)",
7187 SHOW_STR
7188 BGP_STR
7189 "Address family\n"
7190 "Display routes matching the communities\n"
7191 "community number\n"
7192 "Do not send outside local AS (well-known community)\n"
7193 "Do not advertise to any peer (well-known community)\n"
7194 "Do not export to next AS (well-known community)\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 "community number\n"
7200 "Do not send outside local AS (well-known community)\n"
7201 "Do not advertise to any peer (well-known community)\n"
7202 "Do not export to next AS (well-known community)\n"
7203 "community number\n"
7204 "Do not send outside local AS (well-known community)\n"
7205 "Do not advertise to any peer (well-known community)\n"
7206 "Do not export to next AS (well-known community)\n")
7207
7208/* old command */
7209DEFUN (show_ipv6_bgp_community,
7210 show_ipv6_bgp_community_cmd,
7211 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7212 SHOW_STR
7213 IPV6_STR
7214 BGP_STR
7215 "Display routes matching the communities\n"
7216 "community number\n"
7217 "Do not send outside local AS (well-known community)\n"
7218 "Do not advertise to any peer (well-known community)\n"
7219 "Do not export to next AS (well-known community)\n")
7220{
7221 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7222}
7223
7224/* old command */
7225ALIAS (show_ipv6_bgp_community,
7226 show_ipv6_bgp_community2_cmd,
7227 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7228 SHOW_STR
7229 IPV6_STR
7230 BGP_STR
7231 "Display routes matching the communities\n"
7232 "community number\n"
7233 "Do not send outside local AS (well-known community)\n"
7234 "Do not advertise to any peer (well-known community)\n"
7235 "Do not export to next AS (well-known community)\n"
7236 "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
7241/* old command */
7242ALIAS (show_ipv6_bgp_community,
7243 show_ipv6_bgp_community3_cmd,
7244 "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)",
7245 SHOW_STR
7246 IPV6_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
7262/* old command */
7263ALIAS (show_ipv6_bgp_community,
7264 show_ipv6_bgp_community4_cmd,
7265 "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)",
7266 SHOW_STR
7267 IPV6_STR
7268 BGP_STR
7269 "Display routes matching the communities\n"
7270 "community number\n"
7271 "Do not send outside local AS (well-known community)\n"
7272 "Do not advertise to any peer (well-known community)\n"
7273 "Do not export to next AS (well-known community)\n"
7274 "community number\n"
7275 "Do not send outside local AS (well-known community)\n"
7276 "Do not advertise to any peer (well-known community)\n"
7277 "Do not export to next AS (well-known community)\n"
7278 "community number\n"
7279 "Do not send outside local AS (well-known community)\n"
7280 "Do not advertise to any peer (well-known community)\n"
7281 "Do not export to next AS (well-known community)\n"
7282 "community number\n"
7283 "Do not send outside local AS (well-known community)\n"
7284 "Do not advertise to any peer (well-known community)\n"
7285 "Do not export to next AS (well-known community)\n")
7286
7287DEFUN (show_bgp_community_exact,
7288 show_bgp_community_exact_cmd,
7289 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7290 SHOW_STR
7291 BGP_STR
7292 "Display routes matching the communities\n"
7293 "community number\n"
7294 "Do not send outside local AS (well-known community)\n"
7295 "Do not advertise to any peer (well-known community)\n"
7296 "Do not export to next AS (well-known community)\n"
7297 "Exact match of the communities")
7298{
7299 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7300}
7301
7302ALIAS (show_bgp_community_exact,
7303 show_bgp_ipv6_community_exact_cmd,
7304 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7305 SHOW_STR
7306 BGP_STR
7307 "Address family\n"
7308 "Display routes matching the communities\n"
7309 "community number\n"
7310 "Do not send outside local AS (well-known community)\n"
7311 "Do not advertise to any peer (well-known community)\n"
7312 "Do not export to next AS (well-known community)\n"
7313 "Exact match of the communities")
7314
7315ALIAS (show_bgp_community_exact,
7316 show_bgp_community2_exact_cmd,
7317 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7318 SHOW_STR
7319 BGP_STR
7320 "Display routes matching the communities\n"
7321 "community number\n"
7322 "Do not send outside local AS (well-known community)\n"
7323 "Do not advertise to any peer (well-known community)\n"
7324 "Do not export to next AS (well-known community)\n"
7325 "community number\n"
7326 "Do not send outside local AS (well-known community)\n"
7327 "Do not advertise to any peer (well-known community)\n"
7328 "Do not export to next AS (well-known community)\n"
7329 "Exact match of the communities")
7330
7331ALIAS (show_bgp_community_exact,
7332 show_bgp_ipv6_community2_exact_cmd,
7333 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7334 SHOW_STR
7335 BGP_STR
7336 "Address family\n"
7337 "Display routes matching the communities\n"
7338 "community number\n"
7339 "Do not send outside local AS (well-known community)\n"
7340 "Do not advertise to any peer (well-known community)\n"
7341 "Do not export to next AS (well-known community)\n"
7342 "community number\n"
7343 "Do not send outside local AS (well-known community)\n"
7344 "Do not advertise to any peer (well-known community)\n"
7345 "Do not export to next AS (well-known community)\n"
7346 "Exact match of the communities")
7347
7348ALIAS (show_bgp_community_exact,
7349 show_bgp_community3_exact_cmd,
7350 "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",
7351 SHOW_STR
7352 BGP_STR
7353 "Display routes matching the communities\n"
7354 "community number\n"
7355 "Do not send outside local AS (well-known community)\n"
7356 "Do not advertise to any peer (well-known community)\n"
7357 "Do not export to next AS (well-known community)\n"
7358 "community number\n"
7359 "Do not send outside local AS (well-known community)\n"
7360 "Do not advertise to any peer (well-known community)\n"
7361 "Do not export to next AS (well-known community)\n"
7362 "community number\n"
7363 "Do not send outside local AS (well-known community)\n"
7364 "Do not advertise to any peer (well-known community)\n"
7365 "Do not export to next AS (well-known community)\n"
7366 "Exact match of the communities")
7367
7368ALIAS (show_bgp_community_exact,
7369 show_bgp_ipv6_community3_exact_cmd,
7370 "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",
7371 SHOW_STR
7372 BGP_STR
7373 "Address family\n"
7374 "Display routes matching the communities\n"
7375 "community number\n"
7376 "Do not send outside local AS (well-known community)\n"
7377 "Do not advertise to any peer (well-known community)\n"
7378 "Do not export to next AS (well-known community)\n"
7379 "community number\n"
7380 "Do not send outside local AS (well-known community)\n"
7381 "Do not advertise to any peer (well-known community)\n"
7382 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
7388
7389ALIAS (show_bgp_community_exact,
7390 show_bgp_community4_exact_cmd,
7391 "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",
7392 SHOW_STR
7393 BGP_STR
7394 "Display routes matching the communities\n"
7395 "community number\n"
7396 "Do not send outside local AS (well-known community)\n"
7397 "Do not advertise to any peer (well-known community)\n"
7398 "Do not export to next AS (well-known community)\n"
7399 "community number\n"
7400 "Do not send outside local AS (well-known community)\n"
7401 "Do not advertise to any peer (well-known community)\n"
7402 "Do not export to next AS (well-known community)\n"
7403 "community number\n"
7404 "Do not send outside local AS (well-known community)\n"
7405 "Do not advertise to any peer (well-known community)\n"
7406 "Do not export to next AS (well-known community)\n"
7407 "community number\n"
7408 "Do not send outside local AS (well-known community)\n"
7409 "Do not advertise to any peer (well-known community)\n"
7410 "Do not export to next AS (well-known community)\n"
7411 "Exact match of the communities")
7412
7413ALIAS (show_bgp_community_exact,
7414 show_bgp_ipv6_community4_exact_cmd,
7415 "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",
7416 SHOW_STR
7417 BGP_STR
7418 "Address family\n"
7419 "Display routes matching the communities\n"
7420 "community number\n"
7421 "Do not send outside local AS (well-known community)\n"
7422 "Do not advertise to any peer (well-known community)\n"
7423 "Do not export to next AS (well-known community)\n"
7424 "community number\n"
7425 "Do not send outside local AS (well-known community)\n"
7426 "Do not advertise to any peer (well-known community)\n"
7427 "Do not export to next AS (well-known community)\n"
7428 "community number\n"
7429 "Do not send outside local AS (well-known community)\n"
7430 "Do not advertise to any peer (well-known community)\n"
7431 "Do not export to next AS (well-known community)\n"
7432 "community number\n"
7433 "Do not send outside local AS (well-known community)\n"
7434 "Do not advertise to any peer (well-known community)\n"
7435 "Do not export to next AS (well-known community)\n"
7436 "Exact match of the communities")
7437
7438/* old command */
7439DEFUN (show_ipv6_bgp_community_exact,
7440 show_ipv6_bgp_community_exact_cmd,
7441 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7442 SHOW_STR
7443 IPV6_STR
7444 BGP_STR
7445 "Display routes matching the communities\n"
7446 "community number\n"
7447 "Do not send outside local AS (well-known community)\n"
7448 "Do not advertise to any peer (well-known community)\n"
7449 "Do not export to next AS (well-known community)\n"
7450 "Exact match of the communities")
7451{
7452 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
7453}
7454
7455/* old command */
7456ALIAS (show_ipv6_bgp_community_exact,
7457 show_ipv6_bgp_community2_exact_cmd,
7458 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7459 SHOW_STR
7460 IPV6_STR
7461 BGP_STR
7462 "Display routes matching the communities\n"
7463 "community number\n"
7464 "Do not send outside local AS (well-known community)\n"
7465 "Do not advertise to any peer (well-known community)\n"
7466 "Do not export to next AS (well-known community)\n"
7467 "community number\n"
7468 "Do not send outside local AS (well-known community)\n"
7469 "Do not advertise to any peer (well-known community)\n"
7470 "Do not export to next AS (well-known community)\n"
7471 "Exact match of the communities")
7472
7473/* old command */
7474ALIAS (show_ipv6_bgp_community_exact,
7475 show_ipv6_bgp_community3_exact_cmd,
7476 "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",
7477 SHOW_STR
7478 IPV6_STR
7479 BGP_STR
7480 "Display routes matching the communities\n"
7481 "community number\n"
7482 "Do not send outside local AS (well-known community)\n"
7483 "Do not advertise to any peer (well-known community)\n"
7484 "Do not export to next AS (well-known community)\n"
7485 "community number\n"
7486 "Do not send outside local AS (well-known community)\n"
7487 "Do not advertise to any peer (well-known community)\n"
7488 "Do not export to next AS (well-known community)\n"
7489 "community number\n"
7490 "Do not send outside local AS (well-known community)\n"
7491 "Do not advertise to any peer (well-known community)\n"
7492 "Do not export to next AS (well-known community)\n"
7493 "Exact match of the communities")
7494
7495/* old command */
7496ALIAS (show_ipv6_bgp_community_exact,
7497 show_ipv6_bgp_community4_exact_cmd,
7498 "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",
7499 SHOW_STR
7500 IPV6_STR
7501 BGP_STR
7502 "Display routes matching the communities\n"
7503 "community number\n"
7504 "Do not send outside local AS (well-known community)\n"
7505 "Do not advertise to any peer (well-known community)\n"
7506 "Do not export to next AS (well-known community)\n"
7507 "community number\n"
7508 "Do not send outside local AS (well-known community)\n"
7509 "Do not advertise to any peer (well-known community)\n"
7510 "Do not export to next AS (well-known community)\n"
7511 "community number\n"
7512 "Do not send outside local AS (well-known community)\n"
7513 "Do not advertise to any peer (well-known community)\n"
7514 "Do not export to next AS (well-known community)\n"
7515 "community number\n"
7516 "Do not send outside local AS (well-known community)\n"
7517 "Do not advertise to any peer (well-known community)\n"
7518 "Do not export to next AS (well-known community)\n"
7519 "Exact match of the communities")
7520
7521/* old command */
7522DEFUN (show_ipv6_mbgp_community,
7523 show_ipv6_mbgp_community_cmd,
7524 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
7525 SHOW_STR
7526 IPV6_STR
7527 MBGP_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{
7534 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
7535}
7536
7537/* old command */
7538ALIAS (show_ipv6_mbgp_community,
7539 show_ipv6_mbgp_community2_cmd,
7540 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7541 SHOW_STR
7542 IPV6_STR
7543 MBGP_STR
7544 "Display routes matching the communities\n"
7545 "community number\n"
7546 "Do not send outside local AS (well-known community)\n"
7547 "Do not advertise to any peer (well-known community)\n"
7548 "Do not export to next AS (well-known community)\n"
7549 "community number\n"
7550 "Do not send outside local AS (well-known community)\n"
7551 "Do not advertise to any peer (well-known community)\n"
7552 "Do not export to next AS (well-known community)\n")
7553
7554/* old command */
7555ALIAS (show_ipv6_mbgp_community,
7556 show_ipv6_mbgp_community3_cmd,
7557 "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)",
7558 SHOW_STR
7559 IPV6_STR
7560 MBGP_STR
7561 "Display routes matching the communities\n"
7562 "community number\n"
7563 "Do not send outside local AS (well-known community)\n"
7564 "Do not advertise to any peer (well-known community)\n"
7565 "Do not export to next AS (well-known community)\n"
7566 "community number\n"
7567 "Do not send outside local AS (well-known community)\n"
7568 "Do not advertise to any peer (well-known community)\n"
7569 "Do not export to next AS (well-known community)\n"
7570 "community number\n"
7571 "Do not send outside local AS (well-known community)\n"
7572 "Do not advertise to any peer (well-known community)\n"
7573 "Do not export to next AS (well-known community)\n")
7574
7575/* old command */
7576ALIAS (show_ipv6_mbgp_community,
7577 show_ipv6_mbgp_community4_cmd,
7578 "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)",
7579 SHOW_STR
7580 IPV6_STR
7581 MBGP_STR
7582 "Display routes matching the communities\n"
7583 "community number\n"
7584 "Do not send outside local AS (well-known community)\n"
7585 "Do not advertise to any peer (well-known community)\n"
7586 "Do not export to next AS (well-known community)\n"
7587 "community number\n"
7588 "Do not send outside local AS (well-known community)\n"
7589 "Do not advertise to any peer (well-known community)\n"
7590 "Do not export to next AS (well-known community)\n"
7591 "community number\n"
7592 "Do not send outside local AS (well-known community)\n"
7593 "Do not advertise to any peer (well-known community)\n"
7594 "Do not export to next AS (well-known community)\n"
7595 "community number\n"
7596 "Do not send outside local AS (well-known community)\n"
7597 "Do not advertise to any peer (well-known community)\n"
7598 "Do not export to next AS (well-known community)\n")
7599
7600/* old command */
7601DEFUN (show_ipv6_mbgp_community_exact,
7602 show_ipv6_mbgp_community_exact_cmd,
7603 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7604 SHOW_STR
7605 IPV6_STR
7606 MBGP_STR
7607 "Display routes matching the communities\n"
7608 "community number\n"
7609 "Do not send outside local AS (well-known community)\n"
7610 "Do not advertise to any peer (well-known community)\n"
7611 "Do not export to next AS (well-known community)\n"
7612 "Exact match of the communities")
7613{
7614 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
7615}
7616
7617/* old command */
7618ALIAS (show_ipv6_mbgp_community_exact,
7619 show_ipv6_mbgp_community2_exact_cmd,
7620 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7621 SHOW_STR
7622 IPV6_STR
7623 MBGP_STR
7624 "Display routes matching the communities\n"
7625 "community number\n"
7626 "Do not send outside local AS (well-known community)\n"
7627 "Do not advertise to any peer (well-known community)\n"
7628 "Do not export to next AS (well-known community)\n"
7629 "community number\n"
7630 "Do not send outside local AS (well-known community)\n"
7631 "Do not advertise to any peer (well-known community)\n"
7632 "Do not export to next AS (well-known community)\n"
7633 "Exact match of the communities")
7634
7635/* old command */
7636ALIAS (show_ipv6_mbgp_community_exact,
7637 show_ipv6_mbgp_community3_exact_cmd,
7638 "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",
7639 SHOW_STR
7640 IPV6_STR
7641 MBGP_STR
7642 "Display routes matching the communities\n"
7643 "community number\n"
7644 "Do not send outside local AS (well-known community)\n"
7645 "Do not advertise to any peer (well-known community)\n"
7646 "Do not export to next AS (well-known community)\n"
7647 "community number\n"
7648 "Do not send outside local AS (well-known community)\n"
7649 "Do not advertise to any peer (well-known community)\n"
7650 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
7656
7657/* old command */
7658ALIAS (show_ipv6_mbgp_community_exact,
7659 show_ipv6_mbgp_community4_exact_cmd,
7660 "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",
7661 SHOW_STR
7662 IPV6_STR
7663 MBGP_STR
7664 "Display routes matching the communities\n"
7665 "community number\n"
7666 "Do not send outside local AS (well-known community)\n"
7667 "Do not advertise to any peer (well-known community)\n"
7668 "Do not export to next AS (well-known community)\n"
7669 "community number\n"
7670 "Do not send outside local AS (well-known community)\n"
7671 "Do not advertise to any peer (well-known community)\n"
7672 "Do not export to next AS (well-known community)\n"
7673 "community number\n"
7674 "Do not send outside local AS (well-known community)\n"
7675 "Do not advertise to any peer (well-known community)\n"
7676 "Do not export to next AS (well-known community)\n"
7677 "community number\n"
7678 "Do not send outside local AS (well-known community)\n"
7679 "Do not advertise to any peer (well-known community)\n"
7680 "Do not export to next AS (well-known community)\n"
7681 "Exact match of the communities")
7682#endif /* HAVE_IPV6 */
7683
7684int
paulfd79ac92004-10-13 05:06:08 +00007685bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00007686 u_int16_t afi, u_char safi)
7687{
7688 struct community_list *list;
7689
7690 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_AUTO);
7691 if (list == NULL)
7692 {
7693 vty_out (vty, "%% %s is not a valid community-list name%s", com,
7694 VTY_NEWLINE);
7695 return CMD_WARNING;
7696 }
7697
ajs5a646652004-11-05 01:25:55 +00007698 return bgp_show (vty, NULL, afi, safi,
7699 (exact ? bgp_show_type_community_list_exact :
7700 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00007701}
7702
7703DEFUN (show_ip_bgp_community_list,
7704 show_ip_bgp_community_list_cmd,
7705 "show ip bgp community-list WORD",
7706 SHOW_STR
7707 IP_STR
7708 BGP_STR
7709 "Display routes matching the community-list\n"
7710 "community-list name\n")
7711{
7712 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
7713}
7714
7715DEFUN (show_ip_bgp_ipv4_community_list,
7716 show_ip_bgp_ipv4_community_list_cmd,
7717 "show ip bgp ipv4 (unicast|multicast) community-list WORD",
7718 SHOW_STR
7719 IP_STR
7720 BGP_STR
7721 "Address family\n"
7722 "Address Family modifier\n"
7723 "Address Family modifier\n"
7724 "Display routes matching the community-list\n"
7725 "community-list name\n")
7726{
7727 if (strncmp (argv[0], "m", 1) == 0)
7728 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
7729
7730 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
7731}
7732
7733DEFUN (show_ip_bgp_community_list_exact,
7734 show_ip_bgp_community_list_exact_cmd,
7735 "show ip bgp community-list WORD exact-match",
7736 SHOW_STR
7737 IP_STR
7738 BGP_STR
7739 "Display routes matching the community-list\n"
7740 "community-list name\n"
7741 "Exact match of the communities\n")
7742{
7743 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
7744}
7745
7746DEFUN (show_ip_bgp_ipv4_community_list_exact,
7747 show_ip_bgp_ipv4_community_list_exact_cmd,
7748 "show ip bgp ipv4 (unicast|multicast) community-list WORD exact-match",
7749 SHOW_STR
7750 IP_STR
7751 BGP_STR
7752 "Address family\n"
7753 "Address Family modifier\n"
7754 "Address Family modifier\n"
7755 "Display routes matching the community-list\n"
7756 "community-list name\n"
7757 "Exact match of the communities\n")
7758{
7759 if (strncmp (argv[0], "m", 1) == 0)
7760 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
7761
7762 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
7763}
7764
7765#ifdef HAVE_IPV6
7766DEFUN (show_bgp_community_list,
7767 show_bgp_community_list_cmd,
7768 "show bgp community-list WORD",
7769 SHOW_STR
7770 BGP_STR
7771 "Display routes matching the community-list\n"
7772 "community-list name\n")
7773{
7774 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
7775}
7776
7777ALIAS (show_bgp_community_list,
7778 show_bgp_ipv6_community_list_cmd,
7779 "show bgp ipv6 community-list WORD",
7780 SHOW_STR
7781 BGP_STR
7782 "Address family\n"
7783 "Display routes matching the community-list\n"
7784 "community-list name\n")
7785
7786/* old command */
7787DEFUN (show_ipv6_bgp_community_list,
7788 show_ipv6_bgp_community_list_cmd,
7789 "show ipv6 bgp community-list WORD",
7790 SHOW_STR
7791 IPV6_STR
7792 BGP_STR
7793 "Display routes matching the community-list\n"
7794 "community-list name\n")
7795{
7796 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
7797}
7798
7799/* old command */
7800DEFUN (show_ipv6_mbgp_community_list,
7801 show_ipv6_mbgp_community_list_cmd,
7802 "show ipv6 mbgp community-list WORD",
7803 SHOW_STR
7804 IPV6_STR
7805 MBGP_STR
7806 "Display routes matching the community-list\n"
7807 "community-list name\n")
7808{
7809 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
7810}
7811
7812DEFUN (show_bgp_community_list_exact,
7813 show_bgp_community_list_exact_cmd,
7814 "show bgp community-list WORD exact-match",
7815 SHOW_STR
7816 BGP_STR
7817 "Display routes matching the community-list\n"
7818 "community-list name\n"
7819 "Exact match of the communities\n")
7820{
7821 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
7822}
7823
7824ALIAS (show_bgp_community_list_exact,
7825 show_bgp_ipv6_community_list_exact_cmd,
7826 "show bgp ipv6 community-list WORD exact-match",
7827 SHOW_STR
7828 BGP_STR
7829 "Address family\n"
7830 "Display routes matching the community-list\n"
7831 "community-list name\n"
7832 "Exact match of the communities\n")
7833
7834/* old command */
7835DEFUN (show_ipv6_bgp_community_list_exact,
7836 show_ipv6_bgp_community_list_exact_cmd,
7837 "show ipv6 bgp community-list WORD exact-match",
7838 SHOW_STR
7839 IPV6_STR
7840 BGP_STR
7841 "Display routes matching the community-list\n"
7842 "community-list name\n"
7843 "Exact match of the communities\n")
7844{
7845 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
7846}
7847
7848/* old command */
7849DEFUN (show_ipv6_mbgp_community_list_exact,
7850 show_ipv6_mbgp_community_list_exact_cmd,
7851 "show ipv6 mbgp community-list WORD exact-match",
7852 SHOW_STR
7853 IPV6_STR
7854 MBGP_STR
7855 "Display routes matching the community-list\n"
7856 "community-list name\n"
7857 "Exact match of the communities\n")
7858{
7859 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
7860}
7861#endif /* HAVE_IPV6 */
7862
paul718e3742002-12-13 20:15:29 +00007863int
paulfd79ac92004-10-13 05:06:08 +00007864bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007865 safi_t safi, enum bgp_show_type type)
7866{
7867 int ret;
7868 struct prefix *p;
7869
7870 p = prefix_new();
7871
7872 ret = str2prefix (prefix, p);
7873 if (! ret)
7874 {
7875 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
7876 return CMD_WARNING;
7877 }
7878
ajs5a646652004-11-05 01:25:55 +00007879 ret = bgp_show (vty, NULL, afi, safi, type, p);
7880 prefix_free(p);
7881 return ret;
paul718e3742002-12-13 20:15:29 +00007882}
7883
7884DEFUN (show_ip_bgp_prefix_longer,
7885 show_ip_bgp_prefix_longer_cmd,
7886 "show ip bgp A.B.C.D/M longer-prefixes",
7887 SHOW_STR
7888 IP_STR
7889 BGP_STR
7890 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7891 "Display route and more specific routes\n")
7892{
7893 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7894 bgp_show_type_prefix_longer);
7895}
7896
7897DEFUN (show_ip_bgp_flap_prefix_longer,
7898 show_ip_bgp_flap_prefix_longer_cmd,
7899 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
7900 SHOW_STR
7901 IP_STR
7902 BGP_STR
7903 "Display flap statistics of routes\n"
7904 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7905 "Display route and more specific routes\n")
7906{
7907 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7908 bgp_show_type_flap_prefix_longer);
7909}
7910
7911DEFUN (show_ip_bgp_ipv4_prefix_longer,
7912 show_ip_bgp_ipv4_prefix_longer_cmd,
7913 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
7914 SHOW_STR
7915 IP_STR
7916 BGP_STR
7917 "Address family\n"
7918 "Address Family modifier\n"
7919 "Address Family modifier\n"
7920 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7921 "Display route and more specific routes\n")
7922{
7923 if (strncmp (argv[0], "m", 1) == 0)
7924 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7925 bgp_show_type_prefix_longer);
7926
7927 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
7928 bgp_show_type_prefix_longer);
7929}
7930
7931DEFUN (show_ip_bgp_flap_address,
7932 show_ip_bgp_flap_address_cmd,
7933 "show ip bgp flap-statistics A.B.C.D",
7934 SHOW_STR
7935 IP_STR
7936 BGP_STR
7937 "Display flap statistics of routes\n"
7938 "Network in the BGP routing table to display\n")
7939{
7940 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7941 bgp_show_type_flap_address);
7942}
7943
7944DEFUN (show_ip_bgp_flap_prefix,
7945 show_ip_bgp_flap_prefix_cmd,
7946 "show ip bgp flap-statistics A.B.C.D/M",
7947 SHOW_STR
7948 IP_STR
7949 BGP_STR
7950 "Display flap statistics of routes\n"
7951 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7952{
7953 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7954 bgp_show_type_flap_prefix);
7955}
7956#ifdef HAVE_IPV6
7957DEFUN (show_bgp_prefix_longer,
7958 show_bgp_prefix_longer_cmd,
7959 "show bgp X:X::X:X/M longer-prefixes",
7960 SHOW_STR
7961 BGP_STR
7962 "IPv6 prefix <network>/<length>\n"
7963 "Display route and more specific routes\n")
7964{
7965 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7966 bgp_show_type_prefix_longer);
7967}
7968
7969ALIAS (show_bgp_prefix_longer,
7970 show_bgp_ipv6_prefix_longer_cmd,
7971 "show bgp ipv6 X:X::X:X/M longer-prefixes",
7972 SHOW_STR
7973 BGP_STR
7974 "Address family\n"
7975 "IPv6 prefix <network>/<length>\n"
7976 "Display route and more specific routes\n")
7977
7978/* old command */
7979DEFUN (show_ipv6_bgp_prefix_longer,
7980 show_ipv6_bgp_prefix_longer_cmd,
7981 "show ipv6 bgp X:X::X:X/M longer-prefixes",
7982 SHOW_STR
7983 IPV6_STR
7984 BGP_STR
7985 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7986 "Display route and more specific routes\n")
7987{
7988 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7989 bgp_show_type_prefix_longer);
7990}
7991
7992/* old command */
7993DEFUN (show_ipv6_mbgp_prefix_longer,
7994 show_ipv6_mbgp_prefix_longer_cmd,
7995 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
7996 SHOW_STR
7997 IPV6_STR
7998 MBGP_STR
7999 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8000 "Display route and more specific routes\n")
8001{
8002 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8003 bgp_show_type_prefix_longer);
8004}
8005#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008006
8007struct peer *
paulfd79ac92004-10-13 05:06:08 +00008008peer_lookup_in_view (struct vty *vty, const char *view_name,
8009 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008010{
8011 int ret;
8012 struct bgp *bgp;
8013 struct peer *peer;
8014 union sockunion su;
8015
8016 /* BGP structure lookup. */
8017 if (view_name)
8018 {
8019 bgp = bgp_lookup_by_name (view_name);
8020 if (! bgp)
8021 {
8022 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8023 return NULL;
8024 }
8025 }
paul5228ad22004-06-04 17:58:18 +00008026 else
paulbb46e942003-10-24 19:02:03 +00008027 {
8028 bgp = bgp_get_default ();
8029 if (! bgp)
8030 {
8031 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8032 return NULL;
8033 }
8034 }
8035
8036 /* Get peer sockunion. */
8037 ret = str2sockunion (ip_str, &su);
8038 if (ret < 0)
8039 {
8040 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8041 return NULL;
8042 }
8043
8044 /* Peer structure lookup. */
8045 peer = peer_lookup (bgp, &su);
8046 if (! peer)
8047 {
8048 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8049 return NULL;
8050 }
8051
8052 return peer;
8053}
8054
paul718e3742002-12-13 20:15:29 +00008055void
8056show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
8057 int in)
8058{
8059 struct bgp_table *table;
8060 struct bgp_adj_in *ain;
8061 struct bgp_adj_out *adj;
8062 unsigned long output_count;
8063 struct bgp_node *rn;
8064 int header1 = 1;
8065 struct bgp *bgp;
8066 int header2 = 1;
8067
paulbb46e942003-10-24 19:02:03 +00008068 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00008069
8070 if (! bgp)
8071 return;
8072
8073 table = bgp->rib[afi][safi];
8074
8075 output_count = 0;
8076
8077 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
8078 PEER_STATUS_DEFAULT_ORIGINATE))
8079 {
8080 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
8081 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
8082 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
8083
8084 vty_out (vty, "Originating default network 0.0.0.0%s%s",
8085 VTY_NEWLINE, VTY_NEWLINE);
8086 header1 = 0;
8087 }
8088
8089 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8090 if (in)
8091 {
8092 for (ain = rn->adj_in; ain; ain = ain->next)
8093 if (ain->peer == peer)
8094 {
8095 if (header1)
8096 {
8097 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
8098 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
8099 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
8100 header1 = 0;
8101 }
8102 if (header2)
8103 {
8104 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8105 header2 = 0;
8106 }
8107 if (ain->attr)
8108 {
8109 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
8110 output_count++;
8111 }
8112 }
8113 }
8114 else
8115 {
8116 for (adj = rn->adj_out; adj; adj = adj->next)
8117 if (adj->peer == peer)
8118 {
8119 if (header1)
8120 {
8121 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
8122 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
8123 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
8124 header1 = 0;
8125 }
8126 if (header2)
8127 {
8128 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
8129 header2 = 0;
8130 }
8131 if (adj->attr)
8132 {
8133 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
8134 output_count++;
8135 }
8136 }
8137 }
8138
8139 if (output_count != 0)
8140 vty_out (vty, "%sTotal number of prefixes %ld%s",
8141 VTY_NEWLINE, output_count, VTY_NEWLINE);
8142}
8143
8144int
paulbb46e942003-10-24 19:02:03 +00008145peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
8146{
paul718e3742002-12-13 20:15:29 +00008147 if (! peer || ! peer->afc[afi][safi])
8148 {
8149 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
8150 return CMD_WARNING;
8151 }
8152
8153 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
8154 {
8155 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
8156 VTY_NEWLINE);
8157 return CMD_WARNING;
8158 }
8159
8160 show_adj_route (vty, peer, afi, safi, in);
8161
8162 return CMD_SUCCESS;
8163}
8164
8165DEFUN (show_ip_bgp_neighbor_advertised_route,
8166 show_ip_bgp_neighbor_advertised_route_cmd,
8167 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8168 SHOW_STR
8169 IP_STR
8170 BGP_STR
8171 "Detailed information on TCP and BGP neighbor connections\n"
8172 "Neighbor to display information about\n"
8173 "Neighbor to display information about\n"
8174 "Display the routes advertised to a BGP neighbor\n")
8175{
paulbb46e942003-10-24 19:02:03 +00008176 struct peer *peer;
8177
8178 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8179 if (! peer)
8180 return CMD_WARNING;
8181
8182 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008183}
8184
8185DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
8186 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
8187 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8188 SHOW_STR
8189 IP_STR
8190 BGP_STR
8191 "Address family\n"
8192 "Address Family modifier\n"
8193 "Address Family modifier\n"
8194 "Detailed information on TCP and BGP neighbor connections\n"
8195 "Neighbor to display information about\n"
8196 "Neighbor to display information about\n"
8197 "Display the routes advertised to a BGP neighbor\n")
8198{
paulbb46e942003-10-24 19:02:03 +00008199 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008200
paulbb46e942003-10-24 19:02:03 +00008201 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8202 if (! peer)
8203 return CMD_WARNING;
8204
8205 if (strncmp (argv[0], "m", 1) == 0)
8206 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
8207
8208 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00008209}
8210
8211#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008212DEFUN (show_bgp_view_neighbor_advertised_route,
8213 show_bgp_view_neighbor_advertised_route_cmd,
8214 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8215 SHOW_STR
8216 BGP_STR
8217 "BGP view\n"
8218 "View name\n"
8219 "Detailed information on TCP and BGP neighbor connections\n"
8220 "Neighbor to display information about\n"
8221 "Neighbor to display information about\n"
8222 "Display the routes advertised to a BGP neighbor\n")
8223{
8224 struct peer *peer;
8225
8226 if (argc == 2)
8227 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8228 else
8229 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8230
8231 if (! peer)
8232 return CMD_WARNING;
8233
8234 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
8235}
8236
8237ALIAS (show_bgp_view_neighbor_advertised_route,
8238 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
8239 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8240 SHOW_STR
8241 BGP_STR
8242 "BGP view\n"
8243 "View name\n"
8244 "Address family\n"
8245 "Detailed information on TCP and BGP neighbor connections\n"
8246 "Neighbor to display information about\n"
8247 "Neighbor to display information about\n"
8248 "Display the routes advertised to a BGP neighbor\n")
8249
8250DEFUN (show_bgp_view_neighbor_received_routes,
8251 show_bgp_view_neighbor_received_routes_cmd,
8252 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
8253 SHOW_STR
8254 BGP_STR
8255 "BGP view\n"
8256 "View name\n"
8257 "Detailed information on TCP and BGP neighbor connections\n"
8258 "Neighbor to display information about\n"
8259 "Neighbor to display information about\n"
8260 "Display the received routes from neighbor\n")
8261{
8262 struct peer *peer;
8263
8264 if (argc == 2)
8265 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8266 else
8267 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8268
8269 if (! peer)
8270 return CMD_WARNING;
8271
8272 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
8273}
8274
8275ALIAS (show_bgp_view_neighbor_received_routes,
8276 show_bgp_view_ipv6_neighbor_received_routes_cmd,
8277 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8278 SHOW_STR
8279 BGP_STR
8280 "BGP view\n"
8281 "View name\n"
8282 "Address family\n"
8283 "Detailed information on TCP and BGP neighbor connections\n"
8284 "Neighbor to display information about\n"
8285 "Neighbor to display information about\n"
8286 "Display the received routes from neighbor\n")
8287
8288ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008289 show_bgp_neighbor_advertised_route_cmd,
8290 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8291 SHOW_STR
8292 BGP_STR
8293 "Detailed information on TCP and BGP neighbor connections\n"
8294 "Neighbor to display information about\n"
8295 "Neighbor to display information about\n"
8296 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008297
8298ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008299 show_bgp_ipv6_neighbor_advertised_route_cmd,
8300 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8301 SHOW_STR
8302 BGP_STR
8303 "Address family\n"
8304 "Detailed information on TCP and BGP neighbor connections\n"
8305 "Neighbor to display information about\n"
8306 "Neighbor to display information about\n"
8307 "Display the routes advertised to a BGP neighbor\n")
8308
8309/* old command */
paulbb46e942003-10-24 19:02:03 +00008310ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00008311 ipv6_bgp_neighbor_advertised_route_cmd,
8312 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8313 SHOW_STR
8314 IPV6_STR
8315 BGP_STR
8316 "Detailed information on TCP and BGP neighbor connections\n"
8317 "Neighbor to display information about\n"
8318 "Neighbor to display information about\n"
8319 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00008320
paul718e3742002-12-13 20:15:29 +00008321/* old command */
8322DEFUN (ipv6_mbgp_neighbor_advertised_route,
8323 ipv6_mbgp_neighbor_advertised_route_cmd,
8324 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
8325 SHOW_STR
8326 IPV6_STR
8327 MBGP_STR
8328 "Detailed information on TCP and BGP neighbor connections\n"
8329 "Neighbor to display information about\n"
8330 "Neighbor to display information about\n"
8331 "Display the routes advertised to a BGP neighbor\n")
8332{
paulbb46e942003-10-24 19:02:03 +00008333 struct peer *peer;
8334
8335 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8336 if (! peer)
8337 return CMD_WARNING;
8338
8339 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00008340}
8341#endif /* HAVE_IPV6 */
8342
8343DEFUN (show_ip_bgp_neighbor_received_routes,
8344 show_ip_bgp_neighbor_received_routes_cmd,
8345 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8346 SHOW_STR
8347 IP_STR
8348 BGP_STR
8349 "Detailed information on TCP and BGP neighbor connections\n"
8350 "Neighbor to display information about\n"
8351 "Neighbor to display information about\n"
8352 "Display the received routes from neighbor\n")
8353{
paulbb46e942003-10-24 19:02:03 +00008354 struct peer *peer;
8355
8356 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8357 if (! peer)
8358 return CMD_WARNING;
8359
8360 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008361}
8362
8363DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
8364 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
8365 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
8366 SHOW_STR
8367 IP_STR
8368 BGP_STR
8369 "Address family\n"
8370 "Address Family modifier\n"
8371 "Address Family modifier\n"
8372 "Detailed information on TCP and BGP neighbor connections\n"
8373 "Neighbor to display information about\n"
8374 "Neighbor to display information about\n"
8375 "Display the received routes from neighbor\n")
8376{
paulbb46e942003-10-24 19:02:03 +00008377 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00008378
paulbb46e942003-10-24 19:02:03 +00008379 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8380 if (! peer)
8381 return CMD_WARNING;
8382
8383 if (strncmp (argv[0], "m", 1) == 0)
8384 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
8385
8386 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00008387}
8388
8389DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
8390 show_ip_bgp_neighbor_received_prefix_filter_cmd,
8391 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8392 SHOW_STR
8393 IP_STR
8394 BGP_STR
8395 "Detailed information on TCP and BGP neighbor connections\n"
8396 "Neighbor to display information about\n"
8397 "Neighbor to display information about\n"
8398 "Display information received from a BGP neighbor\n"
8399 "Display the prefixlist filter\n")
8400{
8401 char name[BUFSIZ];
8402 union sockunion *su;
8403 struct peer *peer;
8404 int count;
8405
8406 su = sockunion_str2su (argv[0]);
8407 if (su == NULL)
8408 return CMD_WARNING;
8409
8410 peer = peer_lookup (NULL, su);
8411 if (! peer)
8412 return CMD_WARNING;
8413
8414 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8415 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8416 if (count)
8417 {
8418 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8419 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8420 }
8421
8422 return CMD_SUCCESS;
8423}
8424
8425DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
8426 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
8427 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8428 SHOW_STR
8429 IP_STR
8430 BGP_STR
8431 "Address family\n"
8432 "Address Family modifier\n"
8433 "Address Family modifier\n"
8434 "Detailed information on TCP and BGP neighbor connections\n"
8435 "Neighbor to display information about\n"
8436 "Neighbor to display information about\n"
8437 "Display information received from a BGP neighbor\n"
8438 "Display the prefixlist filter\n")
8439{
8440 char name[BUFSIZ];
8441 union sockunion *su;
8442 struct peer *peer;
8443 int count;
8444
8445 su = sockunion_str2su (argv[1]);
8446 if (su == NULL)
8447 return CMD_WARNING;
8448
8449 peer = peer_lookup (NULL, su);
8450 if (! peer)
8451 return CMD_WARNING;
8452
8453 if (strncmp (argv[0], "m", 1) == 0)
8454 {
8455 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
8456 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8457 if (count)
8458 {
8459 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
8460 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8461 }
8462 }
8463 else
8464 {
8465 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
8466 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
8467 if (count)
8468 {
8469 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
8470 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
8471 }
8472 }
8473
8474 return CMD_SUCCESS;
8475}
8476
8477
8478#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008479ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008480 show_bgp_neighbor_received_routes_cmd,
8481 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8482 SHOW_STR
8483 BGP_STR
8484 "Detailed information on TCP and BGP neighbor connections\n"
8485 "Neighbor to display information about\n"
8486 "Neighbor to display information about\n"
8487 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008488
paulbb46e942003-10-24 19:02:03 +00008489ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008490 show_bgp_ipv6_neighbor_received_routes_cmd,
8491 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
8492 SHOW_STR
8493 BGP_STR
8494 "Address family\n"
8495 "Detailed information on TCP and BGP neighbor connections\n"
8496 "Neighbor to display information about\n"
8497 "Neighbor to display information about\n"
8498 "Display the received routes from neighbor\n")
8499
8500DEFUN (show_bgp_neighbor_received_prefix_filter,
8501 show_bgp_neighbor_received_prefix_filter_cmd,
8502 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8503 SHOW_STR
8504 BGP_STR
8505 "Detailed information on TCP and BGP neighbor connections\n"
8506 "Neighbor to display information about\n"
8507 "Neighbor to display information about\n"
8508 "Display information received from a BGP neighbor\n"
8509 "Display the prefixlist filter\n")
8510{
8511 char name[BUFSIZ];
8512 union sockunion *su;
8513 struct peer *peer;
8514 int count;
8515
8516 su = sockunion_str2su (argv[0]);
8517 if (su == NULL)
8518 return CMD_WARNING;
8519
8520 peer = peer_lookup (NULL, su);
8521 if (! peer)
8522 return CMD_WARNING;
8523
8524 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8525 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8526 if (count)
8527 {
8528 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8529 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8530 }
8531
8532 return CMD_SUCCESS;
8533}
8534
8535ALIAS (show_bgp_neighbor_received_prefix_filter,
8536 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
8537 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8538 SHOW_STR
8539 BGP_STR
8540 "Address family\n"
8541 "Detailed information on TCP and BGP neighbor connections\n"
8542 "Neighbor to display information about\n"
8543 "Neighbor to display information about\n"
8544 "Display information received from a BGP neighbor\n"
8545 "Display the prefixlist filter\n")
8546
8547/* old command */
paulbb46e942003-10-24 19:02:03 +00008548ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00008549 ipv6_bgp_neighbor_received_routes_cmd,
8550 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8551 SHOW_STR
8552 IPV6_STR
8553 BGP_STR
8554 "Detailed information on TCP and BGP neighbor connections\n"
8555 "Neighbor to display information about\n"
8556 "Neighbor to display information about\n"
8557 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008558
8559/* old command */
8560DEFUN (ipv6_mbgp_neighbor_received_routes,
8561 ipv6_mbgp_neighbor_received_routes_cmd,
8562 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
8563 SHOW_STR
8564 IPV6_STR
8565 MBGP_STR
8566 "Detailed information on TCP and BGP neighbor connections\n"
8567 "Neighbor to display information about\n"
8568 "Neighbor to display information about\n"
8569 "Display the received routes from neighbor\n")
8570{
paulbb46e942003-10-24 19:02:03 +00008571 struct peer *peer;
8572
8573 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8574 if (! peer)
8575 return CMD_WARNING;
8576
8577 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00008578}
paulbb46e942003-10-24 19:02:03 +00008579
8580DEFUN (show_bgp_view_neighbor_received_prefix_filter,
8581 show_bgp_view_neighbor_received_prefix_filter_cmd,
8582 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8583 SHOW_STR
8584 BGP_STR
8585 "BGP view\n"
8586 "View name\n"
8587 "Detailed information on TCP and BGP neighbor connections\n"
8588 "Neighbor to display information about\n"
8589 "Neighbor to display information about\n"
8590 "Display information received from a BGP neighbor\n"
8591 "Display the prefixlist filter\n")
8592{
8593 char name[BUFSIZ];
8594 union sockunion *su;
8595 struct peer *peer;
8596 struct bgp *bgp;
8597 int count;
8598
8599 /* BGP structure lookup. */
8600 bgp = bgp_lookup_by_name (argv[0]);
8601 if (bgp == NULL)
8602 {
8603 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8604 return CMD_WARNING;
8605 }
8606
8607 su = sockunion_str2su (argv[1]);
8608 if (su == NULL)
8609 return CMD_WARNING;
8610
8611 peer = peer_lookup (bgp, su);
8612 if (! peer)
8613 return CMD_WARNING;
8614
8615 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
8616 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
8617 if (count)
8618 {
8619 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
8620 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
8621 }
8622
8623 return CMD_SUCCESS;
8624}
8625
8626ALIAS (show_bgp_view_neighbor_received_prefix_filter,
8627 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
8628 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8629 SHOW_STR
8630 BGP_STR
8631 "BGP view\n"
8632 "View name\n"
8633 "Address family\n"
8634 "Detailed information on TCP and BGP neighbor connections\n"
8635 "Neighbor to display information about\n"
8636 "Neighbor to display information about\n"
8637 "Display information received from a BGP neighbor\n"
8638 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00008639#endif /* HAVE_IPV6 */
8640
paul718e3742002-12-13 20:15:29 +00008641int
paulbb46e942003-10-24 19:02:03 +00008642bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008643 safi_t safi, enum bgp_show_type type)
8644{
paul718e3742002-12-13 20:15:29 +00008645 if (! peer || ! peer->afc[afi][safi])
8646 {
8647 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008648 return CMD_WARNING;
8649 }
8650
ajs5a646652004-11-05 01:25:55 +00008651 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +00008652}
8653
8654DEFUN (show_ip_bgp_neighbor_routes,
8655 show_ip_bgp_neighbor_routes_cmd,
8656 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
8657 SHOW_STR
8658 IP_STR
8659 BGP_STR
8660 "Detailed information on TCP and BGP neighbor connections\n"
8661 "Neighbor to display information about\n"
8662 "Neighbor to display information about\n"
8663 "Display routes learned from neighbor\n")
8664{
paulbb46e942003-10-24 19:02:03 +00008665 struct peer *peer;
8666
8667 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8668 if (! peer)
8669 return CMD_WARNING;
8670
8671 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008672 bgp_show_type_neighbor);
8673}
8674
8675DEFUN (show_ip_bgp_neighbor_flap,
8676 show_ip_bgp_neighbor_flap_cmd,
8677 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
8678 SHOW_STR
8679 IP_STR
8680 BGP_STR
8681 "Detailed information on TCP and BGP neighbor connections\n"
8682 "Neighbor to display information about\n"
8683 "Neighbor to display information about\n"
8684 "Display flap statistics of the routes learned from neighbor\n")
8685{
paulbb46e942003-10-24 19:02:03 +00008686 struct peer *peer;
8687
8688 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8689 if (! peer)
8690 return CMD_WARNING;
8691
8692 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008693 bgp_show_type_flap_neighbor);
8694}
8695
8696DEFUN (show_ip_bgp_neighbor_damp,
8697 show_ip_bgp_neighbor_damp_cmd,
8698 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
8699 SHOW_STR
8700 IP_STR
8701 BGP_STR
8702 "Detailed information on TCP and BGP neighbor connections\n"
8703 "Neighbor to display information about\n"
8704 "Neighbor to display information about\n"
8705 "Display the dampened routes received from neighbor\n")
8706{
paulbb46e942003-10-24 19:02:03 +00008707 struct peer *peer;
8708
8709 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8710 if (! peer)
8711 return CMD_WARNING;
8712
8713 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008714 bgp_show_type_damp_neighbor);
8715}
8716
8717DEFUN (show_ip_bgp_ipv4_neighbor_routes,
8718 show_ip_bgp_ipv4_neighbor_routes_cmd,
8719 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
8720 SHOW_STR
8721 IP_STR
8722 BGP_STR
8723 "Address family\n"
8724 "Address Family modifier\n"
8725 "Address Family modifier\n"
8726 "Detailed information on TCP and BGP neighbor connections\n"
8727 "Neighbor to display information about\n"
8728 "Neighbor to display information about\n"
8729 "Display routes learned from neighbor\n")
8730{
paulbb46e942003-10-24 19:02:03 +00008731 struct peer *peer;
8732
8733 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8734 if (! peer)
8735 return CMD_WARNING;
8736
paul718e3742002-12-13 20:15:29 +00008737 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00008738 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00008739 bgp_show_type_neighbor);
8740
paulbb46e942003-10-24 19:02:03 +00008741 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008742 bgp_show_type_neighbor);
8743}
paulbb46e942003-10-24 19:02:03 +00008744
paulfee0f4c2004-09-13 05:12:46 +00008745DEFUN (show_ip_bgp_view_rsclient,
8746 show_ip_bgp_view_rsclient_cmd,
8747 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
8748 SHOW_STR
8749 IP_STR
8750 BGP_STR
8751 "BGP view\n"
8752 "BGP view name\n"
8753 "Information about Route Server Client\n"
8754 NEIGHBOR_ADDR_STR)
8755{
8756 struct bgp_table *table;
8757 struct peer *peer;
8758
8759 if (argc == 2)
8760 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8761 else
8762 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8763
8764 if (! peer)
8765 return CMD_WARNING;
8766
8767 if (! peer->afc[AFI_IP][SAFI_UNICAST])
8768 {
8769 vty_out (vty, "%% Activate the neighbor for the address family first%s",
8770 VTY_NEWLINE);
8771 return CMD_WARNING;
8772 }
8773
8774 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
8775 PEER_FLAG_RSERVER_CLIENT))
8776 {
8777 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
8778 VTY_NEWLINE);
8779 return CMD_WARNING;
8780 }
8781
8782 table = peer->rib[AFI_IP][SAFI_UNICAST];
8783
ajs5a646652004-11-05 01:25:55 +00008784 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00008785}
8786
8787ALIAS (show_ip_bgp_view_rsclient,
8788 show_ip_bgp_rsclient_cmd,
8789 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
8790 SHOW_STR
8791 IP_STR
8792 BGP_STR
8793 "Information about Route Server Client\n"
8794 NEIGHBOR_ADDR_STR)
8795
8796DEFUN (show_ip_bgp_view_rsclient_route,
8797 show_ip_bgp_view_rsclient_route_cmd,
8798 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
8799 SHOW_STR
8800 IP_STR
8801 BGP_STR
8802 "BGP view\n"
8803 "BGP view name\n"
8804 "Information about Route Server Client\n"
8805 NEIGHBOR_ADDR_STR
8806 "Network in the BGP routing table to display\n")
8807{
8808 struct bgp *bgp;
8809 struct peer *peer;
8810
8811 /* BGP structure lookup. */
8812 if (argc == 3)
8813 {
8814 bgp = bgp_lookup_by_name (argv[0]);
8815 if (bgp == NULL)
8816 {
8817 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8818 return CMD_WARNING;
8819 }
8820 }
8821 else
8822 {
8823 bgp = bgp_get_default ();
8824 if (bgp == NULL)
8825 {
8826 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8827 return CMD_WARNING;
8828 }
8829 }
8830
8831 if (argc == 3)
8832 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8833 else
8834 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8835
8836 if (! peer)
8837 return CMD_WARNING;
8838
8839 if (! peer->afc[AFI_IP][SAFI_UNICAST])
8840 {
8841 vty_out (vty, "%% Activate the neighbor for the address family first%s",
8842 VTY_NEWLINE);
8843 return CMD_WARNING;
8844}
8845
8846 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
8847 PEER_FLAG_RSERVER_CLIENT))
8848 {
8849 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
8850 VTY_NEWLINE);
8851 return CMD_WARNING;
8852 }
8853
8854 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
8855 (argc == 3) ? argv[2] : argv[1],
8856 AFI_IP, SAFI_UNICAST, NULL, 0);
8857}
8858
8859ALIAS (show_ip_bgp_view_rsclient_route,
8860 show_ip_bgp_rsclient_route_cmd,
8861 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
8862 SHOW_STR
8863 IP_STR
8864 BGP_STR
8865 "Information about Route Server Client\n"
8866 NEIGHBOR_ADDR_STR
8867 "Network in the BGP routing table to display\n")
8868
8869DEFUN (show_ip_bgp_view_rsclient_prefix,
8870 show_ip_bgp_view_rsclient_prefix_cmd,
8871 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
8872 SHOW_STR
8873 IP_STR
8874 BGP_STR
8875 "BGP view\n"
8876 "BGP view name\n"
8877 "Information about Route Server Client\n"
8878 NEIGHBOR_ADDR_STR
8879 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8880{
8881 struct bgp *bgp;
8882 struct peer *peer;
8883
8884 /* BGP structure lookup. */
8885 if (argc == 3)
8886 {
8887 bgp = bgp_lookup_by_name (argv[0]);
8888 if (bgp == NULL)
8889 {
8890 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8891 return CMD_WARNING;
8892 }
8893 }
8894 else
8895 {
8896 bgp = bgp_get_default ();
8897 if (bgp == NULL)
8898 {
8899 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8900 return CMD_WARNING;
8901 }
8902 }
8903
8904 if (argc == 3)
8905 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8906 else
8907 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8908
8909 if (! peer)
8910 return CMD_WARNING;
8911
8912 if (! peer->afc[AFI_IP][SAFI_UNICAST])
8913 {
8914 vty_out (vty, "%% Activate the neighbor for the address family first%s",
8915 VTY_NEWLINE);
8916 return CMD_WARNING;
8917}
8918
8919 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
8920 PEER_FLAG_RSERVER_CLIENT))
8921{
8922 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
8923 VTY_NEWLINE);
8924 return CMD_WARNING;
8925 }
8926
8927 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
8928 (argc == 3) ? argv[2] : argv[1],
8929 AFI_IP, SAFI_UNICAST, NULL, 1);
8930}
8931
8932ALIAS (show_ip_bgp_view_rsclient_prefix,
8933 show_ip_bgp_rsclient_prefix_cmd,
8934 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
8935 SHOW_STR
8936 IP_STR
8937 BGP_STR
8938 "Information about Route Server Client\n"
8939 NEIGHBOR_ADDR_STR
8940 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8941
8942
paul718e3742002-12-13 20:15:29 +00008943#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008944DEFUN (show_bgp_view_neighbor_routes,
8945 show_bgp_view_neighbor_routes_cmd,
8946 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
8947 SHOW_STR
8948 BGP_STR
8949 "BGP view\n"
8950 "BGP view name\n"
8951 "Detailed information on TCP and BGP neighbor connections\n"
8952 "Neighbor to display information about\n"
8953 "Neighbor to display information about\n"
8954 "Display routes learned from neighbor\n")
8955{
8956 struct peer *peer;
8957
8958 if (argc == 2)
8959 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8960 else
8961 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8962
8963 if (! peer)
8964 return CMD_WARNING;
8965
8966 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
8967 bgp_show_type_neighbor);
8968}
8969
8970ALIAS (show_bgp_view_neighbor_routes,
8971 show_bgp_view_ipv6_neighbor_routes_cmd,
8972 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
8973 SHOW_STR
8974 BGP_STR
8975 "BGP view\n"
8976 "BGP view name\n"
8977 "Address family\n"
8978 "Detailed information on TCP and BGP neighbor connections\n"
8979 "Neighbor to display information about\n"
8980 "Neighbor to display information about\n"
8981 "Display routes learned from neighbor\n")
8982
8983DEFUN (show_bgp_view_neighbor_damp,
8984 show_bgp_view_neighbor_damp_cmd,
8985 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
8986 SHOW_STR
8987 BGP_STR
8988 "BGP view\n"
8989 "BGP view name\n"
8990 "Detailed information on TCP and BGP neighbor connections\n"
8991 "Neighbor to display information about\n"
8992 "Neighbor to display information about\n"
8993 "Display the dampened routes received from neighbor\n")
8994{
8995 struct peer *peer;
8996
8997 if (argc == 2)
8998 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8999 else
9000 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9001
9002 if (! peer)
9003 return CMD_WARNING;
9004
9005 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9006 bgp_show_type_damp_neighbor);
9007}
9008
9009ALIAS (show_bgp_view_neighbor_damp,
9010 show_bgp_view_ipv6_neighbor_damp_cmd,
9011 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9012 SHOW_STR
9013 BGP_STR
9014 "BGP view\n"
9015 "BGP view name\n"
9016 "Address family\n"
9017 "Detailed information on TCP and BGP neighbor connections\n"
9018 "Neighbor to display information about\n"
9019 "Neighbor to display information about\n"
9020 "Display the dampened routes received from neighbor\n")
9021
9022DEFUN (show_bgp_view_neighbor_flap,
9023 show_bgp_view_neighbor_flap_cmd,
9024 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9025 SHOW_STR
9026 BGP_STR
9027 "BGP view\n"
9028 "BGP view name\n"
9029 "Detailed information on TCP and BGP neighbor connections\n"
9030 "Neighbor to display information about\n"
9031 "Neighbor to display information about\n"
9032 "Display flap statistics of the routes learned from neighbor\n")
9033{
9034 struct peer *peer;
9035
9036 if (argc == 2)
9037 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9038 else
9039 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9040
9041 if (! peer)
9042 return CMD_WARNING;
9043
9044 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
9045 bgp_show_type_flap_neighbor);
9046}
9047
9048ALIAS (show_bgp_view_neighbor_flap,
9049 show_bgp_view_ipv6_neighbor_flap_cmd,
9050 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9051 SHOW_STR
9052 BGP_STR
9053 "BGP view\n"
9054 "BGP view name\n"
9055 "Address family\n"
9056 "Detailed information on TCP and BGP neighbor connections\n"
9057 "Neighbor to display information about\n"
9058 "Neighbor to display information about\n"
9059 "Display flap statistics of the routes learned from neighbor\n")
9060
9061ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009062 show_bgp_neighbor_routes_cmd,
9063 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
9064 SHOW_STR
9065 BGP_STR
9066 "Detailed information on TCP and BGP neighbor connections\n"
9067 "Neighbor to display information about\n"
9068 "Neighbor to display information about\n"
9069 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009070
paulbb46e942003-10-24 19:02:03 +00009071
9072ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009073 show_bgp_ipv6_neighbor_routes_cmd,
9074 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
9075 SHOW_STR
9076 BGP_STR
9077 "Address family\n"
9078 "Detailed information on TCP and BGP neighbor connections\n"
9079 "Neighbor to display information about\n"
9080 "Neighbor to display information about\n"
9081 "Display routes learned from neighbor\n")
9082
9083/* old command */
paulbb46e942003-10-24 19:02:03 +00009084ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00009085 ipv6_bgp_neighbor_routes_cmd,
9086 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
9087 SHOW_STR
9088 IPV6_STR
9089 BGP_STR
9090 "Detailed information on TCP and BGP neighbor connections\n"
9091 "Neighbor to display information about\n"
9092 "Neighbor to display information about\n"
9093 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009094
9095/* old command */
9096DEFUN (ipv6_mbgp_neighbor_routes,
9097 ipv6_mbgp_neighbor_routes_cmd,
9098 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
9099 SHOW_STR
9100 IPV6_STR
9101 MBGP_STR
9102 "Detailed information on TCP and BGP neighbor connections\n"
9103 "Neighbor to display information about\n"
9104 "Neighbor to display information about\n"
9105 "Display routes learned from neighbor\n")
9106{
paulbb46e942003-10-24 19:02:03 +00009107 struct peer *peer;
9108
9109 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9110 if (! peer)
9111 return CMD_WARNING;
9112
9113 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00009114 bgp_show_type_neighbor);
9115}
paulbb46e942003-10-24 19:02:03 +00009116
9117ALIAS (show_bgp_view_neighbor_flap,
9118 show_bgp_neighbor_flap_cmd,
9119 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9120 SHOW_STR
9121 BGP_STR
9122 "Detailed information on TCP and BGP neighbor connections\n"
9123 "Neighbor to display information about\n"
9124 "Neighbor to display information about\n"
9125 "Display flap statistics of the routes learned from neighbor\n")
9126
9127ALIAS (show_bgp_view_neighbor_flap,
9128 show_bgp_ipv6_neighbor_flap_cmd,
9129 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
9130 SHOW_STR
9131 BGP_STR
9132 "Address family\n"
9133 "Detailed information on TCP and BGP neighbor connections\n"
9134 "Neighbor to display information about\n"
9135 "Neighbor to display information about\n"
9136 "Display flap statistics of the routes learned from neighbor\n")
9137
9138ALIAS (show_bgp_view_neighbor_damp,
9139 show_bgp_neighbor_damp_cmd,
9140 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9141 SHOW_STR
9142 BGP_STR
9143 "Detailed information on TCP and BGP neighbor connections\n"
9144 "Neighbor to display information about\n"
9145 "Neighbor to display information about\n"
9146 "Display the dampened routes received from neighbor\n")
9147
9148ALIAS (show_bgp_view_neighbor_damp,
9149 show_bgp_ipv6_neighbor_damp_cmd,
9150 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
9151 SHOW_STR
9152 BGP_STR
9153 "Address family\n"
9154 "Detailed information on TCP and BGP neighbor connections\n"
9155 "Neighbor to display information about\n"
9156 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +00009157 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +00009158
9159DEFUN (show_bgp_view_rsclient,
9160 show_bgp_view_rsclient_cmd,
9161 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
9162 SHOW_STR
9163 BGP_STR
9164 "BGP view\n"
9165 "BGP view name\n"
9166 "Information about Route Server Client\n"
9167 NEIGHBOR_ADDR_STR)
9168{
9169 struct bgp_table *table;
9170 struct peer *peer;
9171
9172 if (argc == 2)
9173 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9174 else
9175 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9176
9177 if (! peer)
9178 return CMD_WARNING;
9179
9180 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9181 {
9182 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9183 VTY_NEWLINE);
9184 return CMD_WARNING;
9185 }
9186
9187 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9188 PEER_FLAG_RSERVER_CLIENT))
9189 {
9190 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9191 VTY_NEWLINE);
9192 return CMD_WARNING;
9193 }
9194
9195 table = peer->rib[AFI_IP6][SAFI_UNICAST];
9196
ajs5a646652004-11-05 01:25:55 +00009197 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +00009198}
9199
9200ALIAS (show_bgp_view_rsclient,
9201 show_bgp_rsclient_cmd,
9202 "show bgp rsclient (A.B.C.D|X:X::X:X)",
9203 SHOW_STR
9204 BGP_STR
9205 "Information about Route Server Client\n"
9206 NEIGHBOR_ADDR_STR)
9207
9208DEFUN (show_bgp_view_rsclient_route,
9209 show_bgp_view_rsclient_route_cmd,
9210 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9211 SHOW_STR
9212 BGP_STR
9213 "BGP view\n"
9214 "BGP view name\n"
9215 "Information about Route Server Client\n"
9216 NEIGHBOR_ADDR_STR
9217 "Network in the BGP routing table to display\n")
9218{
9219 struct bgp *bgp;
9220 struct peer *peer;
9221
9222 /* BGP structure lookup. */
9223 if (argc == 3)
9224 {
9225 bgp = bgp_lookup_by_name (argv[0]);
9226 if (bgp == NULL)
9227 {
9228 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9229 return CMD_WARNING;
9230 }
9231 }
9232 else
9233 {
9234 bgp = bgp_get_default ();
9235 if (bgp == NULL)
9236 {
9237 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9238 return CMD_WARNING;
9239 }
9240 }
9241
9242 if (argc == 3)
9243 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9244 else
9245 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9246
9247 if (! peer)
9248 return CMD_WARNING;
9249
9250 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9251 {
9252 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9253 VTY_NEWLINE);
9254 return CMD_WARNING;
9255 }
9256
9257 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9258 PEER_FLAG_RSERVER_CLIENT))
9259 {
9260 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9261 VTY_NEWLINE);
9262 return CMD_WARNING;
9263 }
9264
9265 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9266 (argc == 3) ? argv[2] : argv[1],
9267 AFI_IP6, SAFI_UNICAST, NULL, 0);
9268}
9269
9270ALIAS (show_bgp_view_rsclient_route,
9271 show_bgp_rsclient_route_cmd,
9272 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
9273 SHOW_STR
9274 BGP_STR
9275 "Information about Route Server Client\n"
9276 NEIGHBOR_ADDR_STR
9277 "Network in the BGP routing table to display\n")
9278
9279DEFUN (show_bgp_view_rsclient_prefix,
9280 show_bgp_view_rsclient_prefix_cmd,
9281 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9282 SHOW_STR
9283 BGP_STR
9284 "BGP view\n"
9285 "BGP view name\n"
9286 "Information about Route Server Client\n"
9287 NEIGHBOR_ADDR_STR
9288 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9289{
9290 struct bgp *bgp;
9291 struct peer *peer;
9292
9293 /* BGP structure lookup. */
9294 if (argc == 3)
9295 {
9296 bgp = bgp_lookup_by_name (argv[0]);
9297 if (bgp == NULL)
9298 {
9299 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9300 return CMD_WARNING;
9301 }
9302 }
9303 else
9304 {
9305 bgp = bgp_get_default ();
9306 if (bgp == NULL)
9307 {
9308 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9309 return CMD_WARNING;
9310 }
9311 }
9312
9313 if (argc == 3)
9314 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9315 else
9316 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9317
9318 if (! peer)
9319 return CMD_WARNING;
9320
9321 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
9322 {
9323 vty_out (vty, "%% Activate the neighbor for the address family first%s",
9324 VTY_NEWLINE);
9325 return CMD_WARNING;
9326 }
9327
9328 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
9329 PEER_FLAG_RSERVER_CLIENT))
9330 {
9331 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
9332 VTY_NEWLINE);
9333 return CMD_WARNING;
9334 }
9335
9336 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
9337 (argc == 3) ? argv[2] : argv[1],
9338 AFI_IP6, SAFI_UNICAST, NULL, 1);
9339}
9340
9341ALIAS (show_bgp_view_rsclient_prefix,
9342 show_bgp_rsclient_prefix_cmd,
9343 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
9344 SHOW_STR
9345 BGP_STR
9346 "Information about Route Server Client\n"
9347 NEIGHBOR_ADDR_STR
9348 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
9349
paul718e3742002-12-13 20:15:29 +00009350#endif /* HAVE_IPV6 */
9351
9352struct bgp_table *bgp_distance_table;
9353
9354struct bgp_distance
9355{
9356 /* Distance value for the IP source prefix. */
9357 u_char distance;
9358
9359 /* Name of the access-list to be matched. */
9360 char *access_list;
9361};
9362
9363struct bgp_distance *
9364bgp_distance_new ()
9365{
9366 struct bgp_distance *new;
9367 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
9368 memset (new, 0, sizeof (struct bgp_distance));
9369 return new;
9370}
9371
9372void
9373bgp_distance_free (struct bgp_distance *bdistance)
9374{
9375 XFREE (MTYPE_BGP_DISTANCE, bdistance);
9376}
9377
9378int
paulfd79ac92004-10-13 05:06:08 +00009379bgp_distance_set (struct vty *vty, const char *distance_str,
9380 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009381{
9382 int ret;
9383 struct prefix_ipv4 p;
9384 u_char distance;
9385 struct bgp_node *rn;
9386 struct bgp_distance *bdistance;
9387
9388 ret = str2prefix_ipv4 (ip_str, &p);
9389 if (ret == 0)
9390 {
9391 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9392 return CMD_WARNING;
9393 }
9394
9395 distance = atoi (distance_str);
9396
9397 /* Get BGP distance node. */
9398 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
9399 if (rn->info)
9400 {
9401 bdistance = rn->info;
9402 bgp_unlock_node (rn);
9403 }
9404 else
9405 {
9406 bdistance = bgp_distance_new ();
9407 rn->info = bdistance;
9408 }
9409
9410 /* Set distance value. */
9411 bdistance->distance = distance;
9412
9413 /* Reset access-list configuration. */
9414 if (bdistance->access_list)
9415 {
9416 free (bdistance->access_list);
9417 bdistance->access_list = NULL;
9418 }
9419 if (access_list_str)
9420 bdistance->access_list = strdup (access_list_str);
9421
9422 return CMD_SUCCESS;
9423}
9424
9425int
paulfd79ac92004-10-13 05:06:08 +00009426bgp_distance_unset (struct vty *vty, const char *distance_str,
9427 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +00009428{
9429 int ret;
9430 struct prefix_ipv4 p;
9431 u_char distance;
9432 struct bgp_node *rn;
9433 struct bgp_distance *bdistance;
9434
9435 ret = str2prefix_ipv4 (ip_str, &p);
9436 if (ret == 0)
9437 {
9438 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
9439 return CMD_WARNING;
9440 }
9441
9442 distance = atoi (distance_str);
9443
9444 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
9445 if (! rn)
9446 {
9447 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
9448 return CMD_WARNING;
9449 }
9450
9451 bdistance = rn->info;
9452
9453 if (bdistance->access_list)
9454 free (bdistance->access_list);
9455 bgp_distance_free (bdistance);
9456
9457 rn->info = NULL;
9458 bgp_unlock_node (rn);
9459 bgp_unlock_node (rn);
9460
9461 return CMD_SUCCESS;
9462}
9463
9464void
9465bgp_distance_reset ()
9466{
9467 struct bgp_node *rn;
9468 struct bgp_distance *bdistance;
9469
9470 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
9471 if ((bdistance = rn->info) != NULL)
9472 {
9473 if (bdistance->access_list)
9474 free (bdistance->access_list);
9475 bgp_distance_free (bdistance);
9476 rn->info = NULL;
9477 bgp_unlock_node (rn);
9478 }
9479}
9480
9481/* Apply BGP information to distance method. */
9482u_char
9483bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
9484{
9485 struct bgp_node *rn;
9486 struct prefix_ipv4 q;
9487 struct peer *peer;
9488 struct bgp_distance *bdistance;
9489 struct access_list *alist;
9490 struct bgp_static *bgp_static;
9491
9492 if (! bgp)
9493 return 0;
9494
9495 if (p->family != AF_INET)
9496 return 0;
9497
9498 peer = rinfo->peer;
9499
9500 if (peer->su.sa.sa_family != AF_INET)
9501 return 0;
9502
9503 memset (&q, 0, sizeof (struct prefix_ipv4));
9504 q.family = AF_INET;
9505 q.prefix = peer->su.sin.sin_addr;
9506 q.prefixlen = IPV4_MAX_BITLEN;
9507
9508 /* Check source address. */
9509 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
9510 if (rn)
9511 {
9512 bdistance = rn->info;
9513 bgp_unlock_node (rn);
9514
9515 if (bdistance->access_list)
9516 {
9517 alist = access_list_lookup (AFI_IP, bdistance->access_list);
9518 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
9519 return bdistance->distance;
9520 }
9521 else
9522 return bdistance->distance;
9523 }
9524
9525 /* Backdoor check. */
9526 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
9527 if (rn)
9528 {
9529 bgp_static = rn->info;
9530 bgp_unlock_node (rn);
9531
9532 if (bgp_static->backdoor)
9533 {
9534 if (bgp->distance_local)
9535 return bgp->distance_local;
9536 else
9537 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9538 }
9539 }
9540
9541 if (peer_sort (peer) == BGP_PEER_EBGP)
9542 {
9543 if (bgp->distance_ebgp)
9544 return bgp->distance_ebgp;
9545 return ZEBRA_EBGP_DISTANCE_DEFAULT;
9546 }
9547 else
9548 {
9549 if (bgp->distance_ibgp)
9550 return bgp->distance_ibgp;
9551 return ZEBRA_IBGP_DISTANCE_DEFAULT;
9552 }
9553}
9554
9555DEFUN (bgp_distance,
9556 bgp_distance_cmd,
9557 "distance bgp <1-255> <1-255> <1-255>",
9558 "Define an administrative distance\n"
9559 "BGP distance\n"
9560 "Distance for routes external to the AS\n"
9561 "Distance for routes internal to the AS\n"
9562 "Distance for local routes\n")
9563{
9564 struct bgp *bgp;
9565
9566 bgp = vty->index;
9567
9568 bgp->distance_ebgp = atoi (argv[0]);
9569 bgp->distance_ibgp = atoi (argv[1]);
9570 bgp->distance_local = atoi (argv[2]);
9571 return CMD_SUCCESS;
9572}
9573
9574DEFUN (no_bgp_distance,
9575 no_bgp_distance_cmd,
9576 "no distance bgp <1-255> <1-255> <1-255>",
9577 NO_STR
9578 "Define an administrative distance\n"
9579 "BGP distance\n"
9580 "Distance for routes external to the AS\n"
9581 "Distance for routes internal to the AS\n"
9582 "Distance for local routes\n")
9583{
9584 struct bgp *bgp;
9585
9586 bgp = vty->index;
9587
9588 bgp->distance_ebgp= 0;
9589 bgp->distance_ibgp = 0;
9590 bgp->distance_local = 0;
9591 return CMD_SUCCESS;
9592}
9593
9594ALIAS (no_bgp_distance,
9595 no_bgp_distance2_cmd,
9596 "no distance bgp",
9597 NO_STR
9598 "Define an administrative distance\n"
9599 "BGP distance\n")
9600
9601DEFUN (bgp_distance_source,
9602 bgp_distance_source_cmd,
9603 "distance <1-255> A.B.C.D/M",
9604 "Define an administrative distance\n"
9605 "Administrative distance\n"
9606 "IP source prefix\n")
9607{
9608 bgp_distance_set (vty, argv[0], argv[1], NULL);
9609 return CMD_SUCCESS;
9610}
9611
9612DEFUN (no_bgp_distance_source,
9613 no_bgp_distance_source_cmd,
9614 "no distance <1-255> A.B.C.D/M",
9615 NO_STR
9616 "Define an administrative distance\n"
9617 "Administrative distance\n"
9618 "IP source prefix\n")
9619{
9620 bgp_distance_unset (vty, argv[0], argv[1], NULL);
9621 return CMD_SUCCESS;
9622}
9623
9624DEFUN (bgp_distance_source_access_list,
9625 bgp_distance_source_access_list_cmd,
9626 "distance <1-255> A.B.C.D/M WORD",
9627 "Define an administrative distance\n"
9628 "Administrative distance\n"
9629 "IP source prefix\n"
9630 "Access list name\n")
9631{
9632 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
9633 return CMD_SUCCESS;
9634}
9635
9636DEFUN (no_bgp_distance_source_access_list,
9637 no_bgp_distance_source_access_list_cmd,
9638 "no distance <1-255> A.B.C.D/M WORD",
9639 NO_STR
9640 "Define an administrative distance\n"
9641 "Administrative distance\n"
9642 "IP source prefix\n"
9643 "Access list name\n")
9644{
9645 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
9646 return CMD_SUCCESS;
9647}
9648
9649DEFUN (bgp_damp_set,
9650 bgp_damp_set_cmd,
9651 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
9652 "BGP Specific commands\n"
9653 "Enable route-flap dampening\n"
9654 "Half-life time for the penalty\n"
9655 "Value to start reusing a route\n"
9656 "Value to start suppressing a route\n"
9657 "Maximum duration to suppress a stable route\n")
9658{
9659 struct bgp *bgp;
9660 int half = DEFAULT_HALF_LIFE * 60;
9661 int reuse = DEFAULT_REUSE;
9662 int suppress = DEFAULT_SUPPRESS;
9663 int max = 4 * half;
9664
9665 if (argc == 4)
9666 {
9667 half = atoi (argv[0]) * 60;
9668 reuse = atoi (argv[1]);
9669 suppress = atoi (argv[2]);
9670 max = atoi (argv[3]) * 60;
9671 }
9672 else if (argc == 1)
9673 {
9674 half = atoi (argv[0]) * 60;
9675 max = 4 * half;
9676 }
9677
9678 bgp = vty->index;
9679 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
9680 half, reuse, suppress, max);
9681}
9682
9683ALIAS (bgp_damp_set,
9684 bgp_damp_set2_cmd,
9685 "bgp dampening <1-45>",
9686 "BGP Specific commands\n"
9687 "Enable route-flap dampening\n"
9688 "Half-life time for the penalty\n")
9689
9690ALIAS (bgp_damp_set,
9691 bgp_damp_set3_cmd,
9692 "bgp dampening",
9693 "BGP Specific commands\n"
9694 "Enable route-flap dampening\n")
9695
9696DEFUN (bgp_damp_unset,
9697 bgp_damp_unset_cmd,
9698 "no bgp dampening",
9699 NO_STR
9700 "BGP Specific commands\n"
9701 "Enable route-flap dampening\n")
9702{
9703 struct bgp *bgp;
9704
9705 bgp = vty->index;
9706 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
9707}
9708
9709ALIAS (bgp_damp_unset,
9710 bgp_damp_unset2_cmd,
9711 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
9712 NO_STR
9713 "BGP Specific commands\n"
9714 "Enable route-flap dampening\n"
9715 "Half-life time for the penalty\n"
9716 "Value to start reusing a route\n"
9717 "Value to start suppressing a route\n"
9718 "Maximum duration to suppress a stable route\n")
9719
9720DEFUN (show_ip_bgp_dampened_paths,
9721 show_ip_bgp_dampened_paths_cmd,
9722 "show ip bgp dampened-paths",
9723 SHOW_STR
9724 IP_STR
9725 BGP_STR
9726 "Display paths suppressed due to dampening\n")
9727{
ajs5a646652004-11-05 01:25:55 +00009728 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
9729 NULL);
paul718e3742002-12-13 20:15:29 +00009730}
9731
9732DEFUN (show_ip_bgp_flap_statistics,
9733 show_ip_bgp_flap_statistics_cmd,
9734 "show ip bgp flap-statistics",
9735 SHOW_STR
9736 IP_STR
9737 BGP_STR
9738 "Display flap statistics of routes\n")
9739{
ajs5a646652004-11-05 01:25:55 +00009740 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9741 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +00009742}
9743
9744/* Display specified route of BGP table. */
9745int
paulfd79ac92004-10-13 05:06:08 +00009746bgp_clear_damp_route (struct vty *vty, const char *view_name,
9747 const char *ip_str, afi_t afi, safi_t safi,
9748 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +00009749{
9750 int ret;
9751 struct prefix match;
9752 struct bgp_node *rn;
9753 struct bgp_node *rm;
9754 struct bgp_info *ri;
9755 struct bgp_info *ri_temp;
9756 struct bgp *bgp;
9757 struct bgp_table *table;
9758
9759 /* BGP structure lookup. */
9760 if (view_name)
9761 {
9762 bgp = bgp_lookup_by_name (view_name);
9763 if (bgp == NULL)
9764 {
9765 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9766 return CMD_WARNING;
9767 }
9768 }
9769 else
9770 {
9771 bgp = bgp_get_default ();
9772 if (bgp == NULL)
9773 {
9774 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
9775 return CMD_WARNING;
9776 }
9777 }
9778
9779 /* Check IP address argument. */
9780 ret = str2prefix (ip_str, &match);
9781 if (! ret)
9782 {
9783 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
9784 return CMD_WARNING;
9785 }
9786
9787 match.family = afi2family (afi);
9788
9789 if (safi == SAFI_MPLS_VPN)
9790 {
9791 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
9792 {
9793 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
9794 continue;
9795
9796 if ((table = rn->info) != NULL)
9797 if ((rm = bgp_node_match (table, &match)) != NULL)
9798 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
9799 {
9800 ri = rm->info;
9801 while (ri)
9802 {
9803 if (ri->damp_info)
9804 {
9805 ri_temp = ri->next;
9806 bgp_damp_info_free (ri->damp_info, 1);
9807 ri = ri_temp;
9808 }
9809 else
9810 ri = ri->next;
9811 }
9812 }
9813 }
9814 }
9815 else
9816 {
9817 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
9818 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
9819 {
9820 ri = rn->info;
9821 while (ri)
9822 {
9823 if (ri->damp_info)
9824 {
9825 ri_temp = ri->next;
9826 bgp_damp_info_free (ri->damp_info, 1);
9827 ri = ri_temp;
9828 }
9829 else
9830 ri = ri->next;
9831 }
9832 }
9833 }
9834
9835 return CMD_SUCCESS;
9836}
9837
9838DEFUN (clear_ip_bgp_dampening,
9839 clear_ip_bgp_dampening_cmd,
9840 "clear ip bgp dampening",
9841 CLEAR_STR
9842 IP_STR
9843 BGP_STR
9844 "Clear route flap dampening information\n")
9845{
9846 bgp_damp_info_clean ();
9847 return CMD_SUCCESS;
9848}
9849
9850DEFUN (clear_ip_bgp_dampening_prefix,
9851 clear_ip_bgp_dampening_prefix_cmd,
9852 "clear ip bgp dampening A.B.C.D/M",
9853 CLEAR_STR
9854 IP_STR
9855 BGP_STR
9856 "Clear route flap dampening information\n"
9857 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9858{
9859 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
9860 SAFI_UNICAST, NULL, 1);
9861}
9862
9863DEFUN (clear_ip_bgp_dampening_address,
9864 clear_ip_bgp_dampening_address_cmd,
9865 "clear ip bgp dampening A.B.C.D",
9866 CLEAR_STR
9867 IP_STR
9868 BGP_STR
9869 "Clear route flap dampening information\n"
9870 "Network to clear damping information\n")
9871{
9872 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
9873 SAFI_UNICAST, NULL, 0);
9874}
9875
9876DEFUN (clear_ip_bgp_dampening_address_mask,
9877 clear_ip_bgp_dampening_address_mask_cmd,
9878 "clear ip bgp dampening A.B.C.D A.B.C.D",
9879 CLEAR_STR
9880 IP_STR
9881 BGP_STR
9882 "Clear route flap dampening information\n"
9883 "Network to clear damping information\n"
9884 "Network mask\n")
9885{
9886 int ret;
9887 char prefix_str[BUFSIZ];
9888
9889 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
9890 if (! ret)
9891 {
9892 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
9893 return CMD_WARNING;
9894 }
9895
9896 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
9897 SAFI_UNICAST, NULL, 0);
9898}
9899
9900int
9901bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
9902 afi_t afi, safi_t safi, int *write)
9903{
9904 struct bgp_node *prn;
9905 struct bgp_node *rn;
9906 struct bgp_table *table;
9907 struct prefix *p;
9908 struct prefix_rd *prd;
9909 struct bgp_static *bgp_static;
9910 u_int32_t label;
9911 char buf[SU_ADDRSTRLEN];
9912 char rdbuf[RD_ADDRSTRLEN];
9913
9914 /* Network configuration. */
9915 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
9916 if ((table = prn->info) != NULL)
9917 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9918 if ((bgp_static = rn->info) != NULL)
9919 {
9920 p = &rn->p;
9921 prd = (struct prefix_rd *) &prn->p;
9922
9923 /* "address-family" display. */
9924 bgp_config_write_family_header (vty, afi, safi, write);
9925
9926 /* "network" configuration display. */
9927 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
9928 label = decode_label (bgp_static->tag);
9929
9930 vty_out (vty, " network %s/%d rd %s tag %d",
9931 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
9932 p->prefixlen,
9933 rdbuf, label);
9934 vty_out (vty, "%s", VTY_NEWLINE);
9935 }
9936 return 0;
9937}
9938
9939/* Configuration of static route announcement and aggregate
9940 information. */
9941int
9942bgp_config_write_network (struct vty *vty, struct bgp *bgp,
9943 afi_t afi, safi_t safi, int *write)
9944{
9945 struct bgp_node *rn;
9946 struct prefix *p;
9947 struct bgp_static *bgp_static;
9948 struct bgp_aggregate *bgp_aggregate;
9949 char buf[SU_ADDRSTRLEN];
9950
9951 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
9952 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
9953
9954 /* Network configuration. */
9955 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
9956 if ((bgp_static = rn->info) != NULL)
9957 {
9958 p = &rn->p;
9959
9960 /* "address-family" display. */
9961 bgp_config_write_family_header (vty, afi, safi, write);
9962
9963 /* "network" configuration display. */
9964 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
9965 {
9966 u_int32_t destination;
9967 struct in_addr netmask;
9968
9969 destination = ntohl (p->u.prefix4.s_addr);
9970 masklen2ip (p->prefixlen, &netmask);
9971 vty_out (vty, " network %s",
9972 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
9973
9974 if ((IN_CLASSC (destination) && p->prefixlen == 24)
9975 || (IN_CLASSB (destination) && p->prefixlen == 16)
9976 || (IN_CLASSA (destination) && p->prefixlen == 8)
9977 || p->u.prefix4.s_addr == 0)
9978 {
9979 /* Natural mask is not display. */
9980 }
9981 else
9982 vty_out (vty, " mask %s", inet_ntoa (netmask));
9983 }
9984 else
9985 {
9986 vty_out (vty, " network %s/%d",
9987 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
9988 p->prefixlen);
9989 }
9990
9991 if (bgp_static->rmap.name)
9992 vty_out (vty, " route-map %s", bgp_static->rmap.name);
9993 else if (bgp_static->backdoor)
9994 vty_out (vty, " backdoor");
9995
9996 vty_out (vty, "%s", VTY_NEWLINE);
9997 }
9998
9999 /* Aggregate-address configuration. */
10000 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
10001 if ((bgp_aggregate = rn->info) != NULL)
10002 {
10003 p = &rn->p;
10004
10005 /* "address-family" display. */
10006 bgp_config_write_family_header (vty, afi, safi, write);
10007
10008 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
10009 {
10010 struct in_addr netmask;
10011
10012 masklen2ip (p->prefixlen, &netmask);
10013 vty_out (vty, " aggregate-address %s %s",
10014 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10015 inet_ntoa (netmask));
10016 }
10017 else
10018 {
10019 vty_out (vty, " aggregate-address %s/%d",
10020 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
10021 p->prefixlen);
10022 }
10023
10024 if (bgp_aggregate->as_set)
10025 vty_out (vty, " as-set");
10026
10027 if (bgp_aggregate->summary_only)
10028 vty_out (vty, " summary-only");
10029
10030 vty_out (vty, "%s", VTY_NEWLINE);
10031 }
10032
10033 return 0;
10034}
10035
10036int
10037bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
10038{
10039 struct bgp_node *rn;
10040 struct bgp_distance *bdistance;
10041
10042 /* Distance configuration. */
10043 if (bgp->distance_ebgp
10044 && bgp->distance_ibgp
10045 && bgp->distance_local
10046 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
10047 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
10048 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
10049 vty_out (vty, " distance bgp %d %d %d%s",
10050 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
10051 VTY_NEWLINE);
10052
10053 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10054 if ((bdistance = rn->info) != NULL)
10055 {
10056 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
10057 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
10058 bdistance->access_list ? bdistance->access_list : "",
10059 VTY_NEWLINE);
10060 }
10061
10062 return 0;
10063}
10064
10065/* Allocate routing table structure and install commands. */
10066void
10067bgp_route_init ()
10068{
10069 /* Init BGP distance table. */
10070 bgp_distance_table = bgp_table_init ();
10071
10072 /* IPv4 BGP commands. */
10073 install_element (BGP_NODE, &bgp_network_cmd);
10074 install_element (BGP_NODE, &bgp_network_mask_cmd);
10075 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
10076 install_element (BGP_NODE, &bgp_network_route_map_cmd);
10077 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
10078 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
10079 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
10080 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
10081 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
10082 install_element (BGP_NODE, &no_bgp_network_cmd);
10083 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
10084 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
10085 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
10086 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
10087 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10088 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
10089 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
10090 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
10091
10092 install_element (BGP_NODE, &aggregate_address_cmd);
10093 install_element (BGP_NODE, &aggregate_address_mask_cmd);
10094 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
10095 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
10096 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
10097 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
10098 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
10099 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
10100 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
10101 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
10102 install_element (BGP_NODE, &no_aggregate_address_cmd);
10103 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
10104 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
10105 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
10106 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
10107 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
10108 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
10109 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
10110 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10111 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10112
10113 /* IPv4 unicast configuration. */
10114 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
10115 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
10116 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
10117 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
10118 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
10119 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
10120 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
10121 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
10122 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
10123 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
10124 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
10125 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10126 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
10127 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
10128 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
10129 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
10130 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
10131 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
10132 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
10133 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
10134 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
10135 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
10136 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
10137 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
10138 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
10139 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
10140 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
10141 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
10142 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
10143 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
10144 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10145 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10146
10147 /* IPv4 multicast configuration. */
10148 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
10149 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
10150 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
10151 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
10152 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
10153 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
10154 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
10155 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
10156 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
10157 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
10158 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
10159 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
10160 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
10161 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
10162 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
10163 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
10164 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
10165 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
10166 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
10167 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
10168 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
10169 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
10170 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
10171 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
10172 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
10173 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
10174 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
10175 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
10176 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
10177 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
10178 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
10179 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
10180
10181 install_element (VIEW_NODE, &show_ip_bgp_cmd);
10182 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
10183 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
10184 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
10185 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10186 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10187 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
10188 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10189 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10190 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10191 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
10192 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
10193 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
10194 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
10195 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10196 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
10197 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10198 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
10199 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10200 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
10201 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10202 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
10203 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10204 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
10205 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10206 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
10207 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
10208 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
10209 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
10210 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
10211 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
10212 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
10213 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
10214 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
10215 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
10216 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
10217 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
10218 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10219 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10220 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10221 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10222 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
10223 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10224 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
10225 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10226 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
10227 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10228 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10229 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10230 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10231 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10232 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
10233 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10234 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10235 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10236 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
10237 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
10238 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
10239 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
10240 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10241 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
10242 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
10243 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10244 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10245 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
10246 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
10247 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010248 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
10249 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
10250 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10251 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
10252 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10253 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010254
10255 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
10256 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
10257 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
10258 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
10259 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
10260 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
10261 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
10262 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
10263 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
10264 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
10265 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
10266 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
10267 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
10268 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
10269 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
10270 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
10271 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
10272 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
10273 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
10274 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
10275 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
10276 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
10277 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
10278 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
10279 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
10280 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
10281 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
10282 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
10283 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
10284 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
10285 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
10286 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
10287 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
10288 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
10289 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
10290 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
10291 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
10292 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
10293 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
10294 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
10295 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
10296 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
10297 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
10298 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
10299 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
10300 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
10301 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
10302 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
10303 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
10304 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
10305 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
10306 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
10307 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
10308 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
10309 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
10310 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
10311 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
10312 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
10313 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
10314 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
10315 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
10316 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
10317 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
10318 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
10319 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
10320 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
10321 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010322 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
10323 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
10324 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
10325 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
10326 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
10327 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010328
10329 /* BGP dampening clear commands */
10330 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
10331 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
10332 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
10333 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
10334
10335#ifdef HAVE_IPV6
10336 /* New config IPv6 BGP commands. */
10337 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
10338 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
10339 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
10340 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
10341
10342 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
10343 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
10344 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
10345 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
10346
10347 /* Old config IPv6 BGP commands. */
10348 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
10349 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
10350
10351 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
10352 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
10353 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
10354 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
10355
10356 install_element (VIEW_NODE, &show_bgp_cmd);
10357 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
10358 install_element (VIEW_NODE, &show_bgp_route_cmd);
10359 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
10360 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
10361 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
10362 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
10363 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
10364 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
10365 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
10366 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
10367 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
10368 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
10369 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
10370 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
10371 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
10372 install_element (VIEW_NODE, &show_bgp_community_cmd);
10373 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
10374 install_element (VIEW_NODE, &show_bgp_community2_cmd);
10375 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
10376 install_element (VIEW_NODE, &show_bgp_community3_cmd);
10377 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
10378 install_element (VIEW_NODE, &show_bgp_community4_cmd);
10379 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
10380 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
10381 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
10382 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
10383 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
10384 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
10385 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
10386 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
10387 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
10388 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
10389 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
10390 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
10391 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10392 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
10393 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10394 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
10395 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10396 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
10397 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10398 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
10399 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10400 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10401 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010402 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
10403 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10404 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
10405 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010406 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
10407 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
10408 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010409 install_element (VIEW_NODE, &show_bgp_view_cmd);
10410 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
10411 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
10412 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
10413 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
10414 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
10415 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10416 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10417 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10418 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10419 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
10420 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10421 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10422 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10423 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
10424 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10425 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
10426 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010427 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
10428 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
10429 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010430
10431 install_element (ENABLE_NODE, &show_bgp_cmd);
10432 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
10433 install_element (ENABLE_NODE, &show_bgp_route_cmd);
10434 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
10435 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
10436 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
10437 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
10438 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
10439 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
10440 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
10441 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
10442 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
10443 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
10444 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
10445 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
10446 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
10447 install_element (ENABLE_NODE, &show_bgp_community_cmd);
10448 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
10449 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
10450 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
10451 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
10452 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
10453 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
10454 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
10455 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
10456 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
10457 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
10458 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
10459 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
10460 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
10461 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
10462 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
10463 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
10464 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
10465 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
10466 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
10467 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
10468 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
10469 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
10470 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
10471 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
10472 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
10473 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
10474 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
10475 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
10476 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000010477 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
10478 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
10479 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
10480 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010481 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
10482 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
10483 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000010484 install_element (ENABLE_NODE, &show_bgp_view_cmd);
10485 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
10486 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
10487 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
10488 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
10489 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
10490 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
10491 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
10492 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
10493 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
10494 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
10495 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
10496 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
10497 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
10498 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
10499 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
10500 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
10501 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000010502 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
10503 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
10504 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000010505
10506 /* old command */
10507 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
10508 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
10509 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
10510 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
10511 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
10512 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
10513 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
10514 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
10515 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
10516 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
10517 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
10518 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
10519 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
10520 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
10521 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
10522 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
10523 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10524 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10525 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
10526 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
10527 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
10528 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
10529 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10530 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
10531 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
10532 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
10533 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
10534 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
10535 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
10536 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
10537 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10538 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10539 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10540 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
10541 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10542 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000010543
paul718e3742002-12-13 20:15:29 +000010544 /* old command */
10545 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
10546 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
10547 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
10548 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
10549 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
10550 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
10551 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
10552 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
10553 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
10554 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
10555 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
10556 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
10557 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
10558 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
10559 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
10560 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
10561 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
10562 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
10563 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
10564 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
10565 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
10566 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
10567 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
10568 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
10569 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
10570 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
10571 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
10572 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
10573 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
10574 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
10575 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
10576 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
10577 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
10578 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
10579 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
10580 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
10581
10582 /* old command */
10583 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10584 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
10585 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10586 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
10587
10588 /* old command */
10589 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10590 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
10591 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10592 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
10593
10594 /* old command */
10595 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
10596 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
10597 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10598 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
10599#endif /* HAVE_IPV6 */
10600
10601 install_element (BGP_NODE, &bgp_distance_cmd);
10602 install_element (BGP_NODE, &no_bgp_distance_cmd);
10603 install_element (BGP_NODE, &no_bgp_distance2_cmd);
10604 install_element (BGP_NODE, &bgp_distance_source_cmd);
10605 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
10606 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
10607 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
10608
10609 install_element (BGP_NODE, &bgp_damp_set_cmd);
10610 install_element (BGP_NODE, &bgp_damp_set2_cmd);
10611 install_element (BGP_NODE, &bgp_damp_set3_cmd);
10612 install_element (BGP_NODE, &bgp_damp_unset_cmd);
10613 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
10614 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
10615 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
10616 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
10617 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
10618 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
10619}