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