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