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