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