blob: 1dd8b57127262204680421043f68e609acfd24e8 [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 {
1691 zlog (peer->log, LOG_ERR,
1692 "IPv4 unicast NLRI is multicast address %s",
1693 inet_ntoa (p.u.prefix4));
1694 bgp_notify_send (peer,
1695 BGP_NOTIFY_UPDATE_ERR,
1696 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1697 return -1;
1698 }
1699 }
1700
1701#ifdef HAVE_IPV6
1702 /* Check address. */
1703 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
1704 {
1705 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
1706 {
1707 char buf[BUFSIZ];
1708
1709 zlog (peer->log, LOG_WARNING,
1710 "IPv6 link-local NLRI received %s ignore this NLRI",
1711 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
1712
1713 continue;
1714 }
1715 }
1716#endif /* HAVE_IPV6 */
1717
1718 /* Normal process. */
1719 if (attr)
1720 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
1721 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
1722 else
1723 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
1724 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
1725
1726 /* Address family configuration mismatch or maximum-prefix count
1727 overflow. */
1728 if (ret < 0)
1729 return -1;
1730 }
1731
1732 /* Packet length consistency check. */
1733 if (pnt != lim)
1734 return -1;
1735
1736 return 0;
1737}
1738
1739/* NLRI encode syntax check routine. */
1740int
1741bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
1742 bgp_size_t length)
1743{
1744 u_char *end;
1745 u_char prefixlen;
1746 int psize;
1747
1748 end = pnt + length;
1749
1750 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
1751 syntactic validity. If the field is syntactically incorrect,
1752 then the Error Subcode is set to Invalid Network Field. */
1753
1754 while (pnt < end)
1755 {
1756 prefixlen = *pnt++;
1757
1758 /* Prefix length check. */
1759 if ((afi == AFI_IP && prefixlen > 32)
1760 || (afi == AFI_IP6 && prefixlen > 128))
1761 {
1762 plog_err (peer->log,
1763 "%s [Error] Update packet error (wrong prefix length %d)",
1764 peer->host, prefixlen);
1765 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
1766 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1767 return -1;
1768 }
1769
1770 /* Packet size overflow check. */
1771 psize = PSIZE (prefixlen);
1772
1773 if (pnt + psize > end)
1774 {
1775 plog_err (peer->log,
1776 "%s [Error] Update packet error"
1777 " (prefix data overflow prefix size is %d)",
1778 peer->host, psize);
1779 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
1780 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1781 return -1;
1782 }
1783
1784 pnt += psize;
1785 }
1786
1787 /* Packet length consistency check. */
1788 if (pnt != end)
1789 {
1790 plog_err (peer->log,
1791 "%s [Error] Update packet error"
1792 " (prefix length mismatch with total length)",
1793 peer->host);
1794 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
1795 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
1796 return -1;
1797 }
1798 return 0;
1799}
1800
1801struct bgp_static *
1802bgp_static_new ()
1803{
1804 struct bgp_static *new;
1805 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
1806 memset (new, 0, sizeof (struct bgp_static));
1807 return new;
1808}
1809
1810void
1811bgp_static_free (struct bgp_static *bgp_static)
1812{
1813 if (bgp_static->rmap.name)
1814 free (bgp_static->rmap.name);
1815 XFREE (MTYPE_BGP_STATIC, bgp_static);
1816}
1817
1818void
1819bgp_static_update (struct bgp *bgp, struct prefix *p,
1820 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
1821{
1822 struct bgp_node *rn;
1823 struct bgp_info *ri;
1824 struct bgp_info *new;
1825 struct bgp_info info;
1826 struct attr attr;
paul286e1e72003-08-08 00:24:31 +00001827 struct attr attr_tmp;
paul718e3742002-12-13 20:15:29 +00001828 struct attr *attr_new;
1829 int ret;
1830
1831 rn = bgp_afi_node_get (bgp, afi, safi, p, NULL);
1832
1833 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
1834 if (bgp_static)
1835 {
1836 attr.nexthop = bgp_static->igpnexthop;
1837 attr.med = bgp_static->igpmetric;
1838 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
1839 }
1840
1841 /* Apply route-map. */
1842 if (bgp_static->rmap.name)
1843 {
paul286e1e72003-08-08 00:24:31 +00001844 attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00001845 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00001846 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00001847
1848 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00001849
paul718e3742002-12-13 20:15:29 +00001850 if (ret == RMAP_DENYMATCH)
1851 {
1852 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00001853 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00001854
1855 /* Unintern original. */
1856 aspath_unintern (attr.aspath);
1857 bgp_static_withdraw (bgp, p, afi, safi);
1858 return;
1859 }
paul286e1e72003-08-08 00:24:31 +00001860 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00001861 }
paul286e1e72003-08-08 00:24:31 +00001862 else
1863 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00001864
1865 for (ri = rn->info; ri; ri = ri->next)
1866 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
1867 && ri->sub_type == BGP_ROUTE_STATIC)
1868 break;
1869
1870 if (ri)
1871 {
1872 if (attrhash_cmp (ri->attr, attr_new))
1873 {
1874 bgp_unlock_node (rn);
1875 bgp_attr_unintern (attr_new);
1876 aspath_unintern (attr.aspath);
1877 return;
1878 }
1879 else
1880 {
1881 /* The attribute is changed. */
1882 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
1883
1884 /* Rewrite BGP route information. */
1885 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
1886 bgp_attr_unintern (ri->attr);
1887 ri->attr = attr_new;
1888 ri->uptime = time (NULL);
1889
1890 /* Process change. */
1891 bgp_aggregate_increment (bgp, p, ri, afi, safi);
1892 bgp_process (bgp, rn, afi, safi);
1893 bgp_unlock_node (rn);
1894 aspath_unintern (attr.aspath);
1895 return;
1896 }
1897 }
1898
1899 /* Make new BGP info. */
1900 new = bgp_info_new ();
1901 new->type = ZEBRA_ROUTE_BGP;
1902 new->sub_type = BGP_ROUTE_STATIC;
1903 new->peer = bgp->peer_self;
1904 SET_FLAG (new->flags, BGP_INFO_VALID);
1905 new->attr = attr_new;
1906 new->uptime = time (NULL);
1907
1908 /* Aggregate address increment. */
1909 bgp_aggregate_increment (bgp, p, new, afi, safi);
1910
1911 /* Register new BGP information. */
1912 bgp_info_add (rn, new);
1913
1914 /* Process change. */
1915 bgp_process (bgp, rn, afi, safi);
1916
1917 /* Unintern original. */
1918 aspath_unintern (attr.aspath);
1919}
1920
1921void
1922bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
1923 u_char safi, struct prefix_rd *prd, u_char *tag)
1924{
1925 struct bgp_node *rn;
1926 struct bgp_info *new;
1927
1928 rn = bgp_afi_node_get (bgp, afi, safi, p, prd);
1929
1930 /* Make new BGP info. */
1931 new = bgp_info_new ();
1932 new->type = ZEBRA_ROUTE_BGP;
1933 new->sub_type = BGP_ROUTE_STATIC;
1934 new->peer = bgp->peer_self;
1935 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
1936 SET_FLAG (new->flags, BGP_INFO_VALID);
1937 new->uptime = time (NULL);
1938 memcpy (new->tag, tag, 3);
1939
1940 /* Aggregate address increment. */
1941 bgp_aggregate_increment (bgp, p, (struct bgp_info *) new, afi, safi);
1942
1943 /* Register new BGP information. */
1944 bgp_info_add (rn, (struct bgp_info *) new);
1945
1946 /* Process change. */
1947 bgp_process (bgp, rn, afi, safi);
1948}
1949
1950void
1951bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
1952 safi_t safi)
1953{
1954 struct bgp_node *rn;
1955 struct bgp_info *ri;
1956
1957 rn = bgp_afi_node_get (bgp, afi, safi, p, NULL);
1958
1959 /* Check selected route and self inserted route. */
1960 for (ri = rn->info; ri; ri = ri->next)
1961 if (ri->peer == bgp->peer_self
1962 && ri->type == ZEBRA_ROUTE_BGP
1963 && ri->sub_type == BGP_ROUTE_STATIC)
1964 break;
1965
1966 /* Withdraw static BGP route from routing table. */
1967 if (ri)
1968 {
1969 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
1970 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
1971 bgp_process (bgp, rn, afi, safi);
1972 bgp_info_delete (rn, ri);
1973 bgp_info_free (ri);
1974 bgp_unlock_node (rn);
1975 }
1976
1977 /* Unlock bgp_node_lookup. */
1978 bgp_unlock_node (rn);
1979}
1980
1981void
1982bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
1983 u_char safi, struct prefix_rd *prd, u_char *tag)
1984{
1985 struct bgp_node *rn;
1986 struct bgp_info *ri;
1987
1988 rn = bgp_afi_node_get (bgp, afi, safi, p, prd);
1989
1990 /* Check selected route and self inserted route. */
1991 for (ri = rn->info; ri; ri = ri->next)
1992 if (ri->peer == bgp->peer_self
1993 && ri->type == ZEBRA_ROUTE_BGP
1994 && ri->sub_type == BGP_ROUTE_STATIC)
1995 break;
1996
1997 /* Withdraw static BGP route from routing table. */
1998 if (ri)
1999 {
2000 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2001 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
2002 bgp_process (bgp, rn, afi, safi);
2003 bgp_info_delete (rn, ri);
2004 bgp_info_free (ri);
2005 bgp_unlock_node (rn);
2006 }
2007
2008 /* Unlock bgp_node_lookup. */
2009 bgp_unlock_node (rn);
2010}
2011
2012/* Configure static BGP network. When user don't run zebra, static
2013 route should be installed as valid. */
2014int
2015bgp_static_set (struct vty *vty, struct bgp *bgp, char *ip_str, u_int16_t afi,
2016 u_char safi, char *rmap, int backdoor)
2017{
2018 int ret;
2019 struct prefix p;
2020 struct bgp_static *bgp_static;
2021 struct bgp_node *rn;
2022 int need_update = 0;
2023
2024 /* Convert IP prefix string to struct prefix. */
2025 ret = str2prefix (ip_str, &p);
2026 if (! ret)
2027 {
2028 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2029 return CMD_WARNING;
2030 }
2031#ifdef HAVE_IPV6
2032 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2033 {
2034 vty_out (vty, "%% Malformed prefix (link-local address)%s",
2035 VTY_NEWLINE);
2036 return CMD_WARNING;
2037 }
2038#endif /* HAVE_IPV6 */
2039
2040 apply_mask (&p);
2041
2042 /* Set BGP static route configuration. */
2043 rn = bgp_node_get (bgp->route[afi][safi], &p);
2044
2045 if (rn->info)
2046 {
2047 /* Configuration change. */
2048 bgp_static = rn->info;
2049
2050 /* Check previous routes are installed into BGP. */
2051 if (! bgp_static->backdoor && bgp_static->valid)
2052 need_update = 1;
2053
2054 bgp_static->backdoor = backdoor;
2055 if (rmap)
2056 {
2057 if (bgp_static->rmap.name)
2058 free (bgp_static->rmap.name);
2059 bgp_static->rmap.name = strdup (rmap);
2060 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
2061 }
2062 else
2063 {
2064 if (bgp_static->rmap.name)
2065 free (bgp_static->rmap.name);
2066 bgp_static->rmap.name = NULL;
2067 bgp_static->rmap.map = NULL;
2068 bgp_static->valid = 0;
2069 }
2070 bgp_unlock_node (rn);
2071 }
2072 else
2073 {
2074 /* New configuration. */
2075 bgp_static = bgp_static_new ();
2076 bgp_static->backdoor = backdoor;
2077 bgp_static->valid = 0;
2078 bgp_static->igpmetric = 0;
2079 bgp_static->igpnexthop.s_addr = 0;
2080 if (rmap)
2081 {
2082 if (bgp_static->rmap.name)
2083 free (bgp_static->rmap.name);
2084 bgp_static->rmap.name = strdup (rmap);
2085 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
2086 }
2087 rn->info = bgp_static;
2088 }
2089
2090 /* If BGP scan is not enabled, we should install this route here. */
2091 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
2092 {
2093 bgp_static->valid = 1;
2094
2095 if (need_update)
2096 bgp_static_withdraw (bgp, &p, afi, safi);
2097
2098 if (! bgp_static->backdoor)
2099 bgp_static_update (bgp, &p, bgp_static, afi, safi);
2100 }
2101
2102 return CMD_SUCCESS;
2103}
2104
2105/* Configure static BGP network. */
2106int
2107bgp_static_unset (struct vty *vty, struct bgp *bgp, char *ip_str,
2108 u_int16_t afi, u_char safi)
2109{
2110 int ret;
2111 struct prefix p;
2112 struct bgp_static *bgp_static;
2113 struct bgp_node *rn;
2114
2115 /* Convert IP prefix string to struct prefix. */
2116 ret = str2prefix (ip_str, &p);
2117 if (! ret)
2118 {
2119 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2120 return CMD_WARNING;
2121 }
2122#ifdef HAVE_IPV6
2123 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
2124 {
2125 vty_out (vty, "%% Malformed prefix (link-local address)%s",
2126 VTY_NEWLINE);
2127 return CMD_WARNING;
2128 }
2129#endif /* HAVE_IPV6 */
2130
2131 apply_mask (&p);
2132
2133 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
2134 if (! rn)
2135 {
2136 vty_out (vty, "%% Can't find specified static route configuration.%s",
2137 VTY_NEWLINE);
2138 return CMD_WARNING;
2139 }
2140
2141 bgp_static = rn->info;
2142
2143 /* Update BGP RIB. */
2144 if (! bgp_static->backdoor)
2145 bgp_static_withdraw (bgp, &p, afi, safi);
2146
2147 /* Clear configuration. */
2148 bgp_static_free (bgp_static);
2149 rn->info = NULL;
2150 bgp_unlock_node (rn);
2151 bgp_unlock_node (rn);
2152
2153 return CMD_SUCCESS;
2154}
2155
2156/* Called from bgp_delete(). Delete all static routes from the BGP
2157 instance. */
2158void
2159bgp_static_delete (struct bgp *bgp)
2160{
2161 afi_t afi;
2162 safi_t safi;
2163 struct bgp_node *rn;
2164 struct bgp_node *rm;
2165 struct bgp_table *table;
2166 struct bgp_static *bgp_static;
2167
2168 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2169 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2170 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
2171 if (rn->info != NULL)
2172 {
2173 if (safi == SAFI_MPLS_VPN)
2174 {
2175 table = rn->info;
2176
2177 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
2178 {
2179 bgp_static = rn->info;
2180 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
2181 AFI_IP, SAFI_MPLS_VPN,
2182 (struct prefix_rd *)&rn->p,
2183 bgp_static->tag);
2184 bgp_static_free (bgp_static);
2185 rn->info = NULL;
2186 bgp_unlock_node (rn);
2187 }
2188 }
2189 else
2190 {
2191 bgp_static = rn->info;
2192 bgp_static_withdraw (bgp, &rn->p, afi, safi);
2193 bgp_static_free (bgp_static);
2194 rn->info = NULL;
2195 bgp_unlock_node (rn);
2196 }
2197 }
2198}
2199
2200int
2201bgp_static_set_vpnv4 (struct vty *vty, char *ip_str, char *rd_str,
2202 char *tag_str)
2203{
2204 int ret;
2205 struct prefix p;
2206 struct prefix_rd prd;
2207 struct bgp *bgp;
2208 struct bgp_node *prn;
2209 struct bgp_node *rn;
2210 struct bgp_table *table;
2211 struct bgp_static *bgp_static;
2212 u_char tag[3];
2213
2214 bgp = vty->index;
2215
2216 ret = str2prefix (ip_str, &p);
2217 if (! ret)
2218 {
2219 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2220 return CMD_WARNING;
2221 }
2222 apply_mask (&p);
2223
2224 ret = str2prefix_rd (rd_str, &prd);
2225 if (! ret)
2226 {
2227 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
2228 return CMD_WARNING;
2229 }
2230
2231 ret = str2tag (tag_str, tag);
2232 if (! ret)
2233 {
2234 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
2235 return CMD_WARNING;
2236 }
2237
2238 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
2239 (struct prefix *)&prd);
2240 if (prn->info == NULL)
2241 prn->info = bgp_table_init ();
2242 else
2243 bgp_unlock_node (prn);
2244 table = prn->info;
2245
2246 rn = bgp_node_get (table, &p);
2247
2248 if (rn->info)
2249 {
2250 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
2251 bgp_unlock_node (rn);
2252 }
2253 else
2254 {
2255 /* New configuration. */
2256 bgp_static = bgp_static_new ();
2257 bgp_static->valid = 1;
2258 memcpy (bgp_static->tag, tag, 3);
2259 rn->info = bgp_static;
2260
2261 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
2262 }
2263
2264 return CMD_SUCCESS;
2265}
2266
2267/* Configure static BGP network. */
2268int
2269bgp_static_unset_vpnv4 (struct vty *vty, char *ip_str, char *rd_str,
2270 char *tag_str)
2271{
2272 int ret;
2273 struct bgp *bgp;
2274 struct prefix p;
2275 struct prefix_rd prd;
2276 struct bgp_node *prn;
2277 struct bgp_node *rn;
2278 struct bgp_table *table;
2279 struct bgp_static *bgp_static;
2280 u_char tag[3];
2281
2282 bgp = vty->index;
2283
2284 /* Convert IP prefix string to struct prefix. */
2285 ret = str2prefix (ip_str, &p);
2286 if (! ret)
2287 {
2288 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
2289 return CMD_WARNING;
2290 }
2291 apply_mask (&p);
2292
2293 ret = str2prefix_rd (rd_str, &prd);
2294 if (! ret)
2295 {
2296 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
2297 return CMD_WARNING;
2298 }
2299
2300 ret = str2tag (tag_str, tag);
2301 if (! ret)
2302 {
2303 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
2304 return CMD_WARNING;
2305 }
2306
2307 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
2308 (struct prefix *)&prd);
2309 if (prn->info == NULL)
2310 prn->info = bgp_table_init ();
2311 else
2312 bgp_unlock_node (prn);
2313 table = prn->info;
2314
2315 rn = bgp_node_lookup (table, &p);
2316
2317 if (rn)
2318 {
2319 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
2320
2321 bgp_static = rn->info;
2322 bgp_static_free (bgp_static);
2323 rn->info = NULL;
2324 bgp_unlock_node (rn);
2325 bgp_unlock_node (rn);
2326 }
2327 else
2328 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
2329
2330 return CMD_SUCCESS;
2331}
2332
2333DEFUN (bgp_network,
2334 bgp_network_cmd,
2335 "network A.B.C.D/M",
2336 "Specify a network to announce via BGP\n"
2337 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
2338{
2339 return bgp_static_set (vty, vty->index, argv[0],
2340 AFI_IP, bgp_node_safi (vty), NULL, 0);
2341}
2342
2343DEFUN (bgp_network_route_map,
2344 bgp_network_route_map_cmd,
2345 "network A.B.C.D/M route-map WORD",
2346 "Specify a network to announce via BGP\n"
2347 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2348 "Route-map to modify the attributes\n"
2349 "Name of the route map\n")
2350{
2351 return bgp_static_set (vty, vty->index, argv[0],
2352 AFI_IP, bgp_node_safi (vty), argv[1], 0);
2353}
2354
2355DEFUN (bgp_network_backdoor,
2356 bgp_network_backdoor_cmd,
2357 "network A.B.C.D/M backdoor",
2358 "Specify a network to announce via BGP\n"
2359 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2360 "Specify a BGP backdoor route\n")
2361{
2362 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
2363}
2364
2365DEFUN (bgp_network_mask,
2366 bgp_network_mask_cmd,
2367 "network A.B.C.D mask A.B.C.D",
2368 "Specify a network to announce via BGP\n"
2369 "Network number\n"
2370 "Network mask\n"
2371 "Network mask\n")
2372{
2373 int ret;
2374 char prefix_str[BUFSIZ];
2375
2376 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
2377 if (! ret)
2378 {
2379 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2380 return CMD_WARNING;
2381 }
2382
2383 return bgp_static_set (vty, vty->index, prefix_str,
2384 AFI_IP, bgp_node_safi (vty), NULL, 0);
2385}
2386
2387DEFUN (bgp_network_mask_route_map,
2388 bgp_network_mask_route_map_cmd,
2389 "network A.B.C.D mask A.B.C.D route-map WORD",
2390 "Specify a network to announce via BGP\n"
2391 "Network number\n"
2392 "Network mask\n"
2393 "Network mask\n"
2394 "Route-map to modify the attributes\n"
2395 "Name of the route map\n")
2396{
2397 int ret;
2398 char prefix_str[BUFSIZ];
2399
2400 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
2401 if (! ret)
2402 {
2403 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2404 return CMD_WARNING;
2405 }
2406
2407 return bgp_static_set (vty, vty->index, prefix_str,
2408 AFI_IP, bgp_node_safi (vty), argv[2], 0);
2409}
2410
2411DEFUN (bgp_network_mask_backdoor,
2412 bgp_network_mask_backdoor_cmd,
2413 "network A.B.C.D mask A.B.C.D backdoor",
2414 "Specify a network to announce via BGP\n"
2415 "Network number\n"
2416 "Network mask\n"
2417 "Network mask\n"
2418 "Specify a BGP backdoor route\n")
2419{
2420 int ret;
2421 char prefix_str[BUFSIZ];
2422
2423 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
2424 if (! ret)
2425 {
2426 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2427 return CMD_WARNING;
2428 }
2429
2430 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
2431}
2432
2433DEFUN (bgp_network_mask_natural,
2434 bgp_network_mask_natural_cmd,
2435 "network A.B.C.D",
2436 "Specify a network to announce via BGP\n"
2437 "Network number\n")
2438{
2439 int ret;
2440 char prefix_str[BUFSIZ];
2441
2442 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
2443 if (! ret)
2444 {
2445 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2446 return CMD_WARNING;
2447 }
2448
2449 return bgp_static_set (vty, vty->index, prefix_str,
2450 AFI_IP, bgp_node_safi (vty), NULL, 0);
2451}
2452
2453DEFUN (bgp_network_mask_natural_route_map,
2454 bgp_network_mask_natural_route_map_cmd,
2455 "network A.B.C.D route-map WORD",
2456 "Specify a network to announce via BGP\n"
2457 "Network number\n"
2458 "Route-map to modify the attributes\n"
2459 "Name of the route map\n")
2460{
2461 int ret;
2462 char prefix_str[BUFSIZ];
2463
2464 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
2465 if (! ret)
2466 {
2467 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2468 return CMD_WARNING;
2469 }
2470
2471 return bgp_static_set (vty, vty->index, prefix_str,
2472 AFI_IP, bgp_node_safi (vty), argv[1], 0);
2473}
2474
2475DEFUN (bgp_network_mask_natural_backdoor,
2476 bgp_network_mask_natural_backdoor_cmd,
2477 "network A.B.C.D backdoor",
2478 "Specify a network to announce via BGP\n"
2479 "Network number\n"
2480 "Specify a BGP backdoor route\n")
2481{
2482 int ret;
2483 char prefix_str[BUFSIZ];
2484
2485 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
2486 if (! ret)
2487 {
2488 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2489 return CMD_WARNING;
2490 }
2491
2492 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST, NULL, 1);
2493}
2494
2495DEFUN (no_bgp_network,
2496 no_bgp_network_cmd,
2497 "no network A.B.C.D/M",
2498 NO_STR
2499 "Specify a network to announce via BGP\n"
2500 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
2501{
2502 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
2503 bgp_node_safi (vty));
2504}
2505
2506ALIAS (no_bgp_network,
2507 no_bgp_network_route_map_cmd,
2508 "no network A.B.C.D/M route-map WORD",
2509 NO_STR
2510 "Specify a network to announce via BGP\n"
2511 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2512 "Route-map to modify the attributes\n"
2513 "Name of the route map\n")
2514
2515ALIAS (no_bgp_network,
2516 no_bgp_network_backdoor_cmd,
2517 "no network A.B.C.D/M backdoor",
2518 NO_STR
2519 "Specify a network to announce via BGP\n"
2520 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
2521 "Specify a BGP backdoor route\n")
2522
2523DEFUN (no_bgp_network_mask,
2524 no_bgp_network_mask_cmd,
2525 "no network A.B.C.D mask A.B.C.D",
2526 NO_STR
2527 "Specify a network to announce via BGP\n"
2528 "Network number\n"
2529 "Network mask\n"
2530 "Network mask\n")
2531{
2532 int ret;
2533 char prefix_str[BUFSIZ];
2534
2535 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
2536 if (! ret)
2537 {
2538 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2539 return CMD_WARNING;
2540 }
2541
2542 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
2543 bgp_node_safi (vty));
2544}
2545
2546ALIAS (no_bgp_network_mask,
2547 no_bgp_network_mask_route_map_cmd,
2548 "no network A.B.C.D mask A.B.C.D route-map WORD",
2549 NO_STR
2550 "Specify a network to announce via BGP\n"
2551 "Network number\n"
2552 "Network mask\n"
2553 "Network mask\n"
2554 "Route-map to modify the attributes\n"
2555 "Name of the route map\n")
2556
2557ALIAS (no_bgp_network_mask,
2558 no_bgp_network_mask_backdoor_cmd,
2559 "no network A.B.C.D mask A.B.C.D backdoor",
2560 NO_STR
2561 "Specify a network to announce via BGP\n"
2562 "Network number\n"
2563 "Network mask\n"
2564 "Network mask\n"
2565 "Specify a BGP backdoor route\n")
2566
2567DEFUN (no_bgp_network_mask_natural,
2568 no_bgp_network_mask_natural_cmd,
2569 "no network A.B.C.D",
2570 NO_STR
2571 "Specify a network to announce via BGP\n"
2572 "Network number\n")
2573{
2574 int ret;
2575 char prefix_str[BUFSIZ];
2576
2577 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
2578 if (! ret)
2579 {
2580 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
2581 return CMD_WARNING;
2582 }
2583
2584 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
2585 bgp_node_safi (vty));
2586}
2587
2588ALIAS (no_bgp_network_mask_natural,
2589 no_bgp_network_mask_natural_route_map_cmd,
2590 "no network A.B.C.D route-map WORD",
2591 NO_STR
2592 "Specify a network to announce via BGP\n"
2593 "Network number\n"
2594 "Route-map to modify the attributes\n"
2595 "Name of the route map\n")
2596
2597ALIAS (no_bgp_network_mask_natural,
2598 no_bgp_network_mask_natural_backdoor_cmd,
2599 "no network A.B.C.D backdoor",
2600 NO_STR
2601 "Specify a network to announce via BGP\n"
2602 "Network number\n"
2603 "Specify a BGP backdoor route\n")
2604
2605#ifdef HAVE_IPV6
2606DEFUN (ipv6_bgp_network,
2607 ipv6_bgp_network_cmd,
2608 "network X:X::X:X/M",
2609 "Specify a network to announce via BGP\n"
2610 "IPv6 prefix <network>/<length>\n")
2611{
2612 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
2613}
2614
2615DEFUN (ipv6_bgp_network_route_map,
2616 ipv6_bgp_network_route_map_cmd,
2617 "network X:X::X:X/M route-map WORD",
2618 "Specify a network to announce via BGP\n"
2619 "IPv6 prefix <network>/<length>\n"
2620 "Route-map to modify the attributes\n"
2621 "Name of the route map\n")
2622{
2623 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
2624 bgp_node_safi (vty), argv[1], 0);
2625}
2626
2627DEFUN (no_ipv6_bgp_network,
2628 no_ipv6_bgp_network_cmd,
2629 "no network X:X::X:X/M",
2630 NO_STR
2631 "Specify a network to announce via BGP\n"
2632 "IPv6 prefix <network>/<length>\n")
2633{
2634 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
2635}
2636
2637ALIAS (no_ipv6_bgp_network,
2638 no_ipv6_bgp_network_route_map_cmd,
2639 "no network X:X::X:X/M route-map WORD",
2640 NO_STR
2641 "Specify a network to announce via BGP\n"
2642 "IPv6 prefix <network>/<length>\n"
2643 "Route-map to modify the attributes\n"
2644 "Name of the route map\n")
2645
2646ALIAS (ipv6_bgp_network,
2647 old_ipv6_bgp_network_cmd,
2648 "ipv6 bgp network X:X::X:X/M",
2649 IPV6_STR
2650 BGP_STR
2651 "Specify a network to announce via BGP\n"
2652 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
2653
2654ALIAS (no_ipv6_bgp_network,
2655 old_no_ipv6_bgp_network_cmd,
2656 "no ipv6 bgp network X:X::X:X/M",
2657 NO_STR
2658 IPV6_STR
2659 BGP_STR
2660 "Specify a network to announce via BGP\n"
2661 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
2662#endif /* HAVE_IPV6 */
2663
2664/* Aggreagete address:
2665
2666 advertise-map Set condition to advertise attribute
2667 as-set Generate AS set path information
2668 attribute-map Set attributes of aggregate
2669 route-map Set parameters of aggregate
2670 summary-only Filter more specific routes from updates
2671 suppress-map Conditionally filter more specific routes from updates
2672 <cr>
2673 */
2674struct bgp_aggregate
2675{
2676 /* Summary-only flag. */
2677 u_char summary_only;
2678
2679 /* AS set generation. */
2680 u_char as_set;
2681
2682 /* Route-map for aggregated route. */
2683 struct route_map *map;
2684
2685 /* Suppress-count. */
2686 unsigned long count;
2687
2688 /* SAFI configuration. */
2689 safi_t safi;
2690};
2691
2692struct bgp_aggregate *
2693bgp_aggregate_new ()
2694{
2695 struct bgp_aggregate *new;
2696 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
2697 memset (new, 0, sizeof (struct bgp_aggregate));
2698 return new;
2699}
2700
2701void
2702bgp_aggregate_free (struct bgp_aggregate *aggregate)
2703{
2704 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
2705}
2706
2707void
2708bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
2709 afi_t afi, safi_t safi, struct bgp_info *del,
2710 struct bgp_aggregate *aggregate)
2711{
2712 struct bgp_table *table;
2713 struct bgp_node *top;
2714 struct bgp_node *rn;
2715 u_char origin;
2716 struct aspath *aspath = NULL;
2717 struct aspath *asmerge = NULL;
2718 struct community *community = NULL;
2719 struct community *commerge = NULL;
2720 struct in_addr nexthop;
2721 u_int32_t med = 0;
2722 struct bgp_info *ri;
2723 struct bgp_info *new;
2724 int first = 1;
2725 unsigned long match = 0;
2726
2727 /* Record adding route's nexthop and med. */
2728 if (rinew)
2729 {
2730 nexthop = rinew->attr->nexthop;
2731 med = rinew->attr->med;
2732 }
2733
2734 /* ORIGIN attribute: If at least one route among routes that are
2735 aggregated has ORIGIN with the value INCOMPLETE, then the
2736 aggregated route must have the ORIGIN attribute with the value
2737 INCOMPLETE. Otherwise, if at least one route among routes that
2738 are aggregated has ORIGIN with the value EGP, then the aggregated
2739 route must have the origin attribute with the value EGP. In all
2740 other case the value of the ORIGIN attribute of the aggregated
2741 route is INTERNAL. */
2742 origin = BGP_ORIGIN_IGP;
2743
2744 table = bgp->rib[afi][safi];
2745
2746 top = bgp_node_get (table, p);
2747 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
2748 if (rn->p.prefixlen > p->prefixlen)
2749 {
2750 match = 0;
2751
2752 for (ri = rn->info; ri; ri = ri->next)
2753 {
2754 if (BGP_INFO_HOLDDOWN (ri))
2755 continue;
2756
2757 if (del && ri == del)
2758 continue;
2759
2760 if (! rinew && first)
2761 {
2762 nexthop = ri->attr->nexthop;
2763 med = ri->attr->med;
2764 first = 0;
2765 }
2766
2767#ifdef AGGREGATE_NEXTHOP_CHECK
2768 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
2769 || ri->attr->med != med)
2770 {
2771 if (aspath)
2772 aspath_free (aspath);
2773 if (community)
2774 community_free (community);
2775 bgp_unlock_node (rn);
2776 bgp_unlock_node (top);
2777 return;
2778 }
2779#endif /* AGGREGATE_NEXTHOP_CHECK */
2780
2781 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
2782 {
2783 if (aggregate->summary_only)
2784 {
2785 ri->suppress++;
2786 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
2787 match++;
2788 }
2789
2790 aggregate->count++;
2791
2792 if (aggregate->as_set)
2793 {
2794 if (origin < ri->attr->origin)
2795 origin = ri->attr->origin;
2796
2797 if (aspath)
2798 {
2799 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
2800 aspath_free (aspath);
2801 aspath = asmerge;
2802 }
2803 else
2804 aspath = aspath_dup (ri->attr->aspath);
2805
2806 if (ri->attr->community)
2807 {
2808 if (community)
2809 {
2810 commerge = community_merge (community,
2811 ri->attr->community);
2812 community = community_uniq_sort (commerge);
2813 community_free (commerge);
2814 }
2815 else
2816 community = community_dup (ri->attr->community);
2817 }
2818 }
2819 }
2820 }
2821 if (match)
2822 bgp_process (bgp, rn, afi, safi);
2823 }
2824 bgp_unlock_node (top);
2825
2826 if (rinew)
2827 {
2828 aggregate->count++;
2829
2830 if (aggregate->summary_only)
2831 rinew->suppress++;
2832
2833 if (aggregate->as_set)
2834 {
2835 if (origin < rinew->attr->origin)
2836 origin = rinew->attr->origin;
2837
2838 if (aspath)
2839 {
2840 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
2841 aspath_free (aspath);
2842 aspath = asmerge;
2843 }
2844 else
2845 aspath = aspath_dup (rinew->attr->aspath);
2846
2847 if (rinew->attr->community)
2848 {
2849 if (community)
2850 {
2851 commerge = community_merge (community,
2852 rinew->attr->community);
2853 community = community_uniq_sort (commerge);
2854 community_free (commerge);
2855 }
2856 else
2857 community = community_dup (rinew->attr->community);
2858 }
2859 }
2860 }
2861
2862 if (aggregate->count > 0)
2863 {
2864 rn = bgp_node_get (table, p);
2865 new = bgp_info_new ();
2866 new->type = ZEBRA_ROUTE_BGP;
2867 new->sub_type = BGP_ROUTE_AGGREGATE;
2868 new->peer = bgp->peer_self;
2869 SET_FLAG (new->flags, BGP_INFO_VALID);
2870 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
2871 new->uptime = time (NULL);
2872
2873 bgp_info_add (rn, new);
2874 bgp_process (bgp, rn, afi, safi);
2875 }
2876 else
2877 {
2878 if (aspath)
2879 aspath_free (aspath);
2880 if (community)
2881 community_free (community);
2882 }
2883}
2884
2885void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
2886 struct bgp_aggregate *);
2887
2888void
2889bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
2890 struct bgp_info *ri, afi_t afi, safi_t safi)
2891{
2892 struct bgp_node *child;
2893 struct bgp_node *rn;
2894 struct bgp_aggregate *aggregate;
2895
2896 /* MPLS-VPN aggregation is not yet supported. */
2897 if (safi == SAFI_MPLS_VPN)
2898 return;
2899
2900 if (p->prefixlen == 0)
2901 return;
2902
2903 if (BGP_INFO_HOLDDOWN (ri))
2904 return;
2905
2906 child = bgp_node_get (bgp->aggregate[afi][safi], p);
2907
2908 /* Aggregate address configuration check. */
2909 for (rn = child; rn; rn = rn->parent)
2910 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
2911 {
2912 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00002913 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00002914 }
2915 bgp_unlock_node (child);
2916}
2917
2918void
2919bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
2920 struct bgp_info *del, afi_t afi, safi_t safi)
2921{
2922 struct bgp_node *child;
2923 struct bgp_node *rn;
2924 struct bgp_aggregate *aggregate;
2925
2926 /* MPLS-VPN aggregation is not yet supported. */
2927 if (safi == SAFI_MPLS_VPN)
2928 return;
2929
2930 if (p->prefixlen == 0)
2931 return;
2932
2933 child = bgp_node_get (bgp->aggregate[afi][safi], p);
2934
2935 /* Aggregate address configuration check. */
2936 for (rn = child; rn; rn = rn->parent)
2937 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
2938 {
2939 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00002940 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00002941 }
2942 bgp_unlock_node (child);
2943}
2944
2945void
2946bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
2947 struct bgp_aggregate *aggregate)
2948{
2949 struct bgp_table *table;
2950 struct bgp_node *top;
2951 struct bgp_node *rn;
2952 struct bgp_info *new;
2953 struct bgp_info *ri;
2954 unsigned long match;
2955 u_char origin = BGP_ORIGIN_IGP;
2956 struct aspath *aspath = NULL;
2957 struct aspath *asmerge = NULL;
2958 struct community *community = NULL;
2959 struct community *commerge = NULL;
2960
2961 table = bgp->rib[afi][safi];
2962
2963 /* Sanity check. */
2964 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
2965 return;
2966 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
2967 return;
2968
2969 /* If routes exists below this node, generate aggregate routes. */
2970 top = bgp_node_get (table, p);
2971 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
2972 if (rn->p.prefixlen > p->prefixlen)
2973 {
2974 match = 0;
2975
2976 for (ri = rn->info; ri; ri = ri->next)
2977 {
2978 if (BGP_INFO_HOLDDOWN (ri))
2979 continue;
2980
2981 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
2982 {
2983 /* summary-only aggregate route suppress aggregated
2984 route announcement. */
2985 if (aggregate->summary_only)
2986 {
2987 ri->suppress++;
2988 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
2989 match++;
2990 }
2991 /* as-set aggregate route generate origin, as path,
2992 community aggregation. */
2993 if (aggregate->as_set)
2994 {
2995 if (origin < ri->attr->origin)
2996 origin = ri->attr->origin;
2997
2998 if (aspath)
2999 {
3000 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
3001 aspath_free (aspath);
3002 aspath = asmerge;
3003 }
3004 else
3005 aspath = aspath_dup (ri->attr->aspath);
3006
3007 if (ri->attr->community)
3008 {
3009 if (community)
3010 {
3011 commerge = community_merge (community,
3012 ri->attr->community);
3013 community = community_uniq_sort (commerge);
3014 community_free (commerge);
3015 }
3016 else
3017 community = community_dup (ri->attr->community);
3018 }
3019 }
3020 aggregate->count++;
3021 }
3022 }
3023
3024 /* If this node is suppressed, process the change. */
3025 if (match)
3026 bgp_process (bgp, rn, afi, safi);
3027 }
3028 bgp_unlock_node (top);
3029
3030 /* Add aggregate route to BGP table. */
3031 if (aggregate->count)
3032 {
3033 rn = bgp_node_get (table, p);
3034
3035 new = bgp_info_new ();
3036 new->type = ZEBRA_ROUTE_BGP;
3037 new->sub_type = BGP_ROUTE_AGGREGATE;
3038 new->peer = bgp->peer_self;
3039 SET_FLAG (new->flags, BGP_INFO_VALID);
3040 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
3041 new->uptime = time (NULL);
3042
3043 bgp_info_add (rn, new);
3044
3045 /* Process change. */
3046 bgp_process (bgp, rn, afi, safi);
3047 }
3048}
3049
3050void
3051bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
3052 safi_t safi, struct bgp_aggregate *aggregate)
3053{
3054 struct bgp_table *table;
3055 struct bgp_node *top;
3056 struct bgp_node *rn;
3057 struct bgp_info *ri;
3058 unsigned long match;
3059
3060 table = bgp->rib[afi][safi];
3061
3062 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
3063 return;
3064 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
3065 return;
3066
3067 /* If routes exists below this node, generate aggregate routes. */
3068 top = bgp_node_get (table, p);
3069 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
3070 if (rn->p.prefixlen > p->prefixlen)
3071 {
3072 match = 0;
3073
3074 for (ri = rn->info; ri; ri = ri->next)
3075 {
3076 if (BGP_INFO_HOLDDOWN (ri))
3077 continue;
3078
3079 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
3080 {
3081 if (aggregate->summary_only)
3082 {
3083 ri->suppress--;
3084
3085 if (ri->suppress == 0)
3086 {
3087 SET_FLAG (ri->flags, BGP_INFO_ATTR_CHANGED);
3088 match++;
3089 }
3090 }
3091 aggregate->count--;
3092 }
3093 }
3094
3095 /* If this node is suppressed, process the change. */
3096 if (match)
3097 bgp_process (bgp, rn, afi, safi);
3098 }
3099 bgp_unlock_node (top);
3100
3101 /* Delete aggregate route from BGP table. */
3102 rn = bgp_node_get (table, p);
3103
3104 for (ri = rn->info; ri; ri = ri->next)
3105 if (ri->peer == bgp->peer_self
3106 && ri->type == ZEBRA_ROUTE_BGP
3107 && ri->sub_type == BGP_ROUTE_AGGREGATE)
3108 break;
3109
3110 /* Withdraw static BGP route from routing table. */
3111 if (ri)
3112 {
3113 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3114 bgp_process (bgp, rn, afi, safi);
3115 bgp_info_delete (rn, ri);
3116 bgp_info_free (ri);
3117 bgp_unlock_node (rn);
3118 }
3119
3120 /* Unlock bgp_node_lookup. */
3121 bgp_unlock_node (rn);
3122}
3123
3124/* Aggregate route attribute. */
3125#define AGGREGATE_SUMMARY_ONLY 1
3126#define AGGREGATE_AS_SET 1
3127
3128int
3129bgp_aggregate_set (struct vty *vty, char *prefix_str, afi_t afi, safi_t safi,
3130 u_char summary_only, u_char as_set)
3131{
3132 int ret;
3133 struct prefix p;
3134 struct bgp_node *rn;
3135 struct bgp *bgp;
3136 struct bgp_aggregate *aggregate;
3137
3138 /* Convert string to prefix structure. */
3139 ret = str2prefix (prefix_str, &p);
3140 if (!ret)
3141 {
3142 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
3143 return CMD_WARNING;
3144 }
3145 apply_mask (&p);
3146
3147 /* Get BGP structure. */
3148 bgp = vty->index;
3149
3150 /* Old configuration check. */
3151 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
3152
3153 if (rn->info)
3154 {
3155 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
3156 bgp_unlock_node (rn);
3157 return CMD_WARNING;
3158 }
3159
3160 /* Make aggregate address structure. */
3161 aggregate = bgp_aggregate_new ();
3162 aggregate->summary_only = summary_only;
3163 aggregate->as_set = as_set;
3164 aggregate->safi = safi;
3165 rn->info = aggregate;
3166
3167 /* Aggregate address insert into BGP routing table. */
3168 if (safi & SAFI_UNICAST)
3169 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
3170 if (safi & SAFI_MULTICAST)
3171 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
3172
3173 return CMD_SUCCESS;
3174}
3175
3176int
3177bgp_aggregate_unset (struct vty *vty, char *prefix_str, afi_t afi, safi_t safi)
3178{
3179 int ret;
3180 struct prefix p;
3181 struct bgp_node *rn;
3182 struct bgp *bgp;
3183 struct bgp_aggregate *aggregate;
3184
3185 /* Convert string to prefix structure. */
3186 ret = str2prefix (prefix_str, &p);
3187 if (!ret)
3188 {
3189 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
3190 return CMD_WARNING;
3191 }
3192 apply_mask (&p);
3193
3194 /* Get BGP structure. */
3195 bgp = vty->index;
3196
3197 /* Old configuration check. */
3198 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
3199 if (! rn)
3200 {
3201 vty_out (vty, "%% There is no aggregate-address configuration.%s",
3202 VTY_NEWLINE);
3203 return CMD_WARNING;
3204 }
3205
3206 aggregate = rn->info;
3207 if (aggregate->safi & SAFI_UNICAST)
3208 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
3209 if (aggregate->safi & SAFI_MULTICAST)
3210 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
3211
3212 /* Unlock aggregate address configuration. */
3213 rn->info = NULL;
3214 bgp_aggregate_free (aggregate);
3215 bgp_unlock_node (rn);
3216 bgp_unlock_node (rn);
3217
3218 return CMD_SUCCESS;
3219}
3220
3221DEFUN (aggregate_address,
3222 aggregate_address_cmd,
3223 "aggregate-address A.B.C.D/M",
3224 "Configure BGP aggregate entries\n"
3225 "Aggregate prefix\n")
3226{
3227 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
3228}
3229
3230DEFUN (aggregate_address_mask,
3231 aggregate_address_mask_cmd,
3232 "aggregate-address A.B.C.D A.B.C.D",
3233 "Configure BGP aggregate entries\n"
3234 "Aggregate address\n"
3235 "Aggregate mask\n")
3236{
3237 int ret;
3238 char prefix_str[BUFSIZ];
3239
3240 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3241
3242 if (! ret)
3243 {
3244 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3245 return CMD_WARNING;
3246 }
3247
3248 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3249 0, 0);
3250}
3251
3252DEFUN (aggregate_address_summary_only,
3253 aggregate_address_summary_only_cmd,
3254 "aggregate-address A.B.C.D/M summary-only",
3255 "Configure BGP aggregate entries\n"
3256 "Aggregate prefix\n"
3257 "Filter more specific routes from updates\n")
3258{
3259 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
3260 AGGREGATE_SUMMARY_ONLY, 0);
3261}
3262
3263DEFUN (aggregate_address_mask_summary_only,
3264 aggregate_address_mask_summary_only_cmd,
3265 "aggregate-address A.B.C.D A.B.C.D summary-only",
3266 "Configure BGP aggregate entries\n"
3267 "Aggregate address\n"
3268 "Aggregate mask\n"
3269 "Filter more specific routes from updates\n")
3270{
3271 int ret;
3272 char prefix_str[BUFSIZ];
3273
3274 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3275
3276 if (! ret)
3277 {
3278 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3279 return CMD_WARNING;
3280 }
3281
3282 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3283 AGGREGATE_SUMMARY_ONLY, 0);
3284}
3285
3286DEFUN (aggregate_address_as_set,
3287 aggregate_address_as_set_cmd,
3288 "aggregate-address A.B.C.D/M as-set",
3289 "Configure BGP aggregate entries\n"
3290 "Aggregate prefix\n"
3291 "Generate AS set path information\n")
3292{
3293 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
3294 0, AGGREGATE_AS_SET);
3295}
3296
3297DEFUN (aggregate_address_mask_as_set,
3298 aggregate_address_mask_as_set_cmd,
3299 "aggregate-address A.B.C.D A.B.C.D as-set",
3300 "Configure BGP aggregate entries\n"
3301 "Aggregate address\n"
3302 "Aggregate mask\n"
3303 "Generate AS set path information\n")
3304{
3305 int ret;
3306 char prefix_str[BUFSIZ];
3307
3308 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3309
3310 if (! ret)
3311 {
3312 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3313 return CMD_WARNING;
3314 }
3315
3316 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3317 0, AGGREGATE_AS_SET);
3318}
3319
3320
3321DEFUN (aggregate_address_as_set_summary,
3322 aggregate_address_as_set_summary_cmd,
3323 "aggregate-address A.B.C.D/M as-set summary-only",
3324 "Configure BGP aggregate entries\n"
3325 "Aggregate prefix\n"
3326 "Generate AS set path information\n"
3327 "Filter more specific routes from updates\n")
3328{
3329 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
3330 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
3331}
3332
3333ALIAS (aggregate_address_as_set_summary,
3334 aggregate_address_summary_as_set_cmd,
3335 "aggregate-address A.B.C.D/M summary-only as-set",
3336 "Configure BGP aggregate entries\n"
3337 "Aggregate prefix\n"
3338 "Filter more specific routes from updates\n"
3339 "Generate AS set path information\n")
3340
3341DEFUN (aggregate_address_mask_as_set_summary,
3342 aggregate_address_mask_as_set_summary_cmd,
3343 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
3344 "Configure BGP aggregate entries\n"
3345 "Aggregate address\n"
3346 "Aggregate mask\n"
3347 "Generate AS set path information\n"
3348 "Filter more specific routes from updates\n")
3349{
3350 int ret;
3351 char prefix_str[BUFSIZ];
3352
3353 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3354
3355 if (! ret)
3356 {
3357 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3358 return CMD_WARNING;
3359 }
3360
3361 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
3362 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
3363}
3364
3365ALIAS (aggregate_address_mask_as_set_summary,
3366 aggregate_address_mask_summary_as_set_cmd,
3367 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
3368 "Configure BGP aggregate entries\n"
3369 "Aggregate address\n"
3370 "Aggregate mask\n"
3371 "Filter more specific routes from updates\n"
3372 "Generate AS set path information\n")
3373
3374DEFUN (no_aggregate_address,
3375 no_aggregate_address_cmd,
3376 "no aggregate-address A.B.C.D/M",
3377 NO_STR
3378 "Configure BGP aggregate entries\n"
3379 "Aggregate prefix\n")
3380{
3381 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
3382}
3383
3384ALIAS (no_aggregate_address,
3385 no_aggregate_address_summary_only_cmd,
3386 "no aggregate-address A.B.C.D/M summary-only",
3387 NO_STR
3388 "Configure BGP aggregate entries\n"
3389 "Aggregate prefix\n"
3390 "Filter more specific routes from updates\n")
3391
3392ALIAS (no_aggregate_address,
3393 no_aggregate_address_as_set_cmd,
3394 "no aggregate-address A.B.C.D/M as-set",
3395 NO_STR
3396 "Configure BGP aggregate entries\n"
3397 "Aggregate prefix\n"
3398 "Generate AS set path information\n")
3399
3400ALIAS (no_aggregate_address,
3401 no_aggregate_address_as_set_summary_cmd,
3402 "no aggregate-address A.B.C.D/M as-set summary-only",
3403 NO_STR
3404 "Configure BGP aggregate entries\n"
3405 "Aggregate prefix\n"
3406 "Generate AS set path information\n"
3407 "Filter more specific routes from updates\n")
3408
3409ALIAS (no_aggregate_address,
3410 no_aggregate_address_summary_as_set_cmd,
3411 "no aggregate-address A.B.C.D/M summary-only as-set",
3412 NO_STR
3413 "Configure BGP aggregate entries\n"
3414 "Aggregate prefix\n"
3415 "Filter more specific routes from updates\n"
3416 "Generate AS set path information\n")
3417
3418DEFUN (no_aggregate_address_mask,
3419 no_aggregate_address_mask_cmd,
3420 "no aggregate-address A.B.C.D A.B.C.D",
3421 NO_STR
3422 "Configure BGP aggregate entries\n"
3423 "Aggregate address\n"
3424 "Aggregate mask\n")
3425{
3426 int ret;
3427 char prefix_str[BUFSIZ];
3428
3429 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3430
3431 if (! ret)
3432 {
3433 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3434 return CMD_WARNING;
3435 }
3436
3437 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
3438}
3439
3440ALIAS (no_aggregate_address_mask,
3441 no_aggregate_address_mask_summary_only_cmd,
3442 "no aggregate-address A.B.C.D A.B.C.D summary-only",
3443 NO_STR
3444 "Configure BGP aggregate entries\n"
3445 "Aggregate address\n"
3446 "Aggregate mask\n"
3447 "Filter more specific routes from updates\n")
3448
3449ALIAS (no_aggregate_address_mask,
3450 no_aggregate_address_mask_as_set_cmd,
3451 "no aggregate-address A.B.C.D A.B.C.D as-set",
3452 NO_STR
3453 "Configure BGP aggregate entries\n"
3454 "Aggregate address\n"
3455 "Aggregate mask\n"
3456 "Generate AS set path information\n")
3457
3458ALIAS (no_aggregate_address_mask,
3459 no_aggregate_address_mask_as_set_summary_cmd,
3460 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
3461 NO_STR
3462 "Configure BGP aggregate entries\n"
3463 "Aggregate address\n"
3464 "Aggregate mask\n"
3465 "Generate AS set path information\n"
3466 "Filter more specific routes from updates\n")
3467
3468ALIAS (no_aggregate_address_mask,
3469 no_aggregate_address_mask_summary_as_set_cmd,
3470 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
3471 NO_STR
3472 "Configure BGP aggregate entries\n"
3473 "Aggregate address\n"
3474 "Aggregate mask\n"
3475 "Filter more specific routes from updates\n"
3476 "Generate AS set path information\n")
3477
3478#ifdef HAVE_IPV6
3479DEFUN (ipv6_aggregate_address,
3480 ipv6_aggregate_address_cmd,
3481 "aggregate-address X:X::X:X/M",
3482 "Configure BGP aggregate entries\n"
3483 "Aggregate prefix\n")
3484{
3485 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
3486}
3487
3488DEFUN (ipv6_aggregate_address_summary_only,
3489 ipv6_aggregate_address_summary_only_cmd,
3490 "aggregate-address X:X::X:X/M summary-only",
3491 "Configure BGP aggregate entries\n"
3492 "Aggregate prefix\n"
3493 "Filter more specific routes from updates\n")
3494{
3495 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
3496 AGGREGATE_SUMMARY_ONLY, 0);
3497}
3498
3499DEFUN (no_ipv6_aggregate_address,
3500 no_ipv6_aggregate_address_cmd,
3501 "no aggregate-address X:X::X:X/M",
3502 NO_STR
3503 "Configure BGP aggregate entries\n"
3504 "Aggregate prefix\n")
3505{
3506 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
3507}
3508
3509DEFUN (no_ipv6_aggregate_address_summary_only,
3510 no_ipv6_aggregate_address_summary_only_cmd,
3511 "no aggregate-address X:X::X:X/M summary-only",
3512 NO_STR
3513 "Configure BGP aggregate entries\n"
3514 "Aggregate prefix\n"
3515 "Filter more specific routes from updates\n")
3516{
3517 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
3518}
3519
3520ALIAS (ipv6_aggregate_address,
3521 old_ipv6_aggregate_address_cmd,
3522 "ipv6 bgp aggregate-address X:X::X:X/M",
3523 IPV6_STR
3524 BGP_STR
3525 "Configure BGP aggregate entries\n"
3526 "Aggregate prefix\n")
3527
3528ALIAS (ipv6_aggregate_address_summary_only,
3529 old_ipv6_aggregate_address_summary_only_cmd,
3530 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
3531 IPV6_STR
3532 BGP_STR
3533 "Configure BGP aggregate entries\n"
3534 "Aggregate prefix\n"
3535 "Filter more specific routes from updates\n")
3536
3537ALIAS (no_ipv6_aggregate_address,
3538 old_no_ipv6_aggregate_address_cmd,
3539 "no ipv6 bgp aggregate-address X:X::X:X/M",
3540 NO_STR
3541 IPV6_STR
3542 BGP_STR
3543 "Configure BGP aggregate entries\n"
3544 "Aggregate prefix\n")
3545
3546ALIAS (no_ipv6_aggregate_address_summary_only,
3547 old_no_ipv6_aggregate_address_summary_only_cmd,
3548 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
3549 NO_STR
3550 IPV6_STR
3551 BGP_STR
3552 "Configure BGP aggregate entries\n"
3553 "Aggregate prefix\n"
3554 "Filter more specific routes from updates\n")
3555#endif /* HAVE_IPV6 */
3556
3557/* Redistribute route treatment. */
3558void
3559bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
3560 u_int32_t metric, u_char type)
3561{
3562 struct bgp *bgp;
3563 struct listnode *nn;
3564 struct bgp_info *new;
3565 struct bgp_info *bi;
3566 struct bgp_info info;
3567 struct bgp_node *bn;
3568 struct attr attr;
3569 struct attr attr_new;
3570 struct attr *new_attr;
3571 afi_t afi;
3572 int ret;
3573
3574 /* Make default attribute. */
3575 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
3576 if (nexthop)
3577 attr.nexthop = *nexthop;
3578
3579 attr.med = metric;
3580 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3581
3582 LIST_LOOP (bm->bgp, bgp, nn)
3583 {
3584 afi = family2afi (p->family);
3585
3586 if (bgp->redist[afi][type])
3587 {
3588 /* Copy attribute for modification. */
3589 attr_new = attr;
3590
3591 if (bgp->redist_metric_flag[afi][type])
3592 attr_new.med = bgp->redist_metric[afi][type];
3593
3594 /* Apply route-map. */
3595 if (bgp->rmap[afi][type].map)
3596 {
3597 info.peer = bgp->peer_self;
3598 info.attr = &attr_new;
3599
3600 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
3601 &info);
3602 if (ret == RMAP_DENYMATCH)
3603 {
3604 /* Free uninterned attribute. */
3605 bgp_attr_flush (&attr_new);
3606
3607 /* Unintern original. */
3608 aspath_unintern (attr.aspath);
3609 bgp_redistribute_delete (p, type);
3610 return;
3611 }
3612 }
3613
3614 bn = bgp_afi_node_get (bgp, afi, SAFI_UNICAST, p, NULL);
3615 new_attr = bgp_attr_intern (&attr_new);
3616
3617 for (bi = bn->info; bi; bi = bi->next)
3618 if (bi->peer == bgp->peer_self
3619 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
3620 break;
3621
3622 if (bi)
3623 {
3624 if (attrhash_cmp (bi->attr, new_attr))
3625 {
3626 bgp_attr_unintern (new_attr);
3627 aspath_unintern (attr.aspath);
3628 bgp_unlock_node (bn);
3629 return;
3630 }
3631 else
3632 {
3633 /* The attribute is changed. */
3634 SET_FLAG (bi->flags, BGP_INFO_ATTR_CHANGED);
3635
3636 /* Rewrite BGP route information. */
3637 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
3638 bgp_attr_unintern (bi->attr);
3639 bi->attr = new_attr;
3640 bi->uptime = time (NULL);
3641
3642 /* Process change. */
3643 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
3644 bgp_process (bgp, bn, afi, SAFI_UNICAST);
3645 bgp_unlock_node (bn);
3646 aspath_unintern (attr.aspath);
3647 return;
3648 }
3649 }
3650
3651 new = bgp_info_new ();
3652 new->type = type;
3653 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
3654 new->peer = bgp->peer_self;
3655 SET_FLAG (new->flags, BGP_INFO_VALID);
3656 new->attr = new_attr;
3657 new->uptime = time (NULL);
3658
3659 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
3660 bgp_info_add (bn, new);
3661 bgp_process (bgp, bn, afi, SAFI_UNICAST);
3662 }
3663 }
3664
3665 /* Unintern original. */
3666 aspath_unintern (attr.aspath);
3667}
3668
3669void
3670bgp_redistribute_delete (struct prefix *p, u_char type)
3671{
3672 struct bgp *bgp;
3673 struct listnode *nn;
3674 afi_t afi;
3675 struct bgp_node *rn;
3676 struct bgp_info *ri;
3677
3678 LIST_LOOP (bm->bgp, bgp, nn)
3679 {
3680 afi = family2afi (p->family);
3681
3682 if (bgp->redist[afi][type])
3683 {
3684 rn = bgp_afi_node_get (bgp, afi, SAFI_UNICAST, p, NULL);
3685
3686 for (ri = rn->info; ri; ri = ri->next)
3687 if (ri->peer == bgp->peer_self
3688 && ri->type == type)
3689 break;
3690
3691 if (ri)
3692 {
3693 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
3694 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3695 bgp_process (bgp, rn, afi, SAFI_UNICAST);
3696 bgp_info_delete (rn, ri);
3697 bgp_info_free (ri);
3698 bgp_unlock_node (rn);
3699 }
3700 bgp_unlock_node (rn);
3701 }
3702 }
3703}
3704
3705/* Withdraw specified route type's route. */
3706void
3707bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
3708{
3709 struct bgp_node *rn;
3710 struct bgp_info *ri;
3711 struct bgp_table *table;
3712
3713 table = bgp->rib[afi][SAFI_UNICAST];
3714
3715 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3716 {
3717 for (ri = rn->info; ri; ri = ri->next)
3718 if (ri->peer == bgp->peer_self
3719 && ri->type == type)
3720 break;
3721
3722 if (ri)
3723 {
3724 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
3725 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
3726 bgp_process (bgp, rn, afi, SAFI_UNICAST);
3727 bgp_info_delete (rn, ri);
3728 bgp_info_free (ri);
3729 bgp_unlock_node (rn);
3730 }
3731 }
3732}
3733
3734/* Static function to display route. */
3735void
3736route_vty_out_route (struct prefix *p, struct vty *vty)
3737{
3738 int len;
3739 u_int32_t destination;
3740 char buf[BUFSIZ];
3741
3742 if (p->family == AF_INET)
3743 {
3744 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
3745 destination = ntohl (p->u.prefix4.s_addr);
3746
3747 if ((IN_CLASSC (destination) && p->prefixlen == 24)
3748 || (IN_CLASSB (destination) && p->prefixlen == 16)
3749 || (IN_CLASSA (destination) && p->prefixlen == 8)
3750 || p->u.prefix4.s_addr == 0)
3751 {
3752 /* When mask is natural, mask is not displayed. */
3753 }
3754 else
3755 len += vty_out (vty, "/%d", p->prefixlen);
3756 }
3757 else
3758 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
3759 p->prefixlen);
3760
3761 len = 17 - len;
3762 if (len < 1)
3763 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
3764 else
3765 vty_out (vty, "%*s", len, " ");
3766}
3767
3768/* Calculate line number of output data. */
3769int
3770vty_calc_line (struct vty *vty, unsigned long length)
3771{
3772 return vty->width ? (((vty->obuf->length - length) / vty->width) + 1) : 1;
3773}
3774
3775enum bgp_display_type
3776{
3777 normal_list,
3778};
3779
3780/* called from terminal list command */
3781int
3782route_vty_out (struct vty *vty, struct prefix *p,
3783 struct bgp_info *binfo, int display, safi_t safi)
3784{
3785 struct attr *attr;
3786 unsigned long length = 0;
3787
3788 length = vty->obuf->length;
3789
3790 /* Route status display. */
3791 if (binfo->suppress)
3792 vty_out (vty, "s");
3793 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3794 vty_out (vty, "*");
3795 else
3796 vty_out (vty, " ");
3797
3798 /* Selected */
3799 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3800 vty_out (vty, "h");
3801 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
3802 vty_out (vty, "d");
3803 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
3804 vty_out (vty, ">");
3805 else
3806 vty_out (vty, " ");
3807
3808 /* Internal route. */
3809 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
3810 vty_out (vty, "i");
3811 else
3812 vty_out (vty, " ");
3813
3814 /* print prefix and mask */
3815 if (! display)
3816 route_vty_out_route (p, vty);
3817 else
3818 vty_out (vty, "%*s", 17, " ");
3819
3820 /* Print attribute */
3821 attr = binfo->attr;
3822 if (attr)
3823 {
3824 if (p->family == AF_INET)
3825 {
3826 if (safi == SAFI_MPLS_VPN)
3827 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
3828 else
3829 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
3830 }
3831#ifdef HAVE_IPV6
3832 else if (p->family == AF_INET6)
3833 {
3834 int len;
3835 char buf[BUFSIZ];
3836
3837 len = vty_out (vty, "%s",
3838 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
3839 len = 16 - len;
3840 if (len < 1)
3841 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
3842 else
3843 vty_out (vty, "%*s", len, " ");
3844 }
3845#endif /* HAVE_IPV6 */
3846
3847 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
3848 vty_out (vty, "%10d", attr->med);
3849 else
3850 vty_out (vty, " ");
3851
3852 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
3853 vty_out (vty, "%7d", attr->local_pref);
3854 else
3855 vty_out (vty, " ");
3856
3857 vty_out (vty, "%7u ",attr->weight);
3858
3859 /* Print aspath */
3860 if (attr->aspath)
3861 aspath_print_vty (vty, attr->aspath);
3862
3863 /* Print origin */
3864 if (strlen (attr->aspath->str) == 0)
3865 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
3866 else
3867 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
3868 }
3869 vty_out (vty, "%s", VTY_NEWLINE);
3870
3871 return vty_calc_line (vty, length);
3872}
3873
3874/* called from terminal list command */
3875void
3876route_vty_out_tmp (struct vty *vty, struct prefix *p,
3877 struct attr *attr, safi_t safi)
3878{
3879 /* Route status display. */
3880 vty_out (vty, "*");
3881 vty_out (vty, ">");
3882 vty_out (vty, " ");
3883
3884 /* print prefix and mask */
3885 route_vty_out_route (p, vty);
3886
3887 /* Print attribute */
3888 if (attr)
3889 {
3890 if (p->family == AF_INET)
3891 {
3892 if (safi == SAFI_MPLS_VPN)
3893 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
3894 else
3895 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
3896 }
3897#ifdef HAVE_IPV6
3898 else if (p->family == AF_INET6)
3899 {
3900 int len;
3901 char buf[BUFSIZ];
3902
3903 len = vty_out (vty, "%s",
3904 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
3905 len = 16 - len;
3906 if (len < 1)
3907 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
3908 else
3909 vty_out (vty, "%*s", len, " ");
3910 }
3911#endif /* HAVE_IPV6 */
3912
3913 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
3914 vty_out (vty, "%10d", attr->med);
3915 else
3916 vty_out (vty, " ");
3917
3918 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
3919 vty_out (vty, "%7d", attr->local_pref);
3920 else
3921 vty_out (vty, " ");
3922
3923 vty_out (vty, "%7d ",attr->weight);
3924
3925 /* Print aspath */
3926 if (attr->aspath)
3927 aspath_print_vty (vty, attr->aspath);
3928
3929 /* Print origin */
3930 if (strlen (attr->aspath->str) == 0)
3931 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
3932 else
3933 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
3934 }
3935
3936 vty_out (vty, "%s", VTY_NEWLINE);
3937}
3938
3939int
3940route_vty_out_tag (struct vty *vty, struct prefix *p,
3941 struct bgp_info *binfo, int display, safi_t safi)
3942{
3943 struct attr *attr;
3944 unsigned long length = 0;
3945 u_int32_t label = 0;
3946
3947 length = vty->obuf->length;
3948
3949 /* Route status display. */
3950 if (binfo->suppress)
3951 vty_out (vty, "s");
3952 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3953 vty_out (vty, "*");
3954 else
3955 vty_out (vty, " ");
3956
3957 /* Selected */
3958 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
3959 vty_out (vty, "h");
3960 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
3961 vty_out (vty, "d");
3962 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
3963 vty_out (vty, ">");
3964 else
3965 vty_out (vty, " ");
3966
3967 /* Internal route. */
3968 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
3969 vty_out (vty, "i");
3970 else
3971 vty_out (vty, " ");
3972
3973 /* print prefix and mask */
3974 if (! display)
3975 route_vty_out_route (p, vty);
3976 else
3977 vty_out (vty, "%*s", 17, " ");
3978
3979 /* Print attribute */
3980 attr = binfo->attr;
3981 if (attr)
3982 {
3983 if (p->family == AF_INET)
3984 {
3985 if (safi == SAFI_MPLS_VPN)
3986 vty_out (vty, "%-16s", inet_ntoa (attr->mp_nexthop_global_in));
3987 else
3988 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
3989 }
3990#ifdef HAVE_IPV6
3991 else if (p->family == AF_INET6)
3992 {
3993 char buf[BUFSIZ];
3994 char buf1[BUFSIZ];
3995 if (attr->mp_nexthop_len == 16)
3996 vty_out (vty, "%s",
3997 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ));
3998 else if (attr->mp_nexthop_len == 32)
3999 vty_out (vty, "%s(%s)",
4000 inet_ntop (AF_INET6, &attr->mp_nexthop_global, buf, BUFSIZ),
4001 inet_ntop (AF_INET6, &attr->mp_nexthop_local, buf1, BUFSIZ));
4002
4003 }
4004#endif /* HAVE_IPV6 */
4005 }
4006
4007 label = decode_label (binfo->tag);
4008
4009 vty_out (vty, "notag/%d", label);
4010
4011 vty_out (vty, "%s", VTY_NEWLINE);
4012
4013 return vty_calc_line (vty, length);
4014}
4015
4016/* dampening route */
4017int
4018damp_route_vty_out (struct vty *vty, struct prefix *p,
4019 struct bgp_info *binfo, int display, safi_t safi)
4020{
4021 struct attr *attr;
4022 unsigned long length = 0;
4023 int len;
4024
4025 length = vty->obuf->length;
4026
4027 /* Route status display. */
4028 if (binfo->suppress)
4029 vty_out (vty, "s");
4030 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4031 vty_out (vty, "*");
4032 else
4033 vty_out (vty, " ");
4034
4035 /* Selected */
4036 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4037 vty_out (vty, "h");
4038 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4039 vty_out (vty, "d");
4040 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4041 vty_out (vty, ">");
4042 else
4043 vty_out (vty, " ");
4044
4045 vty_out (vty, " ");
4046
4047 /* print prefix and mask */
4048 if (! display)
4049 route_vty_out_route (p, vty);
4050 else
4051 vty_out (vty, "%*s", 17, " ");
4052
4053 len = vty_out (vty, "%s", binfo->peer->host);
4054 len = 17 - len;
4055 if (len < 1)
4056 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
4057 else
4058 vty_out (vty, "%*s", len, " ");
4059
4060 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
4061
4062 /* Print attribute */
4063 attr = binfo->attr;
4064 if (attr)
4065 {
4066 /* Print aspath */
4067 if (attr->aspath)
4068 aspath_print_vty (vty, attr->aspath);
4069
4070 /* Print origin */
4071 if (strlen (attr->aspath->str) == 0)
4072 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4073 else
4074 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4075 }
4076 vty_out (vty, "%s", VTY_NEWLINE);
4077
4078 return vty_calc_line (vty, length);
4079}
4080
4081#define BGP_UPTIME_LEN 25
4082
4083/* flap route */
4084int
4085flap_route_vty_out (struct vty *vty, struct prefix *p,
4086 struct bgp_info *binfo, int display, safi_t safi)
4087{
4088 struct attr *attr;
4089 struct bgp_damp_info *bdi;
4090 unsigned long length = 0;
4091 char timebuf[BGP_UPTIME_LEN];
4092 int len;
4093
4094 length = vty->obuf->length;
4095 bdi = binfo->damp_info;
4096
4097 /* Route status display. */
4098 if (binfo->suppress)
4099 vty_out (vty, "s");
4100 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4101 vty_out (vty, "*");
4102 else
4103 vty_out (vty, " ");
4104
4105 /* Selected */
4106 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4107 vty_out (vty, "h");
4108 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4109 vty_out (vty, "d");
4110 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4111 vty_out (vty, ">");
4112 else
4113 vty_out (vty, " ");
4114
4115 vty_out (vty, " ");
4116
4117 /* print prefix and mask */
4118 if (! display)
4119 route_vty_out_route (p, vty);
4120 else
4121 vty_out (vty, "%*s", 17, " ");
4122
4123 len = vty_out (vty, "%s", binfo->peer->host);
4124 len = 16 - len;
4125 if (len < 1)
4126 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
4127 else
4128 vty_out (vty, "%*s", len, " ");
4129
4130 len = vty_out (vty, "%d", bdi->flap);
4131 len = 5 - len;
4132 if (len < 1)
4133 vty_out (vty, " ");
4134 else
4135 vty_out (vty, "%*s ", len, " ");
4136
4137 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
4138 timebuf, BGP_UPTIME_LEN));
4139
4140 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
4141 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4142 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
4143 else
4144 vty_out (vty, "%*s ", 8, " ");
4145
4146 /* Print attribute */
4147 attr = binfo->attr;
4148 if (attr)
4149 {
4150 /* Print aspath */
4151 if (attr->aspath)
4152 aspath_print_vty (vty, attr->aspath);
4153
4154 /* Print origin */
4155 if (strlen (attr->aspath->str) == 0)
4156 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
4157 else
4158 vty_out (vty, " %s", bgp_origin_str[attr->origin]);
4159 }
4160 vty_out (vty, "%s", VTY_NEWLINE);
4161
4162 return vty_calc_line (vty, length);
4163}
4164
4165void
4166route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
4167 struct bgp_info *binfo, afi_t afi, safi_t safi)
4168{
4169 char buf[INET6_ADDRSTRLEN];
4170 char buf1[BUFSIZ];
4171 struct attr *attr;
4172 int sockunion_vty_out (struct vty *, union sockunion *);
4173
4174 attr = binfo->attr;
4175
4176 if (attr)
4177 {
4178 /* Line1 display AS-path, Aggregator */
4179 if (attr->aspath)
4180 {
4181 vty_out (vty, " ");
4182 if (attr->aspath->length == 0)
4183 vty_out (vty, "Local");
4184 else
4185 aspath_print_vty (vty, attr->aspath);
4186 }
4187
4188 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR)
4189 || CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)
4190 || CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
4191 || CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY)
4192 || CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4193 {
4194 vty_out (vty, ",");
4195
4196 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR))
4197 vty_out (vty, " (aggregated by %d %s)", attr->aggregator_as,
4198 inet_ntoa (attr->aggregator_addr));
4199 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
4200 vty_out (vty, " (Received from a RR-client)");
4201 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
4202 vty_out (vty, " (Received from a RS-client)");
4203 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4204 vty_out (vty, " (history entry)");
4205 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
4206 vty_out (vty, " (suppressed due to dampening)");
4207 }
4208 vty_out (vty, "%s", VTY_NEWLINE);
4209
4210 /* Line2 display Next-hop, Neighbor, Router-id */
4211 if (p->family == AF_INET)
4212 {
4213 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
4214 inet_ntoa (attr->mp_nexthop_global_in) :
4215 inet_ntoa (attr->nexthop));
4216 }
4217#ifdef HAVE_IPV6
4218 else
4219 {
4220 vty_out (vty, " %s",
4221 inet_ntop (AF_INET6, &attr->mp_nexthop_global,
4222 buf, INET6_ADDRSTRLEN));
4223 }
4224#endif /* HAVE_IPV6 */
4225
4226 if (binfo->peer == bgp->peer_self)
4227 {
4228 vty_out (vty, " from %s ",
4229 p->family == AF_INET ? "0.0.0.0" : "::");
4230 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
4231 }
4232 else
4233 {
4234 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
4235 vty_out (vty, " (inaccessible)");
4236 else if (binfo->igpmetric)
4237 vty_out (vty, " (metric %d)", binfo->igpmetric);
pauleb821182004-05-01 08:44:08 +00004238 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00004239 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
4240 vty_out (vty, " (%s)", inet_ntoa (attr->originator_id));
4241 else
4242 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
4243 }
4244 vty_out (vty, "%s", VTY_NEWLINE);
4245
4246#ifdef HAVE_IPV6
4247 /* display nexthop local */
4248 if (attr->mp_nexthop_len == 32)
4249 {
4250 vty_out (vty, " (%s)%s",
4251 inet_ntop (AF_INET6, &attr->mp_nexthop_local,
4252 buf, INET6_ADDRSTRLEN),
4253 VTY_NEWLINE);
4254 }
4255#endif /* HAVE_IPV6 */
4256
4257 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
4258 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
4259
4260 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
4261 vty_out (vty, ", metric %d", attr->med);
4262
4263 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
4264 vty_out (vty, ", localpref %d", attr->local_pref);
4265 else
4266 vty_out (vty, ", localpref %d", bgp->default_local_pref);
4267
4268 if (attr->weight != 0)
4269 vty_out (vty, ", weight %d", attr->weight);
4270
4271 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
4272 vty_out (vty, ", valid");
4273
4274 if (binfo->peer != bgp->peer_self)
4275 {
4276 if (binfo->peer->as == binfo->peer->local_as)
4277 vty_out (vty, ", internal");
4278 else
4279 vty_out (vty, ", %s",
4280 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
4281 }
4282 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
4283 vty_out (vty, ", aggregated, local");
4284 else if (binfo->type != ZEBRA_ROUTE_BGP)
4285 vty_out (vty, ", sourced");
4286 else
4287 vty_out (vty, ", sourced, local");
4288
4289 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4290 vty_out (vty, ", atomic-aggregate");
4291
4292 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
4293 vty_out (vty, ", best");
4294
4295 vty_out (vty, "%s", VTY_NEWLINE);
4296
4297 /* Line 4 display Community */
4298 if (attr->community)
4299 vty_out (vty, " Community: %s%s", attr->community->str,
4300 VTY_NEWLINE);
4301
4302 /* Line 5 display Extended-community */
4303 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
4304 vty_out (vty, " Extended Community: %s%s", attr->ecommunity->str,
4305 VTY_NEWLINE);
4306
4307 /* Line 6 display Originator, Cluster-id */
4308 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
4309 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
4310 {
4311 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
4312 vty_out (vty, " Originator: %s", inet_ntoa (attr->originator_id));
4313
4314 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
4315 {
4316 int i;
4317 vty_out (vty, ", Cluster list: ");
4318 for (i = 0; i < attr->cluster->length / 4; i++)
4319 vty_out (vty, "%s ", inet_ntoa (attr->cluster->list[i]));
4320 }
4321 vty_out (vty, "%s", VTY_NEWLINE);
4322 }
4323
4324 if (binfo->damp_info)
4325 bgp_damp_info_vty (vty, binfo);
4326
4327 /* Line 7 display Uptime */
4328 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
4329 }
4330 vty_out (vty, "%s", VTY_NEWLINE);
4331}
4332
4333#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
4334#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
4335#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
4336
4337enum bgp_show_type
4338{
4339 bgp_show_type_normal,
4340 bgp_show_type_regexp,
4341 bgp_show_type_prefix_list,
4342 bgp_show_type_filter_list,
4343 bgp_show_type_route_map,
4344 bgp_show_type_neighbor,
4345 bgp_show_type_cidr_only,
4346 bgp_show_type_prefix_longer,
4347 bgp_show_type_community_all,
4348 bgp_show_type_community,
4349 bgp_show_type_community_exact,
4350 bgp_show_type_community_list,
4351 bgp_show_type_community_list_exact,
4352 bgp_show_type_flap_statistics,
4353 bgp_show_type_flap_address,
4354 bgp_show_type_flap_prefix,
4355 bgp_show_type_flap_cidr_only,
4356 bgp_show_type_flap_regexp,
4357 bgp_show_type_flap_filter_list,
4358 bgp_show_type_flap_prefix_list,
4359 bgp_show_type_flap_prefix_longer,
4360 bgp_show_type_flap_route_map,
4361 bgp_show_type_flap_neighbor,
4362 bgp_show_type_dampend_paths,
4363 bgp_show_type_damp_neighbor
4364};
4365
4366int
4367bgp_show_callback (struct vty *vty, int unlock)
4368{
4369 struct bgp_node *rn;
4370 struct bgp_info *ri;
4371 int count;
4372 int limit;
4373 int display;
4374
paul5228ad22004-06-04 17:58:18 +00004375 rn = (struct bgp_node *) vty->output_rn;
paul718e3742002-12-13 20:15:29 +00004376 count = 0;
4377 limit = ((vty->lines == 0)
4378 ? 10 : (vty->lines > 0
4379 ? vty->lines : vty->height - 2));
4380 limit = limit > 0 ? limit : 2;
4381
4382 /* Quit of display. */
4383 if (unlock && rn)
4384 {
4385 bgp_unlock_node (rn);
4386 if (vty->output_clean)
4387 (*vty->output_clean) (vty);
4388 vty->output_rn = NULL;
4389 vty->output_func = NULL;
4390 vty->output_clean = NULL;
4391 vty->output_arg = NULL;
4392 return 0;
4393 }
4394
4395 for (; rn; rn = bgp_route_next (rn))
4396 if (rn->info != NULL)
4397 {
4398 display = 0;
4399
4400 for (ri = rn->info; ri; ri = ri->next)
4401 {
4402 if (vty->output_type == bgp_show_type_flap_statistics
4403 || vty->output_type == bgp_show_type_flap_address
4404 || vty->output_type == bgp_show_type_flap_prefix
4405 || vty->output_type == bgp_show_type_flap_cidr_only
4406 || vty->output_type == bgp_show_type_flap_regexp
4407 || vty->output_type == bgp_show_type_flap_filter_list
4408 || vty->output_type == bgp_show_type_flap_prefix_list
4409 || vty->output_type == bgp_show_type_flap_prefix_longer
4410 || vty->output_type == bgp_show_type_flap_route_map
4411 || vty->output_type == bgp_show_type_flap_neighbor
4412 || vty->output_type == bgp_show_type_dampend_paths
4413 || vty->output_type == bgp_show_type_damp_neighbor)
4414 {
4415 if (! ri->damp_info)
4416 continue;
4417 }
4418 if (vty->output_type == bgp_show_type_regexp
4419 || vty->output_type == bgp_show_type_flap_regexp)
4420 {
4421 regex_t *regex = vty->output_arg;
4422
4423 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
4424 continue;
4425 }
4426 if (vty->output_type == bgp_show_type_prefix_list
4427 || vty->output_type == bgp_show_type_flap_prefix_list)
4428 {
4429 struct prefix_list *plist = vty->output_arg;
4430
4431 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
4432 continue;
4433 }
4434 if (vty->output_type == bgp_show_type_filter_list
4435 || vty->output_type == bgp_show_type_flap_filter_list)
4436 {
4437 struct as_list *as_list = vty->output_arg;
4438
4439 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
4440 continue;
4441 }
4442 if (vty->output_type == bgp_show_type_route_map
4443 || vty->output_type == bgp_show_type_flap_route_map)
4444 {
4445 struct route_map *rmap = vty->output_arg;
4446 struct bgp_info binfo;
4447 struct attr dummy_attr;
4448 int ret;
4449
4450 dummy_attr = *ri->attr;
4451 binfo.peer = ri->peer;
4452 binfo.attr = &dummy_attr;
4453
4454 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
4455
4456 if (ret == RMAP_DENYMATCH)
4457 continue;
4458 }
4459 if (vty->output_type == bgp_show_type_neighbor
4460 || vty->output_type == bgp_show_type_flap_neighbor
4461 || vty->output_type == bgp_show_type_damp_neighbor)
4462 {
4463 union sockunion *su = vty->output_arg;
4464
4465 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
4466 continue;
4467 }
4468 if (vty->output_type == bgp_show_type_cidr_only
4469 || vty->output_type == bgp_show_type_flap_cidr_only)
4470 {
4471 u_int32_t destination;
4472
4473 destination = ntohl (rn->p.u.prefix4.s_addr);
4474 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
4475 continue;
4476 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
4477 continue;
4478 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
4479 continue;
4480 }
4481 if (vty->output_type == bgp_show_type_prefix_longer
4482 || vty->output_type == bgp_show_type_flap_prefix_longer)
4483 {
4484 struct prefix *p = vty->output_arg;
4485
4486 if (! prefix_match (p, &rn->p))
4487 continue;
4488 }
4489 if (vty->output_type == bgp_show_type_community_all)
4490 {
4491 if (! ri->attr->community)
4492 continue;
4493 }
4494 if (vty->output_type == bgp_show_type_community)
4495 {
4496 struct community *com = vty->output_arg;
4497
4498 if (! ri->attr->community ||
4499 ! community_match (ri->attr->community, com))
4500 continue;
4501 }
4502 if (vty->output_type == bgp_show_type_community_exact)
4503 {
4504 struct community *com = vty->output_arg;
4505
4506 if (! ri->attr->community ||
4507 ! community_cmp (ri->attr->community, com))
4508 continue;
4509 }
4510 if (vty->output_type == bgp_show_type_community_list)
4511 {
4512 struct community_list *list = vty->output_arg;
4513
4514 if (! community_list_match (ri->attr->community, list))
4515 continue;
4516 }
4517 if (vty->output_type == bgp_show_type_community_list_exact)
4518 {
4519 struct community_list *list = vty->output_arg;
4520
4521 if (! community_list_exact_match (ri->attr->community, list))
4522 continue;
4523 }
4524 if (vty->output_type == bgp_show_type_flap_address
4525 || vty->output_type == bgp_show_type_flap_prefix)
4526 {
4527 struct prefix *p = vty->output_arg;
4528
4529 if (! prefix_match (&rn->p, p))
4530 continue;
4531
4532 if (vty->output_type == bgp_show_type_flap_prefix)
4533 if (p->prefixlen != rn->p.prefixlen)
4534 continue;
4535 }
4536 if (vty->output_type == bgp_show_type_dampend_paths
4537 || vty->output_type == bgp_show_type_damp_neighbor)
4538 {
4539 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
4540 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
4541 continue;
4542 }
4543
4544 if (vty->output_type == bgp_show_type_dampend_paths
4545 || vty->output_type == bgp_show_type_damp_neighbor)
4546 count += damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4547 else if (vty->output_type == bgp_show_type_flap_statistics
4548 || vty->output_type == bgp_show_type_flap_address
4549 || vty->output_type == bgp_show_type_flap_prefix
4550 || vty->output_type == bgp_show_type_flap_cidr_only
4551 || vty->output_type == bgp_show_type_flap_regexp
4552 || vty->output_type == bgp_show_type_flap_filter_list
4553 || vty->output_type == bgp_show_type_flap_prefix_list
4554 || vty->output_type == bgp_show_type_flap_prefix_longer
4555 || vty->output_type == bgp_show_type_flap_route_map
4556 || vty->output_type == bgp_show_type_flap_neighbor)
4557 count += flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4558 else
4559 count += route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4560 display++;
4561 }
4562
4563 if (display)
4564 vty->output_count++;
4565
4566 /* Remember current pointer then suspend output. */
4567 if (count >= limit)
4568 {
4569 vty->status = VTY_CONTINUE;
paul5228ad22004-06-04 17:58:18 +00004570 vty->output_rn = (struct route_node *) bgp_route_next (rn);;
paul718e3742002-12-13 20:15:29 +00004571 vty->output_func = bgp_show_callback;
4572 return 0;
4573 }
4574 }
4575
4576 /* Total line display. */
4577 if (vty->output_count)
4578 vty_out (vty, "%sTotal number of prefixes %ld%s",
4579 VTY_NEWLINE, vty->output_count, VTY_NEWLINE);
4580
4581 if (vty->output_clean)
4582 (*vty->output_clean) (vty);
4583
4584 vty->status = VTY_CONTINUE;
4585 vty->output_rn = NULL;
4586 vty->output_func = NULL;
4587 vty->output_clean = NULL;
4588 vty->output_arg = NULL;
4589
4590 return 0;
4591}
4592
4593int
paulbb46e942003-10-24 19:02:03 +00004594bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004595 enum bgp_show_type type)
4596{
paul718e3742002-12-13 20:15:29 +00004597 struct bgp_info *ri;
4598 struct bgp_node *rn;
4599 struct bgp_table *table;
4600 int header = 1;
4601 int count;
4602 int limit;
4603 int display;
4604
4605 limit = ((vty->lines == 0)
4606 ? 10 : (vty->lines > 0
4607 ? vty->lines : vty->height - 2));
4608 limit = limit > 0 ? limit : 2;
4609
paulbb46e942003-10-24 19:02:03 +00004610 if (bgp == NULL) {
4611 bgp = bgp_get_default ();
4612 }
4613
4614 if (bgp == NULL)
paul718e3742002-12-13 20:15:29 +00004615 {
paulbb46e942003-10-24 19:02:03 +00004616 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
4617 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +00004618 }
4619
4620 count = 0;
4621
4622 /* This is first entry point, so reset total line. */
4623 vty->output_count = 0;
4624 vty->output_type = type;
4625
4626 table = bgp->rib[afi][safi];
4627
4628 /* Start processing of routes. */
4629 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
4630 if (rn->info != NULL)
4631 {
4632 display = 0;
4633
4634 for (ri = rn->info; ri; ri = ri->next)
4635 {
4636 if (vty->output_type == bgp_show_type_flap_statistics
4637 || type == bgp_show_type_flap_address
4638 || type == bgp_show_type_flap_prefix
4639 || type == bgp_show_type_flap_cidr_only
4640 || type == bgp_show_type_flap_regexp
4641 || type == bgp_show_type_flap_filter_list
4642 || type == bgp_show_type_flap_prefix_list
4643 || type == bgp_show_type_flap_prefix_longer
4644 || type == bgp_show_type_flap_route_map
4645 || type == bgp_show_type_flap_neighbor
4646 || type == bgp_show_type_dampend_paths
4647 || type == bgp_show_type_damp_neighbor)
4648 {
4649 if (! ri->damp_info)
4650 continue;
4651 }
4652 if (type == bgp_show_type_regexp
4653 || type == bgp_show_type_flap_regexp)
4654 {
4655 regex_t *regex = vty->output_arg;
4656
4657 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
4658 continue;
4659 }
4660 if (type == bgp_show_type_prefix_list
4661 || type == bgp_show_type_flap_prefix_list)
4662 {
4663 struct prefix_list *plist = vty->output_arg;
4664
4665 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
4666 continue;
4667 }
4668 if (type == bgp_show_type_filter_list
4669 || type == bgp_show_type_flap_filter_list)
4670 {
4671 struct as_list *as_list = vty->output_arg;
4672
4673 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
4674 continue;
4675 }
4676 if (type == bgp_show_type_route_map
4677 || type == bgp_show_type_flap_route_map)
4678 {
4679 struct route_map *rmap = vty->output_arg;
4680 struct bgp_info binfo;
4681 struct attr dummy_attr;
4682 int ret;
4683
4684 dummy_attr = *ri->attr;
4685 binfo.peer = ri->peer;
4686 binfo.attr = &dummy_attr;
4687
4688 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
4689
4690 if (ret == RMAP_DENYMATCH)
4691 continue;
4692 }
4693 if (type == bgp_show_type_neighbor
4694 || type == bgp_show_type_flap_neighbor
4695 || type == bgp_show_type_damp_neighbor)
4696 {
4697 union sockunion *su = vty->output_arg;
4698
4699 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
4700 continue;
4701 }
4702 if (type == bgp_show_type_cidr_only
4703 || type == bgp_show_type_flap_cidr_only)
4704 {
4705 u_int32_t destination;
4706
4707 destination = ntohl (rn->p.u.prefix4.s_addr);
4708 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
4709 continue;
4710 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
4711 continue;
4712 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
4713 continue;
4714 }
4715 if (type == bgp_show_type_prefix_longer
4716 || type == bgp_show_type_flap_prefix_longer)
4717 {
4718 struct prefix *p = vty->output_arg;
4719
4720 if (! prefix_match (p, &rn->p))
4721 continue;
4722 }
4723 if (type == bgp_show_type_community_all)
4724 {
4725 if (! ri->attr->community)
4726 continue;
4727 }
4728 if (type == bgp_show_type_community)
4729 {
4730 struct community *com = vty->output_arg;
4731
4732 if (! ri->attr->community ||
4733 ! community_match (ri->attr->community, com))
4734 continue;
4735 }
4736 if (type == bgp_show_type_community_exact)
4737 {
4738 struct community *com = vty->output_arg;
4739
4740 if (! ri->attr->community ||
4741 ! community_cmp (ri->attr->community, com))
4742 continue;
4743 }
4744 if (type == bgp_show_type_community_list)
4745 {
4746 struct community_list *list = vty->output_arg;
4747
4748 if (! community_list_match (ri->attr->community, list))
4749 continue;
4750 }
4751 if (type == bgp_show_type_community_list_exact)
4752 {
4753 struct community_list *list = vty->output_arg;
4754
4755 if (! community_list_exact_match (ri->attr->community, list))
4756 continue;
4757 }
4758 if (type == bgp_show_type_flap_address
4759 || type == bgp_show_type_flap_prefix)
4760 {
4761 struct prefix *p = vty->output_arg;
4762
4763 if (! prefix_match (&rn->p, p))
4764 continue;
4765
4766 if (type == bgp_show_type_flap_prefix)
4767 if (p->prefixlen != rn->p.prefixlen)
4768 continue;
4769 }
4770 if (type == bgp_show_type_dampend_paths
4771 || type == bgp_show_type_damp_neighbor)
4772 {
4773 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
4774 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
4775 continue;
4776 }
4777
4778 if (header)
4779 {
4780 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
4781 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
4782 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
4783 if (type == bgp_show_type_dampend_paths
4784 || type == bgp_show_type_damp_neighbor)
4785 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
4786 else if (type == bgp_show_type_flap_statistics
4787 || type == bgp_show_type_flap_address
4788 || type == bgp_show_type_flap_prefix
4789 || type == bgp_show_type_flap_cidr_only
4790 || type == bgp_show_type_flap_regexp
4791 || type == bgp_show_type_flap_filter_list
4792 || type == bgp_show_type_flap_prefix_list
4793 || type == bgp_show_type_flap_prefix_longer
4794 || type == bgp_show_type_flap_route_map
4795 || type == bgp_show_type_flap_neighbor)
4796 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
4797 else
4798 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
4799 count += 5;
4800 header = 0;
4801 }
4802
4803 if (type == bgp_show_type_dampend_paths
4804 || type == bgp_show_type_damp_neighbor)
4805 count += damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4806 else if (type == bgp_show_type_flap_statistics
4807 || type == bgp_show_type_flap_address
4808 || type == bgp_show_type_flap_prefix
4809 || type == bgp_show_type_flap_cidr_only
4810 || type == bgp_show_type_flap_regexp
4811 || type == bgp_show_type_flap_filter_list
4812 || type == bgp_show_type_flap_prefix_list
4813 || type == bgp_show_type_flap_prefix_longer
4814 || type == bgp_show_type_flap_route_map
4815 || type == bgp_show_type_flap_neighbor)
4816 count += flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4817 else
4818 count += route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
4819 display++;
4820 }
4821 if (display)
4822 vty->output_count++;
4823
4824 /* Remember current pointer then suspend output. */
4825 if (count >= limit && vty->type != VTY_SHELL_SERV)
4826 {
4827 vty->status = VTY_START;
paul5228ad22004-06-04 17:58:18 +00004828 vty->output_rn = (struct route_node *) bgp_route_next (rn);
paul718e3742002-12-13 20:15:29 +00004829 vty->output_func = bgp_show_callback;
4830 vty->output_type = type;
4831
4832 return CMD_SUCCESS;
4833 }
4834 }
4835
4836 /* No route is displayed */
4837 if (vty->output_count == 0)
4838 {
4839 if (type == bgp_show_type_normal)
4840 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
4841 }
4842 else
4843 vty_out (vty, "%sTotal number of prefixes %ld%s",
4844 VTY_NEWLINE, vty->output_count, VTY_NEWLINE);
4845
4846 /* Clean up allocated resources. */
4847 if (vty->output_clean)
4848 (*vty->output_clean) (vty);
4849
4850 vty->status = VTY_START;
4851 vty->output_rn = NULL;
4852 vty->output_func = NULL;
4853 vty->output_clean = NULL;
4854 vty->output_arg = NULL;
4855
4856 return CMD_SUCCESS;
4857}
4858
4859/* Header of detailed BGP route information */
4860void
4861route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
4862 struct bgp_node *rn,
4863 struct prefix_rd *prd, afi_t afi, safi_t safi)
4864{
4865 struct bgp_info *ri;
4866 struct prefix *p;
4867 struct peer *peer;
4868 struct listnode *nn;
4869 char buf1[INET6_ADDRSTRLEN];
4870 char buf2[INET6_ADDRSTRLEN];
4871 int count = 0;
4872 int best = 0;
4873 int suppress = 0;
4874 int no_export = 0;
4875 int no_advertise = 0;
4876 int local_as = 0;
4877 int first = 0;
4878
4879 p = &rn->p;
4880 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
4881 (safi == SAFI_MPLS_VPN ?
4882 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
4883 safi == SAFI_MPLS_VPN ? ":" : "",
4884 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
4885 p->prefixlen, VTY_NEWLINE);
4886
4887 for (ri = rn->info; ri; ri = ri->next)
4888 {
4889 count++;
4890 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
4891 {
4892 best = count;
4893 if (ri->suppress)
4894 suppress = 1;
4895 if (ri->attr->community != NULL)
4896 {
4897 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
4898 no_advertise = 1;
4899 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
4900 no_export = 1;
4901 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
4902 local_as = 1;
4903 }
4904 }
4905 }
4906
4907 vty_out (vty, "Paths: (%d available", count);
4908 if (best)
4909 {
4910 vty_out (vty, ", best #%d", best);
4911 if (safi == SAFI_UNICAST)
4912 vty_out (vty, ", table Default-IP-Routing-Table");
4913 }
4914 else
4915 vty_out (vty, ", no best path");
4916 if (no_advertise)
4917 vty_out (vty, ", not advertised to any peer");
4918 else if (no_export)
4919 vty_out (vty, ", not advertised to EBGP peer");
4920 else if (local_as)
4921 vty_out (vty, ", not advertised outside local AS");
4922 if (suppress)
4923 vty_out (vty, ", Advertisements suppressed by an aggregate.");
4924 vty_out (vty, ")%s", VTY_NEWLINE);
4925
4926 /* advertised peer */
4927 LIST_LOOP (bgp->peer, peer, nn)
4928 {
4929 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
4930 {
4931 if (! first)
4932 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
4933 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
4934 first = 1;
4935 }
4936 }
4937 if (! first)
4938 vty_out (vty, " Not advertised to any peer");
4939 vty_out (vty, "%s", VTY_NEWLINE);
4940}
4941
4942/* Display specified route of BGP table. */
4943int
4944bgp_show_route (struct vty *vty, char *view_name, char *ip_str,
4945 afi_t afi, safi_t safi, struct prefix_rd *prd,
4946 int prefix_check)
4947{
4948 int ret;
4949 int header;
4950 int display = 0;
4951 struct prefix match;
4952 struct bgp_node *rn;
4953 struct bgp_node *rm;
4954 struct bgp_info *ri;
4955 struct bgp *bgp;
4956 struct bgp_table *table;
4957
4958 /* BGP structure lookup. */
4959 if (view_name)
4960 {
4961 bgp = bgp_lookup_by_name (view_name);
4962 if (bgp == NULL)
4963 {
4964 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
4965 return CMD_WARNING;
4966 }
4967 }
4968 else
4969 {
4970 bgp = bgp_get_default ();
4971 if (bgp == NULL)
4972 {
4973 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
4974 return CMD_WARNING;
4975 }
4976 }
4977
4978 /* Check IP address argument. */
4979 ret = str2prefix (ip_str, &match);
4980 if (! ret)
4981 {
4982 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
4983 return CMD_WARNING;
4984 }
4985
4986 match.family = afi2family (afi);
4987
4988 if (safi == SAFI_MPLS_VPN)
4989 {
4990 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
4991 {
4992 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
4993 continue;
4994
4995 if ((table = rn->info) != NULL)
4996 {
4997 header = 1;
4998
4999 if ((rm = bgp_node_match (table, &match)) != NULL)
5000 {
5001 if (prefix_check && rm->p.prefixlen != match.prefixlen)
5002 continue;
5003
5004 for (ri = rm->info; ri; ri = ri->next)
5005 {
5006 if (header)
5007 {
5008 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
5009 AFI_IP, SAFI_MPLS_VPN);
5010
5011 header = 0;
5012 }
5013 display++;
5014 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
5015 }
5016 }
5017 }
5018 }
5019 }
5020 else
5021 {
5022 header = 1;
5023
5024 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
5025 {
5026 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
5027 {
5028 for (ri = rn->info; ri; ri = ri->next)
5029 {
5030 if (header)
5031 {
5032 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
5033 header = 0;
5034 }
5035 display++;
5036 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
5037 }
5038 }
5039 }
5040 }
5041
5042 if (! display)
5043 {
5044 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
5045 return CMD_WARNING;
5046 }
5047
5048 return CMD_SUCCESS;
5049}
5050
5051/* BGP route print out function. */
5052DEFUN (show_ip_bgp,
5053 show_ip_bgp_cmd,
5054 "show ip bgp",
5055 SHOW_STR
5056 IP_STR
5057 BGP_STR)
5058{
5059 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal);
5060}
5061
5062DEFUN (show_ip_bgp_ipv4,
5063 show_ip_bgp_ipv4_cmd,
5064 "show ip bgp ipv4 (unicast|multicast)",
5065 SHOW_STR
5066 IP_STR
5067 BGP_STR
5068 "Address family\n"
5069 "Address Family modifier\n"
5070 "Address Family modifier\n")
5071{
5072 if (strncmp (argv[0], "m", 1) == 0)
5073 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal);
5074
5075 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal);
5076}
5077
5078DEFUN (show_ip_bgp_route,
5079 show_ip_bgp_route_cmd,
5080 "show ip bgp A.B.C.D",
5081 SHOW_STR
5082 IP_STR
5083 BGP_STR
5084 "Network in the BGP routing table to display\n")
5085{
5086 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
5087}
5088
5089DEFUN (show_ip_bgp_ipv4_route,
5090 show_ip_bgp_ipv4_route_cmd,
5091 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
5092 SHOW_STR
5093 IP_STR
5094 BGP_STR
5095 "Address family\n"
5096 "Address Family modifier\n"
5097 "Address Family modifier\n"
5098 "Network in the BGP routing table to display\n")
5099{
5100 if (strncmp (argv[0], "m", 1) == 0)
5101 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
5102
5103 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
5104}
5105
5106DEFUN (show_ip_bgp_vpnv4_all_route,
5107 show_ip_bgp_vpnv4_all_route_cmd,
5108 "show ip bgp vpnv4 all A.B.C.D",
5109 SHOW_STR
5110 IP_STR
5111 BGP_STR
5112 "Display VPNv4 NLRI specific information\n"
5113 "Display information about all VPNv4 NLRIs\n"
5114 "Network in the BGP routing table to display\n")
5115{
5116 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
5117}
5118
5119DEFUN (show_ip_bgp_vpnv4_rd_route,
5120 show_ip_bgp_vpnv4_rd_route_cmd,
5121 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
5122 SHOW_STR
5123 IP_STR
5124 BGP_STR
5125 "Display VPNv4 NLRI specific information\n"
5126 "Display information for a route distinguisher\n"
5127 "VPN Route Distinguisher\n"
5128 "Network in the BGP routing table to display\n")
5129{
5130 int ret;
5131 struct prefix_rd prd;
5132
5133 ret = str2prefix_rd (argv[0], &prd);
5134 if (! ret)
5135 {
5136 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
5137 return CMD_WARNING;
5138 }
5139 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
5140}
5141
5142DEFUN (show_ip_bgp_prefix,
5143 show_ip_bgp_prefix_cmd,
5144 "show ip bgp A.B.C.D/M",
5145 SHOW_STR
5146 IP_STR
5147 BGP_STR
5148 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5149{
5150 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
5151}
5152
5153DEFUN (show_ip_bgp_ipv4_prefix,
5154 show_ip_bgp_ipv4_prefix_cmd,
5155 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
5156 SHOW_STR
5157 IP_STR
5158 BGP_STR
5159 "Address family\n"
5160 "Address Family modifier\n"
5161 "Address Family modifier\n"
5162 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5163{
5164 if (strncmp (argv[0], "m", 1) == 0)
5165 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
5166
5167 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
5168}
5169
5170DEFUN (show_ip_bgp_vpnv4_all_prefix,
5171 show_ip_bgp_vpnv4_all_prefix_cmd,
5172 "show ip bgp vpnv4 all A.B.C.D/M",
5173 SHOW_STR
5174 IP_STR
5175 BGP_STR
5176 "Display VPNv4 NLRI specific information\n"
5177 "Display information about all VPNv4 NLRIs\n"
5178 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5179{
5180 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
5181}
5182
5183DEFUN (show_ip_bgp_vpnv4_rd_prefix,
5184 show_ip_bgp_vpnv4_rd_prefix_cmd,
5185 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
5186 SHOW_STR
5187 IP_STR
5188 BGP_STR
5189 "Display VPNv4 NLRI specific information\n"
5190 "Display information for a route distinguisher\n"
5191 "VPN Route Distinguisher\n"
5192 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5193{
5194 int ret;
5195 struct prefix_rd prd;
5196
5197 ret = str2prefix_rd (argv[0], &prd);
5198 if (! ret)
5199 {
5200 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
5201 return CMD_WARNING;
5202 }
5203 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
5204}
5205
5206DEFUN (show_ip_bgp_view,
5207 show_ip_bgp_view_cmd,
5208 "show ip bgp view WORD",
5209 SHOW_STR
5210 IP_STR
5211 BGP_STR
5212 "BGP view\n"
5213 "BGP view name\n")
5214{
paulbb46e942003-10-24 19:02:03 +00005215 struct bgp *bgp;
5216
5217 /* BGP structure lookup. */
5218 bgp = bgp_lookup_by_name (argv[0]);
5219 if (bgp == NULL)
5220 {
5221 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
5222 return CMD_WARNING;
5223 }
5224
5225 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal);
paul718e3742002-12-13 20:15:29 +00005226}
5227
5228DEFUN (show_ip_bgp_view_route,
5229 show_ip_bgp_view_route_cmd,
5230 "show ip bgp view WORD A.B.C.D",
5231 SHOW_STR
5232 IP_STR
5233 BGP_STR
5234 "BGP view\n"
5235 "BGP view name\n"
5236 "Network in the BGP routing table to display\n")
5237{
5238 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
5239}
5240
5241DEFUN (show_ip_bgp_view_prefix,
5242 show_ip_bgp_view_prefix_cmd,
5243 "show ip bgp view WORD A.B.C.D/M",
5244 SHOW_STR
5245 IP_STR
5246 BGP_STR
5247 "BGP view\n"
5248 "BGP view name\n"
5249 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
5250{
5251 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
5252}
5253
5254#ifdef HAVE_IPV6
5255DEFUN (show_bgp,
5256 show_bgp_cmd,
5257 "show bgp",
5258 SHOW_STR
5259 BGP_STR)
5260{
5261 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal);
5262}
5263
5264ALIAS (show_bgp,
5265 show_bgp_ipv6_cmd,
5266 "show bgp ipv6",
5267 SHOW_STR
5268 BGP_STR
5269 "Address family\n")
5270
5271/* old command */
5272DEFUN (show_ipv6_bgp,
5273 show_ipv6_bgp_cmd,
5274 "show ipv6 bgp",
5275 SHOW_STR
5276 IP_STR
5277 BGP_STR)
5278{
5279 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal);
5280}
5281
5282DEFUN (show_bgp_route,
5283 show_bgp_route_cmd,
5284 "show bgp X:X::X:X",
5285 SHOW_STR
5286 BGP_STR
5287 "Network in the BGP routing table to display\n")
5288{
5289 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
5290}
5291
5292ALIAS (show_bgp_route,
5293 show_bgp_ipv6_route_cmd,
5294 "show bgp ipv6 X:X::X:X",
5295 SHOW_STR
5296 BGP_STR
5297 "Address family\n"
5298 "Network in the BGP routing table to display\n")
5299
5300/* old command */
5301DEFUN (show_ipv6_bgp_route,
5302 show_ipv6_bgp_route_cmd,
5303 "show ipv6 bgp X:X::X:X",
5304 SHOW_STR
5305 IP_STR
5306 BGP_STR
5307 "Network in the BGP routing table to display\n")
5308{
5309 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
5310}
5311
5312DEFUN (show_bgp_prefix,
5313 show_bgp_prefix_cmd,
5314 "show bgp X:X::X:X/M",
5315 SHOW_STR
5316 BGP_STR
5317 "IPv6 prefix <network>/<length>\n")
5318{
5319 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
5320}
5321
5322ALIAS (show_bgp_prefix,
5323 show_bgp_ipv6_prefix_cmd,
5324 "show bgp ipv6 X:X::X:X/M",
5325 SHOW_STR
5326 BGP_STR
5327 "Address family\n"
5328 "IPv6 prefix <network>/<length>\n")
5329
5330/* old command */
5331DEFUN (show_ipv6_bgp_prefix,
5332 show_ipv6_bgp_prefix_cmd,
5333 "show ipv6 bgp X:X::X:X/M",
5334 SHOW_STR
5335 IP_STR
5336 BGP_STR
5337 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5338{
5339 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
5340}
5341
paulbb46e942003-10-24 19:02:03 +00005342DEFUN (show_bgp_view,
5343 show_bgp_view_cmd,
5344 "show bgp view WORD",
5345 SHOW_STR
5346 BGP_STR
5347 "BGP view\n"
5348 "View name\n")
5349{
5350 struct bgp *bgp;
5351
5352 /* BGP structure lookup. */
5353 bgp = bgp_lookup_by_name (argv[0]);
5354 if (bgp == NULL)
5355 {
5356 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
5357 return CMD_WARNING;
5358 }
5359
5360 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal);
5361}
5362
5363ALIAS (show_bgp_view,
5364 show_bgp_view_ipv6_cmd,
5365 "show bgp view WORD ipv6",
5366 SHOW_STR
5367 BGP_STR
5368 "BGP view\n"
5369 "View name\n"
5370 "Address family\n")
5371
5372DEFUN (show_bgp_view_route,
5373 show_bgp_view_route_cmd,
5374 "show bgp view WORD X:X::X:X",
5375 SHOW_STR
5376 BGP_STR
5377 "BGP view\n"
5378 "View name\n"
5379 "Network in the BGP routing table to display\n")
5380{
5381 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
5382}
5383
5384ALIAS (show_bgp_view_route,
5385 show_bgp_view_ipv6_route_cmd,
5386 "show bgp view WORD ipv6 X:X::X:X",
5387 SHOW_STR
5388 BGP_STR
5389 "BGP view\n"
5390 "View name\n"
5391 "Address family\n"
5392 "Network in the BGP routing table to display\n")
5393
5394DEFUN (show_bgp_view_prefix,
5395 show_bgp_view_prefix_cmd,
5396 "show bgp view WORD X:X::X:X/M",
5397 SHOW_STR
5398 BGP_STR
5399 "BGP view\n"
5400 "View name\n"
5401 "IPv6 prefix <network>/<length>\n")
5402{
5403 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
5404}
5405
5406ALIAS (show_bgp_view_prefix,
5407 show_bgp_view_ipv6_prefix_cmd,
5408 "show bgp view WORD ipv6 X:X::X:X/M",
5409 SHOW_STR
5410 BGP_STR
5411 "BGP view\n"
5412 "View name\n"
5413 "Address family\n"
5414 "IPv6 prefix <network>/<length>\n")
5415
paul718e3742002-12-13 20:15:29 +00005416/* old command */
5417DEFUN (show_ipv6_mbgp,
5418 show_ipv6_mbgp_cmd,
5419 "show ipv6 mbgp",
5420 SHOW_STR
5421 IP_STR
5422 MBGP_STR)
5423{
5424 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal);
5425}
5426
5427/* old command */
5428DEFUN (show_ipv6_mbgp_route,
5429 show_ipv6_mbgp_route_cmd,
5430 "show ipv6 mbgp X:X::X:X",
5431 SHOW_STR
5432 IP_STR
5433 MBGP_STR
5434 "Network in the MBGP routing table to display\n")
5435{
5436 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
5437}
5438
5439/* old command */
5440DEFUN (show_ipv6_mbgp_prefix,
5441 show_ipv6_mbgp_prefix_cmd,
5442 "show ipv6 mbgp X:X::X:X/M",
5443 SHOW_STR
5444 IP_STR
5445 MBGP_STR
5446 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
5447{
5448 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
5449}
5450#endif
5451
5452void
5453bgp_show_regexp_clean (struct vty *vty)
5454{
5455 bgp_regex_free (vty->output_arg);
5456}
5457
5458int
5459bgp_show_regexp (struct vty *vty, int argc, char **argv, afi_t afi,
5460 safi_t safi, enum bgp_show_type type)
5461{
5462 int i;
5463 struct buffer *b;
5464 char *regstr;
5465 int first;
5466 regex_t *regex;
5467
5468 first = 0;
5469 b = buffer_new (1024);
5470 for (i = 0; i < argc; i++)
5471 {
5472 if (first)
5473 buffer_putc (b, ' ');
5474 else
5475 {
5476 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
5477 continue;
5478 first = 1;
5479 }
5480
5481 buffer_putstr (b, argv[i]);
5482 }
5483 buffer_putc (b, '\0');
5484
5485 regstr = buffer_getstr (b);
5486 buffer_free (b);
5487
5488 regex = bgp_regcomp (regstr);
5489 if (! regex)
5490 {
5491 vty_out (vty, "Can't compile regexp %s%s", argv[0],
5492 VTY_NEWLINE);
5493 return CMD_WARNING;
5494 }
5495
5496 vty->output_arg = regex;
5497 vty->output_clean = bgp_show_regexp_clean;
5498
5499 return bgp_show (vty, NULL, afi, safi, type);
5500}
5501
5502DEFUN (show_ip_bgp_regexp,
5503 show_ip_bgp_regexp_cmd,
5504 "show ip bgp regexp .LINE",
5505 SHOW_STR
5506 IP_STR
5507 BGP_STR
5508 "Display routes matching the AS path regular expression\n"
5509 "A regular-expression to match the BGP AS paths\n")
5510{
5511 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
5512 bgp_show_type_regexp);
5513}
5514
5515DEFUN (show_ip_bgp_flap_regexp,
5516 show_ip_bgp_flap_regexp_cmd,
5517 "show ip bgp flap-statistics regexp .LINE",
5518 SHOW_STR
5519 IP_STR
5520 BGP_STR
5521 "Display flap statistics of routes\n"
5522 "Display routes matching the AS path regular expression\n"
5523 "A regular-expression to match the BGP AS paths\n")
5524{
5525 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
5526 bgp_show_type_flap_regexp);
5527}
5528
5529DEFUN (show_ip_bgp_ipv4_regexp,
5530 show_ip_bgp_ipv4_regexp_cmd,
5531 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
5532 SHOW_STR
5533 IP_STR
5534 BGP_STR
5535 "Address family\n"
5536 "Address Family modifier\n"
5537 "Address Family modifier\n"
5538 "Display routes matching the AS path regular expression\n"
5539 "A regular-expression to match the BGP AS paths\n")
5540{
5541 if (strncmp (argv[0], "m", 1) == 0)
5542 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
5543 bgp_show_type_regexp);
5544
5545 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
5546 bgp_show_type_regexp);
5547}
5548
5549#ifdef HAVE_IPV6
5550DEFUN (show_bgp_regexp,
5551 show_bgp_regexp_cmd,
5552 "show bgp regexp .LINE",
5553 SHOW_STR
5554 BGP_STR
5555 "Display routes matching the AS path regular expression\n"
5556 "A regular-expression to match the BGP AS paths\n")
5557{
5558 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
5559 bgp_show_type_regexp);
5560}
5561
5562ALIAS (show_bgp_regexp,
5563 show_bgp_ipv6_regexp_cmd,
5564 "show bgp ipv6 regexp .LINE",
5565 SHOW_STR
5566 BGP_STR
5567 "Address family\n"
5568 "Display routes matching the AS path regular expression\n"
5569 "A regular-expression to match the BGP AS paths\n")
5570
5571/* old command */
5572DEFUN (show_ipv6_bgp_regexp,
5573 show_ipv6_bgp_regexp_cmd,
5574 "show ipv6 bgp regexp .LINE",
5575 SHOW_STR
5576 IP_STR
5577 BGP_STR
5578 "Display routes matching the AS path regular expression\n"
5579 "A regular-expression to match the BGP AS paths\n")
5580{
5581 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
5582 bgp_show_type_regexp);
5583}
5584
5585/* old command */
5586DEFUN (show_ipv6_mbgp_regexp,
5587 show_ipv6_mbgp_regexp_cmd,
5588 "show ipv6 mbgp regexp .LINE",
5589 SHOW_STR
5590 IP_STR
5591 BGP_STR
5592 "Display routes matching the AS path regular expression\n"
5593 "A regular-expression to match the MBGP AS paths\n")
5594{
5595 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
5596 bgp_show_type_regexp);
5597}
5598#endif /* HAVE_IPV6 */
5599
5600int
5601bgp_show_prefix_list (struct vty *vty, char *prefix_list_str, afi_t afi,
5602 safi_t safi, enum bgp_show_type type)
5603{
5604 struct prefix_list *plist;
5605
5606 plist = prefix_list_lookup (afi, prefix_list_str);
5607 if (plist == NULL)
5608 {
5609 vty_out (vty, "%% %s is not a valid prefix-list name%s",
5610 prefix_list_str, VTY_NEWLINE);
5611 return CMD_WARNING;
5612 }
5613
5614 vty->output_arg = plist;
5615
5616 return bgp_show (vty, NULL, afi, safi, type);
5617}
5618
5619DEFUN (show_ip_bgp_prefix_list,
5620 show_ip_bgp_prefix_list_cmd,
5621 "show ip bgp prefix-list WORD",
5622 SHOW_STR
5623 IP_STR
5624 BGP_STR
5625 "Display routes conforming to the prefix-list\n"
5626 "IP prefix-list name\n")
5627{
5628 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
5629 bgp_show_type_prefix_list);
5630}
5631
5632DEFUN (show_ip_bgp_flap_prefix_list,
5633 show_ip_bgp_flap_prefix_list_cmd,
5634 "show ip bgp flap-statistics prefix-list WORD",
5635 SHOW_STR
5636 IP_STR
5637 BGP_STR
5638 "Display flap statistics of routes\n"
5639 "Display routes conforming to the prefix-list\n"
5640 "IP prefix-list name\n")
5641{
5642 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
5643 bgp_show_type_flap_prefix_list);
5644}
5645
5646DEFUN (show_ip_bgp_ipv4_prefix_list,
5647 show_ip_bgp_ipv4_prefix_list_cmd,
5648 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
5649 SHOW_STR
5650 IP_STR
5651 BGP_STR
5652 "Address family\n"
5653 "Address Family modifier\n"
5654 "Address Family modifier\n"
5655 "Display routes conforming to the prefix-list\n"
5656 "IP prefix-list name\n")
5657{
5658 if (strncmp (argv[0], "m", 1) == 0)
5659 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
5660 bgp_show_type_prefix_list);
5661
5662 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
5663 bgp_show_type_prefix_list);
5664}
5665
5666#ifdef HAVE_IPV6
5667DEFUN (show_bgp_prefix_list,
5668 show_bgp_prefix_list_cmd,
5669 "show bgp prefix-list WORD",
5670 SHOW_STR
5671 BGP_STR
5672 "Display routes conforming to the prefix-list\n"
5673 "IPv6 prefix-list name\n")
5674{
5675 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5676 bgp_show_type_prefix_list);
5677}
5678
5679ALIAS (show_bgp_prefix_list,
5680 show_bgp_ipv6_prefix_list_cmd,
5681 "show bgp ipv6 prefix-list WORD",
5682 SHOW_STR
5683 BGP_STR
5684 "Address family\n"
5685 "Display routes conforming to the prefix-list\n"
5686 "IPv6 prefix-list name\n")
5687
5688/* old command */
5689DEFUN (show_ipv6_bgp_prefix_list,
5690 show_ipv6_bgp_prefix_list_cmd,
5691 "show ipv6 bgp prefix-list WORD",
5692 SHOW_STR
5693 IPV6_STR
5694 BGP_STR
5695 "Display routes matching the prefix-list\n"
5696 "IPv6 prefix-list name\n")
5697{
5698 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5699 bgp_show_type_prefix_list);
5700}
5701
5702/* old command */
5703DEFUN (show_ipv6_mbgp_prefix_list,
5704 show_ipv6_mbgp_prefix_list_cmd,
5705 "show ipv6 mbgp prefix-list WORD",
5706 SHOW_STR
5707 IPV6_STR
5708 MBGP_STR
5709 "Display routes matching the prefix-list\n"
5710 "IPv6 prefix-list name\n")
5711{
5712 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
5713 bgp_show_type_prefix_list);
5714}
5715#endif /* HAVE_IPV6 */
5716
5717int
5718bgp_show_filter_list (struct vty *vty, char *filter, afi_t afi,
5719 safi_t safi, enum bgp_show_type type)
5720{
5721 struct as_list *as_list;
5722
5723 as_list = as_list_lookup (filter);
5724 if (as_list == NULL)
5725 {
5726 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
5727 return CMD_WARNING;
5728 }
5729
5730 vty->output_arg = as_list;
5731
5732 return bgp_show (vty, NULL, afi, safi, type);
5733}
5734
5735DEFUN (show_ip_bgp_filter_list,
5736 show_ip_bgp_filter_list_cmd,
5737 "show ip bgp filter-list WORD",
5738 SHOW_STR
5739 IP_STR
5740 BGP_STR
5741 "Display routes conforming to the filter-list\n"
5742 "Regular expression access list name\n")
5743{
5744 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
5745 bgp_show_type_filter_list);
5746}
5747
5748DEFUN (show_ip_bgp_flap_filter_list,
5749 show_ip_bgp_flap_filter_list_cmd,
5750 "show ip bgp flap-statistics filter-list WORD",
5751 SHOW_STR
5752 IP_STR
5753 BGP_STR
5754 "Display flap statistics of routes\n"
5755 "Display routes conforming to the filter-list\n"
5756 "Regular expression access list name\n")
5757{
5758 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
5759 bgp_show_type_flap_filter_list);
5760}
5761
5762DEFUN (show_ip_bgp_ipv4_filter_list,
5763 show_ip_bgp_ipv4_filter_list_cmd,
5764 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
5765 SHOW_STR
5766 IP_STR
5767 BGP_STR
5768 "Address family\n"
5769 "Address Family modifier\n"
5770 "Address Family modifier\n"
5771 "Display routes conforming to the filter-list\n"
5772 "Regular expression access list name\n")
5773{
5774 if (strncmp (argv[0], "m", 1) == 0)
5775 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
5776 bgp_show_type_filter_list);
5777
5778 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
5779 bgp_show_type_filter_list);
5780}
5781
5782#ifdef HAVE_IPV6
5783DEFUN (show_bgp_filter_list,
5784 show_bgp_filter_list_cmd,
5785 "show bgp filter-list WORD",
5786 SHOW_STR
5787 BGP_STR
5788 "Display routes conforming to the filter-list\n"
5789 "Regular expression access list name\n")
5790{
5791 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5792 bgp_show_type_filter_list);
5793}
5794
5795ALIAS (show_bgp_filter_list,
5796 show_bgp_ipv6_filter_list_cmd,
5797 "show bgp ipv6 filter-list WORD",
5798 SHOW_STR
5799 BGP_STR
5800 "Address family\n"
5801 "Display routes conforming to the filter-list\n"
5802 "Regular expression access list name\n")
5803
5804/* old command */
5805DEFUN (show_ipv6_bgp_filter_list,
5806 show_ipv6_bgp_filter_list_cmd,
5807 "show ipv6 bgp filter-list WORD",
5808 SHOW_STR
5809 IPV6_STR
5810 BGP_STR
5811 "Display routes conforming to the filter-list\n"
5812 "Regular expression access list name\n")
5813{
5814 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5815 bgp_show_type_filter_list);
5816}
5817
5818/* old command */
5819DEFUN (show_ipv6_mbgp_filter_list,
5820 show_ipv6_mbgp_filter_list_cmd,
5821 "show ipv6 mbgp filter-list WORD",
5822 SHOW_STR
5823 IPV6_STR
5824 MBGP_STR
5825 "Display routes conforming to the filter-list\n"
5826 "Regular expression access list name\n")
5827{
5828 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
5829 bgp_show_type_filter_list);
5830}
5831#endif /* HAVE_IPV6 */
5832
5833int
5834bgp_show_route_map (struct vty *vty, char *rmap_str, afi_t afi,
5835 safi_t safi, enum bgp_show_type type)
5836{
5837 struct route_map *rmap;
5838
5839 rmap = route_map_lookup_by_name (rmap_str);
5840 if (! rmap)
5841 {
5842 vty_out (vty, "%% %s is not a valid route-map name%s",
5843 rmap_str, VTY_NEWLINE);
5844 return CMD_WARNING;
5845 }
5846
5847 vty->output_arg = rmap;
5848
5849 return bgp_show (vty, NULL, afi, safi, type);
5850}
5851
5852DEFUN (show_ip_bgp_route_map,
5853 show_ip_bgp_route_map_cmd,
5854 "show ip bgp route-map WORD",
5855 SHOW_STR
5856 IP_STR
5857 BGP_STR
5858 "Display routes matching the route-map\n"
5859 "A route-map to match on\n")
5860{
5861 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
5862 bgp_show_type_route_map);
5863}
5864
5865DEFUN (show_ip_bgp_flap_route_map,
5866 show_ip_bgp_flap_route_map_cmd,
5867 "show ip bgp flap-statistics route-map WORD",
5868 SHOW_STR
5869 IP_STR
5870 BGP_STR
5871 "Display flap statistics of routes\n"
5872 "Display routes matching the route-map\n"
5873 "A route-map to match on\n")
5874{
5875 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
5876 bgp_show_type_flap_route_map);
5877}
5878
5879DEFUN (show_ip_bgp_ipv4_route_map,
5880 show_ip_bgp_ipv4_route_map_cmd,
5881 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
5882 SHOW_STR
5883 IP_STR
5884 BGP_STR
5885 "Address family\n"
5886 "Address Family modifier\n"
5887 "Address Family modifier\n"
5888 "Display routes matching the route-map\n"
5889 "A route-map to match on\n")
5890{
5891 if (strncmp (argv[0], "m", 1) == 0)
5892 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
5893 bgp_show_type_route_map);
5894
5895 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
5896 bgp_show_type_route_map);
5897}
5898
5899DEFUN (show_bgp_route_map,
5900 show_bgp_route_map_cmd,
5901 "show bgp route-map WORD",
5902 SHOW_STR
5903 BGP_STR
5904 "Display routes matching the route-map\n"
5905 "A route-map to match on\n")
5906{
5907 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5908 bgp_show_type_route_map);
5909}
5910
5911ALIAS (show_bgp_route_map,
5912 show_bgp_ipv6_route_map_cmd,
5913 "show bgp ipv6 route-map WORD",
5914 SHOW_STR
5915 BGP_STR
5916 "Address family\n"
5917 "Display routes matching the route-map\n"
5918 "A route-map to match on\n")
5919
5920DEFUN (show_ip_bgp_cidr_only,
5921 show_ip_bgp_cidr_only_cmd,
5922 "show ip bgp cidr-only",
5923 SHOW_STR
5924 IP_STR
5925 BGP_STR
5926 "Display only routes with non-natural netmasks\n")
5927{
5928 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5929 bgp_show_type_cidr_only);
5930}
5931
5932DEFUN (show_ip_bgp_flap_cidr_only,
5933 show_ip_bgp_flap_cidr_only_cmd,
5934 "show ip bgp flap-statistics cidr-only",
5935 SHOW_STR
5936 IP_STR
5937 BGP_STR
5938 "Display flap statistics of routes\n"
5939 "Display only routes with non-natural netmasks\n")
5940{
5941 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5942 bgp_show_type_flap_cidr_only);
5943}
5944
5945DEFUN (show_ip_bgp_ipv4_cidr_only,
5946 show_ip_bgp_ipv4_cidr_only_cmd,
5947 "show ip bgp ipv4 (unicast|multicast) cidr-only",
5948 SHOW_STR
5949 IP_STR
5950 BGP_STR
5951 "Address family\n"
5952 "Address Family modifier\n"
5953 "Address Family modifier\n"
5954 "Display only routes with non-natural netmasks\n")
5955{
5956 if (strncmp (argv[0], "m", 1) == 0)
5957 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
5958 bgp_show_type_cidr_only);
5959
5960 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5961 bgp_show_type_cidr_only);
5962}
5963
5964DEFUN (show_ip_bgp_community_all,
5965 show_ip_bgp_community_all_cmd,
5966 "show ip bgp community",
5967 SHOW_STR
5968 IP_STR
5969 BGP_STR
5970 "Display routes matching the communities\n")
5971{
5972 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5973 bgp_show_type_community_all);
5974}
5975
5976DEFUN (show_ip_bgp_ipv4_community_all,
5977 show_ip_bgp_ipv4_community_all_cmd,
5978 "show ip bgp ipv4 (unicast|multicast) community",
5979 SHOW_STR
5980 IP_STR
5981 BGP_STR
5982 "Address family\n"
5983 "Address Family modifier\n"
5984 "Address Family modifier\n"
5985 "Display routes matching the communities\n")
5986{
5987 if (strncmp (argv[0], "m", 1) == 0)
5988 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
5989 bgp_show_type_community_all);
5990
5991 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
5992 bgp_show_type_community_all);
5993}
5994
5995#ifdef HAVE_IPV6
5996DEFUN (show_bgp_community_all,
5997 show_bgp_community_all_cmd,
5998 "show bgp community",
5999 SHOW_STR
6000 BGP_STR
6001 "Display routes matching the communities\n")
6002{
6003 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
6004 bgp_show_type_community_all);
6005}
6006
6007ALIAS (show_bgp_community_all,
6008 show_bgp_ipv6_community_all_cmd,
6009 "show bgp ipv6 community",
6010 SHOW_STR
6011 BGP_STR
6012 "Address family\n"
6013 "Display routes matching the communities\n")
6014
6015/* old command */
6016DEFUN (show_ipv6_bgp_community_all,
6017 show_ipv6_bgp_community_all_cmd,
6018 "show ipv6 bgp community",
6019 SHOW_STR
6020 IPV6_STR
6021 BGP_STR
6022 "Display routes matching the communities\n")
6023{
6024 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
6025 bgp_show_type_community_all);
6026}
6027
6028/* old command */
6029DEFUN (show_ipv6_mbgp_community_all,
6030 show_ipv6_mbgp_community_all_cmd,
6031 "show ipv6 mbgp community",
6032 SHOW_STR
6033 IPV6_STR
6034 MBGP_STR
6035 "Display routes matching the communities\n")
6036{
6037 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
6038 bgp_show_type_community_all);
6039}
6040#endif /* HAVE_IPV6 */
6041
6042int
6043bgp_show_community (struct vty *vty, int argc, char **argv, int exact,
6044 u_int16_t afi, u_char safi)
6045{
6046 struct community *com;
6047 struct buffer *b;
6048 int i;
6049 char *str;
6050 int first = 0;
6051
6052 b = buffer_new (1024);
6053 for (i = 0; i < argc; i++)
6054 {
6055 if (first)
6056 buffer_putc (b, ' ');
6057 else
6058 {
6059 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6060 continue;
6061 first = 1;
6062 }
6063
6064 buffer_putstr (b, argv[i]);
6065 }
6066 buffer_putc (b, '\0');
6067
6068 str = buffer_getstr (b);
6069 buffer_free (b);
6070
6071 com = community_str2com (str);
6072 free (str);
6073 if (! com)
6074 {
6075 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
6076 return CMD_WARNING;
6077 }
6078
6079 vty->output_arg = com;
6080
6081 if (exact)
6082 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_exact);
6083
6084 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community);
6085}
6086
6087DEFUN (show_ip_bgp_community,
6088 show_ip_bgp_community_cmd,
6089 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
6090 SHOW_STR
6091 IP_STR
6092 BGP_STR
6093 "Display routes matching the communities\n"
6094 "community number\n"
6095 "Do not send outside local AS (well-known community)\n"
6096 "Do not advertise to any peer (well-known community)\n"
6097 "Do not export to next AS (well-known community)\n")
6098{
6099 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
6100}
6101
6102ALIAS (show_ip_bgp_community,
6103 show_ip_bgp_community2_cmd,
6104 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6105 SHOW_STR
6106 IP_STR
6107 BGP_STR
6108 "Display routes matching the communities\n"
6109 "community number\n"
6110 "Do not send outside local AS (well-known community)\n"
6111 "Do not advertise to any peer (well-known community)\n"
6112 "Do not export to next AS (well-known community)\n"
6113 "community number\n"
6114 "Do not send outside local AS (well-known community)\n"
6115 "Do not advertise to any peer (well-known community)\n"
6116 "Do not export to next AS (well-known community)\n")
6117
6118ALIAS (show_ip_bgp_community,
6119 show_ip_bgp_community3_cmd,
6120 "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)",
6121 SHOW_STR
6122 IP_STR
6123 BGP_STR
6124 "Display routes matching the communities\n"
6125 "community number\n"
6126 "Do not send outside local AS (well-known community)\n"
6127 "Do not advertise to any peer (well-known community)\n"
6128 "Do not export to next AS (well-known community)\n"
6129 "community number\n"
6130 "Do not send outside local AS (well-known community)\n"
6131 "Do not advertise to any peer (well-known community)\n"
6132 "Do not export to next AS (well-known community)\n"
6133 "community number\n"
6134 "Do not send outside local AS (well-known community)\n"
6135 "Do not advertise to any peer (well-known community)\n"
6136 "Do not export to next AS (well-known community)\n")
6137
6138ALIAS (show_ip_bgp_community,
6139 show_ip_bgp_community4_cmd,
6140 "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)",
6141 SHOW_STR
6142 IP_STR
6143 BGP_STR
6144 "Display routes matching the communities\n"
6145 "community number\n"
6146 "Do not send outside local AS (well-known community)\n"
6147 "Do not advertise to any peer (well-known community)\n"
6148 "Do not export to next AS (well-known community)\n"
6149 "community number\n"
6150 "Do not send outside local AS (well-known community)\n"
6151 "Do not advertise to any peer (well-known community)\n"
6152 "Do not export to next AS (well-known community)\n"
6153 "community number\n"
6154 "Do not send outside local AS (well-known community)\n"
6155 "Do not advertise to any peer (well-known community)\n"
6156 "Do not export to next AS (well-known community)\n"
6157 "community number\n"
6158 "Do not send outside local AS (well-known community)\n"
6159 "Do not advertise to any peer (well-known community)\n"
6160 "Do not export to next AS (well-known community)\n")
6161
6162DEFUN (show_ip_bgp_ipv4_community,
6163 show_ip_bgp_ipv4_community_cmd,
6164 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
6165 SHOW_STR
6166 IP_STR
6167 BGP_STR
6168 "Address family\n"
6169 "Address Family modifier\n"
6170 "Address Family modifier\n"
6171 "Display routes matching the communities\n"
6172 "community number\n"
6173 "Do not send outside local AS (well-known community)\n"
6174 "Do not advertise to any peer (well-known community)\n"
6175 "Do not export to next AS (well-known community)\n")
6176{
6177 if (strncmp (argv[0], "m", 1) == 0)
6178 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
6179
6180 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
6181}
6182
6183ALIAS (show_ip_bgp_ipv4_community,
6184 show_ip_bgp_ipv4_community2_cmd,
6185 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6186 SHOW_STR
6187 IP_STR
6188 BGP_STR
6189 "Address family\n"
6190 "Address Family modifier\n"
6191 "Address Family modifier\n"
6192 "Display routes matching the communities\n"
6193 "community number\n"
6194 "Do not send outside local AS (well-known community)\n"
6195 "Do not advertise to any peer (well-known community)\n"
6196 "Do not export to next AS (well-known community)\n"
6197 "community number\n"
6198 "Do not send outside local AS (well-known community)\n"
6199 "Do not advertise to any peer (well-known community)\n"
6200 "Do not export to next AS (well-known community)\n")
6201
6202ALIAS (show_ip_bgp_ipv4_community,
6203 show_ip_bgp_ipv4_community3_cmd,
6204 "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)",
6205 SHOW_STR
6206 IP_STR
6207 BGP_STR
6208 "Address family\n"
6209 "Address Family modifier\n"
6210 "Address Family modifier\n"
6211 "Display routes matching the communities\n"
6212 "community number\n"
6213 "Do not send outside local AS (well-known community)\n"
6214 "Do not advertise to any peer (well-known community)\n"
6215 "Do not export to next AS (well-known community)\n"
6216 "community number\n"
6217 "Do not send outside local AS (well-known community)\n"
6218 "Do not advertise to any peer (well-known community)\n"
6219 "Do not export to next AS (well-known community)\n"
6220 "community number\n"
6221 "Do not send outside local AS (well-known community)\n"
6222 "Do not advertise to any peer (well-known community)\n"
6223 "Do not export to next AS (well-known community)\n")
6224
6225ALIAS (show_ip_bgp_ipv4_community,
6226 show_ip_bgp_ipv4_community4_cmd,
6227 "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)",
6228 SHOW_STR
6229 IP_STR
6230 BGP_STR
6231 "Address family\n"
6232 "Address Family modifier\n"
6233 "Address Family modifier\n"
6234 "Display routes matching the communities\n"
6235 "community number\n"
6236 "Do not send outside local AS (well-known community)\n"
6237 "Do not advertise to any peer (well-known community)\n"
6238 "Do not export to next AS (well-known community)\n"
6239 "community number\n"
6240 "Do not send outside local AS (well-known community)\n"
6241 "Do not advertise to any peer (well-known community)\n"
6242 "Do not export to next AS (well-known community)\n"
6243 "community number\n"
6244 "Do not send outside local AS (well-known community)\n"
6245 "Do not advertise to any peer (well-known community)\n"
6246 "Do not export to next AS (well-known community)\n"
6247 "community number\n"
6248 "Do not send outside local AS (well-known community)\n"
6249 "Do not advertise to any peer (well-known community)\n"
6250 "Do not export to next AS (well-known community)\n")
6251
6252DEFUN (show_ip_bgp_community_exact,
6253 show_ip_bgp_community_exact_cmd,
6254 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6255 SHOW_STR
6256 IP_STR
6257 BGP_STR
6258 "Display routes matching the communities\n"
6259 "community number\n"
6260 "Do not send outside local AS (well-known community)\n"
6261 "Do not advertise to any peer (well-known community)\n"
6262 "Do not export to next AS (well-known community)\n"
6263 "Exact match of the communities")
6264{
6265 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
6266}
6267
6268ALIAS (show_ip_bgp_community_exact,
6269 show_ip_bgp_community2_exact_cmd,
6270 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6271 SHOW_STR
6272 IP_STR
6273 BGP_STR
6274 "Display routes matching the communities\n"
6275 "community number\n"
6276 "Do not send outside local AS (well-known community)\n"
6277 "Do not advertise to any peer (well-known community)\n"
6278 "Do not export to next AS (well-known community)\n"
6279 "community number\n"
6280 "Do not send outside local AS (well-known community)\n"
6281 "Do not advertise to any peer (well-known community)\n"
6282 "Do not export to next AS (well-known community)\n"
6283 "Exact match of the communities")
6284
6285ALIAS (show_ip_bgp_community_exact,
6286 show_ip_bgp_community3_exact_cmd,
6287 "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",
6288 SHOW_STR
6289 IP_STR
6290 BGP_STR
6291 "Display routes matching the communities\n"
6292 "community number\n"
6293 "Do not send outside local AS (well-known community)\n"
6294 "Do not advertise to any peer (well-known community)\n"
6295 "Do not export to next AS (well-known community)\n"
6296 "community number\n"
6297 "Do not send outside local AS (well-known community)\n"
6298 "Do not advertise to any peer (well-known community)\n"
6299 "Do not export to next AS (well-known community)\n"
6300 "community number\n"
6301 "Do not send outside local AS (well-known community)\n"
6302 "Do not advertise to any peer (well-known community)\n"
6303 "Do not export to next AS (well-known community)\n"
6304 "Exact match of the communities")
6305
6306ALIAS (show_ip_bgp_community_exact,
6307 show_ip_bgp_community4_exact_cmd,
6308 "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",
6309 SHOW_STR
6310 IP_STR
6311 BGP_STR
6312 "Display routes matching the communities\n"
6313 "community number\n"
6314 "Do not send outside local AS (well-known community)\n"
6315 "Do not advertise to any peer (well-known community)\n"
6316 "Do not export to next AS (well-known community)\n"
6317 "community number\n"
6318 "Do not send outside local AS (well-known community)\n"
6319 "Do not advertise to any peer (well-known community)\n"
6320 "Do not export to next AS (well-known community)\n"
6321 "community number\n"
6322 "Do not send outside local AS (well-known community)\n"
6323 "Do not advertise to any peer (well-known community)\n"
6324 "Do not export to next AS (well-known community)\n"
6325 "community number\n"
6326 "Do not send outside local AS (well-known community)\n"
6327 "Do not advertise to any peer (well-known community)\n"
6328 "Do not export to next AS (well-known community)\n"
6329 "Exact match of the communities")
6330
6331DEFUN (show_ip_bgp_ipv4_community_exact,
6332 show_ip_bgp_ipv4_community_exact_cmd,
6333 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6334 SHOW_STR
6335 IP_STR
6336 BGP_STR
6337 "Address family\n"
6338 "Address Family modifier\n"
6339 "Address Family modifier\n"
6340 "Display routes matching the communities\n"
6341 "community number\n"
6342 "Do not send outside local AS (well-known community)\n"
6343 "Do not advertise to any peer (well-known community)\n"
6344 "Do not export to next AS (well-known community)\n"
6345 "Exact match of the communities")
6346{
6347 if (strncmp (argv[0], "m", 1) == 0)
6348 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
6349
6350 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
6351}
6352
6353ALIAS (show_ip_bgp_ipv4_community_exact,
6354 show_ip_bgp_ipv4_community2_exact_cmd,
6355 "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",
6356 SHOW_STR
6357 IP_STR
6358 BGP_STR
6359 "Address family\n"
6360 "Address Family modifier\n"
6361 "Address Family modifier\n"
6362 "Display routes matching the communities\n"
6363 "community number\n"
6364 "Do not send outside local AS (well-known community)\n"
6365 "Do not advertise to any peer (well-known community)\n"
6366 "Do not export to next AS (well-known community)\n"
6367 "community number\n"
6368 "Do not send outside local AS (well-known community)\n"
6369 "Do not advertise to any peer (well-known community)\n"
6370 "Do not export to next AS (well-known community)\n"
6371 "Exact match of the communities")
6372
6373ALIAS (show_ip_bgp_ipv4_community_exact,
6374 show_ip_bgp_ipv4_community3_exact_cmd,
6375 "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",
6376 SHOW_STR
6377 IP_STR
6378 BGP_STR
6379 "Address family\n"
6380 "Address Family modifier\n"
6381 "Address Family modifier\n"
6382 "Display routes matching the communities\n"
6383 "community number\n"
6384 "Do not send outside local AS (well-known community)\n"
6385 "Do not advertise to any peer (well-known community)\n"
6386 "Do not export to next AS (well-known community)\n"
6387 "community number\n"
6388 "Do not send outside local AS (well-known community)\n"
6389 "Do not advertise to any peer (well-known community)\n"
6390 "Do not export to next AS (well-known community)\n"
6391 "community number\n"
6392 "Do not send outside local AS (well-known community)\n"
6393 "Do not advertise to any peer (well-known community)\n"
6394 "Do not export to next AS (well-known community)\n"
6395 "Exact match of the communities")
6396
6397ALIAS (show_ip_bgp_ipv4_community_exact,
6398 show_ip_bgp_ipv4_community4_exact_cmd,
6399 "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",
6400 SHOW_STR
6401 IP_STR
6402 BGP_STR
6403 "Address family\n"
6404 "Address Family modifier\n"
6405 "Address Family modifier\n"
6406 "Display routes matching the communities\n"
6407 "community number\n"
6408 "Do not send outside local AS (well-known community)\n"
6409 "Do not advertise to any peer (well-known community)\n"
6410 "Do not export to next AS (well-known community)\n"
6411 "community number\n"
6412 "Do not send outside local AS (well-known community)\n"
6413 "Do not advertise to any peer (well-known community)\n"
6414 "Do not export to next AS (well-known community)\n"
6415 "community number\n"
6416 "Do not send outside local AS (well-known community)\n"
6417 "Do not advertise to any peer (well-known community)\n"
6418 "Do not export to next AS (well-known community)\n"
6419 "community number\n"
6420 "Do not send outside local AS (well-known community)\n"
6421 "Do not advertise to any peer (well-known community)\n"
6422 "Do not export to next AS (well-known community)\n"
6423 "Exact match of the communities")
6424
6425#ifdef HAVE_IPV6
6426DEFUN (show_bgp_community,
6427 show_bgp_community_cmd,
6428 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
6429 SHOW_STR
6430 BGP_STR
6431 "Display routes matching the communities\n"
6432 "community number\n"
6433 "Do not send outside local AS (well-known community)\n"
6434 "Do not advertise to any peer (well-known community)\n"
6435 "Do not export to next AS (well-known community)\n")
6436{
6437 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
6438}
6439
6440ALIAS (show_bgp_community,
6441 show_bgp_ipv6_community_cmd,
6442 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
6443 SHOW_STR
6444 BGP_STR
6445 "Address family\n"
6446 "Display routes matching the communities\n"
6447 "community number\n"
6448 "Do not send outside local AS (well-known community)\n"
6449 "Do not advertise to any peer (well-known community)\n"
6450 "Do not export to next AS (well-known community)\n")
6451
6452ALIAS (show_bgp_community,
6453 show_bgp_community2_cmd,
6454 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6455 SHOW_STR
6456 BGP_STR
6457 "Display routes matching the communities\n"
6458 "community number\n"
6459 "Do not send outside local AS (well-known community)\n"
6460 "Do not advertise to any peer (well-known community)\n"
6461 "Do not export to next AS (well-known community)\n"
6462 "community number\n"
6463 "Do not send outside local AS (well-known community)\n"
6464 "Do not advertise to any peer (well-known community)\n"
6465 "Do not export to next AS (well-known community)\n")
6466
6467ALIAS (show_bgp_community,
6468 show_bgp_ipv6_community2_cmd,
6469 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6470 SHOW_STR
6471 BGP_STR
6472 "Address family\n"
6473 "Display routes matching the communities\n"
6474 "community number\n"
6475 "Do not send outside local AS (well-known community)\n"
6476 "Do not advertise to any peer (well-known community)\n"
6477 "Do not export to next AS (well-known community)\n"
6478 "community number\n"
6479 "Do not send outside local AS (well-known community)\n"
6480 "Do not advertise to any peer (well-known community)\n"
6481 "Do not export to next AS (well-known community)\n")
6482
6483ALIAS (show_bgp_community,
6484 show_bgp_community3_cmd,
6485 "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)",
6486 SHOW_STR
6487 BGP_STR
6488 "Display routes matching the communities\n"
6489 "community number\n"
6490 "Do not send outside local AS (well-known community)\n"
6491 "Do not advertise to any peer (well-known community)\n"
6492 "Do not export to next AS (well-known community)\n"
6493 "community number\n"
6494 "Do not send outside local AS (well-known community)\n"
6495 "Do not advertise to any peer (well-known community)\n"
6496 "Do not export to next AS (well-known community)\n"
6497 "community number\n"
6498 "Do not send outside local AS (well-known community)\n"
6499 "Do not advertise to any peer (well-known community)\n"
6500 "Do not export to next AS (well-known community)\n")
6501
6502ALIAS (show_bgp_community,
6503 show_bgp_ipv6_community3_cmd,
6504 "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)",
6505 SHOW_STR
6506 BGP_STR
6507 "Address family\n"
6508 "Display routes matching the communities\n"
6509 "community number\n"
6510 "Do not send outside local AS (well-known community)\n"
6511 "Do not advertise to any peer (well-known community)\n"
6512 "Do not export to next AS (well-known community)\n"
6513 "community number\n"
6514 "Do not send outside local AS (well-known community)\n"
6515 "Do not advertise to any peer (well-known community)\n"
6516 "Do not export to next AS (well-known community)\n"
6517 "community number\n"
6518 "Do not send outside local AS (well-known community)\n"
6519 "Do not advertise to any peer (well-known community)\n"
6520 "Do not export to next AS (well-known community)\n")
6521
6522ALIAS (show_bgp_community,
6523 show_bgp_community4_cmd,
6524 "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)",
6525 SHOW_STR
6526 BGP_STR
6527 "Display routes matching the communities\n"
6528 "community number\n"
6529 "Do not send outside local AS (well-known community)\n"
6530 "Do not advertise to any peer (well-known community)\n"
6531 "Do not export to next AS (well-known community)\n"
6532 "community number\n"
6533 "Do not send outside local AS (well-known community)\n"
6534 "Do not advertise to any peer (well-known community)\n"
6535 "Do not export to next AS (well-known community)\n"
6536 "community number\n"
6537 "Do not send outside local AS (well-known community)\n"
6538 "Do not advertise to any peer (well-known community)\n"
6539 "Do not export to next AS (well-known community)\n"
6540 "community number\n"
6541 "Do not send outside local AS (well-known community)\n"
6542 "Do not advertise to any peer (well-known community)\n"
6543 "Do not export to next AS (well-known community)\n")
6544
6545ALIAS (show_bgp_community,
6546 show_bgp_ipv6_community4_cmd,
6547 "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)",
6548 SHOW_STR
6549 BGP_STR
6550 "Address family\n"
6551 "Display routes matching the communities\n"
6552 "community number\n"
6553 "Do not send outside local AS (well-known community)\n"
6554 "Do not advertise to any peer (well-known community)\n"
6555 "Do not export to next AS (well-known community)\n"
6556 "community number\n"
6557 "Do not send outside local AS (well-known community)\n"
6558 "Do not advertise to any peer (well-known community)\n"
6559 "Do not export to next AS (well-known community)\n"
6560 "community number\n"
6561 "Do not send outside local AS (well-known community)\n"
6562 "Do not advertise to any peer (well-known community)\n"
6563 "Do not export to next AS (well-known community)\n"
6564 "community number\n"
6565 "Do not send outside local AS (well-known community)\n"
6566 "Do not advertise to any peer (well-known community)\n"
6567 "Do not export to next AS (well-known community)\n")
6568
6569/* old command */
6570DEFUN (show_ipv6_bgp_community,
6571 show_ipv6_bgp_community_cmd,
6572 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
6573 SHOW_STR
6574 IPV6_STR
6575 BGP_STR
6576 "Display routes matching the communities\n"
6577 "community number\n"
6578 "Do not send outside local AS (well-known community)\n"
6579 "Do not advertise to any peer (well-known community)\n"
6580 "Do not export to next AS (well-known community)\n")
6581{
6582 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
6583}
6584
6585/* old command */
6586ALIAS (show_ipv6_bgp_community,
6587 show_ipv6_bgp_community2_cmd,
6588 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6589 SHOW_STR
6590 IPV6_STR
6591 BGP_STR
6592 "Display routes matching the communities\n"
6593 "community number\n"
6594 "Do not send outside local AS (well-known community)\n"
6595 "Do not advertise to any peer (well-known community)\n"
6596 "Do not export to next AS (well-known community)\n"
6597 "community number\n"
6598 "Do not send outside local AS (well-known community)\n"
6599 "Do not advertise to any peer (well-known community)\n"
6600 "Do not export to next AS (well-known community)\n")
6601
6602/* old command */
6603ALIAS (show_ipv6_bgp_community,
6604 show_ipv6_bgp_community3_cmd,
6605 "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)",
6606 SHOW_STR
6607 IPV6_STR
6608 BGP_STR
6609 "Display routes matching the communities\n"
6610 "community number\n"
6611 "Do not send outside local AS (well-known community)\n"
6612 "Do not advertise to any peer (well-known community)\n"
6613 "Do not export to next AS (well-known community)\n"
6614 "community number\n"
6615 "Do not send outside local AS (well-known community)\n"
6616 "Do not advertise to any peer (well-known community)\n"
6617 "Do not export to next AS (well-known community)\n"
6618 "community number\n"
6619 "Do not send outside local AS (well-known community)\n"
6620 "Do not advertise to any peer (well-known community)\n"
6621 "Do not export to next AS (well-known community)\n")
6622
6623/* old command */
6624ALIAS (show_ipv6_bgp_community,
6625 show_ipv6_bgp_community4_cmd,
6626 "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)",
6627 SHOW_STR
6628 IPV6_STR
6629 BGP_STR
6630 "Display routes matching the communities\n"
6631 "community number\n"
6632 "Do not send outside local AS (well-known community)\n"
6633 "Do not advertise to any peer (well-known community)\n"
6634 "Do not export to next AS (well-known community)\n"
6635 "community number\n"
6636 "Do not send outside local AS (well-known community)\n"
6637 "Do not advertise to any peer (well-known community)\n"
6638 "Do not export to next AS (well-known community)\n"
6639 "community number\n"
6640 "Do not send outside local AS (well-known community)\n"
6641 "Do not advertise to any peer (well-known community)\n"
6642 "Do not export to next AS (well-known community)\n"
6643 "community number\n"
6644 "Do not send outside local AS (well-known community)\n"
6645 "Do not advertise to any peer (well-known community)\n"
6646 "Do not export to next AS (well-known community)\n")
6647
6648DEFUN (show_bgp_community_exact,
6649 show_bgp_community_exact_cmd,
6650 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6651 SHOW_STR
6652 BGP_STR
6653 "Display routes matching the communities\n"
6654 "community number\n"
6655 "Do not send outside local AS (well-known community)\n"
6656 "Do not advertise to any peer (well-known community)\n"
6657 "Do not export to next AS (well-known community)\n"
6658 "Exact match of the communities")
6659{
6660 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
6661}
6662
6663ALIAS (show_bgp_community_exact,
6664 show_bgp_ipv6_community_exact_cmd,
6665 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6666 SHOW_STR
6667 BGP_STR
6668 "Address family\n"
6669 "Display routes matching the communities\n"
6670 "community number\n"
6671 "Do not send outside local AS (well-known community)\n"
6672 "Do not advertise to any peer (well-known community)\n"
6673 "Do not export to next AS (well-known community)\n"
6674 "Exact match of the communities")
6675
6676ALIAS (show_bgp_community_exact,
6677 show_bgp_community2_exact_cmd,
6678 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6679 SHOW_STR
6680 BGP_STR
6681 "Display routes matching the communities\n"
6682 "community number\n"
6683 "Do not send outside local AS (well-known community)\n"
6684 "Do not advertise to any peer (well-known community)\n"
6685 "Do not export to next AS (well-known community)\n"
6686 "community number\n"
6687 "Do not send outside local AS (well-known community)\n"
6688 "Do not advertise to any peer (well-known community)\n"
6689 "Do not export to next AS (well-known community)\n"
6690 "Exact match of the communities")
6691
6692ALIAS (show_bgp_community_exact,
6693 show_bgp_ipv6_community2_exact_cmd,
6694 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6695 SHOW_STR
6696 BGP_STR
6697 "Address family\n"
6698 "Display routes matching the communities\n"
6699 "community number\n"
6700 "Do not send outside local AS (well-known community)\n"
6701 "Do not advertise to any peer (well-known community)\n"
6702 "Do not export to next AS (well-known community)\n"
6703 "community number\n"
6704 "Do not send outside local AS (well-known community)\n"
6705 "Do not advertise to any peer (well-known community)\n"
6706 "Do not export to next AS (well-known community)\n"
6707 "Exact match of the communities")
6708
6709ALIAS (show_bgp_community_exact,
6710 show_bgp_community3_exact_cmd,
6711 "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",
6712 SHOW_STR
6713 BGP_STR
6714 "Display routes matching the communities\n"
6715 "community number\n"
6716 "Do not send outside local AS (well-known community)\n"
6717 "Do not advertise to any peer (well-known community)\n"
6718 "Do not export to next AS (well-known community)\n"
6719 "community number\n"
6720 "Do not send outside local AS (well-known community)\n"
6721 "Do not advertise to any peer (well-known community)\n"
6722 "Do not export to next AS (well-known community)\n"
6723 "community number\n"
6724 "Do not send outside local AS (well-known community)\n"
6725 "Do not advertise to any peer (well-known community)\n"
6726 "Do not export to next AS (well-known community)\n"
6727 "Exact match of the communities")
6728
6729ALIAS (show_bgp_community_exact,
6730 show_bgp_ipv6_community3_exact_cmd,
6731 "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",
6732 SHOW_STR
6733 BGP_STR
6734 "Address family\n"
6735 "Display routes matching the communities\n"
6736 "community number\n"
6737 "Do not send outside local AS (well-known community)\n"
6738 "Do not advertise to any peer (well-known community)\n"
6739 "Do not export to next AS (well-known community)\n"
6740 "community number\n"
6741 "Do not send outside local AS (well-known community)\n"
6742 "Do not advertise to any peer (well-known community)\n"
6743 "Do not export to next AS (well-known community)\n"
6744 "community number\n"
6745 "Do not send outside local AS (well-known community)\n"
6746 "Do not advertise to any peer (well-known community)\n"
6747 "Do not export to next AS (well-known community)\n"
6748 "Exact match of the communities")
6749
6750ALIAS (show_bgp_community_exact,
6751 show_bgp_community4_exact_cmd,
6752 "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",
6753 SHOW_STR
6754 BGP_STR
6755 "Display routes matching the communities\n"
6756 "community number\n"
6757 "Do not send outside local AS (well-known community)\n"
6758 "Do not advertise to any peer (well-known community)\n"
6759 "Do not export to next AS (well-known community)\n"
6760 "community number\n"
6761 "Do not send outside local AS (well-known community)\n"
6762 "Do not advertise to any peer (well-known community)\n"
6763 "Do not export to next AS (well-known community)\n"
6764 "community number\n"
6765 "Do not send outside local AS (well-known community)\n"
6766 "Do not advertise to any peer (well-known community)\n"
6767 "Do not export to next AS (well-known community)\n"
6768 "community number\n"
6769 "Do not send outside local AS (well-known community)\n"
6770 "Do not advertise to any peer (well-known community)\n"
6771 "Do not export to next AS (well-known community)\n"
6772 "Exact match of the communities")
6773
6774ALIAS (show_bgp_community_exact,
6775 show_bgp_ipv6_community4_exact_cmd,
6776 "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",
6777 SHOW_STR
6778 BGP_STR
6779 "Address family\n"
6780 "Display routes matching the communities\n"
6781 "community number\n"
6782 "Do not send outside local AS (well-known community)\n"
6783 "Do not advertise to any peer (well-known community)\n"
6784 "Do not export to next AS (well-known community)\n"
6785 "community number\n"
6786 "Do not send outside local AS (well-known community)\n"
6787 "Do not advertise to any peer (well-known community)\n"
6788 "Do not export to next AS (well-known community)\n"
6789 "community number\n"
6790 "Do not send outside local AS (well-known community)\n"
6791 "Do not advertise to any peer (well-known community)\n"
6792 "Do not export to next AS (well-known community)\n"
6793 "community number\n"
6794 "Do not send outside local AS (well-known community)\n"
6795 "Do not advertise to any peer (well-known community)\n"
6796 "Do not export to next AS (well-known community)\n"
6797 "Exact match of the communities")
6798
6799/* old command */
6800DEFUN (show_ipv6_bgp_community_exact,
6801 show_ipv6_bgp_community_exact_cmd,
6802 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6803 SHOW_STR
6804 IPV6_STR
6805 BGP_STR
6806 "Display routes matching the communities\n"
6807 "community number\n"
6808 "Do not send outside local AS (well-known community)\n"
6809 "Do not advertise to any peer (well-known community)\n"
6810 "Do not export to next AS (well-known community)\n"
6811 "Exact match of the communities")
6812{
6813 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
6814}
6815
6816/* old command */
6817ALIAS (show_ipv6_bgp_community_exact,
6818 show_ipv6_bgp_community2_exact_cmd,
6819 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6820 SHOW_STR
6821 IPV6_STR
6822 BGP_STR
6823 "Display routes matching the communities\n"
6824 "community number\n"
6825 "Do not send outside local AS (well-known community)\n"
6826 "Do not advertise to any peer (well-known community)\n"
6827 "Do not export to next AS (well-known community)\n"
6828 "community number\n"
6829 "Do not send outside local AS (well-known community)\n"
6830 "Do not advertise to any peer (well-known community)\n"
6831 "Do not export to next AS (well-known community)\n"
6832 "Exact match of the communities")
6833
6834/* old command */
6835ALIAS (show_ipv6_bgp_community_exact,
6836 show_ipv6_bgp_community3_exact_cmd,
6837 "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",
6838 SHOW_STR
6839 IPV6_STR
6840 BGP_STR
6841 "Display routes matching the communities\n"
6842 "community number\n"
6843 "Do not send outside local AS (well-known community)\n"
6844 "Do not advertise to any peer (well-known community)\n"
6845 "Do not export to next AS (well-known community)\n"
6846 "community number\n"
6847 "Do not send outside local AS (well-known community)\n"
6848 "Do not advertise to any peer (well-known community)\n"
6849 "Do not export to next AS (well-known community)\n"
6850 "community number\n"
6851 "Do not send outside local AS (well-known community)\n"
6852 "Do not advertise to any peer (well-known community)\n"
6853 "Do not export to next AS (well-known community)\n"
6854 "Exact match of the communities")
6855
6856/* old command */
6857ALIAS (show_ipv6_bgp_community_exact,
6858 show_ipv6_bgp_community4_exact_cmd,
6859 "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",
6860 SHOW_STR
6861 IPV6_STR
6862 BGP_STR
6863 "Display routes matching the communities\n"
6864 "community number\n"
6865 "Do not send outside local AS (well-known community)\n"
6866 "Do not advertise to any peer (well-known community)\n"
6867 "Do not export to next AS (well-known community)\n"
6868 "community number\n"
6869 "Do not send outside local AS (well-known community)\n"
6870 "Do not advertise to any peer (well-known community)\n"
6871 "Do not export to next AS (well-known community)\n"
6872 "community number\n"
6873 "Do not send outside local AS (well-known community)\n"
6874 "Do not advertise to any peer (well-known community)\n"
6875 "Do not export to next AS (well-known community)\n"
6876 "community number\n"
6877 "Do not send outside local AS (well-known community)\n"
6878 "Do not advertise to any peer (well-known community)\n"
6879 "Do not export to next AS (well-known community)\n"
6880 "Exact match of the communities")
6881
6882/* old command */
6883DEFUN (show_ipv6_mbgp_community,
6884 show_ipv6_mbgp_community_cmd,
6885 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
6886 SHOW_STR
6887 IPV6_STR
6888 MBGP_STR
6889 "Display routes matching the communities\n"
6890 "community number\n"
6891 "Do not send outside local AS (well-known community)\n"
6892 "Do not advertise to any peer (well-known community)\n"
6893 "Do not export to next AS (well-known community)\n")
6894{
6895 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
6896}
6897
6898/* old command */
6899ALIAS (show_ipv6_mbgp_community,
6900 show_ipv6_mbgp_community2_cmd,
6901 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
6902 SHOW_STR
6903 IPV6_STR
6904 MBGP_STR
6905 "Display routes matching the communities\n"
6906 "community number\n"
6907 "Do not send outside local AS (well-known community)\n"
6908 "Do not advertise to any peer (well-known community)\n"
6909 "Do not export to next AS (well-known community)\n"
6910 "community number\n"
6911 "Do not send outside local AS (well-known community)\n"
6912 "Do not advertise to any peer (well-known community)\n"
6913 "Do not export to next AS (well-known community)\n")
6914
6915/* old command */
6916ALIAS (show_ipv6_mbgp_community,
6917 show_ipv6_mbgp_community3_cmd,
6918 "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)",
6919 SHOW_STR
6920 IPV6_STR
6921 MBGP_STR
6922 "Display routes matching the communities\n"
6923 "community number\n"
6924 "Do not send outside local AS (well-known community)\n"
6925 "Do not advertise to any peer (well-known community)\n"
6926 "Do not export to next AS (well-known community)\n"
6927 "community number\n"
6928 "Do not send outside local AS (well-known community)\n"
6929 "Do not advertise to any peer (well-known community)\n"
6930 "Do not export to next AS (well-known community)\n"
6931 "community number\n"
6932 "Do not send outside local AS (well-known community)\n"
6933 "Do not advertise to any peer (well-known community)\n"
6934 "Do not export to next AS (well-known community)\n")
6935
6936/* old command */
6937ALIAS (show_ipv6_mbgp_community,
6938 show_ipv6_mbgp_community4_cmd,
6939 "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)",
6940 SHOW_STR
6941 IPV6_STR
6942 MBGP_STR
6943 "Display routes matching the communities\n"
6944 "community number\n"
6945 "Do not send outside local AS (well-known community)\n"
6946 "Do not advertise to any peer (well-known community)\n"
6947 "Do not export to next AS (well-known community)\n"
6948 "community number\n"
6949 "Do not send outside local AS (well-known community)\n"
6950 "Do not advertise to any peer (well-known community)\n"
6951 "Do not export to next AS (well-known community)\n"
6952 "community number\n"
6953 "Do not send outside local AS (well-known community)\n"
6954 "Do not advertise to any peer (well-known community)\n"
6955 "Do not export to next AS (well-known community)\n"
6956 "community number\n"
6957 "Do not send outside local AS (well-known community)\n"
6958 "Do not advertise to any peer (well-known community)\n"
6959 "Do not export to next AS (well-known community)\n")
6960
6961/* old command */
6962DEFUN (show_ipv6_mbgp_community_exact,
6963 show_ipv6_mbgp_community_exact_cmd,
6964 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
6965 SHOW_STR
6966 IPV6_STR
6967 MBGP_STR
6968 "Display routes matching the communities\n"
6969 "community number\n"
6970 "Do not send outside local AS (well-known community)\n"
6971 "Do not advertise to any peer (well-known community)\n"
6972 "Do not export to next AS (well-known community)\n"
6973 "Exact match of the communities")
6974{
6975 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
6976}
6977
6978/* old command */
6979ALIAS (show_ipv6_mbgp_community_exact,
6980 show_ipv6_mbgp_community2_exact_cmd,
6981 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
6982 SHOW_STR
6983 IPV6_STR
6984 MBGP_STR
6985 "Display routes matching the communities\n"
6986 "community number\n"
6987 "Do not send outside local AS (well-known community)\n"
6988 "Do not advertise to any peer (well-known community)\n"
6989 "Do not export to next AS (well-known community)\n"
6990 "community number\n"
6991 "Do not send outside local AS (well-known community)\n"
6992 "Do not advertise to any peer (well-known community)\n"
6993 "Do not export to next AS (well-known community)\n"
6994 "Exact match of the communities")
6995
6996/* old command */
6997ALIAS (show_ipv6_mbgp_community_exact,
6998 show_ipv6_mbgp_community3_exact_cmd,
6999 "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",
7000 SHOW_STR
7001 IPV6_STR
7002 MBGP_STR
7003 "Display routes matching the communities\n"
7004 "community number\n"
7005 "Do not send outside local AS (well-known community)\n"
7006 "Do not advertise to any peer (well-known community)\n"
7007 "Do not export to next AS (well-known community)\n"
7008 "community number\n"
7009 "Do not send outside local AS (well-known community)\n"
7010 "Do not advertise to any peer (well-known community)\n"
7011 "Do not export to next AS (well-known community)\n"
7012 "community number\n"
7013 "Do not send outside local AS (well-known community)\n"
7014 "Do not advertise to any peer (well-known community)\n"
7015 "Do not export to next AS (well-known community)\n"
7016 "Exact match of the communities")
7017
7018/* old command */
7019ALIAS (show_ipv6_mbgp_community_exact,
7020 show_ipv6_mbgp_community4_exact_cmd,
7021 "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",
7022 SHOW_STR
7023 IPV6_STR
7024 MBGP_STR
7025 "Display routes matching the communities\n"
7026 "community number\n"
7027 "Do not send outside local AS (well-known community)\n"
7028 "Do not advertise to any peer (well-known community)\n"
7029 "Do not export to next AS (well-known community)\n"
7030 "community number\n"
7031 "Do not send outside local AS (well-known community)\n"
7032 "Do not advertise to any peer (well-known community)\n"
7033 "Do not export to next AS (well-known community)\n"
7034 "community number\n"
7035 "Do not send outside local AS (well-known community)\n"
7036 "Do not advertise to any peer (well-known community)\n"
7037 "Do not export to next AS (well-known community)\n"
7038 "community number\n"
7039 "Do not send outside local AS (well-known community)\n"
7040 "Do not advertise to any peer (well-known community)\n"
7041 "Do not export to next AS (well-known community)\n"
7042 "Exact match of the communities")
7043#endif /* HAVE_IPV6 */
7044
7045int
7046bgp_show_community_list (struct vty *vty, char *com, int exact,
7047 u_int16_t afi, u_char safi)
7048{
7049 struct community_list *list;
7050
7051 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_AUTO);
7052 if (list == NULL)
7053 {
7054 vty_out (vty, "%% %s is not a valid community-list name%s", com,
7055 VTY_NEWLINE);
7056 return CMD_WARNING;
7057 }
7058
7059 vty->output_arg = list;
7060
7061 if (exact)
7062 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_list_exact);
7063
7064 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_list);
7065}
7066
7067DEFUN (show_ip_bgp_community_list,
7068 show_ip_bgp_community_list_cmd,
7069 "show ip bgp community-list WORD",
7070 SHOW_STR
7071 IP_STR
7072 BGP_STR
7073 "Display routes matching the community-list\n"
7074 "community-list name\n")
7075{
7076 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
7077}
7078
7079DEFUN (show_ip_bgp_ipv4_community_list,
7080 show_ip_bgp_ipv4_community_list_cmd,
7081 "show ip bgp ipv4 (unicast|multicast) community-list WORD",
7082 SHOW_STR
7083 IP_STR
7084 BGP_STR
7085 "Address family\n"
7086 "Address Family modifier\n"
7087 "Address Family modifier\n"
7088 "Display routes matching the community-list\n"
7089 "community-list name\n")
7090{
7091 if (strncmp (argv[0], "m", 1) == 0)
7092 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
7093
7094 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
7095}
7096
7097DEFUN (show_ip_bgp_community_list_exact,
7098 show_ip_bgp_community_list_exact_cmd,
7099 "show ip bgp community-list WORD exact-match",
7100 SHOW_STR
7101 IP_STR
7102 BGP_STR
7103 "Display routes matching the community-list\n"
7104 "community-list name\n"
7105 "Exact match of the communities\n")
7106{
7107 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
7108}
7109
7110DEFUN (show_ip_bgp_ipv4_community_list_exact,
7111 show_ip_bgp_ipv4_community_list_exact_cmd,
7112 "show ip bgp ipv4 (unicast|multicast) community-list WORD exact-match",
7113 SHOW_STR
7114 IP_STR
7115 BGP_STR
7116 "Address family\n"
7117 "Address Family modifier\n"
7118 "Address Family modifier\n"
7119 "Display routes matching the community-list\n"
7120 "community-list name\n"
7121 "Exact match of the communities\n")
7122{
7123 if (strncmp (argv[0], "m", 1) == 0)
7124 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
7125
7126 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
7127}
7128
7129#ifdef HAVE_IPV6
7130DEFUN (show_bgp_community_list,
7131 show_bgp_community_list_cmd,
7132 "show bgp community-list WORD",
7133 SHOW_STR
7134 BGP_STR
7135 "Display routes matching the community-list\n"
7136 "community-list name\n")
7137{
7138 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
7139}
7140
7141ALIAS (show_bgp_community_list,
7142 show_bgp_ipv6_community_list_cmd,
7143 "show bgp ipv6 community-list WORD",
7144 SHOW_STR
7145 BGP_STR
7146 "Address family\n"
7147 "Display routes matching the community-list\n"
7148 "community-list name\n")
7149
7150/* old command */
7151DEFUN (show_ipv6_bgp_community_list,
7152 show_ipv6_bgp_community_list_cmd,
7153 "show ipv6 bgp community-list WORD",
7154 SHOW_STR
7155 IPV6_STR
7156 BGP_STR
7157 "Display routes matching the community-list\n"
7158 "community-list name\n")
7159{
7160 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
7161}
7162
7163/* old command */
7164DEFUN (show_ipv6_mbgp_community_list,
7165 show_ipv6_mbgp_community_list_cmd,
7166 "show ipv6 mbgp community-list WORD",
7167 SHOW_STR
7168 IPV6_STR
7169 MBGP_STR
7170 "Display routes matching the community-list\n"
7171 "community-list name\n")
7172{
7173 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
7174}
7175
7176DEFUN (show_bgp_community_list_exact,
7177 show_bgp_community_list_exact_cmd,
7178 "show bgp community-list WORD exact-match",
7179 SHOW_STR
7180 BGP_STR
7181 "Display routes matching the community-list\n"
7182 "community-list name\n"
7183 "Exact match of the communities\n")
7184{
7185 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
7186}
7187
7188ALIAS (show_bgp_community_list_exact,
7189 show_bgp_ipv6_community_list_exact_cmd,
7190 "show bgp ipv6 community-list WORD exact-match",
7191 SHOW_STR
7192 BGP_STR
7193 "Address family\n"
7194 "Display routes matching the community-list\n"
7195 "community-list name\n"
7196 "Exact match of the communities\n")
7197
7198/* old command */
7199DEFUN (show_ipv6_bgp_community_list_exact,
7200 show_ipv6_bgp_community_list_exact_cmd,
7201 "show ipv6 bgp community-list WORD exact-match",
7202 SHOW_STR
7203 IPV6_STR
7204 BGP_STR
7205 "Display routes matching the community-list\n"
7206 "community-list name\n"
7207 "Exact match of the communities\n")
7208{
7209 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
7210}
7211
7212/* old command */
7213DEFUN (show_ipv6_mbgp_community_list_exact,
7214 show_ipv6_mbgp_community_list_exact_cmd,
7215 "show ipv6 mbgp community-list WORD exact-match",
7216 SHOW_STR
7217 IPV6_STR
7218 MBGP_STR
7219 "Display routes matching the community-list\n"
7220 "community-list name\n"
7221 "Exact match of the communities\n")
7222{
7223 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
7224}
7225#endif /* HAVE_IPV6 */
7226
7227void
7228bgp_show_prefix_longer_clean (struct vty *vty)
7229{
7230 struct prefix *p;
7231
7232 p = vty->output_arg;
7233 prefix_free (p);
7234}
7235
7236int
7237bgp_show_prefix_longer (struct vty *vty, char *prefix, afi_t afi,
7238 safi_t safi, enum bgp_show_type type)
7239{
7240 int ret;
7241 struct prefix *p;
7242
7243 p = prefix_new();
7244
7245 ret = str2prefix (prefix, p);
7246 if (! ret)
7247 {
7248 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
7249 return CMD_WARNING;
7250 }
7251
7252 vty->output_arg = p;
7253 vty->output_clean = bgp_show_prefix_longer_clean;
7254
7255 return bgp_show (vty, NULL, afi, safi, type);
7256}
7257
7258DEFUN (show_ip_bgp_prefix_longer,
7259 show_ip_bgp_prefix_longer_cmd,
7260 "show ip bgp A.B.C.D/M longer-prefixes",
7261 SHOW_STR
7262 IP_STR
7263 BGP_STR
7264 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7265 "Display route and more specific routes\n")
7266{
7267 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7268 bgp_show_type_prefix_longer);
7269}
7270
7271DEFUN (show_ip_bgp_flap_prefix_longer,
7272 show_ip_bgp_flap_prefix_longer_cmd,
7273 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
7274 SHOW_STR
7275 IP_STR
7276 BGP_STR
7277 "Display flap statistics of routes\n"
7278 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7279 "Display route and more specific routes\n")
7280{
7281 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7282 bgp_show_type_flap_prefix_longer);
7283}
7284
7285DEFUN (show_ip_bgp_ipv4_prefix_longer,
7286 show_ip_bgp_ipv4_prefix_longer_cmd,
7287 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
7288 SHOW_STR
7289 IP_STR
7290 BGP_STR
7291 "Address family\n"
7292 "Address Family modifier\n"
7293 "Address Family modifier\n"
7294 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7295 "Display route and more specific routes\n")
7296{
7297 if (strncmp (argv[0], "m", 1) == 0)
7298 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7299 bgp_show_type_prefix_longer);
7300
7301 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
7302 bgp_show_type_prefix_longer);
7303}
7304
7305DEFUN (show_ip_bgp_flap_address,
7306 show_ip_bgp_flap_address_cmd,
7307 "show ip bgp flap-statistics A.B.C.D",
7308 SHOW_STR
7309 IP_STR
7310 BGP_STR
7311 "Display flap statistics of routes\n"
7312 "Network in the BGP routing table to display\n")
7313{
7314 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7315 bgp_show_type_flap_address);
7316}
7317
7318DEFUN (show_ip_bgp_flap_prefix,
7319 show_ip_bgp_flap_prefix_cmd,
7320 "show ip bgp flap-statistics A.B.C.D/M",
7321 SHOW_STR
7322 IP_STR
7323 BGP_STR
7324 "Display flap statistics of routes\n"
7325 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7326{
7327 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
7328 bgp_show_type_flap_prefix);
7329}
7330#ifdef HAVE_IPV6
7331DEFUN (show_bgp_prefix_longer,
7332 show_bgp_prefix_longer_cmd,
7333 "show bgp X:X::X:X/M longer-prefixes",
7334 SHOW_STR
7335 BGP_STR
7336 "IPv6 prefix <network>/<length>\n"
7337 "Display route and more specific routes\n")
7338{
7339 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7340 bgp_show_type_prefix_longer);
7341}
7342
7343ALIAS (show_bgp_prefix_longer,
7344 show_bgp_ipv6_prefix_longer_cmd,
7345 "show bgp ipv6 X:X::X:X/M longer-prefixes",
7346 SHOW_STR
7347 BGP_STR
7348 "Address family\n"
7349 "IPv6 prefix <network>/<length>\n"
7350 "Display route and more specific routes\n")
7351
7352/* old command */
7353DEFUN (show_ipv6_bgp_prefix_longer,
7354 show_ipv6_bgp_prefix_longer_cmd,
7355 "show ipv6 bgp X:X::X:X/M longer-prefixes",
7356 SHOW_STR
7357 IPV6_STR
7358 BGP_STR
7359 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7360 "Display route and more specific routes\n")
7361{
7362 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7363 bgp_show_type_prefix_longer);
7364}
7365
7366/* old command */
7367DEFUN (show_ipv6_mbgp_prefix_longer,
7368 show_ipv6_mbgp_prefix_longer_cmd,
7369 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
7370 SHOW_STR
7371 IPV6_STR
7372 MBGP_STR
7373 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7374 "Display route and more specific routes\n")
7375{
7376 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7377 bgp_show_type_prefix_longer);
7378}
7379#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00007380
7381struct peer *
7382peer_lookup_in_view (struct vty *vty, char *view_name, char *ip_str)
7383{
7384 int ret;
7385 struct bgp *bgp;
7386 struct peer *peer;
7387 union sockunion su;
7388
7389 /* BGP structure lookup. */
7390 if (view_name)
7391 {
7392 bgp = bgp_lookup_by_name (view_name);
7393 if (! bgp)
7394 {
7395 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7396 return NULL;
7397 }
7398 }
paul5228ad22004-06-04 17:58:18 +00007399 else
paulbb46e942003-10-24 19:02:03 +00007400 {
7401 bgp = bgp_get_default ();
7402 if (! bgp)
7403 {
7404 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7405 return NULL;
7406 }
7407 }
7408
7409 /* Get peer sockunion. */
7410 ret = str2sockunion (ip_str, &su);
7411 if (ret < 0)
7412 {
7413 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
7414 return NULL;
7415 }
7416
7417 /* Peer structure lookup. */
7418 peer = peer_lookup (bgp, &su);
7419 if (! peer)
7420 {
7421 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
7422 return NULL;
7423 }
7424
7425 return peer;
7426}
7427
paul718e3742002-12-13 20:15:29 +00007428void
7429show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
7430 int in)
7431{
7432 struct bgp_table *table;
7433 struct bgp_adj_in *ain;
7434 struct bgp_adj_out *adj;
7435 unsigned long output_count;
7436 struct bgp_node *rn;
7437 int header1 = 1;
7438 struct bgp *bgp;
7439 int header2 = 1;
7440
paulbb46e942003-10-24 19:02:03 +00007441 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00007442
7443 if (! bgp)
7444 return;
7445
7446 table = bgp->rib[afi][safi];
7447
7448 output_count = 0;
7449
7450 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
7451 PEER_STATUS_DEFAULT_ORIGINATE))
7452 {
7453 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
7454 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
7455 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
7456
7457 vty_out (vty, "Originating default network 0.0.0.0%s%s",
7458 VTY_NEWLINE, VTY_NEWLINE);
7459 header1 = 0;
7460 }
7461
7462 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
7463 if (in)
7464 {
7465 for (ain = rn->adj_in; ain; ain = ain->next)
7466 if (ain->peer == peer)
7467 {
7468 if (header1)
7469 {
7470 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
7471 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
7472 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
7473 header1 = 0;
7474 }
7475 if (header2)
7476 {
7477 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7478 header2 = 0;
7479 }
7480 if (ain->attr)
7481 {
7482 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
7483 output_count++;
7484 }
7485 }
7486 }
7487 else
7488 {
7489 for (adj = rn->adj_out; adj; adj = adj->next)
7490 if (adj->peer == peer)
7491 {
7492 if (header1)
7493 {
7494 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
7495 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", VTY_NEWLINE);
7496 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", VTY_NEWLINE, VTY_NEWLINE);
7497 header1 = 0;
7498 }
7499 if (header2)
7500 {
7501 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
7502 header2 = 0;
7503 }
7504 if (adj->attr)
7505 {
7506 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
7507 output_count++;
7508 }
7509 }
7510 }
7511
7512 if (output_count != 0)
7513 vty_out (vty, "%sTotal number of prefixes %ld%s",
7514 VTY_NEWLINE, output_count, VTY_NEWLINE);
7515}
7516
7517int
paulbb46e942003-10-24 19:02:03 +00007518peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
7519{
paul718e3742002-12-13 20:15:29 +00007520 if (! peer || ! peer->afc[afi][safi])
7521 {
7522 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
7523 return CMD_WARNING;
7524 }
7525
7526 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
7527 {
7528 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
7529 VTY_NEWLINE);
7530 return CMD_WARNING;
7531 }
7532
7533 show_adj_route (vty, peer, afi, safi, in);
7534
7535 return CMD_SUCCESS;
7536}
7537
7538DEFUN (show_ip_bgp_neighbor_advertised_route,
7539 show_ip_bgp_neighbor_advertised_route_cmd,
7540 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7541 SHOW_STR
7542 IP_STR
7543 BGP_STR
7544 "Detailed information on TCP and BGP neighbor connections\n"
7545 "Neighbor to display information about\n"
7546 "Neighbor to display information about\n"
7547 "Display the routes advertised to a BGP neighbor\n")
7548{
paulbb46e942003-10-24 19:02:03 +00007549 struct peer *peer;
7550
7551 peer = peer_lookup_in_view (vty, NULL, argv[0]);
7552 if (! peer)
7553 return CMD_WARNING;
7554
7555 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00007556}
7557
7558DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
7559 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
7560 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7561 SHOW_STR
7562 IP_STR
7563 BGP_STR
7564 "Address family\n"
7565 "Address Family modifier\n"
7566 "Address Family modifier\n"
7567 "Detailed information on TCP and BGP neighbor connections\n"
7568 "Neighbor to display information about\n"
7569 "Neighbor to display information about\n"
7570 "Display the routes advertised to a BGP neighbor\n")
7571{
paulbb46e942003-10-24 19:02:03 +00007572 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00007573
paulbb46e942003-10-24 19:02:03 +00007574 peer = peer_lookup_in_view (vty, NULL, argv[1]);
7575 if (! peer)
7576 return CMD_WARNING;
7577
7578 if (strncmp (argv[0], "m", 1) == 0)
7579 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
7580
7581 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00007582}
7583
7584#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00007585DEFUN (show_bgp_view_neighbor_advertised_route,
7586 show_bgp_view_neighbor_advertised_route_cmd,
7587 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7588 SHOW_STR
7589 BGP_STR
7590 "BGP view\n"
7591 "View name\n"
7592 "Detailed information on TCP and BGP neighbor connections\n"
7593 "Neighbor to display information about\n"
7594 "Neighbor to display information about\n"
7595 "Display the routes advertised to a BGP neighbor\n")
7596{
7597 struct peer *peer;
7598
7599 if (argc == 2)
7600 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
7601 else
7602 peer = peer_lookup_in_view (vty, NULL, argv[0]);
7603
7604 if (! peer)
7605 return CMD_WARNING;
7606
7607 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
7608}
7609
7610ALIAS (show_bgp_view_neighbor_advertised_route,
7611 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
7612 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7613 SHOW_STR
7614 BGP_STR
7615 "BGP view\n"
7616 "View name\n"
7617 "Address family\n"
7618 "Detailed information on TCP and BGP neighbor connections\n"
7619 "Neighbor to display information about\n"
7620 "Neighbor to display information about\n"
7621 "Display the routes advertised to a BGP neighbor\n")
7622
7623DEFUN (show_bgp_view_neighbor_received_routes,
7624 show_bgp_view_neighbor_received_routes_cmd,
7625 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
7626 SHOW_STR
7627 BGP_STR
7628 "BGP view\n"
7629 "View name\n"
7630 "Detailed information on TCP and BGP neighbor connections\n"
7631 "Neighbor to display information about\n"
7632 "Neighbor to display information about\n"
7633 "Display the received routes from neighbor\n")
7634{
7635 struct peer *peer;
7636
7637 if (argc == 2)
7638 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
7639 else
7640 peer = peer_lookup_in_view (vty, NULL, argv[0]);
7641
7642 if (! peer)
7643 return CMD_WARNING;
7644
7645 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
7646}
7647
7648ALIAS (show_bgp_view_neighbor_received_routes,
7649 show_bgp_view_ipv6_neighbor_received_routes_cmd,
7650 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
7651 SHOW_STR
7652 BGP_STR
7653 "BGP view\n"
7654 "View name\n"
7655 "Address family\n"
7656 "Detailed information on TCP and BGP neighbor connections\n"
7657 "Neighbor to display information about\n"
7658 "Neighbor to display information about\n"
7659 "Display the received routes from neighbor\n")
7660
7661ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00007662 show_bgp_neighbor_advertised_route_cmd,
7663 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7664 SHOW_STR
7665 BGP_STR
7666 "Detailed information on TCP and BGP neighbor connections\n"
7667 "Neighbor to display information about\n"
7668 "Neighbor to display information about\n"
7669 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00007670
7671ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00007672 show_bgp_ipv6_neighbor_advertised_route_cmd,
7673 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7674 SHOW_STR
7675 BGP_STR
7676 "Address family\n"
7677 "Detailed information on TCP and BGP neighbor connections\n"
7678 "Neighbor to display information about\n"
7679 "Neighbor to display information about\n"
7680 "Display the routes advertised to a BGP neighbor\n")
7681
7682/* old command */
paulbb46e942003-10-24 19:02:03 +00007683ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00007684 ipv6_bgp_neighbor_advertised_route_cmd,
7685 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7686 SHOW_STR
7687 IPV6_STR
7688 BGP_STR
7689 "Detailed information on TCP and BGP neighbor connections\n"
7690 "Neighbor to display information about\n"
7691 "Neighbor to display information about\n"
7692 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00007693
paul718e3742002-12-13 20:15:29 +00007694/* old command */
7695DEFUN (ipv6_mbgp_neighbor_advertised_route,
7696 ipv6_mbgp_neighbor_advertised_route_cmd,
7697 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
7698 SHOW_STR
7699 IPV6_STR
7700 MBGP_STR
7701 "Detailed information on TCP and BGP neighbor connections\n"
7702 "Neighbor to display information about\n"
7703 "Neighbor to display information about\n"
7704 "Display the routes advertised to a BGP neighbor\n")
7705{
paulbb46e942003-10-24 19:02:03 +00007706 struct peer *peer;
7707
7708 peer = peer_lookup_in_view (vty, NULL, argv[0]);
7709 if (! peer)
7710 return CMD_WARNING;
7711
7712 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00007713}
7714#endif /* HAVE_IPV6 */
7715
7716DEFUN (show_ip_bgp_neighbor_received_routes,
7717 show_ip_bgp_neighbor_received_routes_cmd,
7718 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
7719 SHOW_STR
7720 IP_STR
7721 BGP_STR
7722 "Detailed information on TCP and BGP neighbor connections\n"
7723 "Neighbor to display information about\n"
7724 "Neighbor to display information about\n"
7725 "Display the received routes from neighbor\n")
7726{
paulbb46e942003-10-24 19:02:03 +00007727 struct peer *peer;
7728
7729 peer = peer_lookup_in_view (vty, NULL, argv[0]);
7730 if (! peer)
7731 return CMD_WARNING;
7732
7733 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00007734}
7735
7736DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
7737 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
7738 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
7739 SHOW_STR
7740 IP_STR
7741 BGP_STR
7742 "Address family\n"
7743 "Address Family modifier\n"
7744 "Address Family modifier\n"
7745 "Detailed information on TCP and BGP neighbor connections\n"
7746 "Neighbor to display information about\n"
7747 "Neighbor to display information about\n"
7748 "Display the received routes from neighbor\n")
7749{
paulbb46e942003-10-24 19:02:03 +00007750 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00007751
paulbb46e942003-10-24 19:02:03 +00007752 peer = peer_lookup_in_view (vty, NULL, argv[1]);
7753 if (! peer)
7754 return CMD_WARNING;
7755
7756 if (strncmp (argv[0], "m", 1) == 0)
7757 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
7758
7759 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00007760}
7761
7762DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
7763 show_ip_bgp_neighbor_received_prefix_filter_cmd,
7764 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
7765 SHOW_STR
7766 IP_STR
7767 BGP_STR
7768 "Detailed information on TCP and BGP neighbor connections\n"
7769 "Neighbor to display information about\n"
7770 "Neighbor to display information about\n"
7771 "Display information received from a BGP neighbor\n"
7772 "Display the prefixlist filter\n")
7773{
7774 char name[BUFSIZ];
7775 union sockunion *su;
7776 struct peer *peer;
7777 int count;
7778
7779 su = sockunion_str2su (argv[0]);
7780 if (su == NULL)
7781 return CMD_WARNING;
7782
7783 peer = peer_lookup (NULL, su);
7784 if (! peer)
7785 return CMD_WARNING;
7786
7787 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
7788 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
7789 if (count)
7790 {
7791 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
7792 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
7793 }
7794
7795 return CMD_SUCCESS;
7796}
7797
7798DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
7799 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
7800 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
7801 SHOW_STR
7802 IP_STR
7803 BGP_STR
7804 "Address family\n"
7805 "Address Family modifier\n"
7806 "Address Family modifier\n"
7807 "Detailed information on TCP and BGP neighbor connections\n"
7808 "Neighbor to display information about\n"
7809 "Neighbor to display information about\n"
7810 "Display information received from a BGP neighbor\n"
7811 "Display the prefixlist filter\n")
7812{
7813 char name[BUFSIZ];
7814 union sockunion *su;
7815 struct peer *peer;
7816 int count;
7817
7818 su = sockunion_str2su (argv[1]);
7819 if (su == NULL)
7820 return CMD_WARNING;
7821
7822 peer = peer_lookup (NULL, su);
7823 if (! peer)
7824 return CMD_WARNING;
7825
7826 if (strncmp (argv[0], "m", 1) == 0)
7827 {
7828 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
7829 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
7830 if (count)
7831 {
7832 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
7833 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
7834 }
7835 }
7836 else
7837 {
7838 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
7839 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
7840 if (count)
7841 {
7842 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
7843 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
7844 }
7845 }
7846
7847 return CMD_SUCCESS;
7848}
7849
7850
7851#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00007852ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00007853 show_bgp_neighbor_received_routes_cmd,
7854 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
7855 SHOW_STR
7856 BGP_STR
7857 "Detailed information on TCP and BGP neighbor connections\n"
7858 "Neighbor to display information about\n"
7859 "Neighbor to display information about\n"
7860 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00007861
paulbb46e942003-10-24 19:02:03 +00007862ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00007863 show_bgp_ipv6_neighbor_received_routes_cmd,
7864 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
7865 SHOW_STR
7866 BGP_STR
7867 "Address family\n"
7868 "Detailed information on TCP and BGP neighbor connections\n"
7869 "Neighbor to display information about\n"
7870 "Neighbor to display information about\n"
7871 "Display the received routes from neighbor\n")
7872
7873DEFUN (show_bgp_neighbor_received_prefix_filter,
7874 show_bgp_neighbor_received_prefix_filter_cmd,
7875 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
7876 SHOW_STR
7877 BGP_STR
7878 "Detailed information on TCP and BGP neighbor connections\n"
7879 "Neighbor to display information about\n"
7880 "Neighbor to display information about\n"
7881 "Display information received from a BGP neighbor\n"
7882 "Display the prefixlist filter\n")
7883{
7884 char name[BUFSIZ];
7885 union sockunion *su;
7886 struct peer *peer;
7887 int count;
7888
7889 su = sockunion_str2su (argv[0]);
7890 if (su == NULL)
7891 return CMD_WARNING;
7892
7893 peer = peer_lookup (NULL, su);
7894 if (! peer)
7895 return CMD_WARNING;
7896
7897 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
7898 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
7899 if (count)
7900 {
7901 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
7902 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
7903 }
7904
7905 return CMD_SUCCESS;
7906}
7907
7908ALIAS (show_bgp_neighbor_received_prefix_filter,
7909 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
7910 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
7911 SHOW_STR
7912 BGP_STR
7913 "Address family\n"
7914 "Detailed information on TCP and BGP neighbor connections\n"
7915 "Neighbor to display information about\n"
7916 "Neighbor to display information about\n"
7917 "Display information received from a BGP neighbor\n"
7918 "Display the prefixlist filter\n")
7919
7920/* old command */
paulbb46e942003-10-24 19:02:03 +00007921ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00007922 ipv6_bgp_neighbor_received_routes_cmd,
7923 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
7924 SHOW_STR
7925 IPV6_STR
7926 BGP_STR
7927 "Detailed information on TCP and BGP neighbor connections\n"
7928 "Neighbor to display information about\n"
7929 "Neighbor to display information about\n"
7930 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00007931
7932/* old command */
7933DEFUN (ipv6_mbgp_neighbor_received_routes,
7934 ipv6_mbgp_neighbor_received_routes_cmd,
7935 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
7936 SHOW_STR
7937 IPV6_STR
7938 MBGP_STR
7939 "Detailed information on TCP and BGP neighbor connections\n"
7940 "Neighbor to display information about\n"
7941 "Neighbor to display information about\n"
7942 "Display the received routes from neighbor\n")
7943{
paulbb46e942003-10-24 19:02:03 +00007944 struct peer *peer;
7945
7946 peer = peer_lookup_in_view (vty, NULL, argv[0]);
7947 if (! peer)
7948 return CMD_WARNING;
7949
7950 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00007951}
paulbb46e942003-10-24 19:02:03 +00007952
7953DEFUN (show_bgp_view_neighbor_received_prefix_filter,
7954 show_bgp_view_neighbor_received_prefix_filter_cmd,
7955 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
7956 SHOW_STR
7957 BGP_STR
7958 "BGP view\n"
7959 "View name\n"
7960 "Detailed information on TCP and BGP neighbor connections\n"
7961 "Neighbor to display information about\n"
7962 "Neighbor to display information about\n"
7963 "Display information received from a BGP neighbor\n"
7964 "Display the prefixlist filter\n")
7965{
7966 char name[BUFSIZ];
7967 union sockunion *su;
7968 struct peer *peer;
7969 struct bgp *bgp;
7970 int count;
7971
7972 /* BGP structure lookup. */
7973 bgp = bgp_lookup_by_name (argv[0]);
7974 if (bgp == NULL)
7975 {
7976 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7977 return CMD_WARNING;
7978 }
7979
7980 su = sockunion_str2su (argv[1]);
7981 if (su == NULL)
7982 return CMD_WARNING;
7983
7984 peer = peer_lookup (bgp, su);
7985 if (! peer)
7986 return CMD_WARNING;
7987
7988 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
7989 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
7990 if (count)
7991 {
7992 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
7993 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
7994 }
7995
7996 return CMD_SUCCESS;
7997}
7998
7999ALIAS (show_bgp_view_neighbor_received_prefix_filter,
8000 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
8001 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
8002 SHOW_STR
8003 BGP_STR
8004 "BGP view\n"
8005 "View name\n"
8006 "Address family\n"
8007 "Detailed information on TCP and BGP neighbor connections\n"
8008 "Neighbor to display information about\n"
8009 "Neighbor to display information about\n"
8010 "Display information received from a BGP neighbor\n"
8011 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +00008012#endif /* HAVE_IPV6 */
8013
8014void
8015bgp_show_neighbor_route_clean (struct vty *vty)
8016{
8017 union sockunion *su;
8018
8019 su = vty->output_arg;
8020 XFREE (MTYPE_SOCKUNION, su);
8021}
8022
8023int
paulbb46e942003-10-24 19:02:03 +00008024bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008025 safi_t safi, enum bgp_show_type type)
8026{
paul718e3742002-12-13 20:15:29 +00008027 if (! peer || ! peer->afc[afi][safi])
8028 {
8029 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00008030 return CMD_WARNING;
8031 }
8032
paulbb46e942003-10-24 19:02:03 +00008033 vty->output_arg = sockunion_dup (&peer->su);
paul718e3742002-12-13 20:15:29 +00008034 vty->output_clean = bgp_show_neighbor_route_clean;
8035
paulbb46e942003-10-24 19:02:03 +00008036 return bgp_show (vty, peer->bgp, afi, safi, type);
paul718e3742002-12-13 20:15:29 +00008037}
8038
8039DEFUN (show_ip_bgp_neighbor_routes,
8040 show_ip_bgp_neighbor_routes_cmd,
8041 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
8042 SHOW_STR
8043 IP_STR
8044 BGP_STR
8045 "Detailed information on TCP and BGP neighbor connections\n"
8046 "Neighbor to display information about\n"
8047 "Neighbor to display information about\n"
8048 "Display routes learned from neighbor\n")
8049{
paulbb46e942003-10-24 19:02:03 +00008050 struct peer *peer;
8051
8052 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8053 if (! peer)
8054 return CMD_WARNING;
8055
8056 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008057 bgp_show_type_neighbor);
8058}
8059
8060DEFUN (show_ip_bgp_neighbor_flap,
8061 show_ip_bgp_neighbor_flap_cmd,
8062 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
8063 SHOW_STR
8064 IP_STR
8065 BGP_STR
8066 "Detailed information on TCP and BGP neighbor connections\n"
8067 "Neighbor to display information about\n"
8068 "Neighbor to display information about\n"
8069 "Display flap statistics of the routes learned from neighbor\n")
8070{
paulbb46e942003-10-24 19:02:03 +00008071 struct peer *peer;
8072
8073 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8074 if (! peer)
8075 return CMD_WARNING;
8076
8077 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008078 bgp_show_type_flap_neighbor);
8079}
8080
8081DEFUN (show_ip_bgp_neighbor_damp,
8082 show_ip_bgp_neighbor_damp_cmd,
8083 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
8084 SHOW_STR
8085 IP_STR
8086 BGP_STR
8087 "Detailed information on TCP and BGP neighbor connections\n"
8088 "Neighbor to display information about\n"
8089 "Neighbor to display information about\n"
8090 "Display the dampened routes received from neighbor\n")
8091{
paulbb46e942003-10-24 19:02:03 +00008092 struct peer *peer;
8093
8094 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8095 if (! peer)
8096 return CMD_WARNING;
8097
8098 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008099 bgp_show_type_damp_neighbor);
8100}
8101
8102DEFUN (show_ip_bgp_ipv4_neighbor_routes,
8103 show_ip_bgp_ipv4_neighbor_routes_cmd,
8104 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
8105 SHOW_STR
8106 IP_STR
8107 BGP_STR
8108 "Address family\n"
8109 "Address Family modifier\n"
8110 "Address Family modifier\n"
8111 "Detailed information on TCP and BGP neighbor connections\n"
8112 "Neighbor to display information about\n"
8113 "Neighbor to display information about\n"
8114 "Display routes learned from neighbor\n")
8115{
paulbb46e942003-10-24 19:02:03 +00008116 struct peer *peer;
8117
8118 peer = peer_lookup_in_view (vty, NULL, argv[1]);
8119 if (! peer)
8120 return CMD_WARNING;
8121
paul718e3742002-12-13 20:15:29 +00008122 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +00008123 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00008124 bgp_show_type_neighbor);
8125
paulbb46e942003-10-24 19:02:03 +00008126 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +00008127 bgp_show_type_neighbor);
8128}
paulbb46e942003-10-24 19:02:03 +00008129
paul718e3742002-12-13 20:15:29 +00008130#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00008131DEFUN (show_bgp_view_neighbor_routes,
8132 show_bgp_view_neighbor_routes_cmd,
8133 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
8134 SHOW_STR
8135 BGP_STR
8136 "BGP view\n"
8137 "BGP view name\n"
8138 "Detailed information on TCP and BGP neighbor connections\n"
8139 "Neighbor to display information about\n"
8140 "Neighbor to display information about\n"
8141 "Display routes learned from neighbor\n")
8142{
8143 struct peer *peer;
8144
8145 if (argc == 2)
8146 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8147 else
8148 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8149
8150 if (! peer)
8151 return CMD_WARNING;
8152
8153 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
8154 bgp_show_type_neighbor);
8155}
8156
8157ALIAS (show_bgp_view_neighbor_routes,
8158 show_bgp_view_ipv6_neighbor_routes_cmd,
8159 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
8160 SHOW_STR
8161 BGP_STR
8162 "BGP view\n"
8163 "BGP view name\n"
8164 "Address family\n"
8165 "Detailed information on TCP and BGP neighbor connections\n"
8166 "Neighbor to display information about\n"
8167 "Neighbor to display information about\n"
8168 "Display routes learned from neighbor\n")
8169
8170DEFUN (show_bgp_view_neighbor_damp,
8171 show_bgp_view_neighbor_damp_cmd,
8172 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
8173 SHOW_STR
8174 BGP_STR
8175 "BGP view\n"
8176 "BGP view name\n"
8177 "Detailed information on TCP and BGP neighbor connections\n"
8178 "Neighbor to display information about\n"
8179 "Neighbor to display information about\n"
8180 "Display the dampened routes received from neighbor\n")
8181{
8182 struct peer *peer;
8183
8184 if (argc == 2)
8185 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8186 else
8187 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8188
8189 if (! peer)
8190 return CMD_WARNING;
8191
8192 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
8193 bgp_show_type_damp_neighbor);
8194}
8195
8196ALIAS (show_bgp_view_neighbor_damp,
8197 show_bgp_view_ipv6_neighbor_damp_cmd,
8198 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
8199 SHOW_STR
8200 BGP_STR
8201 "BGP view\n"
8202 "BGP view name\n"
8203 "Address family\n"
8204 "Detailed information on TCP and BGP neighbor connections\n"
8205 "Neighbor to display information about\n"
8206 "Neighbor to display information about\n"
8207 "Display the dampened routes received from neighbor\n")
8208
8209DEFUN (show_bgp_view_neighbor_flap,
8210 show_bgp_view_neighbor_flap_cmd,
8211 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
8212 SHOW_STR
8213 BGP_STR
8214 "BGP view\n"
8215 "BGP view name\n"
8216 "Detailed information on TCP and BGP neighbor connections\n"
8217 "Neighbor to display information about\n"
8218 "Neighbor to display information about\n"
8219 "Display flap statistics of the routes learned from neighbor\n")
8220{
8221 struct peer *peer;
8222
8223 if (argc == 2)
8224 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
8225 else
8226 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8227
8228 if (! peer)
8229 return CMD_WARNING;
8230
8231 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
8232 bgp_show_type_flap_neighbor);
8233}
8234
8235ALIAS (show_bgp_view_neighbor_flap,
8236 show_bgp_view_ipv6_neighbor_flap_cmd,
8237 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
8238 SHOW_STR
8239 BGP_STR
8240 "BGP view\n"
8241 "BGP view name\n"
8242 "Address family\n"
8243 "Detailed information on TCP and BGP neighbor connections\n"
8244 "Neighbor to display information about\n"
8245 "Neighbor to display information about\n"
8246 "Display flap statistics of the routes learned from neighbor\n")
8247
8248ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00008249 show_bgp_neighbor_routes_cmd,
8250 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
8251 SHOW_STR
8252 BGP_STR
8253 "Detailed information on TCP and BGP neighbor connections\n"
8254 "Neighbor to display information about\n"
8255 "Neighbor to display information about\n"
8256 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008257
paulbb46e942003-10-24 19:02:03 +00008258
8259ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00008260 show_bgp_ipv6_neighbor_routes_cmd,
8261 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
8262 SHOW_STR
8263 BGP_STR
8264 "Address family\n"
8265 "Detailed information on TCP and BGP neighbor connections\n"
8266 "Neighbor to display information about\n"
8267 "Neighbor to display information about\n"
8268 "Display routes learned from neighbor\n")
8269
8270/* old command */
paulbb46e942003-10-24 19:02:03 +00008271ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +00008272 ipv6_bgp_neighbor_routes_cmd,
8273 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
8274 SHOW_STR
8275 IPV6_STR
8276 BGP_STR
8277 "Detailed information on TCP and BGP neighbor connections\n"
8278 "Neighbor to display information about\n"
8279 "Neighbor to display information about\n"
8280 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008281
8282/* old command */
8283DEFUN (ipv6_mbgp_neighbor_routes,
8284 ipv6_mbgp_neighbor_routes_cmd,
8285 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
8286 SHOW_STR
8287 IPV6_STR
8288 MBGP_STR
8289 "Detailed information on TCP and BGP neighbor connections\n"
8290 "Neighbor to display information about\n"
8291 "Neighbor to display information about\n"
8292 "Display routes learned from neighbor\n")
8293{
paulbb46e942003-10-24 19:02:03 +00008294 struct peer *peer;
8295
8296 peer = peer_lookup_in_view (vty, NULL, argv[0]);
8297 if (! peer)
8298 return CMD_WARNING;
8299
8300 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +00008301 bgp_show_type_neighbor);
8302}
paulbb46e942003-10-24 19:02:03 +00008303
8304ALIAS (show_bgp_view_neighbor_flap,
8305 show_bgp_neighbor_flap_cmd,
8306 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
8307 SHOW_STR
8308 BGP_STR
8309 "Detailed information on TCP and BGP neighbor connections\n"
8310 "Neighbor to display information about\n"
8311 "Neighbor to display information about\n"
8312 "Display flap statistics of the routes learned from neighbor\n")
8313
8314ALIAS (show_bgp_view_neighbor_flap,
8315 show_bgp_ipv6_neighbor_flap_cmd,
8316 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
8317 SHOW_STR
8318 BGP_STR
8319 "Address family\n"
8320 "Detailed information on TCP and BGP neighbor connections\n"
8321 "Neighbor to display information about\n"
8322 "Neighbor to display information about\n"
8323 "Display flap statistics of the routes learned from neighbor\n")
8324
8325ALIAS (show_bgp_view_neighbor_damp,
8326 show_bgp_neighbor_damp_cmd,
8327 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
8328 SHOW_STR
8329 BGP_STR
8330 "Detailed information on TCP and BGP neighbor connections\n"
8331 "Neighbor to display information about\n"
8332 "Neighbor to display information about\n"
8333 "Display the dampened routes received from neighbor\n")
8334
8335ALIAS (show_bgp_view_neighbor_damp,
8336 show_bgp_ipv6_neighbor_damp_cmd,
8337 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
8338 SHOW_STR
8339 BGP_STR
8340 "Address family\n"
8341 "Detailed information on TCP and BGP neighbor connections\n"
8342 "Neighbor to display information about\n"
8343 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +00008344 "Display the dampened routes received from neighbor\n")
paul718e3742002-12-13 20:15:29 +00008345#endif /* HAVE_IPV6 */
8346
8347struct bgp_table *bgp_distance_table;
8348
8349struct bgp_distance
8350{
8351 /* Distance value for the IP source prefix. */
8352 u_char distance;
8353
8354 /* Name of the access-list to be matched. */
8355 char *access_list;
8356};
8357
8358struct bgp_distance *
8359bgp_distance_new ()
8360{
8361 struct bgp_distance *new;
8362 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
8363 memset (new, 0, sizeof (struct bgp_distance));
8364 return new;
8365}
8366
8367void
8368bgp_distance_free (struct bgp_distance *bdistance)
8369{
8370 XFREE (MTYPE_BGP_DISTANCE, bdistance);
8371}
8372
8373int
8374bgp_distance_set (struct vty *vty, char *distance_str, char *ip_str,
8375 char *access_list_str)
8376{
8377 int ret;
8378 struct prefix_ipv4 p;
8379 u_char distance;
8380 struct bgp_node *rn;
8381 struct bgp_distance *bdistance;
8382
8383 ret = str2prefix_ipv4 (ip_str, &p);
8384 if (ret == 0)
8385 {
8386 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
8387 return CMD_WARNING;
8388 }
8389
8390 distance = atoi (distance_str);
8391
8392 /* Get BGP distance node. */
8393 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
8394 if (rn->info)
8395 {
8396 bdistance = rn->info;
8397 bgp_unlock_node (rn);
8398 }
8399 else
8400 {
8401 bdistance = bgp_distance_new ();
8402 rn->info = bdistance;
8403 }
8404
8405 /* Set distance value. */
8406 bdistance->distance = distance;
8407
8408 /* Reset access-list configuration. */
8409 if (bdistance->access_list)
8410 {
8411 free (bdistance->access_list);
8412 bdistance->access_list = NULL;
8413 }
8414 if (access_list_str)
8415 bdistance->access_list = strdup (access_list_str);
8416
8417 return CMD_SUCCESS;
8418}
8419
8420int
8421bgp_distance_unset (struct vty *vty, char *distance_str, char *ip_str,
8422 char *access_list_str)
8423{
8424 int ret;
8425 struct prefix_ipv4 p;
8426 u_char distance;
8427 struct bgp_node *rn;
8428 struct bgp_distance *bdistance;
8429
8430 ret = str2prefix_ipv4 (ip_str, &p);
8431 if (ret == 0)
8432 {
8433 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
8434 return CMD_WARNING;
8435 }
8436
8437 distance = atoi (distance_str);
8438
8439 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
8440 if (! rn)
8441 {
8442 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
8443 return CMD_WARNING;
8444 }
8445
8446 bdistance = rn->info;
8447
8448 if (bdistance->access_list)
8449 free (bdistance->access_list);
8450 bgp_distance_free (bdistance);
8451
8452 rn->info = NULL;
8453 bgp_unlock_node (rn);
8454 bgp_unlock_node (rn);
8455
8456 return CMD_SUCCESS;
8457}
8458
8459void
8460bgp_distance_reset ()
8461{
8462 struct bgp_node *rn;
8463 struct bgp_distance *bdistance;
8464
8465 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
8466 if ((bdistance = rn->info) != NULL)
8467 {
8468 if (bdistance->access_list)
8469 free (bdistance->access_list);
8470 bgp_distance_free (bdistance);
8471 rn->info = NULL;
8472 bgp_unlock_node (rn);
8473 }
8474}
8475
8476/* Apply BGP information to distance method. */
8477u_char
8478bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
8479{
8480 struct bgp_node *rn;
8481 struct prefix_ipv4 q;
8482 struct peer *peer;
8483 struct bgp_distance *bdistance;
8484 struct access_list *alist;
8485 struct bgp_static *bgp_static;
8486
8487 if (! bgp)
8488 return 0;
8489
8490 if (p->family != AF_INET)
8491 return 0;
8492
8493 peer = rinfo->peer;
8494
8495 if (peer->su.sa.sa_family != AF_INET)
8496 return 0;
8497
8498 memset (&q, 0, sizeof (struct prefix_ipv4));
8499 q.family = AF_INET;
8500 q.prefix = peer->su.sin.sin_addr;
8501 q.prefixlen = IPV4_MAX_BITLEN;
8502
8503 /* Check source address. */
8504 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
8505 if (rn)
8506 {
8507 bdistance = rn->info;
8508 bgp_unlock_node (rn);
8509
8510 if (bdistance->access_list)
8511 {
8512 alist = access_list_lookup (AFI_IP, bdistance->access_list);
8513 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
8514 return bdistance->distance;
8515 }
8516 else
8517 return bdistance->distance;
8518 }
8519
8520 /* Backdoor check. */
8521 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
8522 if (rn)
8523 {
8524 bgp_static = rn->info;
8525 bgp_unlock_node (rn);
8526
8527 if (bgp_static->backdoor)
8528 {
8529 if (bgp->distance_local)
8530 return bgp->distance_local;
8531 else
8532 return ZEBRA_IBGP_DISTANCE_DEFAULT;
8533 }
8534 }
8535
8536 if (peer_sort (peer) == BGP_PEER_EBGP)
8537 {
8538 if (bgp->distance_ebgp)
8539 return bgp->distance_ebgp;
8540 return ZEBRA_EBGP_DISTANCE_DEFAULT;
8541 }
8542 else
8543 {
8544 if (bgp->distance_ibgp)
8545 return bgp->distance_ibgp;
8546 return ZEBRA_IBGP_DISTANCE_DEFAULT;
8547 }
8548}
8549
8550DEFUN (bgp_distance,
8551 bgp_distance_cmd,
8552 "distance bgp <1-255> <1-255> <1-255>",
8553 "Define an administrative distance\n"
8554 "BGP distance\n"
8555 "Distance for routes external to the AS\n"
8556 "Distance for routes internal to the AS\n"
8557 "Distance for local routes\n")
8558{
8559 struct bgp *bgp;
8560
8561 bgp = vty->index;
8562
8563 bgp->distance_ebgp = atoi (argv[0]);
8564 bgp->distance_ibgp = atoi (argv[1]);
8565 bgp->distance_local = atoi (argv[2]);
8566 return CMD_SUCCESS;
8567}
8568
8569DEFUN (no_bgp_distance,
8570 no_bgp_distance_cmd,
8571 "no distance bgp <1-255> <1-255> <1-255>",
8572 NO_STR
8573 "Define an administrative distance\n"
8574 "BGP distance\n"
8575 "Distance for routes external to the AS\n"
8576 "Distance for routes internal to the AS\n"
8577 "Distance for local routes\n")
8578{
8579 struct bgp *bgp;
8580
8581 bgp = vty->index;
8582
8583 bgp->distance_ebgp= 0;
8584 bgp->distance_ibgp = 0;
8585 bgp->distance_local = 0;
8586 return CMD_SUCCESS;
8587}
8588
8589ALIAS (no_bgp_distance,
8590 no_bgp_distance2_cmd,
8591 "no distance bgp",
8592 NO_STR
8593 "Define an administrative distance\n"
8594 "BGP distance\n")
8595
8596DEFUN (bgp_distance_source,
8597 bgp_distance_source_cmd,
8598 "distance <1-255> A.B.C.D/M",
8599 "Define an administrative distance\n"
8600 "Administrative distance\n"
8601 "IP source prefix\n")
8602{
8603 bgp_distance_set (vty, argv[0], argv[1], NULL);
8604 return CMD_SUCCESS;
8605}
8606
8607DEFUN (no_bgp_distance_source,
8608 no_bgp_distance_source_cmd,
8609 "no distance <1-255> A.B.C.D/M",
8610 NO_STR
8611 "Define an administrative distance\n"
8612 "Administrative distance\n"
8613 "IP source prefix\n")
8614{
8615 bgp_distance_unset (vty, argv[0], argv[1], NULL);
8616 return CMD_SUCCESS;
8617}
8618
8619DEFUN (bgp_distance_source_access_list,
8620 bgp_distance_source_access_list_cmd,
8621 "distance <1-255> A.B.C.D/M WORD",
8622 "Define an administrative distance\n"
8623 "Administrative distance\n"
8624 "IP source prefix\n"
8625 "Access list name\n")
8626{
8627 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
8628 return CMD_SUCCESS;
8629}
8630
8631DEFUN (no_bgp_distance_source_access_list,
8632 no_bgp_distance_source_access_list_cmd,
8633 "no distance <1-255> A.B.C.D/M WORD",
8634 NO_STR
8635 "Define an administrative distance\n"
8636 "Administrative distance\n"
8637 "IP source prefix\n"
8638 "Access list name\n")
8639{
8640 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
8641 return CMD_SUCCESS;
8642}
8643
8644DEFUN (bgp_damp_set,
8645 bgp_damp_set_cmd,
8646 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
8647 "BGP Specific commands\n"
8648 "Enable route-flap dampening\n"
8649 "Half-life time for the penalty\n"
8650 "Value to start reusing a route\n"
8651 "Value to start suppressing a route\n"
8652 "Maximum duration to suppress a stable route\n")
8653{
8654 struct bgp *bgp;
8655 int half = DEFAULT_HALF_LIFE * 60;
8656 int reuse = DEFAULT_REUSE;
8657 int suppress = DEFAULT_SUPPRESS;
8658 int max = 4 * half;
8659
8660 if (argc == 4)
8661 {
8662 half = atoi (argv[0]) * 60;
8663 reuse = atoi (argv[1]);
8664 suppress = atoi (argv[2]);
8665 max = atoi (argv[3]) * 60;
8666 }
8667 else if (argc == 1)
8668 {
8669 half = atoi (argv[0]) * 60;
8670 max = 4 * half;
8671 }
8672
8673 bgp = vty->index;
8674 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
8675 half, reuse, suppress, max);
8676}
8677
8678ALIAS (bgp_damp_set,
8679 bgp_damp_set2_cmd,
8680 "bgp dampening <1-45>",
8681 "BGP Specific commands\n"
8682 "Enable route-flap dampening\n"
8683 "Half-life time for the penalty\n")
8684
8685ALIAS (bgp_damp_set,
8686 bgp_damp_set3_cmd,
8687 "bgp dampening",
8688 "BGP Specific commands\n"
8689 "Enable route-flap dampening\n")
8690
8691DEFUN (bgp_damp_unset,
8692 bgp_damp_unset_cmd,
8693 "no bgp dampening",
8694 NO_STR
8695 "BGP Specific commands\n"
8696 "Enable route-flap dampening\n")
8697{
8698 struct bgp *bgp;
8699
8700 bgp = vty->index;
8701 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
8702}
8703
8704ALIAS (bgp_damp_unset,
8705 bgp_damp_unset2_cmd,
8706 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
8707 NO_STR
8708 "BGP Specific commands\n"
8709 "Enable route-flap dampening\n"
8710 "Half-life time for the penalty\n"
8711 "Value to start reusing a route\n"
8712 "Value to start suppressing a route\n"
8713 "Maximum duration to suppress a stable route\n")
8714
8715DEFUN (show_ip_bgp_dampened_paths,
8716 show_ip_bgp_dampened_paths_cmd,
8717 "show ip bgp dampened-paths",
8718 SHOW_STR
8719 IP_STR
8720 BGP_STR
8721 "Display paths suppressed due to dampening\n")
8722{
8723 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths);
8724}
8725
8726DEFUN (show_ip_bgp_flap_statistics,
8727 show_ip_bgp_flap_statistics_cmd,
8728 "show ip bgp flap-statistics",
8729 SHOW_STR
8730 IP_STR
8731 BGP_STR
8732 "Display flap statistics of routes\n")
8733{
8734 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_flap_statistics);
8735}
8736
8737/* Display specified route of BGP table. */
8738int
8739bgp_clear_damp_route (struct vty *vty, char *view_name, char *ip_str,
8740 afi_t afi, safi_t safi, struct prefix_rd *prd,
8741 int prefix_check)
8742{
8743 int ret;
8744 struct prefix match;
8745 struct bgp_node *rn;
8746 struct bgp_node *rm;
8747 struct bgp_info *ri;
8748 struct bgp_info *ri_temp;
8749 struct bgp *bgp;
8750 struct bgp_table *table;
8751
8752 /* BGP structure lookup. */
8753 if (view_name)
8754 {
8755 bgp = bgp_lookup_by_name (view_name);
8756 if (bgp == NULL)
8757 {
8758 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8759 return CMD_WARNING;
8760 }
8761 }
8762 else
8763 {
8764 bgp = bgp_get_default ();
8765 if (bgp == NULL)
8766 {
8767 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
8768 return CMD_WARNING;
8769 }
8770 }
8771
8772 /* Check IP address argument. */
8773 ret = str2prefix (ip_str, &match);
8774 if (! ret)
8775 {
8776 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
8777 return CMD_WARNING;
8778 }
8779
8780 match.family = afi2family (afi);
8781
8782 if (safi == SAFI_MPLS_VPN)
8783 {
8784 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
8785 {
8786 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
8787 continue;
8788
8789 if ((table = rn->info) != NULL)
8790 if ((rm = bgp_node_match (table, &match)) != NULL)
8791 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
8792 {
8793 ri = rm->info;
8794 while (ri)
8795 {
8796 if (ri->damp_info)
8797 {
8798 ri_temp = ri->next;
8799 bgp_damp_info_free (ri->damp_info, 1);
8800 ri = ri_temp;
8801 }
8802 else
8803 ri = ri->next;
8804 }
8805 }
8806 }
8807 }
8808 else
8809 {
8810 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
8811 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
8812 {
8813 ri = rn->info;
8814 while (ri)
8815 {
8816 if (ri->damp_info)
8817 {
8818 ri_temp = ri->next;
8819 bgp_damp_info_free (ri->damp_info, 1);
8820 ri = ri_temp;
8821 }
8822 else
8823 ri = ri->next;
8824 }
8825 }
8826 }
8827
8828 return CMD_SUCCESS;
8829}
8830
8831DEFUN (clear_ip_bgp_dampening,
8832 clear_ip_bgp_dampening_cmd,
8833 "clear ip bgp dampening",
8834 CLEAR_STR
8835 IP_STR
8836 BGP_STR
8837 "Clear route flap dampening information\n")
8838{
8839 bgp_damp_info_clean ();
8840 return CMD_SUCCESS;
8841}
8842
8843DEFUN (clear_ip_bgp_dampening_prefix,
8844 clear_ip_bgp_dampening_prefix_cmd,
8845 "clear ip bgp dampening A.B.C.D/M",
8846 CLEAR_STR
8847 IP_STR
8848 BGP_STR
8849 "Clear route flap dampening information\n"
8850 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8851{
8852 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
8853 SAFI_UNICAST, NULL, 1);
8854}
8855
8856DEFUN (clear_ip_bgp_dampening_address,
8857 clear_ip_bgp_dampening_address_cmd,
8858 "clear ip bgp dampening A.B.C.D",
8859 CLEAR_STR
8860 IP_STR
8861 BGP_STR
8862 "Clear route flap dampening information\n"
8863 "Network to clear damping information\n")
8864{
8865 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
8866 SAFI_UNICAST, NULL, 0);
8867}
8868
8869DEFUN (clear_ip_bgp_dampening_address_mask,
8870 clear_ip_bgp_dampening_address_mask_cmd,
8871 "clear ip bgp dampening A.B.C.D A.B.C.D",
8872 CLEAR_STR
8873 IP_STR
8874 BGP_STR
8875 "Clear route flap dampening information\n"
8876 "Network to clear damping information\n"
8877 "Network mask\n")
8878{
8879 int ret;
8880 char prefix_str[BUFSIZ];
8881
8882 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
8883 if (! ret)
8884 {
8885 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
8886 return CMD_WARNING;
8887 }
8888
8889 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
8890 SAFI_UNICAST, NULL, 0);
8891}
8892
8893int
8894bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
8895 afi_t afi, safi_t safi, int *write)
8896{
8897 struct bgp_node *prn;
8898 struct bgp_node *rn;
8899 struct bgp_table *table;
8900 struct prefix *p;
8901 struct prefix_rd *prd;
8902 struct bgp_static *bgp_static;
8903 u_int32_t label;
8904 char buf[SU_ADDRSTRLEN];
8905 char rdbuf[RD_ADDRSTRLEN];
8906
8907 /* Network configuration. */
8908 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
8909 if ((table = prn->info) != NULL)
8910 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
8911 if ((bgp_static = rn->info) != NULL)
8912 {
8913 p = &rn->p;
8914 prd = (struct prefix_rd *) &prn->p;
8915
8916 /* "address-family" display. */
8917 bgp_config_write_family_header (vty, afi, safi, write);
8918
8919 /* "network" configuration display. */
8920 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
8921 label = decode_label (bgp_static->tag);
8922
8923 vty_out (vty, " network %s/%d rd %s tag %d",
8924 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
8925 p->prefixlen,
8926 rdbuf, label);
8927 vty_out (vty, "%s", VTY_NEWLINE);
8928 }
8929 return 0;
8930}
8931
8932/* Configuration of static route announcement and aggregate
8933 information. */
8934int
8935bgp_config_write_network (struct vty *vty, struct bgp *bgp,
8936 afi_t afi, safi_t safi, int *write)
8937{
8938 struct bgp_node *rn;
8939 struct prefix *p;
8940 struct bgp_static *bgp_static;
8941 struct bgp_aggregate *bgp_aggregate;
8942 char buf[SU_ADDRSTRLEN];
8943
8944 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
8945 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
8946
8947 /* Network configuration. */
8948 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
8949 if ((bgp_static = rn->info) != NULL)
8950 {
8951 p = &rn->p;
8952
8953 /* "address-family" display. */
8954 bgp_config_write_family_header (vty, afi, safi, write);
8955
8956 /* "network" configuration display. */
8957 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
8958 {
8959 u_int32_t destination;
8960 struct in_addr netmask;
8961
8962 destination = ntohl (p->u.prefix4.s_addr);
8963 masklen2ip (p->prefixlen, &netmask);
8964 vty_out (vty, " network %s",
8965 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
8966
8967 if ((IN_CLASSC (destination) && p->prefixlen == 24)
8968 || (IN_CLASSB (destination) && p->prefixlen == 16)
8969 || (IN_CLASSA (destination) && p->prefixlen == 8)
8970 || p->u.prefix4.s_addr == 0)
8971 {
8972 /* Natural mask is not display. */
8973 }
8974 else
8975 vty_out (vty, " mask %s", inet_ntoa (netmask));
8976 }
8977 else
8978 {
8979 vty_out (vty, " network %s/%d",
8980 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
8981 p->prefixlen);
8982 }
8983
8984 if (bgp_static->rmap.name)
8985 vty_out (vty, " route-map %s", bgp_static->rmap.name);
8986 else if (bgp_static->backdoor)
8987 vty_out (vty, " backdoor");
8988
8989 vty_out (vty, "%s", VTY_NEWLINE);
8990 }
8991
8992 /* Aggregate-address configuration. */
8993 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
8994 if ((bgp_aggregate = rn->info) != NULL)
8995 {
8996 p = &rn->p;
8997
8998 /* "address-family" display. */
8999 bgp_config_write_family_header (vty, afi, safi, write);
9000
9001 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
9002 {
9003 struct in_addr netmask;
9004
9005 masklen2ip (p->prefixlen, &netmask);
9006 vty_out (vty, " aggregate-address %s %s",
9007 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
9008 inet_ntoa (netmask));
9009 }
9010 else
9011 {
9012 vty_out (vty, " aggregate-address %s/%d",
9013 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
9014 p->prefixlen);
9015 }
9016
9017 if (bgp_aggregate->as_set)
9018 vty_out (vty, " as-set");
9019
9020 if (bgp_aggregate->summary_only)
9021 vty_out (vty, " summary-only");
9022
9023 vty_out (vty, "%s", VTY_NEWLINE);
9024 }
9025
9026 return 0;
9027}
9028
9029int
9030bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
9031{
9032 struct bgp_node *rn;
9033 struct bgp_distance *bdistance;
9034
9035 /* Distance configuration. */
9036 if (bgp->distance_ebgp
9037 && bgp->distance_ibgp
9038 && bgp->distance_local
9039 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
9040 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
9041 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
9042 vty_out (vty, " distance bgp %d %d %d%s",
9043 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
9044 VTY_NEWLINE);
9045
9046 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
9047 if ((bdistance = rn->info) != NULL)
9048 {
9049 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
9050 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
9051 bdistance->access_list ? bdistance->access_list : "",
9052 VTY_NEWLINE);
9053 }
9054
9055 return 0;
9056}
9057
9058/* Allocate routing table structure and install commands. */
9059void
9060bgp_route_init ()
9061{
9062 /* Init BGP distance table. */
9063 bgp_distance_table = bgp_table_init ();
9064
9065 /* IPv4 BGP commands. */
9066 install_element (BGP_NODE, &bgp_network_cmd);
9067 install_element (BGP_NODE, &bgp_network_mask_cmd);
9068 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
9069 install_element (BGP_NODE, &bgp_network_route_map_cmd);
9070 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
9071 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
9072 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
9073 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
9074 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
9075 install_element (BGP_NODE, &no_bgp_network_cmd);
9076 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
9077 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
9078 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
9079 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
9080 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
9081 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
9082 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
9083 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
9084
9085 install_element (BGP_NODE, &aggregate_address_cmd);
9086 install_element (BGP_NODE, &aggregate_address_mask_cmd);
9087 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
9088 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
9089 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
9090 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
9091 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
9092 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
9093 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
9094 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
9095 install_element (BGP_NODE, &no_aggregate_address_cmd);
9096 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
9097 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
9098 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
9099 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
9100 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
9101 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
9102 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
9103 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
9104 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
9105
9106 /* IPv4 unicast configuration. */
9107 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
9108 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
9109 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
9110 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
9111 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
9112 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
9113 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
9114 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
9115 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
9116 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
9117 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
9118 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
9119 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
9120 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
9121 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
9122 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
9123 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
9124 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
9125 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
9126 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
9127 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
9128 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
9129 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
9130 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
9131 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
9132 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
9133 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
9134 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
9135 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
9136 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
9137 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
9138 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
9139
9140 /* IPv4 multicast configuration. */
9141 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
9142 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
9143 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
9144 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
9145 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
9146 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
9147 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
9148 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
9149 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
9150 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
9151 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
9152 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
9153 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
9154 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
9155 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
9156 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
9157 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
9158 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
9159 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
9160 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
9161 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
9162 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
9163 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
9164 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
9165 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
9166 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
9167 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
9168 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
9169 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
9170 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
9171 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
9172 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
9173
9174 install_element (VIEW_NODE, &show_ip_bgp_cmd);
9175 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
9176 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
9177 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
9178 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
9179 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
9180 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
9181 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
9182 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
9183 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
9184 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
9185 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
9186 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
9187 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
9188 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
9189 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
9190 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
9191 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
9192 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
9193 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
9194 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
9195 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
9196 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
9197 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
9198 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
9199 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
9200 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
9201 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
9202 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
9203 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
9204 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
9205 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
9206 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
9207 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
9208 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
9209 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
9210 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
9211 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
9212 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
9213 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
9214 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
9215 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
9216 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
9217 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
9218 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
9219 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
9220 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
9221 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
9222 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
9223 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
9224 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
9225 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
9226 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
9227 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
9228 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
9229 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
9230 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
9231 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
9232 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
9233 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
9234 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
9235 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
9236 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
9237 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
9238 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
9239 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
9240 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
9241
9242 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
9243 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
9244 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
9245 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
9246 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
9247 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
9248 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
9249 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
9250 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
9251 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
9252 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
9253 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
9254 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
9255 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
9256 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
9257 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
9258 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
9259 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
9260 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
9261 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
9262 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
9263 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
9264 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
9265 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
9266 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
9267 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
9268 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
9269 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
9270 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
9271 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
9272 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
9273 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
9274 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
9275 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
9276 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
9277 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
9278 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
9279 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
9280 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
9281 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
9282 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
9283 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
9284 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
9285 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
9286 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
9287 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
9288 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
9289 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
9290 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
9291 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
9292 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
9293 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
9294 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
9295 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
9296 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
9297 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
9298 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
9299 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
9300 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
9301 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
9302 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
9303 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
9304 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
9305 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
9306 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
9307 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
9308 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
9309
9310 /* BGP dampening clear commands */
9311 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
9312 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
9313 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
9314 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
9315
9316#ifdef HAVE_IPV6
9317 /* New config IPv6 BGP commands. */
9318 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
9319 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
9320 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
9321 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
9322
9323 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
9324 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
9325 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
9326 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
9327
9328 /* Old config IPv6 BGP commands. */
9329 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
9330 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
9331
9332 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
9333 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
9334 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
9335 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
9336
9337 install_element (VIEW_NODE, &show_bgp_cmd);
9338 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
9339 install_element (VIEW_NODE, &show_bgp_route_cmd);
9340 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
9341 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
9342 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
9343 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
9344 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
9345 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
9346 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
9347 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
9348 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
9349 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
9350 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
9351 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
9352 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
9353 install_element (VIEW_NODE, &show_bgp_community_cmd);
9354 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
9355 install_element (VIEW_NODE, &show_bgp_community2_cmd);
9356 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
9357 install_element (VIEW_NODE, &show_bgp_community3_cmd);
9358 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
9359 install_element (VIEW_NODE, &show_bgp_community4_cmd);
9360 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
9361 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
9362 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
9363 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
9364 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
9365 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
9366 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
9367 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
9368 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
9369 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
9370 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
9371 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
9372 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
9373 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
9374 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
9375 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
9376 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
9377 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
9378 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
9379 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
9380 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
9381 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
9382 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +00009383 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
9384 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
9385 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
9386 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
9387 install_element (VIEW_NODE, &show_bgp_view_cmd);
9388 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
9389 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
9390 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
9391 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
9392 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
9393 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
9394 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
9395 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
9396 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
9397 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
9398 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
9399 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
9400 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
9401 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
9402 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
9403 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
9404 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paul718e3742002-12-13 20:15:29 +00009405
9406 install_element (ENABLE_NODE, &show_bgp_cmd);
9407 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
9408 install_element (ENABLE_NODE, &show_bgp_route_cmd);
9409 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
9410 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
9411 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
9412 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
9413 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
9414 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
9415 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
9416 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
9417 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
9418 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
9419 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
9420 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
9421 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
9422 install_element (ENABLE_NODE, &show_bgp_community_cmd);
9423 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
9424 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
9425 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
9426 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
9427 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
9428 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
9429 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
9430 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
9431 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
9432 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
9433 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
9434 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
9435 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
9436 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
9437 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
9438 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
9439 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
9440 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
9441 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
9442 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
9443 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
9444 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
9445 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
9446 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
9447 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
9448 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
9449 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
9450 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
9451 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +00009452 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
9453 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
9454 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
9455 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
9456 install_element (ENABLE_NODE, &show_bgp_view_cmd);
9457 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
9458 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
9459 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
9460 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
9461 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
9462 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
9463 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
9464 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
9465 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
9466 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
9467 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
9468 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
9469 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
9470 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
9471 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
9472 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
9473 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paul718e3742002-12-13 20:15:29 +00009474
9475 /* old command */
9476 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
9477 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
9478 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
9479 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
9480 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
9481 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
9482 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
9483 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
9484 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
9485 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
9486 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
9487 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
9488 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
9489 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
9490 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
9491 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
9492 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
9493 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
9494 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
9495 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
9496 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
9497 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
9498 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
9499 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
9500 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
9501 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
9502 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
9503 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
9504 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
9505 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
9506 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
9507 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
9508 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
9509 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
9510 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
9511 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +00009512
paul718e3742002-12-13 20:15:29 +00009513 /* old command */
9514 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
9515 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
9516 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
9517 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
9518 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
9519 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
9520 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
9521 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
9522 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
9523 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
9524 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
9525 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
9526 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
9527 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
9528 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
9529 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
9530 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
9531 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
9532 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
9533 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
9534 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
9535 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
9536 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
9537 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
9538 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
9539 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
9540 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
9541 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
9542 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
9543 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
9544 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
9545 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
9546 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
9547 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
9548 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
9549 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
9550
9551 /* old command */
9552 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
9553 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
9554 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
9555 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
9556
9557 /* old command */
9558 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
9559 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
9560 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
9561 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
9562
9563 /* old command */
9564 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
9565 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
9566 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
9567 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
9568#endif /* HAVE_IPV6 */
9569
9570 install_element (BGP_NODE, &bgp_distance_cmd);
9571 install_element (BGP_NODE, &no_bgp_distance_cmd);
9572 install_element (BGP_NODE, &no_bgp_distance2_cmd);
9573 install_element (BGP_NODE, &bgp_distance_source_cmd);
9574 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
9575 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
9576 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
9577
9578 install_element (BGP_NODE, &bgp_damp_set_cmd);
9579 install_element (BGP_NODE, &bgp_damp_set2_cmd);
9580 install_element (BGP_NODE, &bgp_damp_set3_cmd);
9581 install_element (BGP_NODE, &bgp_damp_unset_cmd);
9582 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
9583 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
9584 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
9585 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
9586 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
9587 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
9588}