Annotation of embedaddon/quagga/bgpd/bgp_route.c, revision 1.1.1.2

1.1       misho       1: /* BGP routing information
                      2:    Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
                      3: 
                      4: This file is part of GNU Zebra.
                      5: 
                      6: GNU Zebra is free software; you can redistribute it and/or modify it
                      7: under the terms of the GNU General Public License as published by the
                      8: Free Software Foundation; either version 2, or (at your option) any
                      9: later version.
                     10: 
                     11: GNU Zebra is distributed in the hope that it will be useful, but
                     12: WITHOUT ANY WARRANTY; without even the implied warranty of
                     13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                     14: General Public License for more details.
                     15: 
                     16: You should have received a copy of the GNU General Public License
                     17: along with GNU Zebra; see the file COPYING.  If not, write to the Free
                     18: Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
                     19: 02111-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: #include "workqueue.h"
                     37: 
                     38: #include "bgpd/bgpd.h"
                     39: #include "bgpd/bgp_table.h"
                     40: #include "bgpd/bgp_route.h"
                     41: #include "bgpd/bgp_attr.h"
                     42: #include "bgpd/bgp_debug.h"
                     43: #include "bgpd/bgp_aspath.h"
                     44: #include "bgpd/bgp_regex.h"
                     45: #include "bgpd/bgp_community.h"
                     46: #include "bgpd/bgp_ecommunity.h"
                     47: #include "bgpd/bgp_clist.h"
                     48: #include "bgpd/bgp_packet.h"
                     49: #include "bgpd/bgp_filter.h"
                     50: #include "bgpd/bgp_fsm.h"
                     51: #include "bgpd/bgp_mplsvpn.h"
                     52: #include "bgpd/bgp_nexthop.h"
                     53: #include "bgpd/bgp_damp.h"
                     54: #include "bgpd/bgp_advertise.h"
                     55: #include "bgpd/bgp_zebra.h"
                     56: #include "bgpd/bgp_vty.h"
1.1.1.2 ! misho      57: #include "bgpd/bgp_mpath.h"
1.1       misho      58: 
                     59: /* Extern from bgp_dump.c */
                     60: extern const char *bgp_origin_str[];
                     61: extern const char *bgp_origin_long_str[];
                     62: 
                     63: static struct bgp_node *
                     64: bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
                     65:                  struct prefix_rd *prd)
                     66: {
                     67:   struct bgp_node *rn;
                     68:   struct bgp_node *prn = NULL;
                     69:   
                     70:   assert (table);
                     71:   if (!table)
                     72:     return NULL;
                     73:   
                     74:   if (safi == SAFI_MPLS_VPN)
                     75:     {
                     76:       prn = bgp_node_get (table, (struct prefix *) prd);
                     77: 
                     78:       if (prn->info == NULL)
                     79:        prn->info = bgp_table_init (afi, safi);
                     80:       else
                     81:        bgp_unlock_node (prn);
                     82:       table = prn->info;
                     83:     }
                     84: 
                     85:   rn = bgp_node_get (table, p);
                     86: 
                     87:   if (safi == SAFI_MPLS_VPN)
                     88:     rn->prn = prn;
                     89: 
                     90:   return rn;
                     91: }
                     92: 
                     93: /* Allocate bgp_info_extra */
                     94: static struct bgp_info_extra *
                     95: bgp_info_extra_new (void)
                     96: {
                     97:   struct bgp_info_extra *new;
                     98:   new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
                     99:   return new;
                    100: }
                    101: 
                    102: static void
                    103: bgp_info_extra_free (struct bgp_info_extra **extra)
                    104: {
                    105:   if (extra && *extra)
                    106:     {
                    107:       if ((*extra)->damp_info)
                    108:         bgp_damp_info_free ((*extra)->damp_info, 0);
                    109:       
                    110:       (*extra)->damp_info = NULL;
                    111:       
                    112:       XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
                    113:       
                    114:       *extra = NULL;
                    115:     }
                    116: }
                    117: 
                    118: /* Get bgp_info extra information for the given bgp_info, lazy allocated
                    119:  * if required.
                    120:  */
                    121: struct bgp_info_extra *
                    122: bgp_info_extra_get (struct bgp_info *ri)
                    123: {
                    124:   if (!ri->extra)
                    125:     ri->extra = bgp_info_extra_new();
                    126:   return ri->extra;
                    127: }
                    128: 
                    129: /* Allocate new bgp info structure. */
                    130: static struct bgp_info *
                    131: bgp_info_new (void)
                    132: {
                    133:   return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
                    134: }
                    135: 
                    136: /* Free bgp route information. */
                    137: static void
                    138: bgp_info_free (struct bgp_info *binfo)
                    139: {
                    140:   if (binfo->attr)
                    141:     bgp_attr_unintern (&binfo->attr);
                    142:   
                    143:   bgp_info_extra_free (&binfo->extra);
1.1.1.2 ! misho     144:   bgp_info_mpath_free (&binfo->mpath);
1.1       misho     145: 
                    146:   peer_unlock (binfo->peer); /* bgp_info peer reference */
                    147: 
                    148:   XFREE (MTYPE_BGP_ROUTE, binfo);
                    149: }
                    150: 
                    151: struct bgp_info *
                    152: bgp_info_lock (struct bgp_info *binfo)
                    153: {
                    154:   binfo->lock++;
                    155:   return binfo;
                    156: }
                    157: 
                    158: struct bgp_info *
                    159: bgp_info_unlock (struct bgp_info *binfo)
                    160: {
                    161:   assert (binfo && binfo->lock > 0);
                    162:   binfo->lock--;
                    163:   
                    164:   if (binfo->lock == 0)
                    165:     {
                    166: #if 0
                    167:       zlog_debug ("%s: unlocked and freeing", __func__);
                    168:       zlog_backtrace (LOG_DEBUG);
                    169: #endif
                    170:       bgp_info_free (binfo);
                    171:       return NULL;
                    172:     }
                    173: 
                    174: #if 0
                    175:   if (binfo->lock == 1)
                    176:     {
                    177:       zlog_debug ("%s: unlocked to 1", __func__);
                    178:       zlog_backtrace (LOG_DEBUG);
                    179:     }
                    180: #endif
                    181:   
                    182:   return binfo;
                    183: }
                    184: 
                    185: void
                    186: bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
                    187: {
                    188:   struct bgp_info *top;
                    189: 
                    190:   top = rn->info;
                    191:   
                    192:   ri->next = rn->info;
                    193:   ri->prev = NULL;
                    194:   if (top)
                    195:     top->prev = ri;
                    196:   rn->info = ri;
                    197:   
                    198:   bgp_info_lock (ri);
                    199:   bgp_lock_node (rn);
                    200:   peer_lock (ri->peer); /* bgp_info peer reference */
                    201: }
                    202: 
                    203: /* Do the actual removal of info from RIB, for use by bgp_process 
                    204:    completion callback *only* */
                    205: static void
                    206: bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
                    207: {
                    208:   if (ri->next)
                    209:     ri->next->prev = ri->prev;
                    210:   if (ri->prev)
                    211:     ri->prev->next = ri->next;
                    212:   else
                    213:     rn->info = ri->next;
                    214:   
1.1.1.2 ! misho     215:   bgp_info_mpath_dequeue (ri);
1.1       misho     216:   bgp_info_unlock (ri);
                    217:   bgp_unlock_node (rn);
                    218: }
                    219: 
                    220: void
                    221: bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
                    222: {
                    223:   bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
                    224:   /* set of previous already took care of pcount */
                    225:   UNSET_FLAG (ri->flags, BGP_INFO_VALID);
                    226: }
                    227: 
                    228: /* undo the effects of a previous call to bgp_info_delete; typically
                    229:    called when a route is deleted and then quickly re-added before the
                    230:    deletion has been processed */
                    231: static void
                    232: bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
                    233: {
                    234:   bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
                    235:   /* unset of previous already took care of pcount */
                    236:   SET_FLAG (ri->flags, BGP_INFO_VALID);
                    237: }
                    238: 
                    239: /* Adjust pcount as required */   
                    240: static void
                    241: bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
                    242: {
                    243:   assert (rn && rn->table);
                    244:   assert (ri && ri->peer && ri->peer->bgp);
                    245: 
                    246:   /* Ignore 'pcount' for RS-client tables */
                    247:   if (rn->table->type != BGP_TABLE_MAIN
                    248:       || ri->peer == ri->peer->bgp->peer_self)
                    249:     return;
                    250:     
                    251:   if (BGP_INFO_HOLDDOWN (ri)
                    252:       && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
                    253:     {
                    254:           
                    255:       UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
                    256:       
                    257:       /* slight hack, but more robust against errors. */
                    258:       if (ri->peer->pcount[rn->table->afi][rn->table->safi])
                    259:         ri->peer->pcount[rn->table->afi][rn->table->safi]--;
                    260:       else
                    261:         {
                    262:           zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
                    263:                      __func__, ri->peer->host);
                    264:           zlog_backtrace (LOG_WARNING);
                    265:           zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
                    266:         }      
                    267:     }
                    268:   else if (!BGP_INFO_HOLDDOWN (ri) 
                    269:            && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
                    270:     {
                    271:       SET_FLAG (ri->flags, BGP_INFO_COUNTED);
                    272:       ri->peer->pcount[rn->table->afi][rn->table->safi]++;
                    273:     }
                    274: }
                    275: 
                    276: 
                    277: /* Set/unset bgp_info flags, adjusting any other state as needed.
                    278:  * This is here primarily to keep prefix-count in check.
                    279:  */
                    280: void
                    281: bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
                    282: {
                    283:   SET_FLAG (ri->flags, flag);
                    284:   
                    285:   /* early bath if we know it's not a flag that changes useability state */
                    286:   if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
                    287:     return;
                    288:   
                    289:   bgp_pcount_adjust (rn, ri);
                    290: }
                    291: 
                    292: void
                    293: bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
                    294: {
                    295:   UNSET_FLAG (ri->flags, flag);
                    296:   
                    297:   /* early bath if we know it's not a flag that changes useability state */
                    298:   if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
                    299:     return;
                    300:   
                    301:   bgp_pcount_adjust (rn, ri);
                    302: }
                    303: 
                    304: /* Get MED value.  If MED value is missing and "bgp bestpath
                    305:    missing-as-worst" is specified, treat it as the worst value. */
                    306: static u_int32_t
                    307: bgp_med_value (struct attr *attr, struct bgp *bgp)
                    308: {
                    309:   if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
                    310:     return attr->med;
                    311:   else
                    312:     {
                    313:       if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
                    314:        return BGP_MED_MAX;
                    315:       else
                    316:        return 0;
                    317:     }
                    318: }
                    319: 
                    320: /* Compare two bgp route entity.  br is preferable then return 1. */
                    321: static int
1.1.1.2 ! misho     322: bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
        !           323:              int *paths_eq)
1.1       misho     324: {
                    325:   u_int32_t new_pref;
                    326:   u_int32_t exist_pref;
                    327:   u_int32_t new_med;
                    328:   u_int32_t exist_med;
                    329:   u_int32_t new_weight = 0;
                    330:   u_int32_t exist_weight = 0;
                    331:   struct in_addr new_id;
                    332:   struct in_addr exist_id;
                    333:   int new_cluster;
                    334:   int exist_cluster;
                    335:   int internal_as_route = 0;
                    336:   int confed_as_route = 0;
                    337:   int ret;
1.1.1.2 ! misho     338:   uint32_t newm, existm;
        !           339: 
        !           340:   *paths_eq = 0;
1.1       misho     341: 
                    342:   /* 0. Null check. */
                    343:   if (new == NULL)
                    344:     return 0;
                    345:   if (exist == NULL)
                    346:     return 1;
                    347: 
                    348:   /* 1. Weight check. */
                    349:   if (new->attr->extra)
                    350:     new_weight = new->attr->extra->weight;
                    351:   if (exist->attr->extra)
                    352:     exist_weight = exist->attr->extra->weight;
                    353:   if (new_weight > exist_weight)
                    354:     return 1;
                    355:   if (new_weight < exist_weight)
                    356:     return 0;
                    357: 
                    358:   /* 2. Local preference check. */
                    359:   if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
                    360:     new_pref = new->attr->local_pref;
                    361:   else
                    362:     new_pref = bgp->default_local_pref;
                    363: 
                    364:   if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
                    365:     exist_pref = exist->attr->local_pref;
                    366:   else
                    367:     exist_pref = bgp->default_local_pref;
                    368:     
                    369:   if (new_pref > exist_pref)
                    370:     return 1;
                    371:   if (new_pref < exist_pref)
                    372:     return 0;
                    373: 
                    374:   /* 3. Local route check. */
                    375:   if (new->sub_type == BGP_ROUTE_STATIC)
                    376:     return 1;
                    377:   if (exist->sub_type == BGP_ROUTE_STATIC)
                    378:     return 0;
                    379: 
                    380:   if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
                    381:     return 1;
                    382:   if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
                    383:     return 0;
                    384: 
                    385:   if (new->sub_type == BGP_ROUTE_AGGREGATE)
                    386:     return 1;
                    387:   if (exist->sub_type == BGP_ROUTE_AGGREGATE)
                    388:     return 0;
                    389: 
                    390:   /* 4. AS path length check. */
                    391:   if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
                    392:     {
                    393:       int exist_hops = aspath_count_hops (exist->attr->aspath);
                    394:       int exist_confeds = aspath_count_confeds (exist->attr->aspath);
                    395:       
                    396:       if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
                    397:        {
                    398:          int aspath_hops;
                    399:          
                    400:          aspath_hops = aspath_count_hops (new->attr->aspath);
                    401:           aspath_hops += aspath_count_confeds (new->attr->aspath);
                    402:           
                    403:          if ( aspath_hops < (exist_hops + exist_confeds))
                    404:            return 1;
                    405:          if ( aspath_hops > (exist_hops + exist_confeds))
                    406:            return 0;
                    407:        }
                    408:       else
                    409:        {
                    410:          int newhops = aspath_count_hops (new->attr->aspath);
                    411:          
                    412:          if (newhops < exist_hops)
                    413:            return 1;
                    414:           if (newhops > exist_hops)
                    415:            return 0;
                    416:        }
                    417:     }
                    418: 
                    419:   /* 5. Origin check. */
                    420:   if (new->attr->origin < exist->attr->origin)
                    421:     return 1;
                    422:   if (new->attr->origin > exist->attr->origin)
                    423:     return 0;
                    424: 
                    425:   /* 6. MED check. */
                    426:   internal_as_route = (aspath_count_hops (new->attr->aspath) == 0
                    427:                      && aspath_count_hops (exist->attr->aspath) == 0);
                    428:   confed_as_route = (aspath_count_confeds (new->attr->aspath) > 0
                    429:                    && aspath_count_confeds (exist->attr->aspath) > 0
                    430:                    && aspath_count_hops (new->attr->aspath) == 0
                    431:                    && aspath_count_hops (exist->attr->aspath) == 0);
                    432:   
                    433:   if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
                    434:       || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
                    435:         && confed_as_route)
                    436:       || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
                    437:       || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
                    438:       || internal_as_route)
                    439:     {
                    440:       new_med = bgp_med_value (new->attr, bgp);
                    441:       exist_med = bgp_med_value (exist->attr, bgp);
                    442: 
                    443:       if (new_med < exist_med)
                    444:        return 1;
                    445:       if (new_med > exist_med)
                    446:        return 0;
                    447:     }
                    448: 
                    449:   /* 7. Peer type check. */
                    450:   if (peer_sort (new->peer) == BGP_PEER_EBGP 
                    451:       && peer_sort (exist->peer) == BGP_PEER_IBGP)
                    452:     return 1;
                    453:   if (peer_sort (new->peer) == BGP_PEER_EBGP 
                    454:       && peer_sort (exist->peer) == BGP_PEER_CONFED)
                    455:     return 1;
                    456:   if (peer_sort (new->peer) == BGP_PEER_IBGP 
                    457:       && peer_sort (exist->peer) == BGP_PEER_EBGP)
                    458:     return 0;
                    459:   if (peer_sort (new->peer) == BGP_PEER_CONFED 
                    460:       && peer_sort (exist->peer) == BGP_PEER_EBGP)
                    461:     return 0;
                    462: 
                    463:   /* 8. IGP metric check. */
1.1.1.2 ! misho     464:   newm = (new->extra ? new->extra->igpmetric : 0);
        !           465:   existm = (exist->extra ? exist->extra->igpmetric : 0);
        !           466:   if (newm < existm)
        !           467:     ret = 1;
        !           468:   if (newm > existm)
        !           469:     ret = 0;
1.1       misho     470: 
                    471:   /* 9. Maximum path check. */
1.1.1.2 ! misho     472:   if (newm == existm)
        !           473:     {
        !           474:       if ((peer_sort (new->peer) == BGP_PEER_IBGP))
        !           475:        {
        !           476:          if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
        !           477:            *paths_eq = 1;
        !           478:        }
        !           479:       else if (new->peer->as == exist->peer->as)
        !           480:        *paths_eq = 1;
        !           481:     }
        !           482:   else
        !           483:     {
        !           484:       /*
        !           485:        * TODO: If unequal cost ibgp multipath is enabled we can
        !           486:        * mark the paths as equal here instead of returning
        !           487:        */
        !           488:       return ret;
        !           489:     }
1.1       misho     490: 
                    491:   /* 10. If both paths are external, prefer the path that was received
                    492:      first (the oldest one).  This step minimizes route-flap, since a
                    493:      newer path won't displace an older one, even if it was the
                    494:      preferred route based on the additional decision criteria below.  */
                    495:   if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
                    496:       && peer_sort (new->peer) == BGP_PEER_EBGP
                    497:       && peer_sort (exist->peer) == BGP_PEER_EBGP)
                    498:     {
                    499:       if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
                    500:        return 1;
                    501:       if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
                    502:        return 0;
                    503:     }
                    504: 
                    505:   /* 11. Rourter-ID comparision. */
                    506:   if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
                    507:     new_id.s_addr = new->attr->extra->originator_id.s_addr;
                    508:   else
                    509:     new_id.s_addr = new->peer->remote_id.s_addr;
                    510:   if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
                    511:     exist_id.s_addr = exist->attr->extra->originator_id.s_addr;
                    512:   else
                    513:     exist_id.s_addr = exist->peer->remote_id.s_addr;
                    514: 
                    515:   if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
                    516:     return 1;
                    517:   if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
                    518:     return 0;
                    519: 
                    520:   /* 12. Cluster length comparision. */
                    521:   if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
                    522:     new_cluster = new->attr->extra->cluster->length;
                    523:   else
                    524:     new_cluster = 0;
                    525:   if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
                    526:     exist_cluster = exist->attr->extra->cluster->length;
                    527:   else
                    528:     exist_cluster = 0;
                    529: 
                    530:   if (new_cluster < exist_cluster)
                    531:     return 1;
                    532:   if (new_cluster > exist_cluster)
                    533:     return 0;
                    534: 
                    535:   /* 13. Neighbor address comparision. */
                    536:   ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
                    537: 
                    538:   if (ret == 1)
                    539:     return 0;
                    540:   if (ret == -1)
                    541:     return 1;
                    542: 
                    543:   return 1;
                    544: }
                    545: 
                    546: static enum filter_type
                    547: bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
                    548:                  afi_t afi, safi_t safi)
                    549: {
                    550:   struct bgp_filter *filter;
                    551: 
                    552:   filter = &peer->filter[afi][safi];
                    553: 
                    554: #define FILTER_EXIST_WARN(F,f,filter) \
                    555:   if (BGP_DEBUG (update, UPDATE_IN) \
                    556:       && !(F ## _IN (filter))) \
                    557:     plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
                    558:                peer->host, #f, F ## _IN_NAME(filter));
                    559:   
                    560:   if (DISTRIBUTE_IN_NAME (filter)) {
                    561:     FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
                    562:       
                    563:     if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
                    564:       return FILTER_DENY;
                    565:   }
                    566: 
                    567:   if (PREFIX_LIST_IN_NAME (filter)) {
                    568:     FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
                    569:     
                    570:     if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
                    571:       return FILTER_DENY;
                    572:   }
                    573:   
                    574:   if (FILTER_LIST_IN_NAME (filter)) {
                    575:     FILTER_EXIST_WARN(FILTER_LIST, as, filter);
                    576:     
                    577:     if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
                    578:       return FILTER_DENY;
                    579:   }
                    580:   
                    581:   return FILTER_PERMIT;
                    582: #undef FILTER_EXIST_WARN
                    583: }
                    584: 
                    585: static enum filter_type
                    586: bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
                    587:                   afi_t afi, safi_t safi)
                    588: {
                    589:   struct bgp_filter *filter;
                    590: 
                    591:   filter = &peer->filter[afi][safi];
                    592: 
                    593: #define FILTER_EXIST_WARN(F,f,filter) \
                    594:   if (BGP_DEBUG (update, UPDATE_OUT) \
                    595:       && !(F ## _OUT (filter))) \
                    596:     plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
                    597:                peer->host, #f, F ## _OUT_NAME(filter));
                    598: 
                    599:   if (DISTRIBUTE_OUT_NAME (filter)) {
                    600:     FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
                    601:     
                    602:     if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
                    603:       return FILTER_DENY;
                    604:   }
                    605: 
                    606:   if (PREFIX_LIST_OUT_NAME (filter)) {
                    607:     FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
                    608:     
                    609:     if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
                    610:       return FILTER_DENY;
                    611:   }
                    612: 
                    613:   if (FILTER_LIST_OUT_NAME (filter)) {
                    614:     FILTER_EXIST_WARN(FILTER_LIST, as, filter);
                    615:     
                    616:     if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
                    617:       return FILTER_DENY;
                    618:   }
                    619: 
                    620:   return FILTER_PERMIT;
                    621: #undef FILTER_EXIST_WARN
                    622: }
                    623: 
                    624: /* If community attribute includes no_export then return 1. */
                    625: static int
                    626: bgp_community_filter (struct peer *peer, struct attr *attr)
                    627: {
                    628:   if (attr->community)
                    629:     {
                    630:       /* NO_ADVERTISE check. */
                    631:       if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
                    632:        return 1;
                    633: 
                    634:       /* NO_EXPORT check. */
                    635:       if (peer_sort (peer) == BGP_PEER_EBGP &&
                    636:          community_include (attr->community, COMMUNITY_NO_EXPORT))
                    637:        return 1;
                    638: 
                    639:       /* NO_EXPORT_SUBCONFED check. */
                    640:       if (peer_sort (peer) == BGP_PEER_EBGP 
                    641:          || peer_sort (peer) == BGP_PEER_CONFED)
                    642:        if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
                    643:          return 1;
                    644:     }
                    645:   return 0;
                    646: }
                    647: 
                    648: /* Route reflection loop check.  */
                    649: static int
                    650: bgp_cluster_filter (struct peer *peer, struct attr *attr)
                    651: {
                    652:   struct in_addr cluster_id;
                    653: 
                    654:   if (attr->extra && attr->extra->cluster)
                    655:     {
                    656:       if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
                    657:        cluster_id = peer->bgp->cluster_id;
                    658:       else
                    659:        cluster_id = peer->bgp->router_id;
                    660:       
                    661:       if (cluster_loop_check (attr->extra->cluster, cluster_id))
                    662:        return 1;
                    663:     }
                    664:   return 0;
                    665: }
                    666: 
                    667: static int
                    668: bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
                    669:                    afi_t afi, safi_t safi)
                    670: {
                    671:   struct bgp_filter *filter;
                    672:   struct bgp_info info;
                    673:   route_map_result_t ret;
                    674: 
                    675:   filter = &peer->filter[afi][safi];
                    676: 
                    677:   /* Apply default weight value. */
                    678:   if (peer->weight)
                    679:     (bgp_attr_extra_get (attr))->weight = peer->weight;
                    680: 
                    681:   /* Route map apply. */
                    682:   if (ROUTE_MAP_IN_NAME (filter))
                    683:     {
                    684:       /* Duplicate current value to new strucutre for modification. */
                    685:       info.peer = peer;
                    686:       info.attr = attr;
                    687: 
                    688:       SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN); 
                    689: 
                    690:       /* Apply BGP route map to the attribute. */
                    691:       ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
                    692: 
                    693:       peer->rmap_type = 0;
                    694: 
                    695:       if (ret == RMAP_DENYMATCH)
                    696:        {
                    697:          /* Free newly generated AS path and community by route-map. */
                    698:          bgp_attr_flush (attr);
                    699:          return RMAP_DENY;
                    700:        }
                    701:     }
                    702:   return RMAP_PERMIT;
                    703: }
                    704: 
                    705: static int
                    706: bgp_export_modifier (struct peer *rsclient, struct peer *peer,
                    707:         struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
                    708: {
                    709:   struct bgp_filter *filter;
                    710:   struct bgp_info info;
                    711:   route_map_result_t ret;
                    712: 
                    713:   filter = &peer->filter[afi][safi];
                    714: 
                    715:   /* Route map apply. */
                    716:   if (ROUTE_MAP_EXPORT_NAME (filter))
                    717:     {
                    718:       /* Duplicate current value to new strucutre for modification. */
                    719:       info.peer = rsclient;
                    720:       info.attr = attr;
                    721: 
                    722:       SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
                    723: 
                    724:       /* Apply BGP route map to the attribute. */
                    725:       ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
                    726: 
                    727:       rsclient->rmap_type = 0;
                    728: 
                    729:       if (ret == RMAP_DENYMATCH)
                    730:         {
                    731:           /* Free newly generated AS path and community by route-map. */
                    732:           bgp_attr_flush (attr);
                    733:           return RMAP_DENY;
                    734:         }
                    735:     }
                    736:   return RMAP_PERMIT;
                    737: }
                    738: 
                    739: static int
                    740: bgp_import_modifier (struct peer *rsclient, struct peer *peer,
                    741:         struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
                    742: {
                    743:   struct bgp_filter *filter;
                    744:   struct bgp_info info;
                    745:   route_map_result_t ret;
                    746: 
                    747:   filter = &rsclient->filter[afi][safi];
                    748: 
                    749:   /* Apply default weight value. */
                    750:   if (peer->weight)
                    751:     (bgp_attr_extra_get (attr))->weight = peer->weight;
                    752: 
                    753:   /* Route map apply. */
                    754:   if (ROUTE_MAP_IMPORT_NAME (filter))
                    755:     {
                    756:       /* Duplicate current value to new strucutre for modification. */
                    757:       info.peer = peer;
                    758:       info.attr = attr;
                    759: 
                    760:       SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
                    761: 
                    762:       /* Apply BGP route map to the attribute. */
                    763:       ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
                    764: 
                    765:       peer->rmap_type = 0;
                    766: 
                    767:       if (ret == RMAP_DENYMATCH)
                    768:         {
                    769:           /* Free newly generated AS path and community by route-map. */
                    770:           bgp_attr_flush (attr);
                    771:           return RMAP_DENY;
                    772:         }
                    773:     }
                    774:   return RMAP_PERMIT;
                    775: }
                    776: 
                    777: static int
                    778: bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
                    779:                    struct attr *attr, afi_t afi, safi_t safi)
                    780: {
                    781:   int ret;
                    782:   char buf[SU_ADDRSTRLEN];
                    783:   struct bgp_filter *filter;
                    784:   struct peer *from;
                    785:   struct bgp *bgp;
                    786:   int transparent;
                    787:   int reflect;
1.1.1.2 ! misho     788:   struct attr *riattr;
1.1       misho     789: 
                    790:   from = ri->peer;
                    791:   filter = &peer->filter[afi][safi];
                    792:   bgp = peer->bgp;
1.1.1.2 ! misho     793:   riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1.1       misho     794:   
                    795:   if (DISABLE_BGP_ANNOUNCE)
                    796:     return 0;
                    797: 
                    798:   /* Do not send announces to RS-clients from the 'normal' bgp_table. */
                    799:   if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
                    800:     return 0;
                    801: 
                    802:   /* Do not send back route to sender. */
                    803:   if (from == peer)
                    804:     return 0;
                    805: 
                    806:   /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
                    807:   if (p->family == AF_INET
1.1.1.2 ! misho     808:       && IPV4_ADDR_SAME(&peer->remote_id, &riattr->nexthop))
1.1       misho     809:     return 0;
                    810: #ifdef HAVE_IPV6
                    811:   if (p->family == AF_INET6
1.1.1.2 ! misho     812:      && IPV6_ADDR_SAME(&peer->remote_id, &riattr->nexthop))
1.1       misho     813:     return 0;
                    814: #endif
                    815: 
                    816:   /* Aggregate-address suppress check. */
                    817:   if (ri->extra && ri->extra->suppress)
                    818:     if (! UNSUPPRESS_MAP_NAME (filter))
                    819:       return 0;
                    820: 
                    821:   /* Default route check.  */
                    822:   if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
                    823:     {
                    824:       if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
                    825:        return 0;
                    826: #ifdef HAVE_IPV6
                    827:       else if (p->family == AF_INET6 && p->prefixlen == 0)
                    828:        return 0;
                    829: #endif /* HAVE_IPV6 */
                    830:     }
                    831: 
                    832:   /* Transparency check. */
                    833:   if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
                    834:       && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
                    835:     transparent = 1;
                    836:   else
                    837:     transparent = 0;
                    838: 
                    839:   /* If community is not disabled check the no-export and local. */
1.1.1.2 ! misho     840:   if (! transparent && bgp_community_filter (peer, riattr))
1.1       misho     841:     return 0;
                    842: 
                    843:   /* If the attribute has originator-id and it is same as remote
                    844:      peer's id. */
1.1.1.2 ! misho     845:   if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1.1       misho     846:     {
1.1.1.2 ! misho     847:       if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
1.1       misho     848:        {
                    849:          if (BGP_DEBUG (filter, FILTER))  
                    850:            zlog (peer->log, LOG_DEBUG,
                    851:                  "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
                    852:                  peer->host,
                    853:                  inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                    854:                  p->prefixlen);
                    855:          return 0;
                    856:        }
                    857:     }
                    858:  
                    859:   /* ORF prefix-list filter check */
                    860:   if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
                    861:       && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
                    862:          || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
                    863:     if (peer->orf_plist[afi][safi])
                    864:       {
                    865:        if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
                    866:           return 0;
                    867:       }
                    868: 
                    869:   /* Output filter check. */
1.1.1.2 ! misho     870:   if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
1.1       misho     871:     {
                    872:       if (BGP_DEBUG (filter, FILTER))
                    873:        zlog (peer->log, LOG_DEBUG,
                    874:              "%s [Update:SEND] %s/%d is filtered",
                    875:              peer->host,
                    876:              inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                    877:              p->prefixlen);
                    878:       return 0;
                    879:     }
                    880: 
                    881: #ifdef BGP_SEND_ASPATH_CHECK
                    882:   /* AS path loop check. */
1.1.1.2 ! misho     883:   if (aspath_loop_check (riattr->aspath, peer->as))
1.1       misho     884:     {
                    885:       if (BGP_DEBUG (filter, FILTER))  
                    886:         zlog (peer->log, LOG_DEBUG, 
                    887:              "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
                    888:              peer->host, peer->as);
                    889:       return 0;
                    890:     }
                    891: #endif /* BGP_SEND_ASPATH_CHECK */
                    892: 
                    893:   /* If we're a CONFED we need to loop check the CONFED ID too */
                    894:   if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
                    895:     {
1.1.1.2 ! misho     896:       if (aspath_loop_check(riattr->aspath, bgp->confed_id))
1.1       misho     897:        {
                    898:          if (BGP_DEBUG (filter, FILTER))  
                    899:            zlog (peer->log, LOG_DEBUG, 
                    900:                  "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
                    901:                  peer->host,
                    902:                  bgp->confed_id);
                    903:          return 0;
                    904:        }      
                    905:     }
                    906: 
                    907:   /* Route-Reflect check. */
                    908:   if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
                    909:     reflect = 1;
                    910:   else
                    911:     reflect = 0;
                    912: 
                    913:   /* IBGP reflection check. */
                    914:   if (reflect)
                    915:     {
                    916:       /* A route from a Client peer. */
                    917:       if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
                    918:        {
                    919:          /* Reflect to all the Non-Client peers and also to the
                    920:              Client peers other than the originator.  Originator check
                    921:              is already done.  So there is noting to do. */
                    922:          /* no bgp client-to-client reflection check. */
                    923:          if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
                    924:            if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
                    925:              return 0;
                    926:        }
                    927:       else
                    928:        {
                    929:          /* A route from a Non-client peer. Reflect to all other
                    930:             clients. */
                    931:          if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
                    932:            return 0;
                    933:        }
                    934:     }
                    935:   
                    936:   /* For modify attribute, copy it to temporary structure. */
1.1.1.2 ! misho     937:   bgp_attr_dup (attr, riattr);
1.1       misho     938:   
                    939:   /* If local-preference is not set. */
                    940:   if ((peer_sort (peer) == BGP_PEER_IBGP 
                    941:        || peer_sort (peer) == BGP_PEER_CONFED) 
                    942:       && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
                    943:     {
                    944:       attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
                    945:       attr->local_pref = bgp->default_local_pref;
                    946:     }
                    947: 
                    948:   /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
                    949:   if (peer_sort (peer) == BGP_PEER_EBGP 
                    950:       && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
                    951:     {
                    952:       if (ri->peer != bgp->peer_self && ! transparent
                    953:          && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
                    954:        attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
                    955:     }
                    956: 
                    957:   /* next-hop-set */
                    958:   if (transparent || reflect
                    959:       || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
                    960:          && ((p->family == AF_INET && attr->nexthop.s_addr)
                    961: #ifdef HAVE_IPV6
                    962:              || (p->family == AF_INET6 && 
                    963:                   ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
                    964: #endif /* HAVE_IPV6 */
                    965:              )))
                    966:     {
                    967:       /* NEXT-HOP Unchanged. */
                    968:     }
                    969:   else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
                    970:           || (p->family == AF_INET && attr->nexthop.s_addr == 0)
                    971: #ifdef HAVE_IPV6
                    972:           || (p->family == AF_INET6 && 
                    973:                IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
                    974: #endif /* HAVE_IPV6 */
                    975:           || (peer_sort (peer) == BGP_PEER_EBGP
                    976:               && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
                    977:     {
                    978:       /* Set IPv4 nexthop. */
                    979:       if (p->family == AF_INET)
                    980:        {
                    981:          if (safi == SAFI_MPLS_VPN)
                    982:            memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
                    983:                    IPV4_MAX_BYTELEN);
                    984:          else
                    985:            memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
                    986:        }
                    987: #ifdef HAVE_IPV6
                    988:       /* Set IPv6 nexthop. */
                    989:       if (p->family == AF_INET6)
                    990:        {
                    991:          /* IPv6 global nexthop must be included. */
                    992:          memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global, 
                    993:                  IPV6_MAX_BYTELEN);
                    994:          attr->extra->mp_nexthop_len = 16;
                    995:        }
                    996: #endif /* HAVE_IPV6 */
                    997:     }
                    998: 
                    999: #ifdef HAVE_IPV6
                   1000:   if (p->family == AF_INET6)
                   1001:     {
                   1002:       /* Left nexthop_local unchanged if so configured. */ 
                   1003:       if ( CHECK_FLAG (peer->af_flags[afi][safi], 
                   1004:            PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
                   1005:         {
                   1006:           if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
                   1007:             attr->extra->mp_nexthop_len=32;
                   1008:           else
                   1009:             attr->extra->mp_nexthop_len=16;
                   1010:         }
                   1011: 
                   1012:       /* Default nexthop_local treatment for non-RS-Clients */
                   1013:       else 
                   1014:         {
                   1015:       /* Link-local address should not be transit to different peer. */
                   1016:       attr->extra->mp_nexthop_len = 16;
                   1017: 
                   1018:       /* Set link-local address for shared network peer. */
                   1019:       if (peer->shared_network 
                   1020:          && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
                   1021:        {
                   1022:          memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local, 
                   1023:                  IPV6_MAX_BYTELEN);
                   1024:          attr->extra->mp_nexthop_len = 32;
                   1025:        }
                   1026: 
                   1027:       /* If bgpd act as BGP-4+ route-reflector, do not send link-local
                   1028:         address.*/
                   1029:       if (reflect)
                   1030:        attr->extra->mp_nexthop_len = 16;
                   1031: 
                   1032:       /* If BGP-4+ link-local nexthop is not link-local nexthop. */
                   1033:       if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
                   1034:        attr->extra->mp_nexthop_len = 16;
                   1035:     }
                   1036: 
                   1037:     }
                   1038: #endif /* HAVE_IPV6 */
                   1039: 
                   1040:   /* If this is EBGP peer and remove-private-AS is set.  */
                   1041:   if (peer_sort (peer) == BGP_PEER_EBGP
                   1042:       && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
                   1043:       && aspath_private_as_check (attr->aspath))
                   1044:     attr->aspath = aspath_empty_get ();
                   1045: 
                   1046:   /* Route map & unsuppress-map apply. */
                   1047:   if (ROUTE_MAP_OUT_NAME (filter)
                   1048:       || (ri->extra && ri->extra->suppress) )
                   1049:     {
                   1050:       struct bgp_info info;
                   1051:       struct attr dummy_attr = { 0 };
                   1052:       
                   1053:       info.peer = peer;
                   1054:       info.attr = attr;
                   1055: 
                   1056:       /* The route reflector is not allowed to modify the attributes
                   1057:         of the reflected IBGP routes. */
                   1058:       if (peer_sort (from) == BGP_PEER_IBGP 
                   1059:          && peer_sort (peer) == BGP_PEER_IBGP)
                   1060:        {
                   1061:          bgp_attr_dup (&dummy_attr, attr);
                   1062:          info.attr = &dummy_attr;
                   1063:        }
                   1064: 
                   1065:       SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT); 
                   1066: 
                   1067:       if (ri->extra && ri->extra->suppress)
                   1068:        ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
                   1069:       else
                   1070:        ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
                   1071: 
                   1072:       peer->rmap_type = 0;
                   1073:       
                   1074:       if (dummy_attr.extra)
                   1075:         bgp_attr_extra_free (&dummy_attr);
                   1076:       
                   1077:       if (ret == RMAP_DENYMATCH)
                   1078:        {
                   1079:          bgp_attr_flush (attr);
                   1080:          return 0;
                   1081:        }
                   1082:     }
                   1083:   return 1;
                   1084: }
                   1085: 
                   1086: static int
                   1087: bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
                   1088:         struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
                   1089: {
                   1090:   int ret;
                   1091:   char buf[SU_ADDRSTRLEN];
                   1092:   struct bgp_filter *filter;
                   1093:   struct bgp_info info;
                   1094:   struct peer *from;
1.1.1.2 ! misho    1095:   struct attr *riattr;
1.1       misho    1096: 
                   1097:   from = ri->peer;
                   1098:   filter = &rsclient->filter[afi][safi];
1.1.1.2 ! misho    1099:   riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
1.1       misho    1100: 
                   1101:   if (DISABLE_BGP_ANNOUNCE)
                   1102:     return 0;
                   1103: 
                   1104:   /* Do not send back route to sender. */
                   1105:   if (from == rsclient)
                   1106:     return 0;
                   1107: 
                   1108:   /* Aggregate-address suppress check. */
                   1109:   if (ri->extra && ri->extra->suppress)
                   1110:     if (! UNSUPPRESS_MAP_NAME (filter))
                   1111:       return 0;
                   1112: 
                   1113:   /* Default route check.  */
                   1114:   if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
                   1115:           PEER_STATUS_DEFAULT_ORIGINATE))
                   1116:     {
                   1117:       if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
                   1118:         return 0;
                   1119: #ifdef HAVE_IPV6
                   1120:       else if (p->family == AF_INET6 && p->prefixlen == 0)
                   1121:         return 0;
                   1122: #endif /* HAVE_IPV6 */
                   1123:     }
                   1124: 
                   1125:   /* If the attribute has originator-id and it is same as remote
                   1126:      peer's id. */
1.1.1.2 ! misho    1127:   if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1.1       misho    1128:     {
                   1129:       if (IPV4_ADDR_SAME (&rsclient->remote_id, 
1.1.1.2 ! misho    1130:                           &riattr->extra->originator_id))
1.1       misho    1131:         {
                   1132:          if (BGP_DEBUG (filter, FILTER))
                   1133:            zlog (rsclient->log, LOG_DEBUG,
                   1134:                  "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
                   1135:                  rsclient->host,
                   1136:                  inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   1137:                  p->prefixlen);
                   1138:          return 0;
                   1139:        }
                   1140:     }
                   1141: 
                   1142:   /* ORF prefix-list filter check */
                   1143:   if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
                   1144:       && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
                   1145:          || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
                   1146:     if (rsclient->orf_plist[afi][safi])
                   1147:       {
                   1148:        if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
                   1149:           return 0;
                   1150:       }
                   1151: 
                   1152:   /* Output filter check. */
1.1.1.2 ! misho    1153:   if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
1.1       misho    1154:     {
                   1155:       if (BGP_DEBUG (filter, FILTER))
                   1156:        zlog (rsclient->log, LOG_DEBUG,
                   1157:              "%s [Update:SEND] %s/%d is filtered",
                   1158:              rsclient->host,
                   1159:              inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   1160:              p->prefixlen);
                   1161:       return 0;
                   1162:     }
                   1163: 
                   1164: #ifdef BGP_SEND_ASPATH_CHECK
                   1165:   /* AS path loop check. */
1.1.1.2 ! misho    1166:   if (aspath_loop_check (riattr->aspath, rsclient->as))
1.1       misho    1167:     {
                   1168:       if (BGP_DEBUG (filter, FILTER))
                   1169:         zlog (rsclient->log, LOG_DEBUG,
                   1170:              "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
                   1171:              rsclient->host, rsclient->as);
                   1172:       return 0;
                   1173:     }
                   1174: #endif /* BGP_SEND_ASPATH_CHECK */
                   1175: 
                   1176:   /* For modify attribute, copy it to temporary structure. */
1.1.1.2 ! misho    1177:   bgp_attr_dup (attr, riattr);
1.1       misho    1178: 
                   1179:   /* next-hop-set */
                   1180:   if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
                   1181: #ifdef HAVE_IPV6
                   1182:           || (p->family == AF_INET6 &&
                   1183:               IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
                   1184: #endif /* HAVE_IPV6 */
                   1185:      )
                   1186:   {
                   1187:     /* Set IPv4 nexthop. */
                   1188:     if (p->family == AF_INET)
                   1189:       {
                   1190:         if (safi == SAFI_MPLS_VPN)
                   1191:           memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
                   1192:                   IPV4_MAX_BYTELEN);
                   1193:         else
                   1194:           memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
                   1195:       }
                   1196: #ifdef HAVE_IPV6
                   1197:     /* Set IPv6 nexthop. */
                   1198:     if (p->family == AF_INET6)
                   1199:       {
                   1200:         /* IPv6 global nexthop must be included. */
                   1201:         memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
                   1202:                 IPV6_MAX_BYTELEN);
                   1203:         attr->extra->mp_nexthop_len = 16;
                   1204:       }
                   1205: #endif /* HAVE_IPV6 */
                   1206:   }
                   1207: 
                   1208: #ifdef HAVE_IPV6
                   1209:   if (p->family == AF_INET6)
                   1210:     {
                   1211:       struct attr_extra *attre = attr->extra;
                   1212:       
                   1213:       assert (attr->extra);
                   1214:       
                   1215:       /* Left nexthop_local unchanged if so configured. */
                   1216:       if ( CHECK_FLAG (rsclient->af_flags[afi][safi], 
                   1217:            PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
                   1218:         {
                   1219:           if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
                   1220:             attre->mp_nexthop_len=32;
                   1221:           else
                   1222:             attre->mp_nexthop_len=16;
                   1223:         }
                   1224:         
                   1225:       /* Default nexthop_local treatment for RS-Clients */
                   1226:       else 
                   1227:         { 
                   1228:           /* Announcer and RS-Client are both in the same network */      
                   1229:           if (rsclient->shared_network && from->shared_network &&
                   1230:               (rsclient->ifindex == from->ifindex))
                   1231:             {
                   1232:               if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
                   1233:                 attre->mp_nexthop_len=32;
                   1234:               else
                   1235:                 attre->mp_nexthop_len=16;
                   1236:             }
                   1237: 
                   1238:           /* Set link-local address for shared network peer. */
                   1239:           else if (rsclient->shared_network
                   1240:               && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
                   1241:             {
                   1242:               memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
                   1243:                       IPV6_MAX_BYTELEN);
                   1244:               attre->mp_nexthop_len = 32;
                   1245:             }
                   1246: 
                   1247:           else
                   1248:             attre->mp_nexthop_len = 16;
                   1249:         }
                   1250: 
                   1251:     }
                   1252: #endif /* HAVE_IPV6 */
                   1253: 
                   1254: 
                   1255:   /* If this is EBGP peer and remove-private-AS is set.  */
                   1256:   if (peer_sort (rsclient) == BGP_PEER_EBGP
                   1257:       && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
                   1258:       && aspath_private_as_check (attr->aspath))
                   1259:     attr->aspath = aspath_empty_get ();
                   1260: 
                   1261:   /* Route map & unsuppress-map apply. */
                   1262:   if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
                   1263:     {
                   1264:       info.peer = rsclient;
                   1265:       info.attr = attr;
                   1266: 
                   1267:       SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
                   1268: 
                   1269:       if (ri->extra && ri->extra->suppress)
                   1270:         ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
                   1271:       else
                   1272:         ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
                   1273: 
                   1274:       rsclient->rmap_type = 0;
                   1275: 
                   1276:       if (ret == RMAP_DENYMATCH)
                   1277:        {
                   1278:          bgp_attr_flush (attr);
                   1279:          return 0;
                   1280:        }
                   1281:     }
                   1282: 
                   1283:   return 1;
                   1284: }
                   1285: 
                   1286: struct bgp_info_pair
                   1287: {
                   1288:   struct bgp_info *old;
                   1289:   struct bgp_info *new;
                   1290: };
                   1291: 
                   1292: static void
1.1.1.2 ! misho    1293: bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
        !          1294:                    struct bgp_maxpaths_cfg *mpath_cfg,
        !          1295:                    struct bgp_info_pair *result)
1.1       misho    1296: {
                   1297:   struct bgp_info *new_select;
                   1298:   struct bgp_info *old_select;
                   1299:   struct bgp_info *ri;
                   1300:   struct bgp_info *ri1;
                   1301:   struct bgp_info *ri2;
                   1302:   struct bgp_info *nextri = NULL;
1.1.1.2 ! misho    1303:   int paths_eq, do_mpath;
        !          1304:   struct list mp_list;
        !          1305: 
        !          1306:   bgp_mp_list_init (&mp_list);
        !          1307:   do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
        !          1308:              mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
        !          1309: 
1.1       misho    1310:   /* bgp deterministic-med */
                   1311:   new_select = NULL;
                   1312:   if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
                   1313:     for (ri1 = rn->info; ri1; ri1 = ri1->next)
                   1314:       {
                   1315:        if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
                   1316:          continue;
                   1317:        if (BGP_INFO_HOLDDOWN (ri1))
                   1318:          continue;
                   1319: 
                   1320:        new_select = ri1;
1.1.1.2 ! misho    1321:        if (do_mpath)
        !          1322:          bgp_mp_list_add (&mp_list, ri1);
        !          1323:        old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
1.1       misho    1324:        if (ri1->next)
                   1325:          for (ri2 = ri1->next; ri2; ri2 = ri2->next)
                   1326:            {
                   1327:              if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
                   1328:                continue;
                   1329:              if (BGP_INFO_HOLDDOWN (ri2))
                   1330:                continue;
                   1331: 
                   1332:              if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
                   1333:                  || aspath_cmp_left_confed (ri1->attr->aspath,
                   1334:                                             ri2->attr->aspath))
                   1335:                {
1.1.1.2 ! misho    1336:                  if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
        !          1337:                    old_select = ri2;
        !          1338:                  if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
1.1       misho    1339:                    {
                   1340:                      bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
                   1341:                      new_select = ri2;
1.1.1.2 ! misho    1342:                      if (do_mpath && !paths_eq)
        !          1343:                        {
        !          1344:                          bgp_mp_list_clear (&mp_list);
        !          1345:                          bgp_mp_list_add (&mp_list, ri2);
        !          1346:                        }
1.1       misho    1347:                    }
                   1348: 
1.1.1.2 ! misho    1349:                  if (do_mpath && paths_eq)
        !          1350:                    bgp_mp_list_add (&mp_list, ri2);
        !          1351: 
1.1       misho    1352:                  bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
                   1353:                }
                   1354:            }
                   1355:        bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
                   1356:        bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
1.1.1.2 ! misho    1357: 
        !          1358:        bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
        !          1359:        bgp_mp_list_clear (&mp_list);
1.1       misho    1360:       }
                   1361: 
                   1362:   /* Check old selected route and new selected route. */
                   1363:   old_select = NULL;
                   1364:   new_select = NULL;
                   1365:   for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
                   1366:     {
                   1367:       if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
                   1368:        old_select = ri;
                   1369: 
                   1370:       if (BGP_INFO_HOLDDOWN (ri))
                   1371:         {
                   1372:           /* reap REMOVED routes, if needs be 
                   1373:            * selected route must stay for a while longer though
                   1374:            */
                   1375:           if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
                   1376:               && (ri != old_select))
                   1377:               bgp_info_reap (rn, ri);
                   1378:           
                   1379:           continue;
                   1380:         }
                   1381: 
                   1382:       if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
                   1383:           && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
                   1384:        {
                   1385:          bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
                   1386:          continue;
                   1387:         }
                   1388:       bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
                   1389:       bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
                   1390: 
1.1.1.2 ! misho    1391:       if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
        !          1392:        {
        !          1393:          if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
        !          1394:            bgp_mp_dmed_deselect (new_select);
        !          1395: 
        !          1396:          new_select = ri;
        !          1397: 
        !          1398:          if (do_mpath && !paths_eq)
        !          1399:            {
        !          1400:              bgp_mp_list_clear (&mp_list);
        !          1401:              bgp_mp_list_add (&mp_list, ri);
        !          1402:            }
        !          1403:        }
        !          1404:       else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
        !          1405:        bgp_mp_dmed_deselect (ri);
        !          1406: 
        !          1407:       if (do_mpath && paths_eq)
        !          1408:        bgp_mp_list_add (&mp_list, ri);
1.1       misho    1409:     }
                   1410:     
                   1411: 
1.1.1.2 ! misho    1412:   if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
        !          1413:     bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
        !          1414: 
        !          1415:   bgp_info_mpath_aggregate_update (new_select, old_select);
        !          1416:   bgp_mp_list_clear (&mp_list);
        !          1417: 
        !          1418:   result->old = old_select;
        !          1419:   result->new = new_select;
        !          1420: 
        !          1421:   return;
1.1       misho    1422: }
                   1423: 
                   1424: static int
                   1425: bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
                   1426:                                struct bgp_node *rn, afi_t afi, safi_t safi)
                   1427: {
                   1428:   struct prefix *p;
                   1429:   struct attr attr = { 0 };
                   1430: 
                   1431:   p = &rn->p;
                   1432: 
                   1433:   /* Announce route to Established peer. */
                   1434:   if (peer->status != Established)
                   1435:     return 0;
                   1436: 
                   1437:   /* Address family configuration check. */
                   1438:   if (! peer->afc_nego[afi][safi])
                   1439:     return 0;
                   1440: 
                   1441:   /* First update is deferred until ORF or ROUTE-REFRESH is received */
                   1442:   if (CHECK_FLAG (peer->af_sflags[afi][safi],
                   1443:       PEER_STATUS_ORF_WAIT_REFRESH))
                   1444:     return 0;
                   1445: 
                   1446:   switch (rn->table->type)
                   1447:     {
                   1448:       case BGP_TABLE_MAIN:
                   1449:       /* Announcement to peer->conf.  If the route is filtered,
                   1450:          withdraw it. */
                   1451:         if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
                   1452:           bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
                   1453:         else
                   1454:           bgp_adj_out_unset (rn, peer, p, afi, safi);
                   1455:         break;
                   1456:       case BGP_TABLE_RSCLIENT:
                   1457:         /* Announcement to peer->conf.  If the route is filtered, 
                   1458:            withdraw it. */
                   1459:         if (selected && 
                   1460:             bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
                   1461:           bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
                   1462:         else
                   1463:          bgp_adj_out_unset (rn, peer, p, afi, safi);
                   1464:         break;
                   1465:     }
                   1466:   
                   1467:   bgp_attr_extra_free (&attr);
                   1468:   
                   1469:   return 0;
                   1470: }
                   1471: 
                   1472: struct bgp_process_queue 
                   1473: {
                   1474:   struct bgp *bgp;
                   1475:   struct bgp_node *rn;
                   1476:   afi_t afi;
                   1477:   safi_t safi;
                   1478: };
                   1479: 
                   1480: static wq_item_status
                   1481: bgp_process_rsclient (struct work_queue *wq, void *data)
                   1482: {
                   1483:   struct bgp_process_queue *pq = data;
                   1484:   struct bgp *bgp = pq->bgp;
                   1485:   struct bgp_node *rn = pq->rn;
                   1486:   afi_t afi = pq->afi;
                   1487:   safi_t safi = pq->safi;
                   1488:   struct bgp_info *new_select;
                   1489:   struct bgp_info *old_select;
                   1490:   struct bgp_info_pair old_and_new;
                   1491:   struct listnode *node, *nnode;
                   1492:   struct peer *rsclient = rn->table->owner;
                   1493:   
                   1494:   /* Best path selection. */
1.1.1.2 ! misho    1495:   bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
1.1       misho    1496:   new_select = old_and_new.new;
                   1497:   old_select = old_and_new.old;
                   1498: 
                   1499:   if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
                   1500:     {
                   1501:       if (rsclient->group)
                   1502:         for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
                   1503:           {
                   1504:             /* Nothing to do. */
                   1505:             if (old_select && old_select == new_select)
                   1506:               if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
                   1507:                 continue;
                   1508: 
                   1509:             if (old_select)
                   1510:               bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
                   1511:             if (new_select)
                   1512:               {
                   1513:                 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
                   1514:                 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1.1.1.2 ! misho    1515:                UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
        !          1516:              }
1.1       misho    1517: 
                   1518:             bgp_process_announce_selected (rsclient, new_select, rn,
                   1519:                                            afi, safi);
                   1520:           }
                   1521:     }
                   1522:   else
                   1523:     {
                   1524:       if (old_select)
                   1525:        bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
                   1526:       if (new_select)
                   1527:        {
                   1528:          bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
                   1529:          bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1.1.1.2 ! misho    1530:          UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1.1       misho    1531:        }
                   1532:       bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
                   1533:     }
                   1534: 
                   1535:   if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
                   1536:     bgp_info_reap (rn, old_select);
                   1537:   
                   1538:   UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
                   1539:   return WQ_SUCCESS;
                   1540: }
                   1541: 
                   1542: static wq_item_status
                   1543: bgp_process_main (struct work_queue *wq, void *data)
                   1544: {
                   1545:   struct bgp_process_queue *pq = data;
                   1546:   struct bgp *bgp = pq->bgp;
                   1547:   struct bgp_node *rn = pq->rn;
                   1548:   afi_t afi = pq->afi;
                   1549:   safi_t safi = pq->safi;
                   1550:   struct prefix *p = &rn->p;
                   1551:   struct bgp_info *new_select;
                   1552:   struct bgp_info *old_select;
                   1553:   struct bgp_info_pair old_and_new;
                   1554:   struct listnode *node, *nnode;
                   1555:   struct peer *peer;
                   1556:   
                   1557:   /* Best path selection. */
1.1.1.2 ! misho    1558:   bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
1.1       misho    1559:   old_select = old_and_new.old;
                   1560:   new_select = old_and_new.new;
                   1561: 
                   1562:   /* Nothing to do. */
                   1563:   if (old_select && old_select == new_select)
                   1564:     {
                   1565:       if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
                   1566:         {
1.1.1.2 ! misho    1567:           if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
        !          1568:              CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
        !          1569:             bgp_zebra_announce (p, old_select, bgp, safi);
1.1       misho    1570:           
1.1.1.2 ! misho    1571:          UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
1.1       misho    1572:           UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
                   1573:           return WQ_SUCCESS;
                   1574:         }
                   1575:     }
                   1576: 
                   1577:   if (old_select)
                   1578:     bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
                   1579:   if (new_select)
                   1580:     {
                   1581:       bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
                   1582:       bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1.1.1.2 ! misho    1583:       UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1.1       misho    1584:     }
                   1585: 
                   1586: 
                   1587:   /* Check each BGP peer. */
                   1588:   for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
                   1589:     {
                   1590:       bgp_process_announce_selected (peer, new_select, rn, afi, safi);
                   1591:     }
                   1592: 
                   1593:   /* FIB update. */
1.1.1.2 ! misho    1594:   if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
        !          1595:       ! bgp_option_check (BGP_OPT_NO_FIB)))
1.1       misho    1596:     {
                   1597:       if (new_select 
                   1598:          && new_select->type == ZEBRA_ROUTE_BGP 
                   1599:          && new_select->sub_type == BGP_ROUTE_NORMAL)
1.1.1.2 ! misho    1600:        bgp_zebra_announce (p, new_select, bgp, safi);
1.1       misho    1601:       else
                   1602:        {
                   1603:          /* Withdraw the route from the kernel. */
                   1604:          if (old_select 
                   1605:              && old_select->type == ZEBRA_ROUTE_BGP
                   1606:              && old_select->sub_type == BGP_ROUTE_NORMAL)
1.1.1.2 ! misho    1607:            bgp_zebra_withdraw (p, old_select, safi);
1.1       misho    1608:        }
                   1609:     }
                   1610:     
                   1611:   /* Reap old select bgp_info, it it has been removed */
                   1612:   if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
                   1613:     bgp_info_reap (rn, old_select);
                   1614:   
                   1615:   UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
                   1616:   return WQ_SUCCESS;
                   1617: }
                   1618: 
                   1619: static void
                   1620: bgp_processq_del (struct work_queue *wq, void *data)
                   1621: {
                   1622:   struct bgp_process_queue *pq = data;
                   1623:   struct bgp_table *table = pq->rn->table;
                   1624:   
                   1625:   bgp_unlock (pq->bgp);
                   1626:   bgp_unlock_node (pq->rn);
                   1627:   bgp_table_unlock (table);
                   1628:   XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
                   1629: }
                   1630: 
                   1631: static void
                   1632: bgp_process_queue_init (void)
                   1633: {
                   1634:   bm->process_main_queue
                   1635:     = work_queue_new (bm->master, "process_main_queue");
                   1636:   bm->process_rsclient_queue
                   1637:     = work_queue_new (bm->master, "process_rsclient_queue");
                   1638:   
                   1639:   if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
                   1640:     {
                   1641:       zlog_err ("%s: Failed to allocate work queue", __func__);
                   1642:       exit (1);
                   1643:     }
                   1644:   
                   1645:   bm->process_main_queue->spec.workfunc = &bgp_process_main;
                   1646:   bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
                   1647:   bm->process_main_queue->spec.max_retries = 0;
                   1648:   bm->process_main_queue->spec.hold = 50;
                   1649:   
                   1650:   memcpy (bm->process_rsclient_queue, bm->process_main_queue,
                   1651:           sizeof (struct work_queue *));
                   1652:   bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
                   1653: }
                   1654: 
                   1655: void
                   1656: bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
                   1657: {
                   1658:   struct bgp_process_queue *pqnode;
                   1659:   
                   1660:   /* already scheduled for processing? */
                   1661:   if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
                   1662:     return;
                   1663:   
                   1664:   if ( (bm->process_main_queue == NULL) ||
                   1665:        (bm->process_rsclient_queue == NULL) )
                   1666:     bgp_process_queue_init ();
                   1667:   
                   1668:   pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE, 
                   1669:                     sizeof (struct bgp_process_queue));
                   1670:   if (!pqnode)
                   1671:     return;
                   1672: 
                   1673:   /* all unlocked in bgp_processq_del */
                   1674:   bgp_table_lock (rn->table);
                   1675:   pqnode->rn = bgp_lock_node (rn);
                   1676:   pqnode->bgp = bgp;
                   1677:   bgp_lock (bgp);
                   1678:   pqnode->afi = afi;
                   1679:   pqnode->safi = safi;
                   1680:   
                   1681:   switch (rn->table->type)
                   1682:     {
                   1683:       case BGP_TABLE_MAIN:
                   1684:         work_queue_add (bm->process_main_queue, pqnode);
                   1685:         break;
                   1686:       case BGP_TABLE_RSCLIENT:
                   1687:         work_queue_add (bm->process_rsclient_queue, pqnode);
                   1688:         break;
                   1689:     }
                   1690:   
                   1691:   return;
                   1692: }
                   1693: 
                   1694: static int
                   1695: bgp_maximum_prefix_restart_timer (struct thread *thread)
                   1696: {
                   1697:   struct peer *peer;
                   1698: 
                   1699:   peer = THREAD_ARG (thread);
                   1700:   peer->t_pmax_restart = NULL;
                   1701: 
                   1702:   if (BGP_DEBUG (events, EVENTS))
                   1703:     zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
                   1704:                peer->host);
                   1705: 
                   1706:   peer_clear (peer);
                   1707: 
                   1708:   return 0;
                   1709: }
                   1710: 
                   1711: int
                   1712: bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi, 
                   1713:                              safi_t safi, int always)
                   1714: {
                   1715:   if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
                   1716:     return 0;
                   1717: 
                   1718:   if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
                   1719:     {
                   1720:       if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
                   1721:          && ! always)
                   1722:        return 0;
                   1723: 
                   1724:       zlog (peer->log, LOG_INFO,
                   1725:            "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
                   1726:            "limit %ld", afi_safi_print (afi, safi), peer->host,
                   1727:            peer->pcount[afi][safi], peer->pmax[afi][safi]);
                   1728:       SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
                   1729: 
                   1730:       if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
                   1731:        return 0;
                   1732: 
                   1733:       {
                   1734:        u_int8_t ndata[7];
                   1735: 
                   1736:        if (safi == SAFI_MPLS_VPN)
1.1.1.2 ! misho    1737:          safi = SAFI_MPLS_LABELED_VPN;
1.1       misho    1738:          
                   1739:        ndata[0] = (afi >>  8);
                   1740:        ndata[1] = afi;
                   1741:        ndata[2] = safi;
                   1742:        ndata[3] = (peer->pmax[afi][safi] >> 24);
                   1743:        ndata[4] = (peer->pmax[afi][safi] >> 16);
                   1744:        ndata[5] = (peer->pmax[afi][safi] >> 8);
                   1745:        ndata[6] = (peer->pmax[afi][safi]);
                   1746: 
                   1747:        SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
                   1748:        bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
                   1749:                                   BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
                   1750:       }
                   1751: 
                   1752:       /* restart timer start */
                   1753:       if (peer->pmax_restart[afi][safi])
                   1754:        {
                   1755:          peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
                   1756: 
                   1757:          if (BGP_DEBUG (events, EVENTS))
                   1758:            zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
                   1759:                        peer->host, peer->v_pmax_restart);
                   1760: 
                   1761:          BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
                   1762:                        peer->v_pmax_restart);
                   1763:        }
                   1764: 
                   1765:       return 1;
                   1766:     }
                   1767:   else
                   1768:     UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
                   1769: 
                   1770:   if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
                   1771:     {
                   1772:       if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
                   1773:          && ! always)
                   1774:        return 0;
                   1775: 
                   1776:       zlog (peer->log, LOG_INFO,
                   1777:            "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
                   1778:            afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
                   1779:            peer->pmax[afi][safi]);
                   1780:       SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
                   1781:     }
                   1782:   else
                   1783:     UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
                   1784:   return 0;
                   1785: }
                   1786: 
                   1787: /* Unconditionally remove the route from the RIB, without taking
                   1788:  * damping into consideration (eg, because the session went down)
                   1789:  */
                   1790: static void
                   1791: bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
                   1792:                afi_t afi, safi_t safi)
                   1793: {
                   1794:   bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
                   1795:   
                   1796:   if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
                   1797:     bgp_info_delete (rn, ri); /* keep historical info */
                   1798:     
                   1799:   bgp_process (peer->bgp, rn, afi, safi);
                   1800: }
                   1801: 
                   1802: static void
                   1803: bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
                   1804:                  afi_t afi, safi_t safi)
                   1805: {
                   1806:   int status = BGP_DAMP_NONE;
                   1807: 
                   1808:   /* apply dampening, if result is suppressed, we'll be retaining 
                   1809:    * the bgp_info in the RIB for historical reference.
                   1810:    */
                   1811:   if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
                   1812:       && peer_sort (peer) == BGP_PEER_EBGP)
                   1813:     if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0)) 
                   1814:          == BGP_DAMP_SUPPRESSED)
                   1815:       {
                   1816:         bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
                   1817:         return;
                   1818:       }
                   1819:     
                   1820:   bgp_rib_remove (rn, ri, peer, afi, safi);
                   1821: }
                   1822: 
                   1823: static void
                   1824: bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
                   1825:       struct attr *attr, struct peer *peer, struct prefix *p, int type,
                   1826:       int sub_type, struct prefix_rd *prd, u_char *tag)
                   1827: {
                   1828:   struct bgp_node *rn;
                   1829:   struct bgp *bgp;
                   1830:   struct attr new_attr = { 0 };
                   1831:   struct attr *attr_new;
                   1832:   struct attr *attr_new2;
                   1833:   struct bgp_info *ri;
                   1834:   struct bgp_info *new;
                   1835:   const char *reason;
                   1836:   char buf[SU_ADDRSTRLEN];
                   1837: 
                   1838:   /* Do not insert announces from a rsclient into its own 'bgp_table'. */
                   1839:   if (peer == rsclient)
                   1840:     return;
                   1841: 
                   1842:   bgp = peer->bgp;
                   1843:   rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
                   1844: 
                   1845:   /* Check previously received route. */
                   1846:   for (ri = rn->info; ri; ri = ri->next)
                   1847:     if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
                   1848:       break;
                   1849: 
                   1850:   /* AS path loop check. */
                   1851:   if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
                   1852:     {
                   1853:       reason = "as-path contains our own AS;";
                   1854:       goto filtered;
                   1855:     }
                   1856: 
                   1857:   /* Route reflector originator ID check.  */
                   1858:   if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
                   1859:       && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
                   1860:     {
                   1861:       reason = "originator is us;";
                   1862:       goto filtered;
                   1863:     }
                   1864:   
                   1865:   bgp_attr_dup (&new_attr, attr);
                   1866: 
                   1867:   /* Apply export policy. */
                   1868:   if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
                   1869:         bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
                   1870:     {
                   1871:       reason = "export-policy;";
                   1872:       goto filtered;
                   1873:     }
                   1874: 
                   1875:   attr_new2 = bgp_attr_intern (&new_attr);
                   1876:   
                   1877:   /* Apply import policy. */
                   1878:   if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
                   1879:     {
                   1880:       bgp_attr_unintern (&attr_new2);
                   1881: 
                   1882:       reason = "import-policy;";
                   1883:       goto filtered;
                   1884:     }
                   1885: 
                   1886:   attr_new = bgp_attr_intern (&new_attr);
                   1887:   bgp_attr_unintern (&attr_new2);
                   1888: 
                   1889:   /* IPv4 unicast next hop check.  */
1.1.1.2 ! misho    1890:   if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
1.1       misho    1891:     {
1.1.1.2 ! misho    1892:      /* Next hop must not be 0.0.0.0 nor Class D/E address. */
1.1       misho    1893:       if (new_attr.nexthop.s_addr == 0
1.1.1.2 ! misho    1894:          || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
1.1       misho    1895:        {
                   1896:          bgp_attr_unintern (&attr_new);
                   1897: 
                   1898:          reason = "martian next-hop;";
                   1899:          goto filtered;
                   1900:        }
                   1901:     }
                   1902:   
                   1903:   /* new_attr isn't passed to any functions after here */
                   1904:   bgp_attr_extra_free (&new_attr);
                   1905:   
                   1906:   /* If the update is implicit withdraw. */
                   1907:   if (ri)
                   1908:     {
                   1909:       ri->uptime = bgp_clock ();
                   1910: 
                   1911:       /* Same attribute comes in. */
                   1912:       if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
                   1913:           && attrhash_cmp (ri->attr, attr_new))
                   1914:         {
                   1915: 
                   1916:           bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
                   1917: 
                   1918:           if (BGP_DEBUG (update, UPDATE_IN))
                   1919:             zlog (peer->log, LOG_DEBUG,
                   1920:                     "%s rcvd %s/%d for RS-client %s...duplicate ignored",
                   1921:                     peer->host,
                   1922:                     inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   1923:                     p->prefixlen, rsclient->host);
                   1924: 
                   1925:           bgp_unlock_node (rn);
                   1926:           bgp_attr_unintern (&attr_new);
                   1927: 
                   1928:           return;
                   1929:         }
                   1930: 
                   1931:       /* Withdraw/Announce before we fully processed the withdraw */
                   1932:       if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
                   1933:         bgp_info_restore (rn, ri);
                   1934:       
                   1935:       /* Received Logging. */
                   1936:       if (BGP_DEBUG (update, UPDATE_IN))
                   1937:         zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
                   1938:                 peer->host,
                   1939:                 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   1940:                 p->prefixlen, rsclient->host);
                   1941: 
                   1942:       /* The attribute is changed. */
                   1943:       bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
                   1944: 
                   1945:       /* Update to new attribute.  */
                   1946:       bgp_attr_unintern (&ri->attr);
                   1947:       ri->attr = attr_new;
                   1948: 
                   1949:       /* Update MPLS tag.  */
                   1950:       if (safi == SAFI_MPLS_VPN)
                   1951:         memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
                   1952: 
                   1953:       bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
                   1954: 
                   1955:       /* Process change. */
                   1956:       bgp_process (bgp, rn, afi, safi);
                   1957:       bgp_unlock_node (rn);
                   1958: 
                   1959:       return;
                   1960:     }
                   1961: 
                   1962:   /* Received Logging. */
                   1963:   if (BGP_DEBUG (update, UPDATE_IN))
                   1964:     {
                   1965:       zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
                   1966:               peer->host,
                   1967:               inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   1968:               p->prefixlen, rsclient->host);
                   1969:     }
                   1970: 
                   1971:   /* Make new BGP info. */
                   1972:   new = bgp_info_new ();
                   1973:   new->type = type;
                   1974:   new->sub_type = sub_type;
                   1975:   new->peer = peer;
                   1976:   new->attr = attr_new;
                   1977:   new->uptime = bgp_clock ();
                   1978: 
                   1979:   /* Update MPLS tag. */
                   1980:   if (safi == SAFI_MPLS_VPN)
                   1981:     memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
                   1982: 
                   1983:   bgp_info_set_flag (rn, new, BGP_INFO_VALID);
                   1984: 
                   1985:   /* Register new BGP information. */
                   1986:   bgp_info_add (rn, new);
                   1987:   
                   1988:   /* route_node_get lock */
                   1989:   bgp_unlock_node (rn);
                   1990:   
                   1991:   /* Process change. */
                   1992:   bgp_process (bgp, rn, afi, safi);
                   1993:   
                   1994:   bgp_attr_extra_free (&new_attr);
                   1995:   
                   1996:   return;
                   1997: 
                   1998:  filtered: 
                   1999: 
                   2000:   /* This BGP update is filtered.  Log the reason then update BGP entry.  */
                   2001:   if (BGP_DEBUG (update, UPDATE_IN))
                   2002:         zlog (peer->log, LOG_DEBUG,
                   2003:         "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
                   2004:         peer->host,
                   2005:         inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   2006:         p->prefixlen, rsclient->host, reason);
                   2007: 
                   2008:   if (ri)
                   2009:     bgp_rib_remove (rn, ri, peer, afi, safi);
                   2010: 
                   2011:   bgp_unlock_node (rn);
                   2012:   
                   2013:   if (new_attr.extra)
                   2014:     bgp_attr_extra_free (&new_attr);
                   2015:   
                   2016:   return;
                   2017: }
                   2018: 
                   2019: static void
                   2020: bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
                   2021:       struct peer *peer, struct prefix *p, int type, int sub_type,
                   2022:       struct prefix_rd *prd, u_char *tag)
                   2023: {
                   2024:   struct bgp_node *rn;
                   2025:   struct bgp_info *ri;
                   2026:   char buf[SU_ADDRSTRLEN];
                   2027: 
                   2028:   if (rsclient == peer)
                   2029:     return;
                   2030: 
                   2031:   rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
                   2032: 
                   2033:   /* Lookup withdrawn route. */
                   2034:   for (ri = rn->info; ri; ri = ri->next)
                   2035:     if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
                   2036:       break;
                   2037: 
                   2038:   /* Withdraw specified route from routing table. */
                   2039:   if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
                   2040:     bgp_rib_withdraw (rn, ri, peer, afi, safi);
                   2041:   else if (BGP_DEBUG (update, UPDATE_IN))
                   2042:     zlog (peer->log, LOG_DEBUG,
                   2043:           "%s Can't find the route %s/%d", peer->host,
                   2044:           inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   2045:           p->prefixlen);
                   2046: 
                   2047:   /* Unlock bgp_node_get() lock. */
                   2048:   bgp_unlock_node (rn);
                   2049: }
                   2050: 
                   2051: static int
                   2052: bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
                   2053:            afi_t afi, safi_t safi, int type, int sub_type,
                   2054:            struct prefix_rd *prd, u_char *tag, int soft_reconfig)
                   2055: {
                   2056:   int ret;
                   2057:   int aspath_loop_count = 0;
                   2058:   struct bgp_node *rn;
                   2059:   struct bgp *bgp;
                   2060:   struct attr new_attr = { 0 };
                   2061:   struct attr *attr_new;
                   2062:   struct bgp_info *ri;
                   2063:   struct bgp_info *new;
                   2064:   const char *reason;
                   2065:   char buf[SU_ADDRSTRLEN];
                   2066: 
                   2067:   bgp = peer->bgp;
                   2068:   rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
                   2069:   
                   2070:   /* When peer's soft reconfiguration enabled.  Record input packet in
                   2071:      Adj-RIBs-In.  */
                   2072:   if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
                   2073:       && peer != bgp->peer_self && ! soft_reconfig)
                   2074:     bgp_adj_in_set (rn, peer, attr);
                   2075: 
                   2076:   /* Check previously received route. */
                   2077:   for (ri = rn->info; ri; ri = ri->next)
                   2078:     if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
                   2079:       break;
                   2080: 
                   2081:   /* AS path local-as loop check. */
                   2082:   if (peer->change_local_as)
                   2083:     {
                   2084:       if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
                   2085:        aspath_loop_count = 1;
                   2086: 
                   2087:       if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count) 
                   2088:        {
                   2089:          reason = "as-path contains our own AS;";
                   2090:          goto filtered;
                   2091:        }
                   2092:     }
                   2093: 
                   2094:   /* AS path loop check. */
                   2095:   if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
                   2096:       || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
                   2097:          && aspath_loop_check(attr->aspath, bgp->confed_id)
                   2098:          > peer->allowas_in[afi][safi]))
                   2099:     {
                   2100:       reason = "as-path contains our own AS;";
                   2101:       goto filtered;
                   2102:     }
                   2103: 
                   2104:   /* Route reflector originator ID check.  */
                   2105:   if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
                   2106:       && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
                   2107:     {
                   2108:       reason = "originator is us;";
                   2109:       goto filtered;
                   2110:     }
                   2111: 
                   2112:   /* Route reflector cluster ID check.  */
                   2113:   if (bgp_cluster_filter (peer, attr))
                   2114:     {
                   2115:       reason = "reflected from the same cluster;";
                   2116:       goto  filtered;
                   2117:     }
                   2118: 
                   2119:   /* Apply incoming filter.  */
                   2120:   if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
                   2121:     {
                   2122:       reason = "filter;";
                   2123:       goto filtered;
                   2124:     }
                   2125: 
                   2126:   /* Apply incoming route-map. */
                   2127:   bgp_attr_dup (&new_attr, attr);
                   2128: 
                   2129:   if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
                   2130:     {
                   2131:       reason = "route-map;";
                   2132:       goto filtered;
                   2133:     }
                   2134: 
                   2135:   /* IPv4 unicast next hop check.  */
                   2136:   if (afi == AFI_IP && safi == SAFI_UNICAST)
                   2137:     {
                   2138:       /* If the peer is EBGP and nexthop is not on connected route,
                   2139:         discard it.  */
                   2140:       if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
1.1.1.2 ! misho    2141:          && ! bgp_nexthop_onlink (afi, &new_attr)
1.1       misho    2142:          && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
                   2143:        {
                   2144:          reason = "non-connected next-hop;";
                   2145:          goto filtered;
                   2146:        }
                   2147: 
1.1.1.2 ! misho    2148:       /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
1.1       misho    2149:         must not be my own address.  */
                   2150:       if (bgp_nexthop_self (afi, &new_attr)
                   2151:          || new_attr.nexthop.s_addr == 0
1.1.1.2 ! misho    2152:          || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
1.1       misho    2153:        {
                   2154:          reason = "martian next-hop;";
                   2155:          goto filtered;
                   2156:        }
                   2157:     }
                   2158: 
                   2159:   attr_new = bgp_attr_intern (&new_attr);
                   2160: 
                   2161:   /* If the update is implicit withdraw. */
                   2162:   if (ri)
                   2163:     {
                   2164:       ri->uptime = bgp_clock ();
                   2165: 
                   2166:       /* Same attribute comes in. */
                   2167:       if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED) 
                   2168:           && attrhash_cmp (ri->attr, attr_new))
                   2169:        {
                   2170:          bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
                   2171: 
                   2172:          if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
                   2173:              && peer_sort (peer) == BGP_PEER_EBGP
                   2174:              && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
                   2175:            {
                   2176:              if (BGP_DEBUG (update, UPDATE_IN))  
                   2177:                  zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
                   2178:                  peer->host,
                   2179:                  inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   2180:                  p->prefixlen);
                   2181: 
                   2182:              if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
                   2183:                {
                   2184:                   bgp_aggregate_increment (bgp, p, ri, afi, safi);
                   2185:                   bgp_process (bgp, rn, afi, safi);
                   2186:                 }
                   2187:            }
                   2188:           else /* Duplicate - odd */
                   2189:            {
                   2190:              if (BGP_DEBUG (update, UPDATE_IN))  
                   2191:                zlog (peer->log, LOG_DEBUG,
                   2192:                "%s rcvd %s/%d...duplicate ignored",
                   2193:                peer->host,
                   2194:                inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   2195:                p->prefixlen);
                   2196: 
                   2197:              /* graceful restart STALE flag unset. */
                   2198:              if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
                   2199:                {
                   2200:                  bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
                   2201:                  bgp_process (bgp, rn, afi, safi);
                   2202:                }
                   2203:            }
                   2204: 
                   2205:          bgp_unlock_node (rn);
                   2206:          bgp_attr_unintern (&attr_new);
                   2207:          bgp_attr_extra_free (&new_attr);
                   2208:          
                   2209:          return 0;
                   2210:        }
                   2211: 
                   2212:       /* Withdraw/Announce before we fully processed the withdraw */
                   2213:       if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
                   2214:         {
                   2215:           if (BGP_DEBUG (update, UPDATE_IN))
                   2216:             zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
                   2217:             peer->host,
                   2218:             inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   2219:             p->prefixlen);
                   2220:           bgp_info_restore (rn, ri);
                   2221:         }
                   2222: 
                   2223:       /* Received Logging. */
                   2224:       if (BGP_DEBUG (update, UPDATE_IN))  
                   2225:        zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
                   2226:              peer->host,
                   2227:              inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   2228:              p->prefixlen);
                   2229: 
                   2230:       /* graceful restart STALE flag unset. */
                   2231:       if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
                   2232:        bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
                   2233: 
                   2234:       /* The attribute is changed. */
                   2235:       bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
                   2236:       
                   2237:       /* implicit withdraw, decrement aggregate and pcount here.
                   2238:        * only if update is accepted, they'll increment below.
                   2239:        */
                   2240:       bgp_aggregate_decrement (bgp, p, ri, afi, safi);
                   2241:       
                   2242:       /* Update bgp route dampening information.  */
                   2243:       if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
                   2244:          && peer_sort (peer) == BGP_PEER_EBGP)
                   2245:        {
                   2246:          /* This is implicit withdraw so we should update dampening
                   2247:             information.  */
                   2248:          if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
                   2249:            bgp_damp_withdraw (ri, rn, afi, safi, 1);  
                   2250:        }
                   2251:        
                   2252:       /* Update to new attribute.  */
                   2253:       bgp_attr_unintern (&ri->attr);
                   2254:       ri->attr = attr_new;
                   2255: 
                   2256:       /* Update MPLS tag.  */
                   2257:       if (safi == SAFI_MPLS_VPN)
                   2258:         memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
                   2259: 
                   2260:       /* Update bgp route dampening information.  */
                   2261:       if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
                   2262:          && peer_sort (peer) == BGP_PEER_EBGP)
                   2263:        {
                   2264:          /* Now we do normal update dampening.  */
                   2265:          ret = bgp_damp_update (ri, rn, afi, safi);
                   2266:          if (ret == BGP_DAMP_SUPPRESSED)
                   2267:            {
                   2268:              bgp_unlock_node (rn);
                   2269:              bgp_attr_extra_free (&new_attr);
                   2270:              return 0;
                   2271:            }
                   2272:        }
                   2273: 
                   2274:       /* Nexthop reachability check. */
                   2275:       if ((afi == AFI_IP || afi == AFI_IP6)
                   2276:          && safi == SAFI_UNICAST 
                   2277:          && (peer_sort (peer) == BGP_PEER_IBGP
                   2278:               || peer_sort (peer) == BGP_PEER_CONFED
                   2279:              || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
                   2280:              || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
                   2281:        {
                   2282:          if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
                   2283:            bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
                   2284:          else
                   2285:            bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
                   2286:        }
                   2287:       else
                   2288:         bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
                   2289: 
                   2290:       /* Process change. */
                   2291:       bgp_aggregate_increment (bgp, p, ri, afi, safi);
                   2292: 
                   2293:       bgp_process (bgp, rn, afi, safi);
                   2294:       bgp_unlock_node (rn);
                   2295:       bgp_attr_extra_free (&new_attr);
                   2296:       
                   2297:       return 0;
                   2298:     }
                   2299: 
                   2300:   /* Received Logging. */
                   2301:   if (BGP_DEBUG (update, UPDATE_IN))  
                   2302:     {
                   2303:       zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
                   2304:            peer->host,
                   2305:            inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   2306:            p->prefixlen);
                   2307:     }
                   2308: 
                   2309:   /* Make new BGP info. */
                   2310:   new = bgp_info_new ();
                   2311:   new->type = type;
                   2312:   new->sub_type = sub_type;
                   2313:   new->peer = peer;
                   2314:   new->attr = attr_new;
                   2315:   new->uptime = bgp_clock ();
                   2316: 
                   2317:   /* Update MPLS tag. */
                   2318:   if (safi == SAFI_MPLS_VPN)
                   2319:     memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
                   2320: 
                   2321:   /* Nexthop reachability check. */
                   2322:   if ((afi == AFI_IP || afi == AFI_IP6)
                   2323:       && safi == SAFI_UNICAST
                   2324:       && (peer_sort (peer) == BGP_PEER_IBGP
                   2325:           || peer_sort (peer) == BGP_PEER_CONFED
                   2326:          || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
                   2327:          || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
                   2328:     {
                   2329:       if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
                   2330:        bgp_info_set_flag (rn, new, BGP_INFO_VALID);
                   2331:       else
                   2332:         bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
                   2333:     }
                   2334:   else
                   2335:     bgp_info_set_flag (rn, new, BGP_INFO_VALID);
                   2336: 
                   2337:   /* Increment prefix */
                   2338:   bgp_aggregate_increment (bgp, p, new, afi, safi);
                   2339:   
                   2340:   /* Register new BGP information. */
                   2341:   bgp_info_add (rn, new);
                   2342:   
                   2343:   /* route_node_get lock */
                   2344:   bgp_unlock_node (rn);
                   2345:   
                   2346:   bgp_attr_extra_free (&new_attr);
                   2347:   
                   2348:   /* If maximum prefix count is configured and current prefix
                   2349:      count exeed it. */
                   2350:   if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
                   2351:     return -1;
                   2352: 
                   2353:   /* Process change. */
                   2354:   bgp_process (bgp, rn, afi, safi);
                   2355: 
                   2356:   return 0;
                   2357: 
                   2358:   /* This BGP update is filtered.  Log the reason then update BGP
                   2359:      entry.  */
                   2360:  filtered:
                   2361:   if (BGP_DEBUG (update, UPDATE_IN))
                   2362:     zlog (peer->log, LOG_DEBUG,
                   2363:          "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
                   2364:          peer->host,
                   2365:          inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   2366:          p->prefixlen, reason);
                   2367: 
                   2368:   if (ri)
                   2369:     bgp_rib_remove (rn, ri, peer, afi, safi);
                   2370: 
                   2371:   bgp_unlock_node (rn);
                   2372:   
                   2373:   bgp_attr_extra_free (&new_attr);
                   2374:   
                   2375:   return 0;
                   2376: }
                   2377: 
                   2378: int
                   2379: bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
                   2380:             afi_t afi, safi_t safi, int type, int sub_type,
                   2381:             struct prefix_rd *prd, u_char *tag, int soft_reconfig)
                   2382: {
                   2383:   struct peer *rsclient;
                   2384:   struct listnode *node, *nnode;
                   2385:   struct bgp *bgp;
                   2386:   int ret;
                   2387: 
                   2388:   ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
                   2389:           soft_reconfig);
                   2390: 
                   2391:   bgp = peer->bgp;
                   2392: 
                   2393:   /* Process the update for each RS-client. */
                   2394:   for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
                   2395:     {
                   2396:       if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
                   2397:         bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
                   2398:                 sub_type, prd, tag);
                   2399:     }
                   2400: 
                   2401:   return ret;
                   2402: }
                   2403: 
                   2404: int
                   2405: bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr, 
                   2406:             afi_t afi, safi_t safi, int type, int sub_type, 
                   2407:             struct prefix_rd *prd, u_char *tag)
                   2408: {
                   2409:   struct bgp *bgp;
                   2410:   char buf[SU_ADDRSTRLEN];
                   2411:   struct bgp_node *rn;
                   2412:   struct bgp_info *ri;
                   2413:   struct peer *rsclient;
                   2414:   struct listnode *node, *nnode;
                   2415: 
                   2416:   bgp = peer->bgp;
                   2417: 
                   2418:   /* Process the withdraw for each RS-client. */
                   2419:   for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
                   2420:     {
                   2421:       if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
                   2422:         bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
                   2423:     }
                   2424: 
                   2425:   /* Logging. */
                   2426:   if (BGP_DEBUG (update, UPDATE_IN))  
                   2427:     zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
                   2428:          peer->host,
                   2429:          inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   2430:          p->prefixlen);
                   2431: 
                   2432:   /* Lookup node. */
                   2433:   rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
                   2434: 
                   2435:   /* If peer is soft reconfiguration enabled.  Record input packet for
                   2436:      further calculation. */
                   2437:   if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
                   2438:       && peer != bgp->peer_self)
                   2439:     bgp_adj_in_unset (rn, peer);
                   2440: 
                   2441:   /* Lookup withdrawn route. */
                   2442:   for (ri = rn->info; ri; ri = ri->next)
                   2443:     if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
                   2444:       break;
                   2445: 
                   2446:   /* Withdraw specified route from routing table. */
                   2447:   if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
                   2448:     bgp_rib_withdraw (rn, ri, peer, afi, safi);
                   2449:   else if (BGP_DEBUG (update, UPDATE_IN))
                   2450:     zlog (peer->log, LOG_DEBUG, 
                   2451:          "%s Can't find the route %s/%d", peer->host,
                   2452:          inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   2453:          p->prefixlen);
                   2454: 
                   2455:   /* Unlock bgp_node_get() lock. */
                   2456:   bgp_unlock_node (rn);
                   2457: 
                   2458:   return 0;
                   2459: }
                   2460: 
                   2461: void
                   2462: bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
                   2463: {
                   2464:   struct bgp *bgp;
                   2465:   struct attr attr = { 0 };
                   2466:   struct aspath *aspath = { 0 };
                   2467:   struct prefix p;
                   2468:   struct bgp_info binfo;
                   2469:   struct peer *from;
                   2470:   int ret = RMAP_DENYMATCH;
                   2471:   
                   2472:   if (!(afi == AFI_IP || afi == AFI_IP6))
                   2473:     return;
                   2474:   
                   2475:   bgp = peer->bgp;
                   2476:   from = bgp->peer_self;
                   2477:   
                   2478:   bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
                   2479:   aspath = attr.aspath;
                   2480:   attr.local_pref = bgp->default_local_pref;
                   2481:   memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
                   2482: 
                   2483:   if (afi == AFI_IP)
                   2484:     str2prefix ("0.0.0.0/0", &p);
                   2485: #ifdef HAVE_IPV6
                   2486:   else if (afi == AFI_IP6)
                   2487:     {
                   2488:       struct attr_extra *ae;
                   2489:       attr.extra = NULL;
                   2490:       
                   2491:       ae = bgp_attr_extra_get (&attr);
                   2492:       attr.extra = ae;
                   2493:       
                   2494:       str2prefix ("::/0", &p);
                   2495: 
                   2496:       /* IPv6 global nexthop must be included. */
                   2497:       memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global, 
                   2498:              IPV6_MAX_BYTELEN);
                   2499:              ae->mp_nexthop_len = 16;
                   2500:  
                   2501:       /* If the peer is on shared nextwork and we have link-local
                   2502:         nexthop set it. */
                   2503:       if (peer->shared_network 
                   2504:          && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
                   2505:        {
                   2506:          memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local, 
                   2507:                  IPV6_MAX_BYTELEN);
                   2508:          ae->mp_nexthop_len = 32;
                   2509:        }
                   2510:     }
                   2511: #endif /* HAVE_IPV6 */
                   2512: 
                   2513:   if (peer->default_rmap[afi][safi].name)
                   2514:     {
                   2515:       binfo.peer = bgp->peer_self;
                   2516:       binfo.attr = &attr;
                   2517: 
                   2518:       SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
                   2519: 
                   2520:       ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
                   2521:                             RMAP_BGP, &binfo);
                   2522: 
                   2523:       bgp->peer_self->rmap_type = 0;
                   2524: 
                   2525:       if (ret == RMAP_DENYMATCH)
                   2526:        {
                   2527:          bgp_attr_flush (&attr);
                   2528:          withdraw = 1;
                   2529:        }
                   2530:     }
                   2531: 
                   2532:   if (withdraw)
                   2533:     {
                   2534:       if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
                   2535:        bgp_default_withdraw_send (peer, afi, safi);
                   2536:       UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
                   2537:     }
                   2538:   else
                   2539:     {
                   2540:       SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
                   2541:       bgp_default_update_send (peer, &attr, afi, safi, from);
                   2542:     }
                   2543:   
                   2544:   bgp_attr_extra_free (&attr);
                   2545:   aspath_unintern (&aspath);
                   2546: }
                   2547: 
                   2548: static void
                   2549: bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
                   2550:                    struct bgp_table *table, int rsclient)
                   2551: {
                   2552:   struct bgp_node *rn;
                   2553:   struct bgp_info *ri;
                   2554:   struct attr attr = { 0 };
                   2555:   
                   2556:   if (! table)
                   2557:     table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
                   2558: 
                   2559:   if (safi != SAFI_MPLS_VPN
                   2560:       && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
                   2561:     bgp_default_originate (peer, afi, safi, 0);
                   2562: 
                   2563:   for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
                   2564:     for (ri = rn->info; ri; ri = ri->next)
                   2565:       if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
                   2566:        {
                   2567:          if ( (rsclient) ?
                   2568:               (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
                   2569:               : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
                   2570:            bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
                   2571:          else
                   2572:            bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
                   2573:           
                   2574:           bgp_attr_extra_free (&attr);
                   2575:        }
                   2576: }
                   2577: 
                   2578: void
                   2579: bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
                   2580: {
                   2581:   struct bgp_node *rn;
                   2582:   struct bgp_table *table;
                   2583: 
                   2584:   if (peer->status != Established)
                   2585:     return;
                   2586: 
                   2587:   if (! peer->afc_nego[afi][safi])
                   2588:     return;
                   2589: 
                   2590:   /* First update is deferred until ORF or ROUTE-REFRESH is received */
                   2591:   if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
                   2592:     return;
                   2593: 
                   2594:   if (safi != SAFI_MPLS_VPN)
                   2595:     bgp_announce_table (peer, afi, safi, NULL, 0);
                   2596:   else
                   2597:     for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
                   2598:         rn = bgp_route_next(rn))
                   2599:       if ((table = (rn->info)) != NULL)
                   2600:        bgp_announce_table (peer, afi, safi, table, 0);
                   2601: 
                   2602:   if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
                   2603:     bgp_announce_table (peer, afi, safi, NULL, 1);
                   2604: }
                   2605: 
                   2606: void
                   2607: bgp_announce_route_all (struct peer *peer)
                   2608: {
                   2609:   afi_t afi;
                   2610:   safi_t safi;
                   2611:   
                   2612:   for (afi = AFI_IP; afi < AFI_MAX; afi++)
                   2613:     for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
                   2614:       bgp_announce_route (peer, afi, safi);
                   2615: }
                   2616: 
                   2617: static void
                   2618: bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
                   2619:         safi_t safi, struct bgp_table *table)
                   2620: {
                   2621:   struct bgp_node *rn;
                   2622:   struct bgp_adj_in *ain;
                   2623: 
                   2624:   if (! table)
                   2625:     table = rsclient->bgp->rib[afi][safi];
                   2626: 
                   2627:   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
                   2628:     for (ain = rn->adj_in; ain; ain = ain->next)
                   2629:       {
                   2630:         bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
                   2631:                 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
                   2632:       }
                   2633: }
                   2634: 
                   2635: void
                   2636: bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
                   2637: {
                   2638:   struct bgp_table *table;
                   2639:   struct bgp_node *rn;
                   2640:   
                   2641:   if (safi != SAFI_MPLS_VPN)
                   2642:     bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
                   2643: 
                   2644:   else
                   2645:     for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
                   2646:             rn = bgp_route_next (rn))
                   2647:       if ((table = rn->info) != NULL)
                   2648:         bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
                   2649: }
                   2650: 
                   2651: static void
                   2652: bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
                   2653:                         struct bgp_table *table)
                   2654: {
                   2655:   int ret;
                   2656:   struct bgp_node *rn;
                   2657:   struct bgp_adj_in *ain;
                   2658: 
                   2659:   if (! table)
                   2660:     table = peer->bgp->rib[afi][safi];
                   2661: 
                   2662:   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
                   2663:     for (ain = rn->adj_in; ain; ain = ain->next)
                   2664:       {
                   2665:        if (ain->peer == peer)
                   2666:          {
                   2667:            ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
                   2668:                              ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
                   2669:                              NULL, NULL, 1);
                   2670:            if (ret < 0)
                   2671:              {
                   2672:                bgp_unlock_node (rn);
                   2673:                return;
                   2674:              }
                   2675:            continue;
                   2676:          }
                   2677:       }
                   2678: }
                   2679: 
                   2680: void
                   2681: bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
                   2682: {
                   2683:   struct bgp_node *rn;
                   2684:   struct bgp_table *table;
                   2685: 
                   2686:   if (peer->status != Established)
                   2687:     return;
                   2688: 
                   2689:   if (safi != SAFI_MPLS_VPN)
                   2690:     bgp_soft_reconfig_table (peer, afi, safi, NULL);
                   2691:   else
                   2692:     for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
                   2693:         rn = bgp_route_next (rn))
                   2694:       if ((table = rn->info) != NULL)
                   2695:        bgp_soft_reconfig_table (peer, afi, safi, table);
                   2696: }
                   2697: 
                   2698: 
                   2699: struct bgp_clear_node_queue
                   2700: {
                   2701:   struct bgp_node *rn;
                   2702:   enum bgp_clear_route_type purpose;
                   2703: };
                   2704: 
                   2705: static wq_item_status
                   2706: bgp_clear_route_node (struct work_queue *wq, void *data)
                   2707: {
                   2708:   struct bgp_clear_node_queue *cnq = data;
                   2709:   struct bgp_node *rn = cnq->rn;
                   2710:   struct peer *peer = wq->spec.data;
                   2711:   struct bgp_info *ri;
                   2712:   afi_t afi = rn->table->afi;
                   2713:   safi_t safi = rn->table->safi;
                   2714:   
                   2715:   assert (rn && peer);
                   2716:   
                   2717:   for (ri = rn->info; ri; ri = ri->next)
                   2718:     if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
                   2719:       {
                   2720:         /* graceful restart STALE flag set. */
                   2721:         if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
                   2722:             && peer->nsf[afi][safi]
                   2723:             && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
                   2724:             && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
                   2725:           bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
                   2726:         else
                   2727:           bgp_rib_remove (rn, ri, peer, afi, safi);
                   2728:         break;
                   2729:       }
                   2730:   return WQ_SUCCESS;
                   2731: }
                   2732: 
                   2733: static void
                   2734: bgp_clear_node_queue_del (struct work_queue *wq, void *data)
                   2735: {
                   2736:   struct bgp_clear_node_queue *cnq = data;
                   2737:   struct bgp_node *rn = cnq->rn;
                   2738:   struct bgp_table *table = rn->table;
                   2739:   
                   2740:   bgp_unlock_node (rn); 
                   2741:   bgp_table_unlock (table);
                   2742:   XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
                   2743: }
                   2744: 
                   2745: static void
                   2746: bgp_clear_node_complete (struct work_queue *wq)
                   2747: {
                   2748:   struct peer *peer = wq->spec.data;
                   2749:   
                   2750:   /* Tickle FSM to start moving again */
                   2751:   BGP_EVENT_ADD (peer, Clearing_Completed);
                   2752: 
                   2753:   peer_unlock (peer); /* bgp_clear_route */
                   2754: }
                   2755: 
                   2756: static void
                   2757: bgp_clear_node_queue_init (struct peer *peer)
                   2758: {
                   2759:   char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
                   2760:   
                   2761:   snprintf (wname, sizeof(wname), "clear %s", peer->host);
                   2762: #undef CLEAR_QUEUE_NAME_LEN
                   2763: 
                   2764:   if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
                   2765:     {
                   2766:       zlog_err ("%s: Failed to allocate work queue", __func__);
                   2767:       exit (1);
                   2768:     }
                   2769:   peer->clear_node_queue->spec.hold = 10;
                   2770:   peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
                   2771:   peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
                   2772:   peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
                   2773:   peer->clear_node_queue->spec.max_retries = 0;
                   2774:   
                   2775:   /* we only 'lock' this peer reference when the queue is actually active */
                   2776:   peer->clear_node_queue->spec.data = peer;
                   2777: }
                   2778: 
                   2779: static void
                   2780: bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
                   2781:                        struct bgp_table *table, struct peer *rsclient,
                   2782:                        enum bgp_clear_route_type purpose)
                   2783: {
                   2784:   struct bgp_node *rn;
                   2785:   
                   2786:   
                   2787:   if (! table)
                   2788:     table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
                   2789:   
                   2790:   /* If still no table => afi/safi isn't configured at all or smth. */
                   2791:   if (! table)
                   2792:     return;
                   2793:   
                   2794:   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
                   2795:     {
                   2796:       struct bgp_info *ri;
                   2797:       struct bgp_adj_in *ain;
                   2798:       struct bgp_adj_out *aout;
                   2799:       
                   2800:       if (rn->info == NULL)
                   2801:         continue;
                   2802: 
                   2803:       /* XXX:TODO: This is suboptimal, every non-empty route_node is
                   2804:        * queued for every clearing peer, regardless of whether it is
                   2805:        * relevant to the peer at hand.
                   2806:        *
                   2807:        * Overview: There are 3 different indices which need to be
                   2808:        * scrubbed, potentially, when a peer is removed:
                   2809:        *
                   2810:        * 1 peer's routes visible via the RIB (ie accepted routes)
                   2811:        * 2 peer's routes visible by the (optional) peer's adj-in index
                   2812:        * 3 other routes visible by the peer's adj-out index
                   2813:        *
                   2814:        * 3 there is no hurry in scrubbing, once the struct peer is
                   2815:        * removed from bgp->peer, we could just GC such deleted peer's
                   2816:        * adj-outs at our leisure.
                   2817:        *
                   2818:        * 1 and 2 must be 'scrubbed' in some way, at least made
                   2819:        * invisible via RIB index before peer session is allowed to be
                   2820:        * brought back up. So one needs to know when such a 'search' is
                   2821:        * complete.
                   2822:        *
                   2823:        * Ideally:
                   2824:        *
                   2825:        * - there'd be a single global queue or a single RIB walker
                   2826:        * - rather than tracking which route_nodes still need to be
                   2827:        *   examined on a peer basis, we'd track which peers still
                   2828:        *   aren't cleared
                   2829:        *
                   2830:        * Given that our per-peer prefix-counts now should be reliable,
                   2831:        * this may actually be achievable. It doesn't seem to be a huge
                   2832:        * problem at this time,
                   2833:        */
                   2834:       for (ri = rn->info; ri; ri = ri->next)
                   2835:         if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
                   2836:           {
                   2837:             struct bgp_clear_node_queue *cnq;
                   2838: 
                   2839:             /* both unlocked in bgp_clear_node_queue_del */
                   2840:             bgp_table_lock (rn->table);
                   2841:             bgp_lock_node (rn);
                   2842:             cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
                   2843:                            sizeof (struct bgp_clear_node_queue));
                   2844:             cnq->rn = rn;
                   2845:             cnq->purpose = purpose;
                   2846:             work_queue_add (peer->clear_node_queue, cnq);
                   2847:             break;
                   2848:           }
                   2849: 
                   2850:       for (ain = rn->adj_in; ain; ain = ain->next)
                   2851:         if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
                   2852:           {
                   2853:             bgp_adj_in_remove (rn, ain);
                   2854:             bgp_unlock_node (rn);
                   2855:             break;
                   2856:           }
                   2857:       for (aout = rn->adj_out; aout; aout = aout->next)
                   2858:         if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
                   2859:           {
                   2860:             bgp_adj_out_remove (rn, aout, peer, afi, safi);
                   2861:             bgp_unlock_node (rn);
                   2862:             break;
                   2863:           }
                   2864:     }
                   2865:   return;
                   2866: }
                   2867: 
                   2868: void
                   2869: bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
                   2870:                  enum bgp_clear_route_type purpose)
                   2871: {
                   2872:   struct bgp_node *rn;
                   2873:   struct bgp_table *table;
                   2874:   struct peer *rsclient;
                   2875:   struct listnode *node, *nnode;
                   2876: 
                   2877:   if (peer->clear_node_queue == NULL)
                   2878:     bgp_clear_node_queue_init (peer);
                   2879:   
                   2880:   /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
                   2881:    * Idle until it receives a Clearing_Completed event. This protects
                   2882:    * against peers which flap faster than we can we clear, which could
                   2883:    * lead to:
                   2884:    *
                   2885:    * a) race with routes from the new session being installed before
                   2886:    *    clear_route_node visits the node (to delete the route of that
                   2887:    *    peer)
                   2888:    * b) resource exhaustion, clear_route_node likely leads to an entry
                   2889:    *    on the process_main queue. Fast-flapping could cause that queue
                   2890:    *    to grow and grow.
                   2891:    */
                   2892:   if (!peer->clear_node_queue->thread)
                   2893:     peer_lock (peer); /* bgp_clear_node_complete */
                   2894: 
                   2895:   switch (purpose)
                   2896:     {
                   2897:     case BGP_CLEAR_ROUTE_NORMAL:
                   2898:       if (safi != SAFI_MPLS_VPN)
                   2899:         bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
                   2900:       else
                   2901:         for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
                   2902:              rn = bgp_route_next (rn))
                   2903:           if ((table = rn->info) != NULL)
                   2904:             bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
                   2905: 
                   2906:       for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
                   2907:         if (CHECK_FLAG(rsclient->af_flags[afi][safi],
                   2908:                        PEER_FLAG_RSERVER_CLIENT))
                   2909:           bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
                   2910:       break;
                   2911: 
                   2912:     case BGP_CLEAR_ROUTE_MY_RSCLIENT:
                   2913:       bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
                   2914:       break;
                   2915: 
                   2916:     default:
                   2917:       assert (0);
                   2918:       break;
                   2919:     }
                   2920:   
                   2921:   /* If no routes were cleared, nothing was added to workqueue, the
                   2922:    * completion function won't be run by workqueue code - call it here. 
                   2923:    * XXX: Actually, this assumption doesn't hold, see
                   2924:    * bgp_clear_route_table(), we queue all non-empty nodes.
                   2925:    *
                   2926:    * Additionally, there is a presumption in FSM that clearing is only
                   2927:    * really needed if peer state is Established - peers in
                   2928:    * pre-Established states shouldn't have any route-update state
                   2929:    * associated with them (in or out).
                   2930:    *
                   2931:    * We still can get here in pre-Established though, through
                   2932:    * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
                   2933:    * check to ensure the assumption above holds.
                   2934:    *
                   2935:    * At some future point, this check could be move to the top of the
                   2936:    * function, and do a quick early-return when state is
                   2937:    * pre-Established, avoiding above list and table scans. Once we're
                   2938:    * sure it is safe..
                   2939:    */
                   2940:   if (!peer->clear_node_queue->thread)
                   2941:     bgp_clear_node_complete (peer->clear_node_queue);
                   2942: }
                   2943:   
                   2944: void
                   2945: bgp_clear_route_all (struct peer *peer)
                   2946: {
                   2947:   afi_t afi;
                   2948:   safi_t safi;
                   2949: 
                   2950:   for (afi = AFI_IP; afi < AFI_MAX; afi++)
                   2951:     for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
                   2952:       bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
                   2953: }
                   2954: 
                   2955: void
                   2956: bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
                   2957: {
                   2958:   struct bgp_table *table;
                   2959:   struct bgp_node *rn;
                   2960:   struct bgp_adj_in *ain;
                   2961: 
                   2962:   table = peer->bgp->rib[afi][safi];
                   2963: 
                   2964:   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
                   2965:     for (ain = rn->adj_in; ain ; ain = ain->next)
                   2966:       if (ain->peer == peer)
                   2967:        {
                   2968:           bgp_adj_in_remove (rn, ain);
                   2969:           bgp_unlock_node (rn);
                   2970:           break;
                   2971:        }
                   2972: }
                   2973: 
                   2974: void
                   2975: bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
                   2976: {
                   2977:   struct bgp_node *rn;
                   2978:   struct bgp_info *ri;
                   2979:   struct bgp_table *table;
                   2980: 
                   2981:   table = peer->bgp->rib[afi][safi];
                   2982: 
                   2983:   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
                   2984:     {
                   2985:       for (ri = rn->info; ri; ri = ri->next)
                   2986:        if (ri->peer == peer)
                   2987:          {
                   2988:            if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
                   2989:              bgp_rib_remove (rn, ri, peer, afi, safi);
                   2990:            break;
                   2991:          }
                   2992:     }
                   2993: }
                   2994: 
                   2995: /* Delete all kernel routes. */
                   2996: void
                   2997: bgp_cleanup_routes (void)
                   2998: {
                   2999:   struct bgp *bgp;
                   3000:   struct listnode *node, *nnode;
                   3001:   struct bgp_node *rn;
                   3002:   struct bgp_table *table;
                   3003:   struct bgp_info *ri;
                   3004: 
                   3005:   for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
                   3006:     {
                   3007:       table = bgp->rib[AFI_IP][SAFI_UNICAST];
                   3008: 
                   3009:       for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
                   3010:        for (ri = rn->info; ri; ri = ri->next)
                   3011:          if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
                   3012:              && ri->type == ZEBRA_ROUTE_BGP 
                   3013:              && ri->sub_type == BGP_ROUTE_NORMAL)
1.1.1.2 ! misho    3014:            bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
1.1       misho    3015: 
                   3016:       table = bgp->rib[AFI_IP6][SAFI_UNICAST];
                   3017: 
                   3018:       for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
                   3019:        for (ri = rn->info; ri; ri = ri->next)
                   3020:          if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
                   3021:              && ri->type == ZEBRA_ROUTE_BGP 
                   3022:              && ri->sub_type == BGP_ROUTE_NORMAL)
1.1.1.2 ! misho    3023:            bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
1.1       misho    3024:     }
                   3025: }
                   3026: 
                   3027: void
                   3028: bgp_reset (void)
                   3029: {
                   3030:   vty_reset ();
                   3031:   bgp_zclient_reset ();
                   3032:   access_list_reset ();
                   3033:   prefix_list_reset ();
                   3034: }
                   3035: 
                   3036: /* Parse NLRI stream.  Withdraw NLRI is recognized by NULL attr
                   3037:    value. */
                   3038: int
                   3039: bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
                   3040: {
                   3041:   u_char *pnt;
                   3042:   u_char *lim;
                   3043:   struct prefix p;
                   3044:   int psize;
                   3045:   int ret;
                   3046: 
                   3047:   /* Check peer status. */
                   3048:   if (peer->status != Established)
                   3049:     return 0;
                   3050:   
                   3051:   pnt = packet->nlri;
                   3052:   lim = pnt + packet->length;
                   3053: 
                   3054:   for (; pnt < lim; pnt += psize)
                   3055:     {
                   3056:       /* Clear prefix structure. */
                   3057:       memset (&p, 0, sizeof (struct prefix));
                   3058: 
                   3059:       /* Fetch prefix length. */
                   3060:       p.prefixlen = *pnt++;
                   3061:       p.family = afi2family (packet->afi);
                   3062:       
                   3063:       /* Already checked in nlri_sanity_check().  We do double check
                   3064:          here. */
                   3065:       if ((packet->afi == AFI_IP && p.prefixlen > 32)
                   3066:          || (packet->afi == AFI_IP6 && p.prefixlen > 128))
                   3067:        return -1;
                   3068: 
                   3069:       /* Packet size overflow check. */
                   3070:       psize = PSIZE (p.prefixlen);
                   3071: 
                   3072:       /* When packet overflow occur return immediately. */
                   3073:       if (pnt + psize > lim)
                   3074:        return -1;
                   3075: 
                   3076:       /* Fetch prefix from NLRI packet. */
                   3077:       memcpy (&p.u.prefix, pnt, psize);
                   3078: 
                   3079:       /* Check address. */
                   3080:       if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
                   3081:        {
                   3082:          if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
                   3083:            {
                   3084:             /* 
                   3085:              * From draft-ietf-idr-bgp4-22, Section 6.3: 
                   3086:              * If a BGP router receives an UPDATE message with a
                   3087:              * semantically incorrect NLRI field, in which a prefix is
                   3088:              * semantically incorrect (eg. an unexpected multicast IP
                   3089:              * address), it should ignore the prefix.
                   3090:              */
                   3091:              zlog (peer->log, LOG_ERR, 
                   3092:                    "IPv4 unicast NLRI is multicast address %s",
                   3093:                    inet_ntoa (p.u.prefix4));
                   3094: 
                   3095:              return -1;
                   3096:            }
                   3097:        }
                   3098: 
                   3099: #ifdef HAVE_IPV6
                   3100:       /* Check address. */
                   3101:       if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
                   3102:        {
                   3103:          if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
                   3104:            {
                   3105:              char buf[BUFSIZ];
                   3106: 
                   3107:              zlog (peer->log, LOG_WARNING, 
                   3108:                    "IPv6 link-local NLRI received %s ignore this NLRI",
                   3109:                    inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
                   3110: 
                   3111:              continue;
                   3112:            }
                   3113:        }
                   3114: #endif /* HAVE_IPV6 */
                   3115: 
                   3116:       /* Normal process. */
                   3117:       if (attr)
                   3118:        ret = bgp_update (peer, &p, attr, packet->afi, packet->safi, 
                   3119:                          ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
                   3120:       else
                   3121:        ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi, 
                   3122:                            ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
                   3123: 
                   3124:       /* Address family configuration mismatch or maximum-prefix count
                   3125:          overflow. */
                   3126:       if (ret < 0)
                   3127:        return -1;
                   3128:     }
                   3129: 
                   3130:   /* Packet length consistency check. */
                   3131:   if (pnt != lim)
                   3132:     return -1;
                   3133: 
                   3134:   return 0;
                   3135: }
                   3136: 
                   3137: /* NLRI encode syntax check routine. */
                   3138: int
                   3139: bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
                   3140:                       bgp_size_t length)
                   3141: {
                   3142:   u_char *end;
                   3143:   u_char prefixlen;
                   3144:   int psize;
                   3145: 
                   3146:   end = pnt + length;
                   3147: 
                   3148:   /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
                   3149:      syntactic validity.  If the field is syntactically incorrect,
                   3150:      then the Error Subcode is set to Invalid Network Field. */
                   3151: 
                   3152:   while (pnt < end)
                   3153:     {
                   3154:       prefixlen = *pnt++;
                   3155:       
                   3156:       /* Prefix length check. */
                   3157:       if ((afi == AFI_IP && prefixlen > 32)
                   3158:          || (afi == AFI_IP6 && prefixlen > 128))
                   3159:        {
                   3160:          plog_err (peer->log, 
                   3161:                    "%s [Error] Update packet error (wrong prefix length %d)",
                   3162:                    peer->host, prefixlen);
                   3163:          bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR, 
                   3164:                           BGP_NOTIFY_UPDATE_INVAL_NETWORK);
                   3165:          return -1;
                   3166:        }
                   3167: 
                   3168:       /* Packet size overflow check. */
                   3169:       psize = PSIZE (prefixlen);
                   3170: 
                   3171:       if (pnt + psize > end)
                   3172:        {
                   3173:          plog_err (peer->log, 
                   3174:                    "%s [Error] Update packet error"
                   3175:                    " (prefix data overflow prefix size is %d)",
                   3176:                    peer->host, psize);
                   3177:          bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR, 
                   3178:                           BGP_NOTIFY_UPDATE_INVAL_NETWORK);
                   3179:          return -1;
                   3180:        }
                   3181: 
                   3182:       pnt += psize;
                   3183:     }
                   3184: 
                   3185:   /* Packet length consistency check. */
                   3186:   if (pnt != end)
                   3187:     {
                   3188:       plog_err (peer->log,
                   3189:                "%s [Error] Update packet error"
                   3190:                " (prefix length mismatch with total length)",
                   3191:                peer->host);
                   3192:       bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR, 
                   3193:                       BGP_NOTIFY_UPDATE_INVAL_NETWORK);
                   3194:       return -1;
                   3195:     }
                   3196:   return 0;
                   3197: }
                   3198: 
                   3199: static struct bgp_static *
                   3200: bgp_static_new (void)
                   3201: {
                   3202:   return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
                   3203: }
                   3204: 
                   3205: static void
                   3206: bgp_static_free (struct bgp_static *bgp_static)
                   3207: {
                   3208:   if (bgp_static->rmap.name)
                   3209:     free (bgp_static->rmap.name);
                   3210:   XFREE (MTYPE_BGP_STATIC, bgp_static);
                   3211: }
                   3212: 
                   3213: static void
                   3214: bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
                   3215:         struct prefix *p, afi_t afi, safi_t safi)
                   3216: {
                   3217:   struct bgp_node *rn;
                   3218:   struct bgp_info *ri;
                   3219: 
                   3220:   rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
                   3221: 
                   3222:   /* Check selected route and self inserted route. */
                   3223:   for (ri = rn->info; ri; ri = ri->next)
                   3224:     if (ri->peer == bgp->peer_self
                   3225:        && ri->type == ZEBRA_ROUTE_BGP
                   3226:        && ri->sub_type == BGP_ROUTE_STATIC)
                   3227:       break;
                   3228: 
                   3229:   /* Withdraw static BGP route from routing table. */
                   3230:   if (ri)
                   3231:     {
                   3232:       bgp_info_delete (rn, ri);
                   3233:       bgp_process (bgp, rn, afi, safi);
                   3234:     }
                   3235: 
                   3236:   /* Unlock bgp_node_lookup. */
                   3237:   bgp_unlock_node (rn);
                   3238: }
                   3239: 
                   3240: static void
                   3241: bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
                   3242:                             struct bgp_static *bgp_static,
                   3243:                             afi_t afi, safi_t safi)
                   3244: {
                   3245:   struct bgp_node *rn;
                   3246:   struct bgp_info *ri;
                   3247:   struct bgp_info *new;
                   3248:   struct bgp_info info;
                   3249:   struct attr *attr_new;
                   3250:   struct attr attr = {0 };
                   3251:   struct attr new_attr = { .extra = 0 };
                   3252:   struct bgp *bgp;
                   3253:   int ret;
                   3254:   char buf[SU_ADDRSTRLEN];
                   3255: 
                   3256:   bgp = rsclient->bgp;
                   3257: 
                   3258:   assert (bgp_static);
                   3259:   if (!bgp_static)
                   3260:     return;
                   3261: 
                   3262:   rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
                   3263: 
                   3264:   bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
                   3265: 
                   3266:   attr.nexthop = bgp_static->igpnexthop;
                   3267:   attr.med = bgp_static->igpmetric;
                   3268:   attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
                   3269:   
                   3270:   if (bgp_static->atomic)
                   3271:     attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
                   3272:   
                   3273:   /* Apply network route-map for export to this rsclient. */
                   3274:   if (bgp_static->rmap.name)
                   3275:     {
                   3276:       struct attr attr_tmp = attr;
                   3277:       info.peer = rsclient;
                   3278:       info.attr = &attr_tmp;
                   3279:       
                   3280:       SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
                   3281:       SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
                   3282: 
                   3283:       ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
                   3284: 
                   3285:       rsclient->rmap_type = 0;
                   3286: 
                   3287:       if (ret == RMAP_DENYMATCH)
                   3288:         {
                   3289:           /* Free uninterned attribute. */
                   3290:           bgp_attr_flush (&attr_tmp);
                   3291: 
                   3292:           /* Unintern original. */
                   3293:           aspath_unintern (&attr.aspath);
                   3294:           bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
                   3295:           bgp_attr_extra_free (&attr);
                   3296:           
                   3297:           return;
                   3298:         }
                   3299:       attr_new = bgp_attr_intern (&attr_tmp);
                   3300:     }
                   3301:   else
                   3302:     attr_new = bgp_attr_intern (&attr);
                   3303:   
                   3304:   bgp_attr_dup(&new_attr, attr_new);
                   3305:   
                   3306:   SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
                   3307: 
                   3308:   if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi) 
                   3309:         == RMAP_DENY)
                   3310:     {
                   3311:       /* This BGP update is filtered.  Log the reason then update BGP entry.  */
                   3312:       if (BGP_DEBUG (update, UPDATE_IN))
                   3313:               zlog (rsclient->log, LOG_DEBUG,
                   3314:               "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
                   3315:               inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   3316:               p->prefixlen, rsclient->host);
                   3317: 
                   3318:       bgp->peer_self->rmap_type = 0;
                   3319: 
                   3320:       bgp_attr_unintern (&attr_new);
                   3321:       aspath_unintern (&attr.aspath);
                   3322:       bgp_attr_extra_free (&attr);
                   3323: 
                   3324:       bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
                   3325:       
                   3326:       return;
                   3327:     }
                   3328: 
                   3329:   bgp->peer_self->rmap_type = 0;
                   3330: 
                   3331:   bgp_attr_unintern (&attr_new);
                   3332:   attr_new = bgp_attr_intern (&new_attr);
                   3333:   bgp_attr_extra_free (&new_attr);
                   3334: 
                   3335:   for (ri = rn->info; ri; ri = ri->next)
                   3336:     if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
                   3337:             && ri->sub_type == BGP_ROUTE_STATIC)
                   3338:       break;
                   3339: 
                   3340:   if (ri)
                   3341:        {
                   3342:       if (attrhash_cmp (ri->attr, attr_new) &&
                   3343:          !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
                   3344:         {
                   3345:           bgp_unlock_node (rn);
                   3346:           bgp_attr_unintern (&attr_new);
                   3347:           aspath_unintern (&attr.aspath);
                   3348:           bgp_attr_extra_free (&attr);
                   3349:           return;
                   3350:        }
                   3351:       else
                   3352:         {
                   3353:           /* The attribute is changed. */
                   3354:           bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
                   3355: 
                   3356:           /* Rewrite BGP route information. */
                   3357:          if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
                   3358:            bgp_info_restore(rn, ri);
                   3359:           bgp_attr_unintern (&ri->attr);
                   3360:           ri->attr = attr_new;
                   3361:           ri->uptime = bgp_clock ();
                   3362: 
                   3363:           /* Process change. */
                   3364:           bgp_process (bgp, rn, afi, safi);
                   3365:           bgp_unlock_node (rn);
                   3366:           aspath_unintern (&attr.aspath);
                   3367:           bgp_attr_extra_free (&attr);
                   3368:           return;
                   3369:         }
                   3370:     }
                   3371:   
                   3372:   /* Make new BGP info. */
                   3373:   new = bgp_info_new ();
                   3374:   new->type = ZEBRA_ROUTE_BGP;
                   3375:   new->sub_type = BGP_ROUTE_STATIC;
                   3376:   new->peer = bgp->peer_self;
                   3377:   SET_FLAG (new->flags, BGP_INFO_VALID);
                   3378:   new->attr = attr_new;
                   3379:   new->uptime = bgp_clock ();
                   3380: 
                   3381:   /* Register new BGP information. */
                   3382:   bgp_info_add (rn, new);
                   3383:   
                   3384:   /* route_node_get lock */
                   3385:   bgp_unlock_node (rn);
                   3386:   
                   3387:   /* Process change. */
                   3388:   bgp_process (bgp, rn, afi, safi);
                   3389: 
                   3390:   /* Unintern original. */
                   3391:   aspath_unintern (&attr.aspath);
                   3392:   bgp_attr_extra_free (&attr);
                   3393: }
                   3394: 
                   3395: static void
                   3396: bgp_static_update_main (struct bgp *bgp, struct prefix *p,
                   3397:                   struct bgp_static *bgp_static, afi_t afi, safi_t safi)
                   3398: {
                   3399:   struct bgp_node *rn;
                   3400:   struct bgp_info *ri;
                   3401:   struct bgp_info *new;
                   3402:   struct bgp_info info;
                   3403:   struct attr attr = { 0 };
                   3404:   struct attr *attr_new;
                   3405:   int ret;
                   3406: 
                   3407:   assert (bgp_static);
                   3408:   if (!bgp_static)
                   3409:     return;
                   3410: 
                   3411:   rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
                   3412: 
                   3413:   bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
                   3414:   
                   3415:   attr.nexthop = bgp_static->igpnexthop;
                   3416:   attr.med = bgp_static->igpmetric;
                   3417:   attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
                   3418: 
                   3419:   if (bgp_static->atomic)
                   3420:     attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
                   3421: 
                   3422:   /* Apply route-map. */
                   3423:   if (bgp_static->rmap.name)
                   3424:     {
                   3425:       struct attr attr_tmp = attr;
                   3426:       info.peer = bgp->peer_self;
                   3427:       info.attr = &attr_tmp;
                   3428: 
                   3429:       SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
                   3430: 
                   3431:       ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
                   3432: 
                   3433:       bgp->peer_self->rmap_type = 0;
                   3434: 
                   3435:       if (ret == RMAP_DENYMATCH)
                   3436:        {    
                   3437:          /* Free uninterned attribute. */
                   3438:          bgp_attr_flush (&attr_tmp);
                   3439: 
                   3440:          /* Unintern original. */
                   3441:          aspath_unintern (&attr.aspath);
                   3442:          bgp_attr_extra_free (&attr);
                   3443:          bgp_static_withdraw (bgp, p, afi, safi);
                   3444:          return;
                   3445:        }
                   3446:       attr_new = bgp_attr_intern (&attr_tmp);
                   3447:     }
                   3448:   else
                   3449:     attr_new = bgp_attr_intern (&attr);
                   3450: 
                   3451:   for (ri = rn->info; ri; ri = ri->next)
                   3452:     if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
                   3453:        && ri->sub_type == BGP_ROUTE_STATIC)
                   3454:       break;
                   3455: 
                   3456:   if (ri)
                   3457:     {
                   3458:       if (attrhash_cmp (ri->attr, attr_new) &&
                   3459:          !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
                   3460:        {
                   3461:          bgp_unlock_node (rn);
                   3462:          bgp_attr_unintern (&attr_new);
                   3463:          aspath_unintern (&attr.aspath);
                   3464:          bgp_attr_extra_free (&attr);
                   3465:          return;
                   3466:        }
                   3467:       else
                   3468:        {
                   3469:          /* The attribute is changed. */
                   3470:          bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
                   3471: 
                   3472:          /* Rewrite BGP route information. */
                   3473:          if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
                   3474:            bgp_info_restore(rn, ri);
                   3475:          else
                   3476:            bgp_aggregate_decrement (bgp, p, ri, afi, safi);
                   3477:          bgp_attr_unintern (&ri->attr);
                   3478:          ri->attr = attr_new;
                   3479:          ri->uptime = bgp_clock ();
                   3480: 
                   3481:          /* Process change. */
                   3482:          bgp_aggregate_increment (bgp, p, ri, afi, safi);
                   3483:          bgp_process (bgp, rn, afi, safi);
                   3484:          bgp_unlock_node (rn);
                   3485:          aspath_unintern (&attr.aspath);
                   3486:          bgp_attr_extra_free (&attr);
                   3487:          return;
                   3488:        }
                   3489:     }
                   3490: 
                   3491:   /* Make new BGP info. */
                   3492:   new = bgp_info_new ();
                   3493:   new->type = ZEBRA_ROUTE_BGP;
                   3494:   new->sub_type = BGP_ROUTE_STATIC;
                   3495:   new->peer = bgp->peer_self;
                   3496:   SET_FLAG (new->flags, BGP_INFO_VALID);
                   3497:   new->attr = attr_new;
                   3498:   new->uptime = bgp_clock ();
                   3499: 
                   3500:   /* Aggregate address increment. */
                   3501:   bgp_aggregate_increment (bgp, p, new, afi, safi);
                   3502:   
                   3503:   /* Register new BGP information. */
                   3504:   bgp_info_add (rn, new);
                   3505:   
                   3506:   /* route_node_get lock */
                   3507:   bgp_unlock_node (rn);
                   3508:   
                   3509:   /* Process change. */
                   3510:   bgp_process (bgp, rn, afi, safi);
                   3511: 
                   3512:   /* Unintern original. */
                   3513:   aspath_unintern (&attr.aspath);
                   3514:   bgp_attr_extra_free (&attr);
                   3515: }
                   3516: 
                   3517: void
                   3518: bgp_static_update (struct bgp *bgp, struct prefix *p,
                   3519:                   struct bgp_static *bgp_static, afi_t afi, safi_t safi)
                   3520: {
                   3521:   struct peer *rsclient;
                   3522:   struct listnode *node, *nnode;
                   3523: 
                   3524:   bgp_static_update_main (bgp, p, bgp_static, afi, safi);
                   3525: 
                   3526:   for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
                   3527:     {
                   3528:       if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
                   3529:         bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
                   3530:     }
                   3531: }
                   3532: 
                   3533: static void
                   3534: bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
                   3535:                         safi_t safi, struct prefix_rd *prd, u_char *tag)
                   3536: {
                   3537:   struct bgp_node *rn;
                   3538:   struct bgp_info *new;
                   3539:   
                   3540:   rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
                   3541: 
                   3542:   /* Make new BGP info. */
                   3543:   new = bgp_info_new ();
                   3544:   new->type = ZEBRA_ROUTE_BGP;
                   3545:   new->sub_type = BGP_ROUTE_STATIC;
                   3546:   new->peer = bgp->peer_self;
                   3547:   new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
                   3548:   SET_FLAG (new->flags, BGP_INFO_VALID);
                   3549:   new->uptime = bgp_clock ();
                   3550:   new->extra = bgp_info_extra_new();
                   3551:   memcpy (new->extra->tag, tag, 3);
                   3552: 
                   3553:   /* Aggregate address increment. */
                   3554:   bgp_aggregate_increment (bgp, p, new, afi, safi);
                   3555:   
                   3556:   /* Register new BGP information. */
                   3557:   bgp_info_add (rn, new);
                   3558: 
                   3559:   /* route_node_get lock */
                   3560:   bgp_unlock_node (rn);
                   3561:   
                   3562:   /* Process change. */
                   3563:   bgp_process (bgp, rn, afi, safi);
                   3564: }
                   3565: 
                   3566: void
                   3567: bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
                   3568:                     safi_t safi)
                   3569: {
                   3570:   struct bgp_node *rn;
                   3571:   struct bgp_info *ri;
                   3572: 
                   3573:   rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
                   3574: 
                   3575:   /* Check selected route and self inserted route. */
                   3576:   for (ri = rn->info; ri; ri = ri->next)
                   3577:     if (ri->peer == bgp->peer_self 
                   3578:        && ri->type == ZEBRA_ROUTE_BGP
                   3579:        && ri->sub_type == BGP_ROUTE_STATIC)
                   3580:       break;
                   3581: 
                   3582:   /* Withdraw static BGP route from routing table. */
                   3583:   if (ri)
                   3584:     {
                   3585:       bgp_aggregate_decrement (bgp, p, ri, afi, safi);
                   3586:       bgp_info_delete (rn, ri);
                   3587:       bgp_process (bgp, rn, afi, safi);
                   3588:     }
                   3589: 
                   3590:   /* Unlock bgp_node_lookup. */
                   3591:   bgp_unlock_node (rn);
                   3592: }
                   3593: 
                   3594: void
                   3595: bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
                   3596: {
                   3597:   struct bgp_static *bgp_static;
                   3598:   struct bgp *bgp;
                   3599:   struct bgp_node *rn;
                   3600:   struct prefix *p;
                   3601: 
                   3602:   bgp = rsclient->bgp;
                   3603: 
                   3604:   for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
                   3605:     if ((bgp_static = rn->info) != NULL)
                   3606:       {
                   3607:         p = &rn->p;
                   3608: 
                   3609:         bgp_static_update_rsclient (rsclient, p, bgp_static,
                   3610:                 afi, safi);
                   3611:       }
                   3612: }
                   3613: 
                   3614: static void
                   3615: bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
                   3616:                           safi_t safi, struct prefix_rd *prd, u_char *tag)
                   3617: {
                   3618:   struct bgp_node *rn;
                   3619:   struct bgp_info *ri;
                   3620: 
                   3621:   rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
                   3622: 
                   3623:   /* Check selected route and self inserted route. */
                   3624:   for (ri = rn->info; ri; ri = ri->next)
                   3625:     if (ri->peer == bgp->peer_self 
                   3626:        && ri->type == ZEBRA_ROUTE_BGP
                   3627:        && ri->sub_type == BGP_ROUTE_STATIC)
                   3628:       break;
                   3629: 
                   3630:   /* Withdraw static BGP route from routing table. */
                   3631:   if (ri)
                   3632:     {
                   3633:       bgp_aggregate_decrement (bgp, p, ri, afi, safi);
                   3634:       bgp_info_delete (rn, ri);
                   3635:       bgp_process (bgp, rn, afi, safi);
                   3636:     }
                   3637: 
                   3638:   /* Unlock bgp_node_lookup. */
                   3639:   bgp_unlock_node (rn);
                   3640: }
                   3641: 
                   3642: /* Configure static BGP network.  When user don't run zebra, static
                   3643:    route should be installed as valid.  */
                   3644: static int
                   3645: bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str, 
                   3646:                 afi_t afi, safi_t safi, const char *rmap, int backdoor)
                   3647: {
                   3648:   int ret;
                   3649:   struct prefix p;
                   3650:   struct bgp_static *bgp_static;
                   3651:   struct bgp_node *rn;
                   3652:   u_char need_update = 0;
                   3653: 
                   3654:   /* Convert IP prefix string to struct prefix. */
                   3655:   ret = str2prefix (ip_str, &p);
                   3656:   if (! ret)
                   3657:     {
                   3658:       vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
                   3659:       return CMD_WARNING;
                   3660:     }
                   3661: #ifdef HAVE_IPV6
                   3662:   if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
                   3663:     {
                   3664:       vty_out (vty, "%% Malformed prefix (link-local address)%s",
                   3665:               VTY_NEWLINE);
                   3666:       return CMD_WARNING;
                   3667:     }
                   3668: #endif /* HAVE_IPV6 */
                   3669: 
                   3670:   apply_mask (&p);
                   3671: 
                   3672:   /* Set BGP static route configuration. */
                   3673:   rn = bgp_node_get (bgp->route[afi][safi], &p);
                   3674: 
                   3675:   if (rn->info)
                   3676:     {
                   3677:       /* Configuration change. */
                   3678:       bgp_static = rn->info;
                   3679: 
                   3680:       /* Check previous routes are installed into BGP.  */
                   3681:       if (bgp_static->valid && bgp_static->backdoor != backdoor)
                   3682:         need_update = 1;
                   3683:       
                   3684:       bgp_static->backdoor = backdoor;
                   3685:       
                   3686:       if (rmap)
                   3687:        {
                   3688:          if (bgp_static->rmap.name)
                   3689:            free (bgp_static->rmap.name);
                   3690:          bgp_static->rmap.name = strdup (rmap);
                   3691:          bgp_static->rmap.map = route_map_lookup_by_name (rmap);
                   3692:        }
                   3693:       else
                   3694:        {
                   3695:          if (bgp_static->rmap.name)
                   3696:            free (bgp_static->rmap.name);
                   3697:          bgp_static->rmap.name = NULL;
                   3698:          bgp_static->rmap.map = NULL;
                   3699:          bgp_static->valid = 0;
                   3700:        }
                   3701:       bgp_unlock_node (rn);
                   3702:     }
                   3703:   else
                   3704:     {
                   3705:       /* New configuration. */
                   3706:       bgp_static = bgp_static_new ();
                   3707:       bgp_static->backdoor = backdoor;
                   3708:       bgp_static->valid = 0;
                   3709:       bgp_static->igpmetric = 0;
                   3710:       bgp_static->igpnexthop.s_addr = 0;
                   3711:       
                   3712:       if (rmap)
                   3713:        {
                   3714:          if (bgp_static->rmap.name)
                   3715:            free (bgp_static->rmap.name);
                   3716:          bgp_static->rmap.name = strdup (rmap);
                   3717:          bgp_static->rmap.map = route_map_lookup_by_name (rmap);
                   3718:        }
                   3719:       rn->info = bgp_static;
                   3720:     }
                   3721: 
                   3722:   /* If BGP scan is not enabled, we should install this route here.  */
                   3723:   if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
                   3724:     {
                   3725:       bgp_static->valid = 1;
                   3726: 
                   3727:       if (need_update)
                   3728:        bgp_static_withdraw (bgp, &p, afi, safi);
                   3729: 
                   3730:       if (! bgp_static->backdoor)
                   3731:        bgp_static_update (bgp, &p, bgp_static, afi, safi);
                   3732:     }
                   3733: 
                   3734:   return CMD_SUCCESS;
                   3735: }
                   3736: 
                   3737: /* Configure static BGP network. */
                   3738: static int
                   3739: bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
                   3740:                  afi_t afi, safi_t safi)
                   3741: {
                   3742:   int ret;
                   3743:   struct prefix p;
                   3744:   struct bgp_static *bgp_static;
                   3745:   struct bgp_node *rn;
                   3746: 
                   3747:   /* Convert IP prefix string to struct prefix. */
                   3748:   ret = str2prefix (ip_str, &p);
                   3749:   if (! ret)
                   3750:     {
                   3751:       vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
                   3752:       return CMD_WARNING;
                   3753:     }
                   3754: #ifdef HAVE_IPV6
                   3755:   if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
                   3756:     {
                   3757:       vty_out (vty, "%% Malformed prefix (link-local address)%s",
                   3758:               VTY_NEWLINE);
                   3759:       return CMD_WARNING;
                   3760:     }
                   3761: #endif /* HAVE_IPV6 */
                   3762: 
                   3763:   apply_mask (&p);
                   3764: 
                   3765:   rn = bgp_node_lookup (bgp->route[afi][safi], &p);
                   3766:   if (! rn)
                   3767:     {
                   3768:       vty_out (vty, "%% Can't find specified static route configuration.%s",
                   3769:               VTY_NEWLINE);
                   3770:       return CMD_WARNING;
                   3771:     }
                   3772: 
                   3773:   bgp_static = rn->info;
                   3774:   
                   3775:   /* Update BGP RIB. */
                   3776:   if (! bgp_static->backdoor)
                   3777:     bgp_static_withdraw (bgp, &p, afi, safi);
                   3778: 
                   3779:   /* Clear configuration. */
                   3780:   bgp_static_free (bgp_static);
                   3781:   rn->info = NULL;
                   3782:   bgp_unlock_node (rn);
                   3783:   bgp_unlock_node (rn);
                   3784: 
                   3785:   return CMD_SUCCESS;
                   3786: }
                   3787: 
                   3788: /* Called from bgp_delete().  Delete all static routes from the BGP
                   3789:    instance. */
                   3790: void
                   3791: bgp_static_delete (struct bgp *bgp)
                   3792: {
                   3793:   afi_t afi;
                   3794:   safi_t safi;
                   3795:   struct bgp_node *rn;
                   3796:   struct bgp_node *rm;
                   3797:   struct bgp_table *table;
                   3798:   struct bgp_static *bgp_static;
                   3799: 
                   3800:   for (afi = AFI_IP; afi < AFI_MAX; afi++)
                   3801:     for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
                   3802:       for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
                   3803:        if (rn->info != NULL)
                   3804:          {      
                   3805:            if (safi == SAFI_MPLS_VPN)
                   3806:              {
                   3807:                table = rn->info;
                   3808: 
                   3809:                for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
                   3810:                  {
                   3811:                    bgp_static = rn->info;
                   3812:                    bgp_static_withdraw_vpnv4 (bgp, &rm->p,
                   3813:                                               AFI_IP, SAFI_MPLS_VPN,
                   3814:                                               (struct prefix_rd *)&rn->p,
                   3815:                                               bgp_static->tag);
                   3816:                    bgp_static_free (bgp_static);
                   3817:                    rn->info = NULL;
                   3818:                    bgp_unlock_node (rn);
                   3819:                  }
                   3820:              }
                   3821:            else
                   3822:              {
                   3823:                bgp_static = rn->info;
                   3824:                bgp_static_withdraw (bgp, &rn->p, afi, safi);
                   3825:                bgp_static_free (bgp_static);
                   3826:                rn->info = NULL;
                   3827:                bgp_unlock_node (rn);
                   3828:              }
                   3829:          }
                   3830: }
                   3831: 
                   3832: int
                   3833: bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
                   3834:                      const char *tag_str)
                   3835: {
                   3836:   int ret;
                   3837:   struct prefix p;
                   3838:   struct prefix_rd prd;
                   3839:   struct bgp *bgp;
                   3840:   struct bgp_node *prn;
                   3841:   struct bgp_node *rn;
                   3842:   struct bgp_table *table;
                   3843:   struct bgp_static *bgp_static;
                   3844:   u_char tag[3];
                   3845: 
                   3846:   bgp = vty->index;
                   3847: 
                   3848:   ret = str2prefix (ip_str, &p);
                   3849:   if (! ret)
                   3850:     {
                   3851:       vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
                   3852:       return CMD_WARNING;
                   3853:     }
                   3854:   apply_mask (&p);
                   3855: 
                   3856:   ret = str2prefix_rd (rd_str, &prd);
                   3857:   if (! ret)
                   3858:     {
                   3859:       vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
                   3860:       return CMD_WARNING;
                   3861:     }
                   3862: 
                   3863:   ret = str2tag (tag_str, tag);
                   3864:   if (! ret)
                   3865:     {
                   3866:       vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
                   3867:       return CMD_WARNING;
                   3868:     }
                   3869: 
                   3870:   prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
                   3871:                        (struct prefix *)&prd);
                   3872:   if (prn->info == NULL)
                   3873:     prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
                   3874:   else
                   3875:     bgp_unlock_node (prn);
                   3876:   table = prn->info;
                   3877: 
                   3878:   rn = bgp_node_get (table, &p);
                   3879: 
                   3880:   if (rn->info)
                   3881:     {
                   3882:       vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
                   3883:       bgp_unlock_node (rn);
                   3884:     }
                   3885:   else
                   3886:     {
                   3887:       /* New configuration. */
                   3888:       bgp_static = bgp_static_new ();
                   3889:       bgp_static->valid = 1;
                   3890:       memcpy (bgp_static->tag, tag, 3);
                   3891:       rn->info = bgp_static;
                   3892: 
                   3893:       bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
                   3894:     }
                   3895: 
                   3896:   return CMD_SUCCESS;
                   3897: }
                   3898: 
                   3899: /* Configure static BGP network. */
                   3900: int
                   3901: bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str, 
                   3902:                         const char *rd_str, const char *tag_str)
                   3903: {
                   3904:   int ret;
                   3905:   struct bgp *bgp;
                   3906:   struct prefix p;
                   3907:   struct prefix_rd prd;
                   3908:   struct bgp_node *prn;
                   3909:   struct bgp_node *rn;
                   3910:   struct bgp_table *table;
                   3911:   struct bgp_static *bgp_static;
                   3912:   u_char tag[3];
                   3913: 
                   3914:   bgp = vty->index;
                   3915: 
                   3916:   /* Convert IP prefix string to struct prefix. */
                   3917:   ret = str2prefix (ip_str, &p);
                   3918:   if (! ret)
                   3919:     {
                   3920:       vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
                   3921:       return CMD_WARNING;
                   3922:     }
                   3923:   apply_mask (&p);
                   3924: 
                   3925:   ret = str2prefix_rd (rd_str, &prd);
                   3926:   if (! ret)
                   3927:     {
                   3928:       vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
                   3929:       return CMD_WARNING;
                   3930:     }
                   3931: 
                   3932:   ret = str2tag (tag_str, tag);
                   3933:   if (! ret)
                   3934:     {
                   3935:       vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
                   3936:       return CMD_WARNING;
                   3937:     }
                   3938: 
                   3939:   prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
                   3940:                        (struct prefix *)&prd);
                   3941:   if (prn->info == NULL)
                   3942:     prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
                   3943:   else
                   3944:     bgp_unlock_node (prn);
                   3945:   table = prn->info;
                   3946: 
                   3947:   rn = bgp_node_lookup (table, &p);
                   3948: 
                   3949:   if (rn)
                   3950:     {
                   3951:       bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
                   3952: 
                   3953:       bgp_static = rn->info;
                   3954:       bgp_static_free (bgp_static);
                   3955:       rn->info = NULL;
                   3956:       bgp_unlock_node (rn);
                   3957:       bgp_unlock_node (rn);
                   3958:     }
                   3959:   else
                   3960:     vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
                   3961: 
                   3962:   return CMD_SUCCESS;
                   3963: }
                   3964: 
                   3965: DEFUN (bgp_network,
                   3966:        bgp_network_cmd,
                   3967:        "network A.B.C.D/M",
                   3968:        "Specify a network to announce via BGP\n"
                   3969:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
                   3970: {
                   3971:   return bgp_static_set (vty, vty->index, argv[0],
                   3972:                         AFI_IP, bgp_node_safi (vty), NULL, 0);
                   3973: }
                   3974: 
                   3975: DEFUN (bgp_network_route_map,
                   3976:        bgp_network_route_map_cmd,
                   3977:        "network A.B.C.D/M route-map WORD",
                   3978:        "Specify a network to announce via BGP\n"
                   3979:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
                   3980:        "Route-map to modify the attributes\n"
                   3981:        "Name of the route map\n")
                   3982: {
                   3983:   return bgp_static_set (vty, vty->index, argv[0],
                   3984:                         AFI_IP, bgp_node_safi (vty), argv[1], 0);
                   3985: }
                   3986: 
                   3987: DEFUN (bgp_network_backdoor,
                   3988:        bgp_network_backdoor_cmd,
                   3989:        "network A.B.C.D/M backdoor",
                   3990:        "Specify a network to announce via BGP\n"
                   3991:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
                   3992:        "Specify a BGP backdoor route\n")
                   3993: {
                   3994:   return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
                   3995:                          NULL, 1);
                   3996: }
                   3997: 
                   3998: DEFUN (bgp_network_mask,
                   3999:        bgp_network_mask_cmd,
                   4000:        "network A.B.C.D mask A.B.C.D",
                   4001:        "Specify a network to announce via BGP\n"
                   4002:        "Network number\n"
                   4003:        "Network mask\n"
                   4004:        "Network mask\n")
                   4005: {
                   4006:   int ret;
                   4007:   char prefix_str[BUFSIZ];
                   4008:   
                   4009:   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
                   4010:   if (! ret)
                   4011:     {
                   4012:       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
                   4013:       return CMD_WARNING;
                   4014:     }
                   4015: 
                   4016:   return bgp_static_set (vty, vty->index, prefix_str,
                   4017:                         AFI_IP, bgp_node_safi (vty), NULL, 0);
                   4018: }
                   4019: 
                   4020: DEFUN (bgp_network_mask_route_map,
                   4021:        bgp_network_mask_route_map_cmd,
                   4022:        "network A.B.C.D mask A.B.C.D route-map WORD",
                   4023:        "Specify a network to announce via BGP\n"
                   4024:        "Network number\n"
                   4025:        "Network mask\n"
                   4026:        "Network mask\n"
                   4027:        "Route-map to modify the attributes\n"
                   4028:        "Name of the route map\n")
                   4029: {
                   4030:   int ret;
                   4031:   char prefix_str[BUFSIZ];
                   4032:   
                   4033:   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
                   4034:   if (! ret)
                   4035:     {
                   4036:       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
                   4037:       return CMD_WARNING;
                   4038:     }
                   4039: 
                   4040:   return bgp_static_set (vty, vty->index, prefix_str,
                   4041:                         AFI_IP, bgp_node_safi (vty), argv[2], 0);
                   4042: }
                   4043: 
                   4044: DEFUN (bgp_network_mask_backdoor,
                   4045:        bgp_network_mask_backdoor_cmd,
                   4046:        "network A.B.C.D mask A.B.C.D backdoor",
                   4047:        "Specify a network to announce via BGP\n"
                   4048:        "Network number\n"
                   4049:        "Network mask\n"
                   4050:        "Network mask\n"
                   4051:        "Specify a BGP backdoor route\n")
                   4052: {
                   4053:   int ret;
                   4054:   char prefix_str[BUFSIZ];
                   4055:   
                   4056:   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
                   4057:   if (! ret)
                   4058:     {
                   4059:       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
                   4060:       return CMD_WARNING;
                   4061:     }
                   4062: 
                   4063:   return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
                   4064:                          NULL, 1);
                   4065: }
                   4066: 
                   4067: DEFUN (bgp_network_mask_natural,
                   4068:        bgp_network_mask_natural_cmd,
                   4069:        "network A.B.C.D",
                   4070:        "Specify a network to announce via BGP\n"
                   4071:        "Network number\n")
                   4072: {
                   4073:   int ret;
                   4074:   char prefix_str[BUFSIZ];
                   4075: 
                   4076:   ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
                   4077:   if (! ret)
                   4078:     {
                   4079:       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
                   4080:       return CMD_WARNING;
                   4081:     }
                   4082: 
                   4083:   return bgp_static_set (vty, vty->index, prefix_str,
                   4084:                         AFI_IP, bgp_node_safi (vty), NULL, 0);
                   4085: }
                   4086: 
                   4087: DEFUN (bgp_network_mask_natural_route_map,
                   4088:        bgp_network_mask_natural_route_map_cmd,
                   4089:        "network A.B.C.D route-map WORD",
                   4090:        "Specify a network to announce via BGP\n"
                   4091:        "Network number\n"
                   4092:        "Route-map to modify the attributes\n"
                   4093:        "Name of the route map\n")
                   4094: {
                   4095:   int ret;
                   4096:   char prefix_str[BUFSIZ];
                   4097: 
                   4098:   ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
                   4099:   if (! ret)
                   4100:     {
                   4101:       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
                   4102:       return CMD_WARNING;
                   4103:     }
                   4104: 
                   4105:   return bgp_static_set (vty, vty->index, prefix_str,
                   4106:                         AFI_IP, bgp_node_safi (vty), argv[1], 0);
                   4107: }
                   4108: 
                   4109: DEFUN (bgp_network_mask_natural_backdoor,
                   4110:        bgp_network_mask_natural_backdoor_cmd,
                   4111:        "network A.B.C.D backdoor",
                   4112:        "Specify a network to announce via BGP\n"
                   4113:        "Network number\n"
                   4114:        "Specify a BGP backdoor route\n")
                   4115: {
                   4116:   int ret;
                   4117:   char prefix_str[BUFSIZ];
                   4118: 
                   4119:   ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
                   4120:   if (! ret)
                   4121:     {
                   4122:       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
                   4123:       return CMD_WARNING;
                   4124:     }
                   4125: 
                   4126:   return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
                   4127:                          NULL, 1);
                   4128: }
                   4129: 
                   4130: DEFUN (no_bgp_network,
                   4131:        no_bgp_network_cmd,
                   4132:        "no network A.B.C.D/M",
                   4133:        NO_STR
                   4134:        "Specify a network to announce via BGP\n"
                   4135:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
                   4136: {
                   4137:   return bgp_static_unset (vty, vty->index, argv[0], AFI_IP, 
                   4138:                           bgp_node_safi (vty));
                   4139: }
                   4140: 
                   4141: ALIAS (no_bgp_network,
                   4142:        no_bgp_network_route_map_cmd,
                   4143:        "no network A.B.C.D/M route-map WORD",
                   4144:        NO_STR
                   4145:        "Specify a network to announce via BGP\n"
                   4146:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
                   4147:        "Route-map to modify the attributes\n"
                   4148:        "Name of the route map\n")
                   4149: 
                   4150: ALIAS (no_bgp_network,
                   4151:        no_bgp_network_backdoor_cmd,
                   4152:        "no network A.B.C.D/M backdoor",
                   4153:        NO_STR
                   4154:        "Specify a network to announce via BGP\n"
                   4155:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
                   4156:        "Specify a BGP backdoor route\n")
                   4157: 
                   4158: DEFUN (no_bgp_network_mask,
                   4159:        no_bgp_network_mask_cmd,
                   4160:        "no network A.B.C.D mask A.B.C.D",
                   4161:        NO_STR
                   4162:        "Specify a network to announce via BGP\n"
                   4163:        "Network number\n"
                   4164:        "Network mask\n"
                   4165:        "Network mask\n")
                   4166: {
                   4167:   int ret;
                   4168:   char prefix_str[BUFSIZ];
                   4169: 
                   4170:   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
                   4171:   if (! ret)
                   4172:     {
                   4173:       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
                   4174:       return CMD_WARNING;
                   4175:     }
                   4176: 
                   4177:   return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP, 
                   4178:                           bgp_node_safi (vty));
                   4179: }
                   4180: 
                   4181: ALIAS (no_bgp_network_mask,
                   4182:        no_bgp_network_mask_route_map_cmd,
                   4183:        "no network A.B.C.D mask A.B.C.D route-map WORD",
                   4184:        NO_STR
                   4185:        "Specify a network to announce via BGP\n"
                   4186:        "Network number\n"
                   4187:        "Network mask\n"
                   4188:        "Network mask\n"
                   4189:        "Route-map to modify the attributes\n"
                   4190:        "Name of the route map\n")
                   4191: 
                   4192: ALIAS (no_bgp_network_mask,
                   4193:        no_bgp_network_mask_backdoor_cmd,
                   4194:        "no network A.B.C.D mask A.B.C.D backdoor",
                   4195:        NO_STR
                   4196:        "Specify a network to announce via BGP\n"
                   4197:        "Network number\n"
                   4198:        "Network mask\n"
                   4199:        "Network mask\n"
                   4200:        "Specify a BGP backdoor route\n")
                   4201: 
                   4202: DEFUN (no_bgp_network_mask_natural,
                   4203:        no_bgp_network_mask_natural_cmd,
                   4204:        "no network A.B.C.D",
                   4205:        NO_STR
                   4206:        "Specify a network to announce via BGP\n"
                   4207:        "Network number\n")
                   4208: {
                   4209:   int ret;
                   4210:   char prefix_str[BUFSIZ];
                   4211: 
                   4212:   ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
                   4213:   if (! ret)
                   4214:     {
                   4215:       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
                   4216:       return CMD_WARNING;
                   4217:     }
                   4218: 
                   4219:   return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP, 
                   4220:                           bgp_node_safi (vty));
                   4221: }
                   4222: 
                   4223: ALIAS (no_bgp_network_mask_natural,
                   4224:        no_bgp_network_mask_natural_route_map_cmd,
                   4225:        "no network A.B.C.D route-map WORD",
                   4226:        NO_STR
                   4227:        "Specify a network to announce via BGP\n"
                   4228:        "Network number\n"
                   4229:        "Route-map to modify the attributes\n"
                   4230:        "Name of the route map\n")
                   4231: 
                   4232: ALIAS (no_bgp_network_mask_natural,
                   4233:        no_bgp_network_mask_natural_backdoor_cmd,
                   4234:        "no network A.B.C.D backdoor",
                   4235:        NO_STR
                   4236:        "Specify a network to announce via BGP\n"
                   4237:        "Network number\n"
                   4238:        "Specify a BGP backdoor route\n")
                   4239: 
                   4240: #ifdef HAVE_IPV6
                   4241: DEFUN (ipv6_bgp_network,
                   4242:        ipv6_bgp_network_cmd,
                   4243:        "network X:X::X:X/M",
                   4244:        "Specify a network to announce via BGP\n"
                   4245:        "IPv6 prefix <network>/<length>\n")
                   4246: {
1.1.1.2 ! misho    4247:   return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
1.1       misho    4248:                          NULL, 0);
                   4249: }
                   4250: 
                   4251: DEFUN (ipv6_bgp_network_route_map,
                   4252:        ipv6_bgp_network_route_map_cmd,
                   4253:        "network X:X::X:X/M route-map WORD",
                   4254:        "Specify a network to announce via BGP\n"
                   4255:        "IPv6 prefix <network>/<length>\n"
                   4256:        "Route-map to modify the attributes\n"
                   4257:        "Name of the route map\n")
                   4258: {
                   4259:   return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
                   4260:                         bgp_node_safi (vty), argv[1], 0);
                   4261: }
                   4262: 
                   4263: DEFUN (no_ipv6_bgp_network,
                   4264:        no_ipv6_bgp_network_cmd,
                   4265:        "no network X:X::X:X/M",
                   4266:        NO_STR
                   4267:        "Specify a network to announce via BGP\n"
                   4268:        "IPv6 prefix <network>/<length>\n")
                   4269: {
1.1.1.2 ! misho    4270:   return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
1.1       misho    4271: }
                   4272: 
                   4273: ALIAS (no_ipv6_bgp_network,
                   4274:        no_ipv6_bgp_network_route_map_cmd,
                   4275:        "no network X:X::X:X/M route-map WORD",
                   4276:        NO_STR
                   4277:        "Specify a network to announce via BGP\n"
                   4278:        "IPv6 prefix <network>/<length>\n"
                   4279:        "Route-map to modify the attributes\n"
                   4280:        "Name of the route map\n")
                   4281: 
                   4282: ALIAS (ipv6_bgp_network,
                   4283:        old_ipv6_bgp_network_cmd,
                   4284:        "ipv6 bgp network X:X::X:X/M",
                   4285:        IPV6_STR
                   4286:        BGP_STR
                   4287:        "Specify a network to announce via BGP\n"
                   4288:        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
                   4289: 
                   4290: ALIAS (no_ipv6_bgp_network,
                   4291:        old_no_ipv6_bgp_network_cmd,
                   4292:        "no ipv6 bgp network X:X::X:X/M",
                   4293:        NO_STR
                   4294:        IPV6_STR
                   4295:        BGP_STR
                   4296:        "Specify a network to announce via BGP\n"
                   4297:        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
                   4298: #endif /* HAVE_IPV6 */
                   4299: 
                   4300: /* stubs for removed AS-Pathlimit commands, kept for config compatibility */
                   4301: ALIAS_DEPRECATED (bgp_network,
                   4302:        bgp_network_ttl_cmd,
                   4303:        "network A.B.C.D/M pathlimit <0-255>",
                   4304:        "Specify a network to announce via BGP\n"
                   4305:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
                   4306:        "AS-Path hopcount limit attribute\n"
                   4307:        "AS-Pathlimit TTL, in number of AS-Path hops\n")
                   4308: ALIAS_DEPRECATED (bgp_network_backdoor,
                   4309:        bgp_network_backdoor_ttl_cmd,
                   4310:        "network A.B.C.D/M backdoor pathlimit <0-255>",
                   4311:        "Specify a network to announce via BGP\n"
                   4312:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
                   4313:        "Specify a BGP backdoor route\n"
                   4314:        "AS-Path hopcount limit attribute\n"
                   4315:        "AS-Pathlimit TTL, in number of AS-Path hops\n")
                   4316: ALIAS_DEPRECATED (bgp_network_mask,
                   4317:        bgp_network_mask_ttl_cmd,
                   4318:        "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
                   4319:        "Specify a network to announce via BGP\n"
                   4320:        "Network number\n"
                   4321:        "Network mask\n"
                   4322:        "Network mask\n"
                   4323:        "AS-Path hopcount limit attribute\n"
                   4324:        "AS-Pathlimit TTL, in number of AS-Path hops\n")
                   4325: ALIAS_DEPRECATED (bgp_network_mask_backdoor,
                   4326:        bgp_network_mask_backdoor_ttl_cmd,
                   4327:        "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
                   4328:        "Specify a network to announce via BGP\n"
                   4329:        "Network number\n"
                   4330:        "Network mask\n"
                   4331:        "Network mask\n"
                   4332:        "Specify a BGP backdoor route\n"
                   4333:        "AS-Path hopcount limit attribute\n"
                   4334:        "AS-Pathlimit TTL, in number of AS-Path hops\n")
                   4335: ALIAS_DEPRECATED (bgp_network_mask_natural,
                   4336:        bgp_network_mask_natural_ttl_cmd,
                   4337:        "network A.B.C.D pathlimit <0-255>",
                   4338:        "Specify a network to announce via BGP\n"
                   4339:        "Network number\n"
                   4340:        "AS-Path hopcount limit attribute\n"
                   4341:        "AS-Pathlimit TTL, in number of AS-Path hops\n")
                   4342: ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
                   4343:        bgp_network_mask_natural_backdoor_ttl_cmd,
                   4344:        "network A.B.C.D backdoor pathlimit (1-255>",
                   4345:        "Specify a network to announce via BGP\n"
                   4346:        "Network number\n"
                   4347:        "Specify a BGP backdoor route\n"
                   4348:        "AS-Path hopcount limit attribute\n"
                   4349:        "AS-Pathlimit TTL, in number of AS-Path hops\n")
                   4350: ALIAS_DEPRECATED (no_bgp_network,
                   4351:        no_bgp_network_ttl_cmd,
                   4352:        "no network A.B.C.D/M pathlimit <0-255>",
                   4353:        NO_STR
                   4354:        "Specify a network to announce via BGP\n"
                   4355:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
                   4356:        "AS-Path hopcount limit attribute\n"
                   4357:        "AS-Pathlimit TTL, in number of AS-Path hops\n")
                   4358: ALIAS_DEPRECATED (no_bgp_network,
                   4359:        no_bgp_network_backdoor_ttl_cmd,
                   4360:        "no network A.B.C.D/M backdoor pathlimit <0-255>",
                   4361:        NO_STR
                   4362:        "Specify a network to announce via BGP\n"
                   4363:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
                   4364:        "Specify a BGP backdoor route\n"
                   4365:        "AS-Path hopcount limit attribute\n"
                   4366:        "AS-Pathlimit TTL, in number of AS-Path hops\n")
                   4367: ALIAS_DEPRECATED (no_bgp_network,
                   4368:        no_bgp_network_mask_ttl_cmd,
                   4369:        "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
                   4370:        NO_STR
                   4371:        "Specify a network to announce via BGP\n"
                   4372:        "Network number\n"
                   4373:        "Network mask\n"
                   4374:        "Network mask\n"
                   4375:        "AS-Path hopcount limit attribute\n"
                   4376:        "AS-Pathlimit TTL, in number of AS-Path hops\n")
                   4377: ALIAS_DEPRECATED (no_bgp_network_mask,
                   4378:        no_bgp_network_mask_backdoor_ttl_cmd,
                   4379:        "no network A.B.C.D mask A.B.C.D  backdoor pathlimit <0-255>",
                   4380:        NO_STR
                   4381:        "Specify a network to announce via BGP\n"
                   4382:        "Network number\n"
                   4383:        "Network mask\n"
                   4384:        "Network mask\n"
                   4385:        "Specify a BGP backdoor route\n"
                   4386:        "AS-Path hopcount limit attribute\n"
                   4387:        "AS-Pathlimit TTL, in number of AS-Path hops\n")
                   4388: ALIAS_DEPRECATED (no_bgp_network_mask_natural,
                   4389:        no_bgp_network_mask_natural_ttl_cmd,
                   4390:        "no network A.B.C.D pathlimit <0-255>",
                   4391:        NO_STR
                   4392:        "Specify a network to announce via BGP\n"
                   4393:        "Network number\n"
                   4394:        "AS-Path hopcount limit attribute\n"
                   4395:        "AS-Pathlimit TTL, in number of AS-Path hops\n")
                   4396: ALIAS_DEPRECATED (no_bgp_network_mask_natural,
                   4397:        no_bgp_network_mask_natural_backdoor_ttl_cmd,
                   4398:        "no network A.B.C.D backdoor pathlimit <0-255>",
                   4399:        NO_STR
                   4400:        "Specify a network to announce via BGP\n"
                   4401:        "Network number\n"
                   4402:        "Specify a BGP backdoor route\n"
                   4403:        "AS-Path hopcount limit attribute\n"
                   4404:        "AS-Pathlimit TTL, in number of AS-Path hops\n")
                   4405: #ifdef HAVE_IPV6
                   4406: ALIAS_DEPRECATED (ipv6_bgp_network,
                   4407:        ipv6_bgp_network_ttl_cmd,
                   4408:        "network X:X::X:X/M pathlimit <0-255>",
                   4409:        "Specify a network to announce via BGP\n"
                   4410:        "IPv6 prefix <network>/<length>\n"
                   4411:        "AS-Path hopcount limit attribute\n"
                   4412:        "AS-Pathlimit TTL, in number of AS-Path hops\n")
                   4413: ALIAS_DEPRECATED (no_ipv6_bgp_network,
                   4414:        no_ipv6_bgp_network_ttl_cmd,
                   4415:        "no network X:X::X:X/M pathlimit <0-255>",
                   4416:        NO_STR
                   4417:        "Specify a network to announce via BGP\n"
                   4418:        "IPv6 prefix <network>/<length>\n"
                   4419:        "AS-Path hopcount limit attribute\n"
                   4420:        "AS-Pathlimit TTL, in number of AS-Path hops\n")
                   4421: #endif /* HAVE_IPV6 */
                   4422: 
                   4423: /* Aggreagete address:
                   4424: 
                   4425:   advertise-map  Set condition to advertise attribute
                   4426:   as-set         Generate AS set path information
                   4427:   attribute-map  Set attributes of aggregate
                   4428:   route-map      Set parameters of aggregate
                   4429:   summary-only   Filter more specific routes from updates
                   4430:   suppress-map   Conditionally filter more specific routes from updates
                   4431:   <cr>
                   4432:  */
                   4433: struct bgp_aggregate
                   4434: {
                   4435:   /* Summary-only flag. */
                   4436:   u_char summary_only;
                   4437: 
                   4438:   /* AS set generation. */
                   4439:   u_char as_set;
                   4440: 
                   4441:   /* Route-map for aggregated route. */
                   4442:   struct route_map *map;
                   4443: 
                   4444:   /* Suppress-count. */
                   4445:   unsigned long count;
                   4446: 
                   4447:   /* SAFI configuration. */
                   4448:   safi_t safi;
                   4449: };
                   4450: 
                   4451: static struct bgp_aggregate *
                   4452: bgp_aggregate_new (void)
                   4453: {
                   4454:   return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
                   4455: }
                   4456: 
                   4457: static void
                   4458: bgp_aggregate_free (struct bgp_aggregate *aggregate)
                   4459: {
                   4460:   XFREE (MTYPE_BGP_AGGREGATE, aggregate);
                   4461: }     
                   4462: 
                   4463: static void
                   4464: bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
                   4465:                     afi_t afi, safi_t safi, struct bgp_info *del, 
                   4466:                     struct bgp_aggregate *aggregate)
                   4467: {
                   4468:   struct bgp_table *table;
                   4469:   struct bgp_node *top;
                   4470:   struct bgp_node *rn;
                   4471:   u_char origin;
                   4472:   struct aspath *aspath = NULL;
                   4473:   struct aspath *asmerge = NULL;
                   4474:   struct community *community = NULL;
                   4475:   struct community *commerge = NULL;
                   4476:   struct in_addr nexthop;
                   4477:   u_int32_t med = 0;
                   4478:   struct bgp_info *ri;
                   4479:   struct bgp_info *new;
                   4480:   int first = 1;
                   4481:   unsigned long match = 0;
                   4482: 
                   4483:   /* Record adding route's nexthop and med. */
                   4484:   if (rinew)
                   4485:     {
                   4486:       nexthop = rinew->attr->nexthop;
                   4487:       med = rinew->attr->med;
                   4488:     }
                   4489: 
                   4490:   /* ORIGIN attribute: If at least one route among routes that are
                   4491:      aggregated has ORIGIN with the value INCOMPLETE, then the
                   4492:      aggregated route must have the ORIGIN attribute with the value
                   4493:      INCOMPLETE. Otherwise, if at least one route among routes that
                   4494:      are aggregated has ORIGIN with the value EGP, then the aggregated
                   4495:      route must have the origin attribute with the value EGP. In all
                   4496:      other case the value of the ORIGIN attribute of the aggregated
                   4497:      route is INTERNAL. */
                   4498:   origin = BGP_ORIGIN_IGP;
                   4499: 
                   4500:   table = bgp->rib[afi][safi];
                   4501: 
                   4502:   top = bgp_node_get (table, p);
                   4503:   for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
                   4504:     if (rn->p.prefixlen > p->prefixlen)
                   4505:       {
                   4506:        match = 0;
                   4507: 
                   4508:        for (ri = rn->info; ri; ri = ri->next)
                   4509:          {
                   4510:            if (BGP_INFO_HOLDDOWN (ri))
                   4511:              continue;
                   4512: 
                   4513:            if (del && ri == del)
                   4514:              continue;
                   4515: 
                   4516:            if (! rinew && first)
                   4517:              {
                   4518:                nexthop = ri->attr->nexthop;
                   4519:                med = ri->attr->med;
                   4520:                first = 0;
                   4521:              }
                   4522: 
                   4523: #ifdef AGGREGATE_NEXTHOP_CHECK
                   4524:            if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
                   4525:                || ri->attr->med != med)
                   4526:              {
                   4527:                if (aspath)
                   4528:                  aspath_free (aspath);
                   4529:                if (community)
                   4530:                  community_free (community);
                   4531:                bgp_unlock_node (rn);
                   4532:                bgp_unlock_node (top);
                   4533:                return;
                   4534:              }
                   4535: #endif /* AGGREGATE_NEXTHOP_CHECK */
                   4536: 
                   4537:            if (ri->sub_type != BGP_ROUTE_AGGREGATE)
                   4538:              {
                   4539:                if (aggregate->summary_only)
                   4540:                  {
                   4541:                    (bgp_info_extra_get (ri))->suppress++;
                   4542:                    bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
                   4543:                    match++;
                   4544:                  }
                   4545: 
                   4546:                aggregate->count++;
                   4547: 
                   4548:                if (aggregate->as_set)
                   4549:                  {
                   4550:                    if (origin < ri->attr->origin)
                   4551:                      origin = ri->attr->origin;
                   4552: 
                   4553:                    if (aspath)
                   4554:                      {
                   4555:                        asmerge = aspath_aggregate (aspath, ri->attr->aspath);
                   4556:                        aspath_free (aspath);
                   4557:                        aspath = asmerge;
                   4558:                      }
                   4559:                    else
                   4560:                      aspath = aspath_dup (ri->attr->aspath);
                   4561: 
                   4562:                    if (ri->attr->community)
                   4563:                      {
                   4564:                        if (community)
                   4565:                          {
                   4566:                            commerge = community_merge (community,
                   4567:                                                        ri->attr->community);
                   4568:                            community = community_uniq_sort (commerge);
                   4569:                            community_free (commerge);
                   4570:                          }
                   4571:                        else
                   4572:                          community = community_dup (ri->attr->community);
                   4573:                      }
                   4574:                  }
                   4575:              }
                   4576:          }
                   4577:        if (match)
                   4578:          bgp_process (bgp, rn, afi, safi);
                   4579:       }
                   4580:   bgp_unlock_node (top);
                   4581: 
                   4582:   if (rinew)
                   4583:     {
                   4584:       aggregate->count++;
                   4585:       
                   4586:       if (aggregate->summary_only)
                   4587:         (bgp_info_extra_get (rinew))->suppress++;
                   4588: 
                   4589:       if (aggregate->as_set)
                   4590:        {
                   4591:          if (origin < rinew->attr->origin)
                   4592:            origin = rinew->attr->origin;
                   4593: 
                   4594:          if (aspath)
                   4595:            {
                   4596:              asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
                   4597:              aspath_free (aspath);
                   4598:              aspath = asmerge;
                   4599:            }
                   4600:          else
                   4601:            aspath = aspath_dup (rinew->attr->aspath);
                   4602: 
                   4603:          if (rinew->attr->community)
                   4604:            {
                   4605:              if (community)
                   4606:                {
                   4607:                  commerge = community_merge (community,
                   4608:                                              rinew->attr->community);
                   4609:                  community = community_uniq_sort (commerge);
                   4610:                  community_free (commerge);
                   4611:                }
                   4612:              else
                   4613:                community = community_dup (rinew->attr->community);
                   4614:            }
                   4615:        }
                   4616:     }
                   4617: 
                   4618:   if (aggregate->count > 0)
                   4619:     {
                   4620:       rn = bgp_node_get (table, p);
                   4621:       new = bgp_info_new ();
                   4622:       new->type = ZEBRA_ROUTE_BGP;
                   4623:       new->sub_type = BGP_ROUTE_AGGREGATE;
                   4624:       new->peer = bgp->peer_self;
                   4625:       SET_FLAG (new->flags, BGP_INFO_VALID);
                   4626:       new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
                   4627:       new->uptime = bgp_clock ();
                   4628: 
                   4629:       bgp_info_add (rn, new);
                   4630:       bgp_unlock_node (rn);
                   4631:       bgp_process (bgp, rn, afi, safi);
                   4632:     }
                   4633:   else
                   4634:     {
                   4635:       if (aspath)
                   4636:        aspath_free (aspath);
                   4637:       if (community)
                   4638:        community_free (community);
                   4639:     }
                   4640: }
                   4641: 
                   4642: void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
                   4643:                           struct bgp_aggregate *);
                   4644: 
                   4645: void
                   4646: bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
                   4647:                         struct bgp_info *ri, afi_t afi, safi_t safi)
                   4648: {
                   4649:   struct bgp_node *child;
                   4650:   struct bgp_node *rn;
                   4651:   struct bgp_aggregate *aggregate;
                   4652: 
                   4653:   /* MPLS-VPN aggregation is not yet supported. */
                   4654:   if (safi == SAFI_MPLS_VPN)
                   4655:     return;
                   4656: 
                   4657:   if (p->prefixlen == 0)
                   4658:     return;
                   4659: 
                   4660:   if (BGP_INFO_HOLDDOWN (ri))
                   4661:     return;
                   4662: 
                   4663:   child = bgp_node_get (bgp->aggregate[afi][safi], p);
                   4664: 
                   4665:   /* Aggregate address configuration check. */
                   4666:   for (rn = child; rn; rn = rn->parent)
                   4667:     if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
                   4668:       {
                   4669:        bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
                   4670:        bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
                   4671:       }
                   4672:   bgp_unlock_node (child);
                   4673: }
                   4674: 
                   4675: void
                   4676: bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p, 
                   4677:                         struct bgp_info *del, afi_t afi, safi_t safi)
                   4678: {
                   4679:   struct bgp_node *child;
                   4680:   struct bgp_node *rn;
                   4681:   struct bgp_aggregate *aggregate;
                   4682: 
                   4683:   /* MPLS-VPN aggregation is not yet supported. */
                   4684:   if (safi == SAFI_MPLS_VPN)
                   4685:     return;
                   4686: 
                   4687:   if (p->prefixlen == 0)
                   4688:     return;
                   4689: 
                   4690:   child = bgp_node_get (bgp->aggregate[afi][safi], p);
                   4691: 
                   4692:   /* Aggregate address configuration check. */
                   4693:   for (rn = child; rn; rn = rn->parent)
                   4694:     if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
                   4695:       {
                   4696:        bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
                   4697:        bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
                   4698:       }
                   4699:   bgp_unlock_node (child);
                   4700: }
                   4701: 
                   4702: static void
                   4703: bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
                   4704:                   struct bgp_aggregate *aggregate)
                   4705: {
                   4706:   struct bgp_table *table;
                   4707:   struct bgp_node *top;
                   4708:   struct bgp_node *rn;
                   4709:   struct bgp_info *new;
                   4710:   struct bgp_info *ri;
                   4711:   unsigned long match;
                   4712:   u_char origin = BGP_ORIGIN_IGP;
                   4713:   struct aspath *aspath = NULL;
                   4714:   struct aspath *asmerge = NULL;
                   4715:   struct community *community = NULL;
                   4716:   struct community *commerge = NULL;
                   4717: 
                   4718:   table = bgp->rib[afi][safi];
                   4719: 
                   4720:   /* Sanity check. */
                   4721:   if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
                   4722:     return;
                   4723:   if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
                   4724:     return;
                   4725:     
                   4726:   /* If routes exists below this node, generate aggregate routes. */
                   4727:   top = bgp_node_get (table, p);
                   4728:   for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
                   4729:     if (rn->p.prefixlen > p->prefixlen)
                   4730:       {
                   4731:        match = 0;
                   4732: 
                   4733:        for (ri = rn->info; ri; ri = ri->next)
                   4734:          {
                   4735:            if (BGP_INFO_HOLDDOWN (ri))
                   4736:              continue;
                   4737: 
                   4738:            if (ri->sub_type != BGP_ROUTE_AGGREGATE)
                   4739:              {
                   4740:                /* summary-only aggregate route suppress aggregated
                   4741:                   route announcement.  */
                   4742:                if (aggregate->summary_only)
                   4743:                  {
                   4744:                    (bgp_info_extra_get (ri))->suppress++;
                   4745:                    bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
                   4746:                    match++;
                   4747:                  }
                   4748:                /* as-set aggregate route generate origin, as path,
                   4749:                   community aggregation.  */
                   4750:                if (aggregate->as_set)
                   4751:                  {
                   4752:                    if (origin < ri->attr->origin)
                   4753:                      origin = ri->attr->origin;
                   4754: 
                   4755:                    if (aspath)
                   4756:                      {
                   4757:                        asmerge = aspath_aggregate (aspath, ri->attr->aspath);
                   4758:                        aspath_free (aspath);
                   4759:                        aspath = asmerge;
                   4760:                      }
                   4761:                    else
                   4762:                      aspath = aspath_dup (ri->attr->aspath);
                   4763: 
                   4764:                    if (ri->attr->community)
                   4765:                      {
                   4766:                        if (community)
                   4767:                          {
                   4768:                            commerge = community_merge (community,
                   4769:                                                        ri->attr->community);
                   4770:                            community = community_uniq_sort (commerge);
                   4771:                            community_free (commerge);
                   4772:                          }
                   4773:                        else
                   4774:                          community = community_dup (ri->attr->community);
                   4775:                      }
                   4776:                  }
                   4777:                aggregate->count++;
                   4778:              }
                   4779:          }
                   4780:        
                   4781:        /* If this node is suppressed, process the change. */
                   4782:        if (match)
                   4783:          bgp_process (bgp, rn, afi, safi);
                   4784:       }
                   4785:   bgp_unlock_node (top);
                   4786: 
                   4787:   /* Add aggregate route to BGP table. */
                   4788:   if (aggregate->count)
                   4789:     {
                   4790:       rn = bgp_node_get (table, p);
                   4791: 
                   4792:       new = bgp_info_new ();
                   4793:       new->type = ZEBRA_ROUTE_BGP;
                   4794:       new->sub_type = BGP_ROUTE_AGGREGATE;
                   4795:       new->peer = bgp->peer_self;
                   4796:       SET_FLAG (new->flags, BGP_INFO_VALID);
                   4797:       new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
                   4798:       new->uptime = bgp_clock ();
                   4799: 
                   4800:       bgp_info_add (rn, new);
                   4801:       bgp_unlock_node (rn);
                   4802:       
                   4803:       /* Process change. */
                   4804:       bgp_process (bgp, rn, afi, safi);
                   4805:     }
                   4806: }
                   4807: 
                   4808: void
                   4809: bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi, 
                   4810:                      safi_t safi, struct bgp_aggregate *aggregate)
                   4811: {
                   4812:   struct bgp_table *table;
                   4813:   struct bgp_node *top;
                   4814:   struct bgp_node *rn;
                   4815:   struct bgp_info *ri;
                   4816:   unsigned long match;
                   4817: 
                   4818:   table = bgp->rib[afi][safi];
                   4819: 
                   4820:   if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
                   4821:     return;
                   4822:   if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
                   4823:     return;
                   4824: 
                   4825:   /* If routes exists below this node, generate aggregate routes. */
                   4826:   top = bgp_node_get (table, p);
                   4827:   for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
                   4828:     if (rn->p.prefixlen > p->prefixlen)
                   4829:       {
                   4830:        match = 0;
                   4831: 
                   4832:        for (ri = rn->info; ri; ri = ri->next)
                   4833:          {
                   4834:            if (BGP_INFO_HOLDDOWN (ri))
                   4835:              continue;
                   4836: 
                   4837:            if (ri->sub_type != BGP_ROUTE_AGGREGATE)
                   4838:              {
                   4839:                if (aggregate->summary_only && ri->extra)
                   4840:                  {
                   4841:                    ri->extra->suppress--;
                   4842: 
                   4843:                    if (ri->extra->suppress == 0)
                   4844:                      {
                   4845:                        bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
                   4846:                        match++;
                   4847:                      }
                   4848:                  }
                   4849:                aggregate->count--;
                   4850:              }
                   4851:          }
                   4852: 
                   4853:        /* If this node was suppressed, process the change. */
                   4854:        if (match)
                   4855:          bgp_process (bgp, rn, afi, safi);
                   4856:       }
                   4857:   bgp_unlock_node (top);
                   4858: 
                   4859:   /* Delete aggregate route from BGP table. */
                   4860:   rn = bgp_node_get (table, p);
                   4861: 
                   4862:   for (ri = rn->info; ri; ri = ri->next)
                   4863:     if (ri->peer == bgp->peer_self 
                   4864:        && ri->type == ZEBRA_ROUTE_BGP
                   4865:        && ri->sub_type == BGP_ROUTE_AGGREGATE)
                   4866:       break;
                   4867: 
                   4868:   /* Withdraw static BGP route from routing table. */
                   4869:   if (ri)
                   4870:     {
                   4871:       bgp_info_delete (rn, ri);
                   4872:       bgp_process (bgp, rn, afi, safi);
                   4873:     }
                   4874: 
                   4875:   /* Unlock bgp_node_lookup. */
                   4876:   bgp_unlock_node (rn);
                   4877: }
                   4878: 
                   4879: /* Aggregate route attribute. */
                   4880: #define AGGREGATE_SUMMARY_ONLY 1
                   4881: #define AGGREGATE_AS_SET       1
                   4882: 
                   4883: static int
                   4884: bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
                   4885:                      afi_t afi, safi_t safi)
                   4886: {
                   4887:   int ret;
                   4888:   struct prefix p;
                   4889:   struct bgp_node *rn;
                   4890:   struct bgp *bgp;
                   4891:   struct bgp_aggregate *aggregate;
                   4892: 
                   4893:   /* Convert string to prefix structure. */
                   4894:   ret = str2prefix (prefix_str, &p);
                   4895:   if (!ret)
                   4896:     {
                   4897:       vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
                   4898:       return CMD_WARNING;
                   4899:     }
                   4900:   apply_mask (&p);
                   4901: 
                   4902:   /* Get BGP structure. */
                   4903:   bgp = vty->index;
                   4904: 
                   4905:   /* Old configuration check. */
                   4906:   rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
                   4907:   if (! rn)
                   4908:     {
                   4909:       vty_out (vty, "%% There is no aggregate-address configuration.%s",
                   4910:                VTY_NEWLINE);
                   4911:       return CMD_WARNING;
                   4912:     }
                   4913: 
                   4914:   aggregate = rn->info;
                   4915:   if (aggregate->safi & SAFI_UNICAST)
                   4916:     bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
                   4917:   if (aggregate->safi & SAFI_MULTICAST)
                   4918:     bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
                   4919: 
                   4920:   /* Unlock aggregate address configuration. */
                   4921:   rn->info = NULL;
                   4922:   bgp_aggregate_free (aggregate);
                   4923:   bgp_unlock_node (rn);
                   4924:   bgp_unlock_node (rn);
                   4925: 
                   4926:   return CMD_SUCCESS;
                   4927: }
                   4928: 
                   4929: static int
                   4930: bgp_aggregate_set (struct vty *vty, const char *prefix_str,
                   4931:                    afi_t afi, safi_t safi,
                   4932:                   u_char summary_only, u_char as_set)
                   4933: {
                   4934:   int ret;
                   4935:   struct prefix p;
                   4936:   struct bgp_node *rn;
                   4937:   struct bgp *bgp;
                   4938:   struct bgp_aggregate *aggregate;
                   4939: 
                   4940:   /* Convert string to prefix structure. */
                   4941:   ret = str2prefix (prefix_str, &p);
                   4942:   if (!ret)
                   4943:     {
                   4944:       vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
                   4945:       return CMD_WARNING;
                   4946:     }
                   4947:   apply_mask (&p);
                   4948: 
                   4949:   /* Get BGP structure. */
                   4950:   bgp = vty->index;
                   4951: 
                   4952:   /* Old configuration check. */
                   4953:   rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
                   4954: 
                   4955:   if (rn->info)
                   4956:     {
                   4957:       vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
                   4958:       /* try to remove the old entry */
                   4959:       ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
                   4960:       if (ret)
                   4961:         {
                   4962:           vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
                   4963:          bgp_unlock_node (rn);
                   4964:          return CMD_WARNING;
                   4965:         }
                   4966:     }
                   4967: 
                   4968:   /* Make aggregate address structure. */
                   4969:   aggregate = bgp_aggregate_new ();
                   4970:   aggregate->summary_only = summary_only;
                   4971:   aggregate->as_set = as_set;
                   4972:   aggregate->safi = safi;
                   4973:   rn->info = aggregate;
                   4974: 
                   4975:   /* Aggregate address insert into BGP routing table. */
                   4976:   if (safi & SAFI_UNICAST)
                   4977:     bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
                   4978:   if (safi & SAFI_MULTICAST)
                   4979:     bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
                   4980: 
                   4981:   return CMD_SUCCESS;
                   4982: }
                   4983: 
                   4984: DEFUN (aggregate_address,
                   4985:        aggregate_address_cmd,
                   4986:        "aggregate-address A.B.C.D/M",
                   4987:        "Configure BGP aggregate entries\n"
                   4988:        "Aggregate prefix\n")
                   4989: {
                   4990:   return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
                   4991: }
                   4992: 
                   4993: DEFUN (aggregate_address_mask,
                   4994:        aggregate_address_mask_cmd,
                   4995:        "aggregate-address A.B.C.D A.B.C.D",
                   4996:        "Configure BGP aggregate entries\n"
                   4997:        "Aggregate address\n"
                   4998:        "Aggregate mask\n")
                   4999: {
                   5000:   int ret;
                   5001:   char prefix_str[BUFSIZ];
                   5002: 
                   5003:   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
                   5004: 
                   5005:   if (! ret)
                   5006:     {
                   5007:       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
                   5008:       return CMD_WARNING;
                   5009:     }
                   5010: 
                   5011:   return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
                   5012:                            0, 0);
                   5013: }
                   5014: 
                   5015: DEFUN (aggregate_address_summary_only,
                   5016:        aggregate_address_summary_only_cmd,
                   5017:        "aggregate-address A.B.C.D/M summary-only",
                   5018:        "Configure BGP aggregate entries\n"
                   5019:        "Aggregate prefix\n"
                   5020:        "Filter more specific routes from updates\n")
                   5021: {
                   5022:   return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
                   5023:                            AGGREGATE_SUMMARY_ONLY, 0);
                   5024: }
                   5025: 
                   5026: DEFUN (aggregate_address_mask_summary_only,
                   5027:        aggregate_address_mask_summary_only_cmd,
                   5028:        "aggregate-address A.B.C.D A.B.C.D summary-only",
                   5029:        "Configure BGP aggregate entries\n"
                   5030:        "Aggregate address\n"
                   5031:        "Aggregate mask\n"
                   5032:        "Filter more specific routes from updates\n")
                   5033: {
                   5034:   int ret;
                   5035:   char prefix_str[BUFSIZ];
                   5036: 
                   5037:   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
                   5038: 
                   5039:   if (! ret)
                   5040:     {
                   5041:       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
                   5042:       return CMD_WARNING;
                   5043:     }
                   5044: 
                   5045:   return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
                   5046:                            AGGREGATE_SUMMARY_ONLY, 0);
                   5047: }
                   5048: 
                   5049: DEFUN (aggregate_address_as_set,
                   5050:        aggregate_address_as_set_cmd,
                   5051:        "aggregate-address A.B.C.D/M as-set",
                   5052:        "Configure BGP aggregate entries\n"
                   5053:        "Aggregate prefix\n"
                   5054:        "Generate AS set path information\n")
                   5055: {
                   5056:   return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
                   5057:                            0, AGGREGATE_AS_SET);
                   5058: }
                   5059: 
                   5060: DEFUN (aggregate_address_mask_as_set,
                   5061:        aggregate_address_mask_as_set_cmd,
                   5062:        "aggregate-address A.B.C.D A.B.C.D as-set",
                   5063:        "Configure BGP aggregate entries\n"
                   5064:        "Aggregate address\n"
                   5065:        "Aggregate mask\n"
                   5066:        "Generate AS set path information\n")
                   5067: {
                   5068:   int ret;
                   5069:   char prefix_str[BUFSIZ];
                   5070: 
                   5071:   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
                   5072: 
                   5073:   if (! ret)
                   5074:     {
                   5075:       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
                   5076:       return CMD_WARNING;
                   5077:     }
                   5078: 
                   5079:   return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
                   5080:                            0, AGGREGATE_AS_SET);
                   5081: }
                   5082: 
                   5083: 
                   5084: DEFUN (aggregate_address_as_set_summary,
                   5085:        aggregate_address_as_set_summary_cmd,
                   5086:        "aggregate-address A.B.C.D/M as-set summary-only",
                   5087:        "Configure BGP aggregate entries\n"
                   5088:        "Aggregate prefix\n"
                   5089:        "Generate AS set path information\n"
                   5090:        "Filter more specific routes from updates\n")
                   5091: {
                   5092:   return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
                   5093:                            AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
                   5094: }
                   5095: 
                   5096: ALIAS (aggregate_address_as_set_summary,
                   5097:        aggregate_address_summary_as_set_cmd,
                   5098:        "aggregate-address A.B.C.D/M summary-only as-set",
                   5099:        "Configure BGP aggregate entries\n"
                   5100:        "Aggregate prefix\n"
                   5101:        "Filter more specific routes from updates\n"
                   5102:        "Generate AS set path information\n")
                   5103: 
                   5104: DEFUN (aggregate_address_mask_as_set_summary,
                   5105:        aggregate_address_mask_as_set_summary_cmd,
                   5106:        "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
                   5107:        "Configure BGP aggregate entries\n"
                   5108:        "Aggregate address\n"
                   5109:        "Aggregate mask\n"
                   5110:        "Generate AS set path information\n"
                   5111:        "Filter more specific routes from updates\n")
                   5112: {
                   5113:   int ret;
                   5114:   char prefix_str[BUFSIZ];
                   5115: 
                   5116:   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
                   5117: 
                   5118:   if (! ret)
                   5119:     {
                   5120:       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
                   5121:       return CMD_WARNING;
                   5122:     }
                   5123: 
                   5124:   return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
                   5125:                            AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
                   5126: }
                   5127: 
                   5128: ALIAS (aggregate_address_mask_as_set_summary,
                   5129:        aggregate_address_mask_summary_as_set_cmd,
                   5130:        "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
                   5131:        "Configure BGP aggregate entries\n"
                   5132:        "Aggregate address\n"
                   5133:        "Aggregate mask\n"
                   5134:        "Filter more specific routes from updates\n"
                   5135:        "Generate AS set path information\n")
                   5136: 
                   5137: DEFUN (no_aggregate_address,
                   5138:        no_aggregate_address_cmd,
                   5139:        "no aggregate-address A.B.C.D/M",
                   5140:        NO_STR
                   5141:        "Configure BGP aggregate entries\n"
                   5142:        "Aggregate prefix\n")
                   5143: {
                   5144:   return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
                   5145: }
                   5146: 
                   5147: ALIAS (no_aggregate_address,
                   5148:        no_aggregate_address_summary_only_cmd,
                   5149:        "no aggregate-address A.B.C.D/M summary-only",
                   5150:        NO_STR
                   5151:        "Configure BGP aggregate entries\n"
                   5152:        "Aggregate prefix\n"
                   5153:        "Filter more specific routes from updates\n")
                   5154: 
                   5155: ALIAS (no_aggregate_address,
                   5156:        no_aggregate_address_as_set_cmd,
                   5157:        "no aggregate-address A.B.C.D/M as-set",
                   5158:        NO_STR
                   5159:        "Configure BGP aggregate entries\n"
                   5160:        "Aggregate prefix\n"
                   5161:        "Generate AS set path information\n")
                   5162: 
                   5163: ALIAS (no_aggregate_address,
                   5164:        no_aggregate_address_as_set_summary_cmd,
                   5165:        "no aggregate-address A.B.C.D/M as-set summary-only",
                   5166:        NO_STR
                   5167:        "Configure BGP aggregate entries\n"
                   5168:        "Aggregate prefix\n"
                   5169:        "Generate AS set path information\n"
                   5170:        "Filter more specific routes from updates\n")
                   5171: 
                   5172: ALIAS (no_aggregate_address,
                   5173:        no_aggregate_address_summary_as_set_cmd,
                   5174:        "no aggregate-address A.B.C.D/M summary-only as-set",
                   5175:        NO_STR
                   5176:        "Configure BGP aggregate entries\n"
                   5177:        "Aggregate prefix\n"
                   5178:        "Filter more specific routes from updates\n"
                   5179:        "Generate AS set path information\n")
                   5180: 
                   5181: DEFUN (no_aggregate_address_mask,
                   5182:        no_aggregate_address_mask_cmd,
                   5183:        "no aggregate-address A.B.C.D A.B.C.D",
                   5184:        NO_STR
                   5185:        "Configure BGP aggregate entries\n"
                   5186:        "Aggregate address\n"
                   5187:        "Aggregate mask\n")
                   5188: {
                   5189:   int ret;
                   5190:   char prefix_str[BUFSIZ];
                   5191: 
                   5192:   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
                   5193: 
                   5194:   if (! ret)
                   5195:     {
                   5196:       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
                   5197:       return CMD_WARNING;
                   5198:     }
                   5199: 
                   5200:   return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
                   5201: }
                   5202: 
                   5203: ALIAS (no_aggregate_address_mask,
                   5204:        no_aggregate_address_mask_summary_only_cmd,
                   5205:        "no aggregate-address A.B.C.D A.B.C.D summary-only",
                   5206:        NO_STR
                   5207:        "Configure BGP aggregate entries\n"
                   5208:        "Aggregate address\n"
                   5209:        "Aggregate mask\n"
                   5210:        "Filter more specific routes from updates\n")
                   5211: 
                   5212: ALIAS (no_aggregate_address_mask,
                   5213:        no_aggregate_address_mask_as_set_cmd,
                   5214:        "no aggregate-address A.B.C.D A.B.C.D as-set",
                   5215:        NO_STR
                   5216:        "Configure BGP aggregate entries\n"
                   5217:        "Aggregate address\n"
                   5218:        "Aggregate mask\n"
                   5219:        "Generate AS set path information\n")
                   5220: 
                   5221: ALIAS (no_aggregate_address_mask,
                   5222:        no_aggregate_address_mask_as_set_summary_cmd,
                   5223:        "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
                   5224:        NO_STR
                   5225:        "Configure BGP aggregate entries\n"
                   5226:        "Aggregate address\n"
                   5227:        "Aggregate mask\n"
                   5228:        "Generate AS set path information\n"
                   5229:        "Filter more specific routes from updates\n")
                   5230: 
                   5231: ALIAS (no_aggregate_address_mask,
                   5232:        no_aggregate_address_mask_summary_as_set_cmd,
                   5233:        "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
                   5234:        NO_STR
                   5235:        "Configure BGP aggregate entries\n"
                   5236:        "Aggregate address\n"
                   5237:        "Aggregate mask\n"
                   5238:        "Filter more specific routes from updates\n"
                   5239:        "Generate AS set path information\n")
                   5240: 
                   5241: #ifdef HAVE_IPV6
                   5242: DEFUN (ipv6_aggregate_address,
                   5243:        ipv6_aggregate_address_cmd,
                   5244:        "aggregate-address X:X::X:X/M",
                   5245:        "Configure BGP aggregate entries\n"
                   5246:        "Aggregate prefix\n")
                   5247: {
                   5248:   return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
                   5249: }
                   5250: 
                   5251: DEFUN (ipv6_aggregate_address_summary_only,
                   5252:        ipv6_aggregate_address_summary_only_cmd,
                   5253:        "aggregate-address X:X::X:X/M summary-only",
                   5254:        "Configure BGP aggregate entries\n"
                   5255:        "Aggregate prefix\n"
                   5256:        "Filter more specific routes from updates\n")
                   5257: {
                   5258:   return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 
                   5259:                            AGGREGATE_SUMMARY_ONLY, 0);
                   5260: }
                   5261: 
                   5262: DEFUN (no_ipv6_aggregate_address,
                   5263:        no_ipv6_aggregate_address_cmd,
                   5264:        "no aggregate-address X:X::X:X/M",
                   5265:        NO_STR
                   5266:        "Configure BGP aggregate entries\n"
                   5267:        "Aggregate prefix\n")
                   5268: {
                   5269:   return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
                   5270: }
                   5271: 
                   5272: DEFUN (no_ipv6_aggregate_address_summary_only,
                   5273:        no_ipv6_aggregate_address_summary_only_cmd,
                   5274:        "no aggregate-address X:X::X:X/M summary-only",
                   5275:        NO_STR
                   5276:        "Configure BGP aggregate entries\n"
                   5277:        "Aggregate prefix\n"
                   5278:        "Filter more specific routes from updates\n")
                   5279: {
                   5280:   return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
                   5281: }
                   5282: 
                   5283: ALIAS (ipv6_aggregate_address,
                   5284:        old_ipv6_aggregate_address_cmd,
                   5285:        "ipv6 bgp aggregate-address X:X::X:X/M",
                   5286:        IPV6_STR
                   5287:        BGP_STR
                   5288:        "Configure BGP aggregate entries\n"
                   5289:        "Aggregate prefix\n")
                   5290: 
                   5291: ALIAS (ipv6_aggregate_address_summary_only,
                   5292:        old_ipv6_aggregate_address_summary_only_cmd,
                   5293:        "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
                   5294:        IPV6_STR
                   5295:        BGP_STR
                   5296:        "Configure BGP aggregate entries\n"
                   5297:        "Aggregate prefix\n"
                   5298:        "Filter more specific routes from updates\n")
                   5299: 
                   5300: ALIAS (no_ipv6_aggregate_address,
                   5301:        old_no_ipv6_aggregate_address_cmd,
                   5302:        "no ipv6 bgp aggregate-address X:X::X:X/M",
                   5303:        NO_STR
                   5304:        IPV6_STR
                   5305:        BGP_STR
                   5306:        "Configure BGP aggregate entries\n"
                   5307:        "Aggregate prefix\n")
                   5308: 
                   5309: ALIAS (no_ipv6_aggregate_address_summary_only,
                   5310:        old_no_ipv6_aggregate_address_summary_only_cmd,
                   5311:        "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
                   5312:        NO_STR
                   5313:        IPV6_STR
                   5314:        BGP_STR
                   5315:        "Configure BGP aggregate entries\n"
                   5316:        "Aggregate prefix\n"
                   5317:        "Filter more specific routes from updates\n")
                   5318: #endif /* HAVE_IPV6 */
                   5319: 
                   5320: /* Redistribute route treatment. */
                   5321: void
1.1.1.2 ! misho    5322: bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
        !          5323:                      const struct in6_addr *nexthop6,
1.1       misho    5324:                      u_int32_t metric, u_char type)
                   5325: {
                   5326:   struct bgp *bgp;
                   5327:   struct listnode *node, *nnode;
                   5328:   struct bgp_info *new;
                   5329:   struct bgp_info *bi;
                   5330:   struct bgp_info info;
                   5331:   struct bgp_node *bn;
                   5332:   struct attr attr = { 0 };
                   5333:   struct attr attr_new = { 0 };
                   5334:   struct attr *new_attr;
                   5335:   afi_t afi;
                   5336:   int ret;
                   5337: 
                   5338:   /* Make default attribute. */
                   5339:   bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
                   5340:   if (nexthop)
                   5341:     attr.nexthop = *nexthop;
                   5342: 
1.1.1.2 ! misho    5343: #ifdef HAVE_IPV6
        !          5344:   if (nexthop6)
        !          5345:     {
        !          5346:       struct attr_extra *extra = bgp_attr_extra_get(&attr);
        !          5347:       extra->mp_nexthop_global = *nexthop6;
        !          5348:       extra->mp_nexthop_len = 16;
        !          5349:     }
        !          5350: #endif
        !          5351: 
1.1       misho    5352:   attr.med = metric;
                   5353:   attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
                   5354: 
                   5355:   for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
                   5356:     {
                   5357:       afi = family2afi (p->family);
                   5358: 
                   5359:       if (bgp->redist[afi][type])
                   5360:        {
                   5361:          /* Copy attribute for modification. */
                   5362:          bgp_attr_dup (&attr_new, &attr);
                   5363: 
                   5364:          if (bgp->redist_metric_flag[afi][type])
                   5365:            attr_new.med = bgp->redist_metric[afi][type];
                   5366: 
                   5367:          /* Apply route-map. */
                   5368:          if (bgp->rmap[afi][type].map)
                   5369:            {
                   5370:              info.peer = bgp->peer_self;
                   5371:              info.attr = &attr_new;
                   5372: 
                   5373:               SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
                   5374: 
                   5375:              ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
                   5376:                                     &info);
                   5377: 
                   5378:               bgp->peer_self->rmap_type = 0;
                   5379: 
                   5380:              if (ret == RMAP_DENYMATCH)
                   5381:                {
                   5382:                  /* Free uninterned attribute. */
                   5383:                  bgp_attr_flush (&attr_new);
                   5384:                  bgp_attr_extra_free (&attr_new);
                   5385:                  
                   5386:                  /* Unintern original. */
                   5387:                  aspath_unintern (&attr.aspath);
                   5388:                  bgp_attr_extra_free (&attr);
                   5389:                  bgp_redistribute_delete (p, type);
                   5390:                  return;
                   5391:                }
                   5392:            }
                   5393: 
                   5394:           bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], 
                   5395:                                  afi, SAFI_UNICAST, p, NULL);
                   5396:           
                   5397:          new_attr = bgp_attr_intern (&attr_new);
                   5398:          bgp_attr_extra_free (&attr_new);
                   5399:          
                   5400:          for (bi = bn->info; bi; bi = bi->next)
                   5401:            if (bi->peer == bgp->peer_self
                   5402:                && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
                   5403:              break;
                   5404:  
                   5405:          if (bi)
                   5406:            {
                   5407:              if (attrhash_cmp (bi->attr, new_attr) &&
                   5408:                  !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
                   5409:                {
                   5410:                  bgp_attr_unintern (&new_attr);
                   5411:                  aspath_unintern (&attr.aspath);
                   5412:                  bgp_attr_extra_free (&attr);
                   5413:                  bgp_unlock_node (bn);
                   5414:                  return;
                   5415:                }
                   5416:              else
                   5417:                {
                   5418:                  /* The attribute is changed. */
                   5419:                  bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
                   5420:  
                   5421:                  /* Rewrite BGP route information. */
                   5422:                  if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
                   5423:                    bgp_info_restore(bn, bi);
                   5424:                  else
                   5425:                    bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
                   5426:                  bgp_attr_unintern (&bi->attr);
                   5427:                  bi->attr = new_attr;
                   5428:                  bi->uptime = bgp_clock ();
                   5429:  
                   5430:                  /* Process change. */
                   5431:                  bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
                   5432:                  bgp_process (bgp, bn, afi, SAFI_UNICAST);
                   5433:                  bgp_unlock_node (bn);
                   5434:                  aspath_unintern (&attr.aspath);
                   5435:                  bgp_attr_extra_free (&attr);
                   5436:                  return;
                   5437:                } 
                   5438:            }
                   5439: 
                   5440:          new = bgp_info_new ();
                   5441:          new->type = type;
                   5442:          new->sub_type = BGP_ROUTE_REDISTRIBUTE;
                   5443:          new->peer = bgp->peer_self;
                   5444:          SET_FLAG (new->flags, BGP_INFO_VALID);
                   5445:          new->attr = new_attr;
                   5446:          new->uptime = bgp_clock ();
                   5447: 
                   5448:          bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
                   5449:          bgp_info_add (bn, new);
                   5450:          bgp_unlock_node (bn);
                   5451:          bgp_process (bgp, bn, afi, SAFI_UNICAST);
                   5452:        }
                   5453:     }
                   5454: 
                   5455:   /* Unintern original. */
                   5456:   aspath_unintern (&attr.aspath);
                   5457:   bgp_attr_extra_free (&attr);
                   5458: }
                   5459: 
                   5460: void
                   5461: bgp_redistribute_delete (struct prefix *p, u_char type)
                   5462: {
                   5463:   struct bgp *bgp;
                   5464:   struct listnode *node, *nnode;
                   5465:   afi_t afi;
                   5466:   struct bgp_node *rn;
                   5467:   struct bgp_info *ri;
                   5468: 
                   5469:   for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
                   5470:     {
                   5471:       afi = family2afi (p->family);
                   5472: 
                   5473:       if (bgp->redist[afi][type])
                   5474:        {
                   5475:          rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
                   5476: 
                   5477:          for (ri = rn->info; ri; ri = ri->next)
                   5478:            if (ri->peer == bgp->peer_self
                   5479:                && ri->type == type)
                   5480:              break;
                   5481: 
                   5482:          if (ri)
                   5483:            {
                   5484:              bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
                   5485:              bgp_info_delete (rn, ri);
                   5486:              bgp_process (bgp, rn, afi, SAFI_UNICAST);
                   5487:            }
                   5488:          bgp_unlock_node (rn);
                   5489:        }
                   5490:     }
                   5491: }
                   5492: 
                   5493: /* Withdraw specified route type's route. */
                   5494: void
                   5495: bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
                   5496: {
                   5497:   struct bgp_node *rn;
                   5498:   struct bgp_info *ri;
                   5499:   struct bgp_table *table;
                   5500: 
                   5501:   table = bgp->rib[afi][SAFI_UNICAST];
                   5502: 
                   5503:   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
                   5504:     {
                   5505:       for (ri = rn->info; ri; ri = ri->next)
                   5506:        if (ri->peer == bgp->peer_self
                   5507:            && ri->type == type)
                   5508:          break;
                   5509: 
                   5510:       if (ri)
                   5511:        {
                   5512:          bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
                   5513:          bgp_info_delete (rn, ri);
                   5514:          bgp_process (bgp, rn, afi, SAFI_UNICAST);
                   5515:        }
                   5516:     }
                   5517: }
                   5518: 
                   5519: /* Static function to display route. */
                   5520: static void
                   5521: route_vty_out_route (struct prefix *p, struct vty *vty)
                   5522: {
                   5523:   int len;
                   5524:   u_int32_t destination; 
                   5525:   char buf[BUFSIZ];
                   5526: 
                   5527:   if (p->family == AF_INET)
                   5528:     {
                   5529:       len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
                   5530:       destination = ntohl (p->u.prefix4.s_addr);
                   5531: 
                   5532:       if ((IN_CLASSC (destination) && p->prefixlen == 24)
                   5533:          || (IN_CLASSB (destination) && p->prefixlen == 16)
                   5534:          || (IN_CLASSA (destination) && p->prefixlen == 8)
                   5535:          || p->u.prefix4.s_addr == 0)
                   5536:        {
                   5537:          /* When mask is natural, mask is not displayed. */
                   5538:        }
                   5539:       else
                   5540:        len += vty_out (vty, "/%d", p->prefixlen);
                   5541:     }
                   5542:   else
                   5543:     len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
                   5544:                   p->prefixlen);
                   5545: 
                   5546:   len = 17 - len;
                   5547:   if (len < 1)
                   5548:     vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
                   5549:   else
                   5550:     vty_out (vty, "%*s", len, " ");
                   5551: }
                   5552: 
                   5553: enum bgp_display_type
                   5554: {
                   5555:   normal_list,
                   5556: };
                   5557: 
                   5558: /* Print the short form route status for a bgp_info */
                   5559: static void
                   5560: route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
                   5561: {
                   5562:  /* Route status display. */
                   5563:   if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
                   5564:     vty_out (vty, "R");
                   5565:   else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
                   5566:     vty_out (vty, "S");
                   5567:   else if (binfo->extra && binfo->extra->suppress)
                   5568:     vty_out (vty, "s");
                   5569:   else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
                   5570:     vty_out (vty, "*");
                   5571:   else
                   5572:     vty_out (vty, " ");
                   5573: 
                   5574:   /* Selected */
                   5575:   if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
                   5576:     vty_out (vty, "h");
                   5577:   else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
                   5578:     vty_out (vty, "d");
                   5579:   else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
                   5580:     vty_out (vty, ">");
                   5581:   else
                   5582:     vty_out (vty, " ");
                   5583: 
                   5584:   /* Internal route. */
                   5585:     if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
                   5586:       vty_out (vty, "i");
                   5587:     else
                   5588:       vty_out (vty, " "); 
                   5589: }
                   5590: 
                   5591: /* called from terminal list command */
                   5592: void
                   5593: route_vty_out (struct vty *vty, struct prefix *p,
                   5594:               struct bgp_info *binfo, int display, safi_t safi)
                   5595: {
                   5596:   struct attr *attr;
                   5597:   
                   5598:   /* short status lead text */ 
                   5599:   route_vty_short_status_out (vty, binfo);
                   5600:   
                   5601:   /* print prefix and mask */
                   5602:   if (! display)
                   5603:     route_vty_out_route (p, vty);
                   5604:   else
                   5605:     vty_out (vty, "%*s", 17, " ");
                   5606: 
                   5607:   /* Print attribute */
                   5608:   attr = binfo->attr;
                   5609:   if (attr) 
                   5610:     {
                   5611:       if (p->family == AF_INET)
                   5612:        {
                   5613:          if (safi == SAFI_MPLS_VPN)
                   5614:            vty_out (vty, "%-16s",
                   5615:                      inet_ntoa (attr->extra->mp_nexthop_global_in));
                   5616:          else
                   5617:            vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
                   5618:        }
                   5619: #ifdef HAVE_IPV6      
                   5620:       else if (p->family == AF_INET6)
                   5621:        {
                   5622:          int len;
                   5623:          char buf[BUFSIZ];
                   5624: 
                   5625:          len = vty_out (vty, "%s", 
                   5626:                         inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
                   5627:                         buf, BUFSIZ));
                   5628:          len = 16 - len;
                   5629:          if (len < 1)
                   5630:            vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
                   5631:          else
                   5632:            vty_out (vty, "%*s", len, " ");
                   5633:        }
                   5634: #endif /* HAVE_IPV6 */
                   5635: 
                   5636:       if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
                   5637:        vty_out (vty, "%10u", attr->med);
                   5638:       else
                   5639:        vty_out (vty, "          ");
                   5640: 
                   5641:       if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
                   5642:        vty_out (vty, "%7u", attr->local_pref);
                   5643:       else
                   5644:        vty_out (vty, "       ");
                   5645: 
                   5646:       vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
                   5647:     
                   5648:       /* Print aspath */
                   5649:       if (attr->aspath)
                   5650:         aspath_print_vty (vty, "%s", attr->aspath, " ");
                   5651: 
                   5652:       /* Print origin */
                   5653:       vty_out (vty, "%s", bgp_origin_str[attr->origin]);
                   5654:     }
                   5655:   vty_out (vty, "%s", VTY_NEWLINE);
                   5656: }  
                   5657: 
                   5658: /* called from terminal list command */
                   5659: void
                   5660: route_vty_out_tmp (struct vty *vty, struct prefix *p,
                   5661:                   struct attr *attr, safi_t safi)
                   5662: {
                   5663:   /* Route status display. */
                   5664:   vty_out (vty, "*");
                   5665:   vty_out (vty, ">");
                   5666:   vty_out (vty, " ");
                   5667: 
                   5668:   /* print prefix and mask */
                   5669:   route_vty_out_route (p, vty);
                   5670: 
                   5671:   /* Print attribute */
                   5672:   if (attr) 
                   5673:     {
                   5674:       if (p->family == AF_INET)
                   5675:        {
                   5676:          if (safi == SAFI_MPLS_VPN)
                   5677:            vty_out (vty, "%-16s",
                   5678:                      inet_ntoa (attr->extra->mp_nexthop_global_in));
                   5679:          else
                   5680:            vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
                   5681:        }
                   5682: #ifdef HAVE_IPV6
                   5683:       else if (p->family == AF_INET6)
                   5684:         {
                   5685:           int len;
                   5686:           char buf[BUFSIZ];
                   5687:           
                   5688:           assert (attr->extra);
                   5689: 
                   5690:           len = vty_out (vty, "%s",
                   5691:                          inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
                   5692:                          buf, BUFSIZ));
                   5693:           len = 16 - len;
                   5694:           if (len < 1)
                   5695:             vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
                   5696:           else
                   5697:             vty_out (vty, "%*s", len, " ");
                   5698:         }
                   5699: #endif /* HAVE_IPV6 */
                   5700: 
                   5701:       if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
                   5702:        vty_out (vty, "%10u", attr->med);
                   5703:       else
                   5704:        vty_out (vty, "          ");
                   5705: 
                   5706:       if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
                   5707:        vty_out (vty, "%7u", attr->local_pref);
                   5708:       else
                   5709:        vty_out (vty, "       ");
                   5710:       
                   5711:       vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
                   5712:       
                   5713:       /* Print aspath */
                   5714:       if (attr->aspath)
                   5715:         aspath_print_vty (vty, "%s", attr->aspath, " ");
                   5716: 
                   5717:       /* Print origin */
                   5718:       vty_out (vty, "%s", bgp_origin_str[attr->origin]);
                   5719:     }
                   5720: 
                   5721:   vty_out (vty, "%s", VTY_NEWLINE);
                   5722: }  
                   5723: 
                   5724: void
                   5725: route_vty_out_tag (struct vty *vty, struct prefix *p,
                   5726:                   struct bgp_info *binfo, int display, safi_t safi)
                   5727: {
                   5728:   struct attr *attr;
                   5729:   u_int32_t label = 0;
                   5730:   
                   5731:   if (!binfo->extra)
                   5732:     return;
                   5733:   
                   5734:   /* short status lead text */ 
                   5735:   route_vty_short_status_out (vty, binfo);
                   5736:     
                   5737:   /* print prefix and mask */
                   5738:   if (! display)
                   5739:     route_vty_out_route (p, vty);
                   5740:   else
                   5741:     vty_out (vty, "%*s", 17, " ");
                   5742: 
                   5743:   /* Print attribute */
                   5744:   attr = binfo->attr;
                   5745:   if (attr) 
                   5746:     {
                   5747:       if (p->family == AF_INET)
                   5748:        {
                   5749:          if (safi == SAFI_MPLS_VPN)
                   5750:            vty_out (vty, "%-16s",
                   5751:                      inet_ntoa (attr->extra->mp_nexthop_global_in));
                   5752:          else
                   5753:            vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
                   5754:        }
                   5755: #ifdef HAVE_IPV6      
                   5756:       else if (p->family == AF_INET6)
                   5757:        {
                   5758:          assert (attr->extra);
                   5759:          char buf[BUFSIZ];
                   5760:          char buf1[BUFSIZ];
                   5761:          if (attr->extra->mp_nexthop_len == 16)
                   5762:            vty_out (vty, "%s", 
                   5763:                     inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
                   5764:                      buf, BUFSIZ));
                   5765:          else if (attr->extra->mp_nexthop_len == 32)
                   5766:            vty_out (vty, "%s(%s)",
                   5767:                     inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
                   5768:                                buf, BUFSIZ),
                   5769:                     inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
                   5770:                                buf1, BUFSIZ));
                   5771:          
                   5772:        }
                   5773: #endif /* HAVE_IPV6 */
                   5774:     }
                   5775: 
                   5776:   label = decode_label (binfo->extra->tag);
                   5777: 
                   5778:   vty_out (vty, "notag/%d", label);
                   5779: 
                   5780:   vty_out (vty, "%s", VTY_NEWLINE);
                   5781: }  
                   5782: 
                   5783: /* dampening route */
                   5784: static void
                   5785: damp_route_vty_out (struct vty *vty, struct prefix *p,
                   5786:                    struct bgp_info *binfo, int display, safi_t safi)
                   5787: {
                   5788:   struct attr *attr;
                   5789:   int len;
                   5790:   char timebuf[BGP_UPTIME_LEN];
                   5791: 
                   5792:   /* short status lead text */ 
                   5793:   route_vty_short_status_out (vty, binfo);
                   5794:   
                   5795:   /* print prefix and mask */
                   5796:   if (! display)
                   5797:     route_vty_out_route (p, vty);
                   5798:   else
                   5799:     vty_out (vty, "%*s", 17, " ");
                   5800: 
                   5801:   len = vty_out (vty, "%s", binfo->peer->host);
                   5802:   len = 17 - len;
                   5803:   if (len < 1)
                   5804:     vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
                   5805:   else
                   5806:     vty_out (vty, "%*s", len, " ");
                   5807: 
                   5808:   vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
                   5809: 
                   5810:   /* Print attribute */
                   5811:   attr = binfo->attr;
                   5812:   if (attr)
                   5813:     {
                   5814:       /* Print aspath */
                   5815:       if (attr->aspath)
                   5816:        aspath_print_vty (vty, "%s", attr->aspath, " ");
                   5817: 
                   5818:       /* Print origin */
                   5819:       vty_out (vty, "%s", bgp_origin_str[attr->origin]);
                   5820:     }
                   5821:   vty_out (vty, "%s", VTY_NEWLINE);
                   5822: }
                   5823: 
                   5824: /* flap route */
                   5825: static void
                   5826: flap_route_vty_out (struct vty *vty, struct prefix *p,
                   5827:                    struct bgp_info *binfo, int display, safi_t safi)
                   5828: {
                   5829:   struct attr *attr;
                   5830:   struct bgp_damp_info *bdi;
                   5831:   char timebuf[BGP_UPTIME_LEN];
                   5832:   int len;
                   5833:   
                   5834:   if (!binfo->extra)
                   5835:     return;
                   5836:   
                   5837:   bdi = binfo->extra->damp_info;
                   5838: 
                   5839:   /* short status lead text */
                   5840:   route_vty_short_status_out (vty, binfo);
                   5841:   
                   5842:   /* print prefix and mask */
                   5843:   if (! display)
                   5844:     route_vty_out_route (p, vty);
                   5845:   else
                   5846:     vty_out (vty, "%*s", 17, " ");
                   5847: 
                   5848:   len = vty_out (vty, "%s", binfo->peer->host);
                   5849:   len = 16 - len;
                   5850:   if (len < 1)
                   5851:     vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
                   5852:   else
                   5853:     vty_out (vty, "%*s", len, " ");
                   5854: 
                   5855:   len = vty_out (vty, "%d", bdi->flap);
                   5856:   len = 5 - len;
                   5857:   if (len < 1)
                   5858:     vty_out (vty, " ");
                   5859:   else
                   5860:     vty_out (vty, "%*s ", len, " ");
                   5861:     
                   5862:   vty_out (vty, "%s ", peer_uptime (bdi->start_time,
                   5863:           timebuf, BGP_UPTIME_LEN));
                   5864: 
                   5865:   if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
                   5866:       && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
                   5867:     vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
                   5868:   else
                   5869:     vty_out (vty, "%*s ", 8, " ");
                   5870: 
                   5871:   /* Print attribute */
                   5872:   attr = binfo->attr;
                   5873:   if (attr)
                   5874:     {
                   5875:       /* Print aspath */
                   5876:       if (attr->aspath)
                   5877:        aspath_print_vty (vty, "%s", attr->aspath, " ");
                   5878: 
                   5879:       /* Print origin */
                   5880:       vty_out (vty, "%s", bgp_origin_str[attr->origin]);
                   5881:     }
                   5882:   vty_out (vty, "%s", VTY_NEWLINE);
                   5883: }
                   5884: 
                   5885: static void
                   5886: route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p, 
                   5887:                      struct bgp_info *binfo, afi_t afi, safi_t safi)
                   5888: {
                   5889:   char buf[INET6_ADDRSTRLEN];
                   5890:   char buf1[BUFSIZ];
                   5891:   struct attr *attr;
                   5892:   int sockunion_vty_out (struct vty *, union sockunion *);
                   5893: #ifdef HAVE_CLOCK_MONOTONIC
                   5894:   time_t tbuf;
                   5895: #endif
                   5896:        
                   5897:   attr = binfo->attr;
                   5898: 
                   5899:   if (attr)
                   5900:     {
                   5901:       /* Line1 display AS-path, Aggregator */
                   5902:       if (attr->aspath)
                   5903:        {
                   5904:          vty_out (vty, "  ");
                   5905:          if (aspath_count_hops (attr->aspath) == 0)
                   5906:            vty_out (vty, "Local");
                   5907:          else
                   5908:            aspath_print_vty (vty, "%s", attr->aspath, "");
                   5909:        }
                   5910: 
                   5911:       if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
                   5912:         vty_out (vty, ", (removed)");
                   5913:       if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
                   5914:        vty_out (vty, ", (stale)");
                   5915:       if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
                   5916:        vty_out (vty, ", (aggregated by %u %s)", 
                   5917:                 attr->extra->aggregator_as,
                   5918:                 inet_ntoa (attr->extra->aggregator_addr));
                   5919:       if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
                   5920:        vty_out (vty, ", (Received from a RR-client)");
                   5921:       if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
                   5922:        vty_out (vty, ", (Received from a RS-client)");
                   5923:       if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
                   5924:        vty_out (vty, ", (history entry)");
                   5925:       else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
                   5926:        vty_out (vty, ", (suppressed due to dampening)");
                   5927:       vty_out (vty, "%s", VTY_NEWLINE);
                   5928:          
                   5929:       /* Line2 display Next-hop, Neighbor, Router-id */
                   5930:       if (p->family == AF_INET)
                   5931:        {
                   5932:          vty_out (vty, "    %s", safi == SAFI_MPLS_VPN ?
                   5933:                   inet_ntoa (attr->extra->mp_nexthop_global_in) :
                   5934:                   inet_ntoa (attr->nexthop));
                   5935:        }
                   5936: #ifdef HAVE_IPV6
                   5937:       else
                   5938:        {
                   5939:          assert (attr->extra);
                   5940:          vty_out (vty, "    %s",
                   5941:                   inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
                   5942:                              buf, INET6_ADDRSTRLEN));
                   5943:        }
                   5944: #endif /* HAVE_IPV6 */
                   5945: 
                   5946:       if (binfo->peer == bgp->peer_self)
                   5947:        {
                   5948:          vty_out (vty, " from %s ", 
                   5949:                   p->family == AF_INET ? "0.0.0.0" : "::");
                   5950:          vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
                   5951:        }
                   5952:       else
                   5953:        {
                   5954:          if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
                   5955:            vty_out (vty, " (inaccessible)"); 
                   5956:          else if (binfo->extra && binfo->extra->igpmetric)
                   5957:            vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
                   5958:          vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
                   5959:          if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
                   5960:            vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
                   5961:          else
                   5962:            vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
                   5963:        }
                   5964:       vty_out (vty, "%s", VTY_NEWLINE);
                   5965: 
                   5966: #ifdef HAVE_IPV6
                   5967:       /* display nexthop local */
                   5968:       if (attr->extra && attr->extra->mp_nexthop_len == 32)
                   5969:        {
                   5970:          vty_out (vty, "    (%s)%s",
                   5971:                   inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
                   5972:                              buf, INET6_ADDRSTRLEN),
                   5973:                   VTY_NEWLINE);
                   5974:        }
                   5975: #endif /* HAVE_IPV6 */
                   5976: 
                   5977:       /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
                   5978:       vty_out (vty, "      Origin %s", bgp_origin_long_str[attr->origin]);
                   5979:          
                   5980:       if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
                   5981:        vty_out (vty, ", metric %u", attr->med);
                   5982:          
                   5983:       if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
                   5984:        vty_out (vty, ", localpref %u", attr->local_pref);
                   5985:       else
                   5986:        vty_out (vty, ", localpref %u", bgp->default_local_pref);
                   5987: 
                   5988:       if (attr->extra && attr->extra->weight != 0)
                   5989:        vty_out (vty, ", weight %u", attr->extra->weight);
                   5990:        
                   5991:       if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
                   5992:        vty_out (vty, ", valid");
                   5993: 
                   5994:       if (binfo->peer != bgp->peer_self)
                   5995:        {
                   5996:          if (binfo->peer->as == binfo->peer->local_as)
                   5997:            vty_out (vty, ", internal");
                   5998:          else 
                   5999:            vty_out (vty, ", %s", 
                   6000:                     (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
                   6001:        }
                   6002:       else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
                   6003:        vty_out (vty, ", aggregated, local");
                   6004:       else if (binfo->type != ZEBRA_ROUTE_BGP)
                   6005:        vty_out (vty, ", sourced");
                   6006:       else
                   6007:        vty_out (vty, ", sourced, local");
                   6008: 
                   6009:       if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
                   6010:        vty_out (vty, ", atomic-aggregate");
                   6011:          
1.1.1.2 ! misho    6012:       if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
        !          6013:          (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
        !          6014:           bgp_info_mpath_count (binfo)))
        !          6015:        vty_out (vty, ", multipath");
        !          6016: 
1.1       misho    6017:       if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
                   6018:        vty_out (vty, ", best");
                   6019: 
                   6020:       vty_out (vty, "%s", VTY_NEWLINE);
                   6021:          
                   6022:       /* Line 4 display Community */
                   6023:       if (attr->community)
                   6024:        vty_out (vty, "      Community: %s%s", attr->community->str,
                   6025:                 VTY_NEWLINE);
                   6026:          
                   6027:       /* Line 5 display Extended-community */
                   6028:       if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
                   6029:        vty_out (vty, "      Extended Community: %s%s", 
                   6030:                 attr->extra->ecommunity->str, VTY_NEWLINE);
                   6031:          
                   6032:       /* Line 6 display Originator, Cluster-id */
                   6033:       if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
                   6034:          (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
                   6035:        {
                   6036:          assert (attr->extra);
                   6037:          if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
                   6038:            vty_out (vty, "      Originator: %s", 
                   6039:                     inet_ntoa (attr->extra->originator_id));
                   6040: 
                   6041:          if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
                   6042:            {
                   6043:              int i;
                   6044:              vty_out (vty, ", Cluster list: ");
                   6045:              for (i = 0; i < attr->extra->cluster->length / 4; i++)
                   6046:                vty_out (vty, "%s ", 
                   6047:                         inet_ntoa (attr->extra->cluster->list[i]));
                   6048:            }
                   6049:          vty_out (vty, "%s", VTY_NEWLINE);
                   6050:        }
                   6051:       
                   6052:       if (binfo->extra && binfo->extra->damp_info)
                   6053:        bgp_damp_info_vty (vty, binfo);
                   6054: 
                   6055:       /* Line 7 display Uptime */
                   6056: #ifdef HAVE_CLOCK_MONOTONIC
                   6057:       tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
                   6058:       vty_out (vty, "      Last update: %s", ctime(&tbuf));
                   6059: #else
                   6060:       vty_out (vty, "      Last update: %s", ctime(&binfo->uptime));
                   6061: #endif /* HAVE_CLOCK_MONOTONIC */
                   6062:     }
                   6063:   vty_out (vty, "%s", VTY_NEWLINE);
                   6064: }  
                   6065: 
                   6066: #define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,%s              r RIB-failure, S Stale, R Removed%s"
                   6067: #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
                   6068: #define BGP_SHOW_HEADER "   Network          Next Hop            Metric LocPrf Weight Path%s"
                   6069: #define BGP_SHOW_DAMP_HEADER "   Network          From             Reuse    Path%s"
                   6070: #define BGP_SHOW_FLAP_HEADER "   Network          From            Flaps Duration Reuse    Path%s"
                   6071: 
                   6072: enum bgp_show_type
                   6073: {
                   6074:   bgp_show_type_normal,
                   6075:   bgp_show_type_regexp,
                   6076:   bgp_show_type_prefix_list,
                   6077:   bgp_show_type_filter_list,
                   6078:   bgp_show_type_route_map,
                   6079:   bgp_show_type_neighbor,
                   6080:   bgp_show_type_cidr_only,
                   6081:   bgp_show_type_prefix_longer,
                   6082:   bgp_show_type_community_all,
                   6083:   bgp_show_type_community,
                   6084:   bgp_show_type_community_exact,
                   6085:   bgp_show_type_community_list,
                   6086:   bgp_show_type_community_list_exact,
                   6087:   bgp_show_type_flap_statistics,
                   6088:   bgp_show_type_flap_address,
                   6089:   bgp_show_type_flap_prefix,
                   6090:   bgp_show_type_flap_cidr_only,
                   6091:   bgp_show_type_flap_regexp,
                   6092:   bgp_show_type_flap_filter_list,
                   6093:   bgp_show_type_flap_prefix_list,
                   6094:   bgp_show_type_flap_prefix_longer,
                   6095:   bgp_show_type_flap_route_map,
                   6096:   bgp_show_type_flap_neighbor,
                   6097:   bgp_show_type_dampend_paths,
                   6098:   bgp_show_type_damp_neighbor
                   6099: };
                   6100: 
                   6101: static int
                   6102: bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
                   6103:          enum bgp_show_type type, void *output_arg)
                   6104: {
                   6105:   struct bgp_info *ri;
                   6106:   struct bgp_node *rn;
                   6107:   int header = 1;
                   6108:   int display;
                   6109:   unsigned long output_count;
                   6110: 
                   6111:   /* This is first entry point, so reset total line. */
                   6112:   output_count = 0;
                   6113: 
                   6114:   /* Start processing of routes. */
                   6115:   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) 
                   6116:     if (rn->info != NULL)
                   6117:       {
                   6118:        display = 0;
                   6119: 
                   6120:        for (ri = rn->info; ri; ri = ri->next)
                   6121:          {
                   6122:            if (type == bgp_show_type_flap_statistics
                   6123:                || type == bgp_show_type_flap_address
                   6124:                || type == bgp_show_type_flap_prefix
                   6125:                || type == bgp_show_type_flap_cidr_only
                   6126:                || type == bgp_show_type_flap_regexp
                   6127:                || type == bgp_show_type_flap_filter_list
                   6128:                || type == bgp_show_type_flap_prefix_list
                   6129:                || type == bgp_show_type_flap_prefix_longer
                   6130:                || type == bgp_show_type_flap_route_map
                   6131:                || type == bgp_show_type_flap_neighbor
                   6132:                || type == bgp_show_type_dampend_paths
                   6133:                || type == bgp_show_type_damp_neighbor)
                   6134:              {
                   6135:                if (!(ri->extra && ri->extra->damp_info))
                   6136:                  continue;
                   6137:              }
                   6138:            if (type == bgp_show_type_regexp
                   6139:                || type == bgp_show_type_flap_regexp)
                   6140:              {
                   6141:                regex_t *regex = output_arg;
                   6142:                    
                   6143:                if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
                   6144:                  continue;
                   6145:              }
                   6146:            if (type == bgp_show_type_prefix_list
                   6147:                || type == bgp_show_type_flap_prefix_list)
                   6148:              {
                   6149:                struct prefix_list *plist = output_arg;
                   6150:                    
                   6151:                if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
                   6152:                  continue;
                   6153:              }
                   6154:            if (type == bgp_show_type_filter_list
                   6155:                || type == bgp_show_type_flap_filter_list)
                   6156:              {
                   6157:                struct as_list *as_list = output_arg;
                   6158: 
                   6159:                if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
                   6160:                  continue;
                   6161:              }
                   6162:            if (type == bgp_show_type_route_map
                   6163:                || type == bgp_show_type_flap_route_map)
                   6164:              {
                   6165:                struct route_map *rmap = output_arg;
                   6166:                struct bgp_info binfo;
                   6167:                struct attr dummy_attr = { 0 }; 
                   6168:                int ret;
                   6169: 
                   6170:                bgp_attr_dup (&dummy_attr, ri->attr);
                   6171:                binfo.peer = ri->peer;
                   6172:                binfo.attr = &dummy_attr;
                   6173: 
                   6174:                ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
                   6175:                
                   6176:                bgp_attr_extra_free (&dummy_attr);
                   6177:                
                   6178:                if (ret == RMAP_DENYMATCH)
                   6179:                  continue;
                   6180:              }
                   6181:            if (type == bgp_show_type_neighbor
                   6182:                || type == bgp_show_type_flap_neighbor
                   6183:                || type == bgp_show_type_damp_neighbor)
                   6184:              {
                   6185:                union sockunion *su = output_arg;
                   6186: 
                   6187:                if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
                   6188:                  continue;
                   6189:              }
                   6190:            if (type == bgp_show_type_cidr_only
                   6191:                || type == bgp_show_type_flap_cidr_only)
                   6192:              {
                   6193:                u_int32_t destination;
                   6194: 
                   6195:                destination = ntohl (rn->p.u.prefix4.s_addr);
                   6196:                if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
                   6197:                  continue;
                   6198:                if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
                   6199:                  continue;
                   6200:                if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
                   6201:                  continue;
                   6202:              }
                   6203:            if (type == bgp_show_type_prefix_longer
                   6204:                || type == bgp_show_type_flap_prefix_longer)
                   6205:              {
                   6206:                struct prefix *p = output_arg;
                   6207: 
                   6208:                if (! prefix_match (p, &rn->p))
                   6209:                  continue;
                   6210:              }
                   6211:            if (type == bgp_show_type_community_all)
                   6212:              {
                   6213:                if (! ri->attr->community)
                   6214:                  continue;
                   6215:              }
                   6216:            if (type == bgp_show_type_community)
                   6217:              {
                   6218:                struct community *com = output_arg;
                   6219: 
                   6220:                if (! ri->attr->community ||
                   6221:                    ! community_match (ri->attr->community, com))
                   6222:                  continue;
                   6223:              }
                   6224:            if (type == bgp_show_type_community_exact)
                   6225:              {
                   6226:                struct community *com = output_arg;
                   6227: 
                   6228:                if (! ri->attr->community ||
                   6229:                    ! community_cmp (ri->attr->community, com))
                   6230:                  continue;
                   6231:              }
                   6232:            if (type == bgp_show_type_community_list)
                   6233:              {
                   6234:                struct community_list *list = output_arg;
                   6235: 
                   6236:                if (! community_list_match (ri->attr->community, list))
                   6237:                  continue;
                   6238:              }
                   6239:            if (type == bgp_show_type_community_list_exact)
                   6240:              {
                   6241:                struct community_list *list = output_arg;
                   6242: 
                   6243:                if (! community_list_exact_match (ri->attr->community, list))
                   6244:                  continue;
                   6245:              }
                   6246:            if (type == bgp_show_type_flap_address
                   6247:                || type == bgp_show_type_flap_prefix)
                   6248:              {
                   6249:                struct prefix *p = output_arg;
                   6250: 
                   6251:                if (! prefix_match (&rn->p, p))
                   6252:                  continue;
                   6253: 
                   6254:                if (type == bgp_show_type_flap_prefix)
                   6255:                  if (p->prefixlen != rn->p.prefixlen)
                   6256:                    continue;
                   6257:              }
                   6258:            if (type == bgp_show_type_dampend_paths
                   6259:                || type == bgp_show_type_damp_neighbor)
                   6260:              {
                   6261:                if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
                   6262:                    || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
                   6263:                  continue;
                   6264:              }
                   6265: 
                   6266:            if (header)
                   6267:              {
                   6268:                vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
                   6269:                vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
                   6270:                vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
                   6271:                if (type == bgp_show_type_dampend_paths
                   6272:                    || type == bgp_show_type_damp_neighbor)
                   6273:                  vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
                   6274:                else if (type == bgp_show_type_flap_statistics
                   6275:                         || type == bgp_show_type_flap_address
                   6276:                         || type == bgp_show_type_flap_prefix
                   6277:                         || type == bgp_show_type_flap_cidr_only
                   6278:                         || type == bgp_show_type_flap_regexp
                   6279:                         || type == bgp_show_type_flap_filter_list
                   6280:                         || type == bgp_show_type_flap_prefix_list
                   6281:                         || type == bgp_show_type_flap_prefix_longer
                   6282:                         || type == bgp_show_type_flap_route_map
                   6283:                         || type == bgp_show_type_flap_neighbor)
                   6284:                  vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
                   6285:                else
                   6286:                  vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
                   6287:                header = 0;
                   6288:              }
                   6289: 
                   6290:            if (type == bgp_show_type_dampend_paths
                   6291:                || type == bgp_show_type_damp_neighbor)
                   6292:              damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
                   6293:            else if (type == bgp_show_type_flap_statistics
                   6294:                     || type == bgp_show_type_flap_address
                   6295:                     || type == bgp_show_type_flap_prefix
                   6296:                     || type == bgp_show_type_flap_cidr_only
                   6297:                     || type == bgp_show_type_flap_regexp
                   6298:                     || type == bgp_show_type_flap_filter_list
                   6299:                     || type == bgp_show_type_flap_prefix_list
                   6300:                     || type == bgp_show_type_flap_prefix_longer
                   6301:                     || type == bgp_show_type_flap_route_map
                   6302:                     || type == bgp_show_type_flap_neighbor)
                   6303:              flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
                   6304:            else
                   6305:              route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
                   6306:            display++;
                   6307:          }
                   6308:        if (display)
                   6309:          output_count++;
                   6310:       }
                   6311: 
                   6312:   /* No route is displayed */
                   6313:   if (output_count == 0)
                   6314:     {
                   6315:       if (type == bgp_show_type_normal)
                   6316:        vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
                   6317:     }
                   6318:   else
                   6319:     vty_out (vty, "%sTotal number of prefixes %ld%s",
                   6320:             VTY_NEWLINE, output_count, VTY_NEWLINE);
                   6321: 
                   6322:   return CMD_SUCCESS;
                   6323: }
                   6324: 
                   6325: static int
                   6326: bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
                   6327:          enum bgp_show_type type, void *output_arg)
                   6328: {
                   6329:   struct bgp_table *table;
                   6330: 
                   6331:   if (bgp == NULL) {
                   6332:     bgp = bgp_get_default ();
                   6333:   }
                   6334: 
                   6335:   if (bgp == NULL)
                   6336:     {
                   6337:       vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
                   6338:       return CMD_WARNING;
                   6339:     }
                   6340: 
                   6341: 
                   6342:   table = bgp->rib[afi][safi];
                   6343: 
                   6344:   return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
                   6345: }
                   6346: 
                   6347: /* Header of detailed BGP route information */
                   6348: static void
                   6349: route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
                   6350:                             struct bgp_node *rn,
                   6351:                              struct prefix_rd *prd, afi_t afi, safi_t safi)
                   6352: {
                   6353:   struct bgp_info *ri;
                   6354:   struct prefix *p;
                   6355:   struct peer *peer;
                   6356:   struct listnode *node, *nnode;
                   6357:   char buf1[INET6_ADDRSTRLEN];
                   6358:   char buf2[INET6_ADDRSTRLEN];
                   6359:   int count = 0;
                   6360:   int best = 0;
                   6361:   int suppress = 0;
                   6362:   int no_export = 0;
                   6363:   int no_advertise = 0;
                   6364:   int local_as = 0;
                   6365:   int first = 0;
                   6366: 
                   6367:   p = &rn->p;
                   6368:   vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
                   6369:           (safi == SAFI_MPLS_VPN ?
                   6370:           prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
                   6371:           safi == SAFI_MPLS_VPN ? ":" : "",
                   6372:           inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
                   6373:           p->prefixlen, VTY_NEWLINE);
                   6374: 
                   6375:   for (ri = rn->info; ri; ri = ri->next)
                   6376:     {
                   6377:       count++;
                   6378:       if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
                   6379:        {
                   6380:          best = count;
                   6381:          if (ri->extra && ri->extra->suppress)
                   6382:            suppress = 1;
                   6383:          if (ri->attr->community != NULL)
                   6384:            {
                   6385:              if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
                   6386:                no_advertise = 1;
                   6387:              if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
                   6388:                no_export = 1;
                   6389:              if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
                   6390:                local_as = 1;
                   6391:            }
                   6392:        }
                   6393:     }
                   6394: 
                   6395:   vty_out (vty, "Paths: (%d available", count);
                   6396:   if (best)
                   6397:     {
                   6398:       vty_out (vty, ", best #%d", best);
                   6399:       if (safi == SAFI_UNICAST)
                   6400:        vty_out (vty, ", table Default-IP-Routing-Table");
                   6401:     }
                   6402:   else
                   6403:     vty_out (vty, ", no best path");
                   6404:   if (no_advertise)
                   6405:     vty_out (vty, ", not advertised to any peer");
                   6406:   else if (no_export)
                   6407:     vty_out (vty, ", not advertised to EBGP peer");
                   6408:   else if (local_as)
                   6409:     vty_out (vty, ", not advertised outside local AS");
                   6410:   if (suppress)
                   6411:     vty_out (vty, ", Advertisements suppressed by an aggregate.");
                   6412:   vty_out (vty, ")%s", VTY_NEWLINE);
                   6413: 
                   6414:   /* advertised peer */
                   6415:   for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
                   6416:     {
                   6417:       if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
                   6418:        {
                   6419:          if (! first)
                   6420:            vty_out (vty, "  Advertised to non peer-group peers:%s ", VTY_NEWLINE);
                   6421:          vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
                   6422:          first = 1;
                   6423:        }
                   6424:     }
                   6425:   if (! first)
                   6426:     vty_out (vty, "  Not advertised to any peer");
                   6427:   vty_out (vty, "%s", VTY_NEWLINE);
                   6428: }
                   6429: 
                   6430: /* Display specified route of BGP table. */
                   6431: static int
                   6432: bgp_show_route_in_table (struct vty *vty, struct bgp *bgp, 
                   6433:                          struct bgp_table *rib, const char *ip_str,
                   6434:                          afi_t afi, safi_t safi, struct prefix_rd *prd,
                   6435:                          int prefix_check)
                   6436: {
                   6437:   int ret;
                   6438:   int header;
                   6439:   int display = 0;
                   6440:   struct prefix match;
                   6441:   struct bgp_node *rn;
                   6442:   struct bgp_node *rm;
                   6443:   struct bgp_info *ri;
                   6444:   struct bgp_table *table;
                   6445: 
                   6446:   /* Check IP address argument. */
                   6447:   ret = str2prefix (ip_str, &match);
                   6448:   if (! ret)
                   6449:     {
                   6450:       vty_out (vty, "address is malformed%s", VTY_NEWLINE);
                   6451:       return CMD_WARNING;
                   6452:     }
                   6453: 
                   6454:   match.family = afi2family (afi);
                   6455: 
                   6456:   if (safi == SAFI_MPLS_VPN)
                   6457:     {
                   6458:       for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
                   6459:         {
                   6460:           if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
                   6461:             continue;
                   6462: 
                   6463:           if ((table = rn->info) != NULL)
                   6464:             {
                   6465:               header = 1;
                   6466: 
                   6467:               if ((rm = bgp_node_match (table, &match)) != NULL)
                   6468:                 {
                   6469:                   if (prefix_check && rm->p.prefixlen != match.prefixlen)
                   6470:                     {
                   6471:                       bgp_unlock_node (rm);
                   6472:                       continue;
                   6473:                     }
                   6474: 
                   6475:                   for (ri = rm->info; ri; ri = ri->next)
                   6476:                     {
                   6477:                       if (header)
                   6478:                         {
                   6479:                           route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
                   6480:                                                        AFI_IP, SAFI_MPLS_VPN);
                   6481: 
                   6482:                           header = 0;
                   6483:                         }
                   6484:                       display++;
                   6485:                       route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
                   6486:                     }
                   6487: 
                   6488:                   bgp_unlock_node (rm);
                   6489:                 }
                   6490:             }
                   6491:         }
                   6492:     }
                   6493:   else
                   6494:     {
                   6495:       header = 1;
                   6496: 
                   6497:       if ((rn = bgp_node_match (rib, &match)) != NULL)
                   6498:         {
                   6499:           if (! prefix_check || rn->p.prefixlen == match.prefixlen)
                   6500:             {
                   6501:               for (ri = rn->info; ri; ri = ri->next)
                   6502:                 {
                   6503:                   if (header)
                   6504:                     {
                   6505:                       route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
                   6506:                       header = 0;
                   6507:                     }
                   6508:                   display++;
                   6509:                   route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
                   6510:                 }
                   6511:             }
                   6512: 
                   6513:           bgp_unlock_node (rn);
                   6514:         }
                   6515:     }
                   6516: 
                   6517:   if (! display)
                   6518:     {
                   6519:       vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
                   6520:       return CMD_WARNING;
                   6521:     }
                   6522: 
                   6523:   return CMD_SUCCESS;
                   6524: }
                   6525: 
                   6526: /* Display specified route of Main RIB */
                   6527: static int
                   6528: bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
                   6529:                afi_t afi, safi_t safi, struct prefix_rd *prd,
                   6530:                int prefix_check)
                   6531: {
                   6532:   struct bgp *bgp;
                   6533: 
                   6534:   /* BGP structure lookup. */
                   6535:   if (view_name)
                   6536:     {
                   6537:       bgp = bgp_lookup_by_name (view_name);
                   6538:       if (bgp == NULL)
                   6539:        {
                   6540:          vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
                   6541:          return CMD_WARNING;
                   6542:        }
                   6543:     }
                   6544:   else
                   6545:     {
                   6546:       bgp = bgp_get_default ();
                   6547:       if (bgp == NULL)
                   6548:        {
                   6549:          vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
                   6550:          return CMD_WARNING;
                   6551:        }
                   6552:     }
                   6553:  
                   6554:   return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str, 
                   6555:                                    afi, safi, prd, prefix_check);
                   6556: }
                   6557: 
                   6558: /* BGP route print out function. */
                   6559: DEFUN (show_ip_bgp,
                   6560:        show_ip_bgp_cmd,
                   6561:        "show ip bgp",
                   6562:        SHOW_STR
                   6563:        IP_STR
                   6564:        BGP_STR)
                   6565: {
                   6566:   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
                   6567: }
                   6568: 
                   6569: DEFUN (show_ip_bgp_ipv4,
                   6570:        show_ip_bgp_ipv4_cmd,
                   6571:        "show ip bgp ipv4 (unicast|multicast)",
                   6572:        SHOW_STR
                   6573:        IP_STR
                   6574:        BGP_STR
                   6575:        "Address family\n"
                   6576:        "Address Family modifier\n"
                   6577:        "Address Family modifier\n")
                   6578: {
                   6579:   if (strncmp (argv[0], "m", 1) == 0)
                   6580:     return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
                   6581:                      NULL);
                   6582:  
                   6583:   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
                   6584: }
                   6585: 
                   6586: ALIAS (show_ip_bgp_ipv4,
                   6587:        show_bgp_ipv4_safi_cmd,
                   6588:        "show bgp ipv4 (unicast|multicast)",
                   6589:        SHOW_STR
                   6590:        BGP_STR
                   6591:        "Address family\n"
                   6592:        "Address Family modifier\n"
                   6593:        "Address Family modifier\n")
                   6594: 
                   6595: DEFUN (show_ip_bgp_route,
                   6596:        show_ip_bgp_route_cmd,
                   6597:        "show ip bgp A.B.C.D",
                   6598:        SHOW_STR
                   6599:        IP_STR
                   6600:        BGP_STR
                   6601:        "Network in the BGP routing table to display\n")
                   6602: {
                   6603:   return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
                   6604: }
                   6605: 
                   6606: DEFUN (show_ip_bgp_ipv4_route,
                   6607:        show_ip_bgp_ipv4_route_cmd,
                   6608:        "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
                   6609:        SHOW_STR
                   6610:        IP_STR
                   6611:        BGP_STR
                   6612:        "Address family\n"
                   6613:        "Address Family modifier\n"
                   6614:        "Address Family modifier\n"
                   6615:        "Network in the BGP routing table to display\n")
                   6616: {
                   6617:   if (strncmp (argv[0], "m", 1) == 0)
                   6618:     return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
                   6619: 
                   6620:   return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
                   6621: }
                   6622: 
                   6623: ALIAS (show_ip_bgp_ipv4_route,
                   6624:        show_bgp_ipv4_safi_route_cmd,
                   6625:        "show bgp ipv4 (unicast|multicast) A.B.C.D",
                   6626:        SHOW_STR
                   6627:        BGP_STR
                   6628:        "Address family\n"
                   6629:        "Address Family modifier\n"
                   6630:        "Address Family modifier\n"
                   6631:        "Network in the BGP routing table to display\n")
                   6632: 
                   6633: DEFUN (show_ip_bgp_vpnv4_all_route,
                   6634:        show_ip_bgp_vpnv4_all_route_cmd,
                   6635:        "show ip bgp vpnv4 all A.B.C.D",
                   6636:        SHOW_STR
                   6637:        IP_STR
                   6638:        BGP_STR
                   6639:        "Display VPNv4 NLRI specific information\n"
                   6640:        "Display information about all VPNv4 NLRIs\n"
                   6641:        "Network in the BGP routing table to display\n")
                   6642: {
                   6643:   return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
                   6644: }
                   6645: 
                   6646: DEFUN (show_ip_bgp_vpnv4_rd_route,
                   6647:        show_ip_bgp_vpnv4_rd_route_cmd,
                   6648:        "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
                   6649:        SHOW_STR
                   6650:        IP_STR
                   6651:        BGP_STR
                   6652:        "Display VPNv4 NLRI specific information\n"
                   6653:        "Display information for a route distinguisher\n"
                   6654:        "VPN Route Distinguisher\n"
                   6655:        "Network in the BGP routing table to display\n")
                   6656: {
                   6657:   int ret;
                   6658:   struct prefix_rd prd;
                   6659: 
                   6660:   ret = str2prefix_rd (argv[0], &prd);
                   6661:   if (! ret)
                   6662:     {
                   6663:       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
                   6664:       return CMD_WARNING;
                   6665:     }
                   6666:   return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
                   6667: }
                   6668: 
                   6669: DEFUN (show_ip_bgp_prefix,
                   6670:        show_ip_bgp_prefix_cmd,
                   6671:        "show ip bgp A.B.C.D/M",
                   6672:        SHOW_STR
                   6673:        IP_STR
                   6674:        BGP_STR
                   6675:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
                   6676: {
                   6677:   return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
                   6678: }
                   6679: 
                   6680: DEFUN (show_ip_bgp_ipv4_prefix,
                   6681:        show_ip_bgp_ipv4_prefix_cmd,
                   6682:        "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
                   6683:        SHOW_STR
                   6684:        IP_STR
                   6685:        BGP_STR
                   6686:        "Address family\n"
                   6687:        "Address Family modifier\n"
                   6688:        "Address Family modifier\n"
                   6689:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
                   6690: {
                   6691:   if (strncmp (argv[0], "m", 1) == 0)
                   6692:     return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
                   6693: 
                   6694:   return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
                   6695: }
                   6696: 
                   6697: ALIAS (show_ip_bgp_ipv4_prefix,
                   6698:        show_bgp_ipv4_safi_prefix_cmd,
                   6699:        "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
                   6700:        SHOW_STR
                   6701:        BGP_STR
                   6702:        "Address family\n"
                   6703:        "Address Family modifier\n"
                   6704:        "Address Family modifier\n"
                   6705:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
                   6706: 
                   6707: DEFUN (show_ip_bgp_vpnv4_all_prefix,
                   6708:        show_ip_bgp_vpnv4_all_prefix_cmd,
                   6709:        "show ip bgp vpnv4 all A.B.C.D/M",
                   6710:        SHOW_STR
                   6711:        IP_STR
                   6712:        BGP_STR
                   6713:        "Display VPNv4 NLRI specific information\n"
                   6714:        "Display information about all VPNv4 NLRIs\n"
                   6715:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
                   6716: {
                   6717:   return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
                   6718: }
                   6719: 
                   6720: DEFUN (show_ip_bgp_vpnv4_rd_prefix,
                   6721:        show_ip_bgp_vpnv4_rd_prefix_cmd,
                   6722:        "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
                   6723:        SHOW_STR
                   6724:        IP_STR
                   6725:        BGP_STR
                   6726:        "Display VPNv4 NLRI specific information\n"
                   6727:        "Display information for a route distinguisher\n"
                   6728:        "VPN Route Distinguisher\n"
                   6729:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
                   6730: {
                   6731:   int ret;
                   6732:   struct prefix_rd prd;
                   6733: 
                   6734:   ret = str2prefix_rd (argv[0], &prd);
                   6735:   if (! ret)
                   6736:     {
                   6737:       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
                   6738:       return CMD_WARNING;
                   6739:     }
                   6740:   return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
                   6741: }
                   6742: 
                   6743: DEFUN (show_ip_bgp_view,
                   6744:        show_ip_bgp_view_cmd,
                   6745:        "show ip bgp view WORD",
                   6746:        SHOW_STR
                   6747:        IP_STR
                   6748:        BGP_STR
                   6749:        "BGP view\n"
                   6750:        "BGP view name\n")
                   6751: {
                   6752:   struct bgp *bgp;
                   6753: 
                   6754:   /* BGP structure lookup. */
                   6755:   bgp = bgp_lookup_by_name (argv[0]);
                   6756:   if (bgp == NULL)
                   6757:        {
                   6758:          vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
                   6759:          return CMD_WARNING;
                   6760:        }
                   6761: 
                   6762:   return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
                   6763: }
                   6764: 
                   6765: DEFUN (show_ip_bgp_view_route,
                   6766:        show_ip_bgp_view_route_cmd,
                   6767:        "show ip bgp view WORD A.B.C.D",
                   6768:        SHOW_STR
                   6769:        IP_STR
                   6770:        BGP_STR
                   6771:        "BGP view\n"
                   6772:        "BGP view name\n"
                   6773:        "Network in the BGP routing table to display\n")
                   6774: {
                   6775:   return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
                   6776: }
                   6777: 
                   6778: DEFUN (show_ip_bgp_view_prefix,
                   6779:        show_ip_bgp_view_prefix_cmd,
                   6780:        "show ip bgp view WORD A.B.C.D/M",
                   6781:        SHOW_STR
                   6782:        IP_STR
                   6783:        BGP_STR
                   6784:        "BGP view\n"
                   6785:        "BGP view name\n"
                   6786:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
                   6787: {
                   6788:   return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
                   6789: }
                   6790: 
                   6791: #ifdef HAVE_IPV6
                   6792: DEFUN (show_bgp,
                   6793:        show_bgp_cmd,
                   6794:        "show bgp",
                   6795:        SHOW_STR
                   6796:        BGP_STR)
                   6797: {
                   6798:   return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
                   6799:                    NULL);
                   6800: }
                   6801: 
                   6802: ALIAS (show_bgp,
                   6803:        show_bgp_ipv6_cmd,
                   6804:        "show bgp ipv6",
                   6805:        SHOW_STR
                   6806:        BGP_STR
                   6807:        "Address family\n")
                   6808: 
                   6809: DEFUN (show_bgp_ipv6_safi,
                   6810:        show_bgp_ipv6_safi_cmd,
                   6811:        "show bgp ipv6 (unicast|multicast)",
                   6812:        SHOW_STR
                   6813:        BGP_STR
                   6814:        "Address family\n"
                   6815:        "Address Family modifier\n"
                   6816:        "Address Family modifier\n")
                   6817: {
                   6818:   if (strncmp (argv[0], "m", 1) == 0)
                   6819:     return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
                   6820:                      NULL);
                   6821: 
                   6822:   return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
                   6823: }
                   6824: 
                   6825: /* old command */
                   6826: DEFUN (show_ipv6_bgp,
                   6827:        show_ipv6_bgp_cmd,
                   6828:        "show ipv6 bgp",
                   6829:        SHOW_STR
                   6830:        IP_STR
                   6831:        BGP_STR)
                   6832: {
                   6833:   return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
                   6834:                    NULL);
                   6835: }
                   6836: 
                   6837: DEFUN (show_bgp_route,
                   6838:        show_bgp_route_cmd,
                   6839:        "show bgp X:X::X:X",
                   6840:        SHOW_STR
                   6841:        BGP_STR
                   6842:        "Network in the BGP routing table to display\n")
                   6843: {
                   6844:   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
                   6845: }
                   6846: 
                   6847: ALIAS (show_bgp_route,
                   6848:        show_bgp_ipv6_route_cmd,
                   6849:        "show bgp ipv6 X:X::X:X",
                   6850:        SHOW_STR
                   6851:        BGP_STR
                   6852:        "Address family\n"
                   6853:        "Network in the BGP routing table to display\n")
                   6854: 
                   6855: DEFUN (show_bgp_ipv6_safi_route,
                   6856:        show_bgp_ipv6_safi_route_cmd,
                   6857:        "show bgp ipv6 (unicast|multicast) X:X::X:X",
                   6858:        SHOW_STR
                   6859:        BGP_STR
                   6860:        "Address family\n"
                   6861:        "Address Family modifier\n"
                   6862:        "Address Family modifier\n"
                   6863:        "Network in the BGP routing table to display\n")
                   6864: {
                   6865:   if (strncmp (argv[0], "m", 1) == 0)
                   6866:     return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
                   6867: 
                   6868:   return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
                   6869: }
                   6870: 
                   6871: /* old command */
                   6872: DEFUN (show_ipv6_bgp_route,
                   6873:        show_ipv6_bgp_route_cmd,
                   6874:        "show ipv6 bgp X:X::X:X",
                   6875:        SHOW_STR
                   6876:        IP_STR
                   6877:        BGP_STR
                   6878:        "Network in the BGP routing table to display\n")
                   6879: {
                   6880:   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
                   6881: }
                   6882: 
                   6883: DEFUN (show_bgp_prefix,
                   6884:        show_bgp_prefix_cmd,
                   6885:        "show bgp X:X::X:X/M",
                   6886:        SHOW_STR
                   6887:        BGP_STR
                   6888:        "IPv6 prefix <network>/<length>\n")
                   6889: {
                   6890:   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
                   6891: }
                   6892: 
                   6893: ALIAS (show_bgp_prefix,
                   6894:        show_bgp_ipv6_prefix_cmd,
                   6895:        "show bgp ipv6 X:X::X:X/M",
                   6896:        SHOW_STR
                   6897:        BGP_STR
                   6898:        "Address family\n"
                   6899:        "IPv6 prefix <network>/<length>\n")
                   6900: 
                   6901: DEFUN (show_bgp_ipv6_safi_prefix,
                   6902:        show_bgp_ipv6_safi_prefix_cmd,
                   6903:        "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
                   6904:        SHOW_STR
                   6905:        BGP_STR
                   6906:        "Address family\n"
                   6907:        "Address Family modifier\n"
                   6908:        "Address Family modifier\n"
                   6909:        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
                   6910: {
                   6911:   if (strncmp (argv[0], "m", 1) == 0)
                   6912:     return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
                   6913: 
                   6914:   return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
                   6915: }
                   6916: 
                   6917: /* old command */
                   6918: DEFUN (show_ipv6_bgp_prefix,
                   6919:        show_ipv6_bgp_prefix_cmd,
                   6920:        "show ipv6 bgp X:X::X:X/M",
                   6921:        SHOW_STR
                   6922:        IP_STR
                   6923:        BGP_STR
                   6924:        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
                   6925: {
                   6926:   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
                   6927: }
                   6928: 
                   6929: DEFUN (show_bgp_view,
                   6930:        show_bgp_view_cmd,
                   6931:        "show bgp view WORD",
                   6932:        SHOW_STR
                   6933:        BGP_STR
                   6934:        "BGP view\n"
                   6935:        "View name\n")
                   6936: {
                   6937:   struct bgp *bgp;
                   6938: 
                   6939:   /* BGP structure lookup. */
                   6940:   bgp = bgp_lookup_by_name (argv[0]);
                   6941:   if (bgp == NULL)
                   6942:        {
                   6943:          vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
                   6944:          return CMD_WARNING;
                   6945:        }
                   6946:   
                   6947:   return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
                   6948: }
                   6949: 
                   6950: ALIAS (show_bgp_view,
                   6951:        show_bgp_view_ipv6_cmd,
                   6952:        "show bgp view WORD ipv6",
                   6953:        SHOW_STR
                   6954:        BGP_STR             
                   6955:        "BGP view\n"
                   6956:        "View name\n"
                   6957:        "Address family\n")
                   6958:   
                   6959: DEFUN (show_bgp_view_route,
                   6960:        show_bgp_view_route_cmd,
                   6961:        "show bgp view WORD X:X::X:X",
                   6962:        SHOW_STR
                   6963:        BGP_STR
                   6964:        "BGP view\n"
                   6965:        "View name\n"
                   6966:        "Network in the BGP routing table to display\n")
                   6967: {
                   6968:   return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
                   6969: }
                   6970: 
                   6971: ALIAS (show_bgp_view_route,
                   6972:        show_bgp_view_ipv6_route_cmd,
                   6973:        "show bgp view WORD ipv6 X:X::X:X",
                   6974:        SHOW_STR
                   6975:        BGP_STR
                   6976:        "BGP view\n"
                   6977:        "View name\n"
                   6978:        "Address family\n"
                   6979:        "Network in the BGP routing table to display\n")
                   6980: 
                   6981: DEFUN (show_bgp_view_prefix,
                   6982:        show_bgp_view_prefix_cmd,
                   6983:        "show bgp view WORD X:X::X:X/M",
                   6984:        SHOW_STR
                   6985:        BGP_STR
                   6986:        "BGP view\n"
                   6987:        "View name\n"       
                   6988:        "IPv6 prefix <network>/<length>\n")
                   6989: {
                   6990:   return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1); 
                   6991: }
                   6992: 
                   6993: ALIAS (show_bgp_view_prefix,
                   6994:        show_bgp_view_ipv6_prefix_cmd,
                   6995:        "show bgp view WORD ipv6 X:X::X:X/M",
                   6996:        SHOW_STR
                   6997:        BGP_STR
                   6998:        "BGP view\n"
                   6999:        "View name\n"
                   7000:        "Address family\n"
                   7001:        "IPv6 prefix <network>/<length>\n")  
                   7002: 
                   7003: /* old command */
                   7004: DEFUN (show_ipv6_mbgp,
                   7005:        show_ipv6_mbgp_cmd,
                   7006:        "show ipv6 mbgp",
                   7007:        SHOW_STR
                   7008:        IP_STR
                   7009:        MBGP_STR)
                   7010: {
                   7011:   return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
                   7012:                    NULL);
                   7013: }
                   7014: 
                   7015: /* old command */
                   7016: DEFUN (show_ipv6_mbgp_route,
                   7017:        show_ipv6_mbgp_route_cmd,
                   7018:        "show ipv6 mbgp X:X::X:X",
                   7019:        SHOW_STR
                   7020:        IP_STR
                   7021:        MBGP_STR
                   7022:        "Network in the MBGP routing table to display\n")
                   7023: {
                   7024:   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
                   7025: }
                   7026: 
                   7027: /* old command */
                   7028: DEFUN (show_ipv6_mbgp_prefix,
                   7029:        show_ipv6_mbgp_prefix_cmd,
                   7030:        "show ipv6 mbgp X:X::X:X/M",
                   7031:        SHOW_STR
                   7032:        IP_STR
                   7033:        MBGP_STR
                   7034:        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
                   7035: {
                   7036:   return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
                   7037: }
                   7038: #endif
                   7039: 
                   7040: 
                   7041: static int
                   7042: bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
                   7043:                 safi_t safi, enum bgp_show_type type)
                   7044: {
                   7045:   int i;
                   7046:   struct buffer *b;
                   7047:   char *regstr;
                   7048:   int first;
                   7049:   regex_t *regex;
                   7050:   int rc;
                   7051:   
                   7052:   first = 0;
                   7053:   b = buffer_new (1024);
                   7054:   for (i = 0; i < argc; i++)
                   7055:     {
                   7056:       if (first)
                   7057:        buffer_putc (b, ' ');
                   7058:       else
                   7059:        {
                   7060:          if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
                   7061:            continue;
                   7062:          first = 1;
                   7063:        }
                   7064: 
                   7065:       buffer_putstr (b, argv[i]);
                   7066:     }
                   7067:   buffer_putc (b, '\0');
                   7068: 
                   7069:   regstr = buffer_getstr (b);
                   7070:   buffer_free (b);
                   7071: 
                   7072:   regex = bgp_regcomp (regstr);
                   7073:   XFREE(MTYPE_TMP, regstr);
                   7074:   if (! regex)
                   7075:     {
                   7076:       vty_out (vty, "Can't compile regexp %s%s", argv[0],
                   7077:               VTY_NEWLINE);
                   7078:       return CMD_WARNING;
                   7079:     }
                   7080: 
                   7081:   rc = bgp_show (vty, NULL, afi, safi, type, regex);
                   7082:   bgp_regex_free (regex);
                   7083:   return rc;
                   7084: }
                   7085: 
                   7086: DEFUN (show_ip_bgp_regexp, 
                   7087:        show_ip_bgp_regexp_cmd,
                   7088:        "show ip bgp regexp .LINE",
                   7089:        SHOW_STR
                   7090:        IP_STR
                   7091:        BGP_STR
                   7092:        "Display routes matching the AS path regular expression\n"
                   7093:        "A regular-expression to match the BGP AS paths\n")
                   7094: {
                   7095:   return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
                   7096:                          bgp_show_type_regexp);
                   7097: }
                   7098: 
                   7099: DEFUN (show_ip_bgp_flap_regexp, 
                   7100:        show_ip_bgp_flap_regexp_cmd,
                   7101:        "show ip bgp flap-statistics regexp .LINE",
                   7102:        SHOW_STR
                   7103:        IP_STR
                   7104:        BGP_STR
                   7105:        "Display flap statistics of routes\n"
                   7106:        "Display routes matching the AS path regular expression\n"
                   7107:        "A regular-expression to match the BGP AS paths\n")
                   7108: {
                   7109:   return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
                   7110:                          bgp_show_type_flap_regexp);
                   7111: }
                   7112: 
                   7113: DEFUN (show_ip_bgp_ipv4_regexp, 
                   7114:        show_ip_bgp_ipv4_regexp_cmd,
                   7115:        "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
                   7116:        SHOW_STR
                   7117:        IP_STR
                   7118:        BGP_STR
                   7119:        "Address family\n"
                   7120:        "Address Family modifier\n"
                   7121:        "Address Family modifier\n"
                   7122:        "Display routes matching the AS path regular expression\n"
                   7123:        "A regular-expression to match the BGP AS paths\n")
                   7124: {
                   7125:   if (strncmp (argv[0], "m", 1) == 0)
                   7126:     return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
                   7127:                            bgp_show_type_regexp);
                   7128: 
                   7129:   return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
                   7130:                          bgp_show_type_regexp);
                   7131: }
                   7132: 
                   7133: #ifdef HAVE_IPV6
                   7134: DEFUN (show_bgp_regexp, 
                   7135:        show_bgp_regexp_cmd,
                   7136:        "show bgp regexp .LINE",
                   7137:        SHOW_STR
                   7138:        BGP_STR
                   7139:        "Display routes matching the AS path regular expression\n"
                   7140:        "A regular-expression to match the BGP AS paths\n")
                   7141: {
                   7142:   return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
                   7143:                          bgp_show_type_regexp);
                   7144: }
                   7145: 
                   7146: ALIAS (show_bgp_regexp, 
                   7147:        show_bgp_ipv6_regexp_cmd,
                   7148:        "show bgp ipv6 regexp .LINE",
                   7149:        SHOW_STR
                   7150:        BGP_STR
                   7151:        "Address family\n"
                   7152:        "Display routes matching the AS path regular expression\n"
                   7153:        "A regular-expression to match the BGP AS paths\n")
                   7154: 
                   7155: /* old command */
                   7156: DEFUN (show_ipv6_bgp_regexp, 
                   7157:        show_ipv6_bgp_regexp_cmd,
                   7158:        "show ipv6 bgp regexp .LINE",
                   7159:        SHOW_STR
                   7160:        IP_STR
                   7161:        BGP_STR
                   7162:        "Display routes matching the AS path regular expression\n"
                   7163:        "A regular-expression to match the BGP AS paths\n")
                   7164: {
                   7165:   return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
                   7166:                          bgp_show_type_regexp);
                   7167: }
                   7168: 
                   7169: /* old command */
                   7170: DEFUN (show_ipv6_mbgp_regexp, 
                   7171:        show_ipv6_mbgp_regexp_cmd,
                   7172:        "show ipv6 mbgp regexp .LINE",
                   7173:        SHOW_STR
                   7174:        IP_STR
                   7175:        BGP_STR
                   7176:        "Display routes matching the AS path regular expression\n"
                   7177:        "A regular-expression to match the MBGP AS paths\n")
                   7178: {
                   7179:   return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
                   7180:                          bgp_show_type_regexp);
                   7181: }
                   7182: #endif /* HAVE_IPV6 */
                   7183: 
                   7184: static int
                   7185: bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
                   7186:                      safi_t safi, enum bgp_show_type type)
                   7187: {
                   7188:   struct prefix_list *plist;
                   7189: 
                   7190:   plist = prefix_list_lookup (afi, prefix_list_str);
                   7191:   if (plist == NULL)
                   7192:     {
                   7193:       vty_out (vty, "%% %s is not a valid prefix-list name%s",
                   7194:                prefix_list_str, VTY_NEWLINE);      
                   7195:       return CMD_WARNING;
                   7196:     }
                   7197: 
                   7198:   return bgp_show (vty, NULL, afi, safi, type, plist);
                   7199: }
                   7200: 
                   7201: DEFUN (show_ip_bgp_prefix_list, 
                   7202:        show_ip_bgp_prefix_list_cmd,
                   7203:        "show ip bgp prefix-list WORD",
                   7204:        SHOW_STR
                   7205:        IP_STR
                   7206:        BGP_STR
                   7207:        "Display routes conforming to the prefix-list\n"
                   7208:        "IP prefix-list name\n")
                   7209: {
                   7210:   return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
                   7211:                               bgp_show_type_prefix_list);
                   7212: }
                   7213: 
                   7214: DEFUN (show_ip_bgp_flap_prefix_list, 
                   7215:        show_ip_bgp_flap_prefix_list_cmd,
                   7216:        "show ip bgp flap-statistics prefix-list WORD",
                   7217:        SHOW_STR
                   7218:        IP_STR
                   7219:        BGP_STR
                   7220:        "Display flap statistics of routes\n"
                   7221:        "Display routes conforming to the prefix-list\n"
                   7222:        "IP prefix-list name\n")
                   7223: {
                   7224:   return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
                   7225:                               bgp_show_type_flap_prefix_list);
                   7226: }
                   7227: 
                   7228: DEFUN (show_ip_bgp_ipv4_prefix_list, 
                   7229:        show_ip_bgp_ipv4_prefix_list_cmd,
                   7230:        "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
                   7231:        SHOW_STR
                   7232:        IP_STR
                   7233:        BGP_STR
                   7234:        "Address family\n"
                   7235:        "Address Family modifier\n"
                   7236:        "Address Family modifier\n"
                   7237:        "Display routes conforming to the prefix-list\n"
                   7238:        "IP prefix-list name\n")
                   7239: {
                   7240:   if (strncmp (argv[0], "m", 1) == 0)
                   7241:     return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
                   7242:                                 bgp_show_type_prefix_list);
                   7243: 
                   7244:   return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
                   7245:                               bgp_show_type_prefix_list);
                   7246: }
                   7247: 
                   7248: #ifdef HAVE_IPV6
                   7249: DEFUN (show_bgp_prefix_list, 
                   7250:        show_bgp_prefix_list_cmd,
                   7251:        "show bgp prefix-list WORD",
                   7252:        SHOW_STR
                   7253:        BGP_STR
                   7254:        "Display routes conforming to the prefix-list\n"
                   7255:        "IPv6 prefix-list name\n")
                   7256: {
                   7257:   return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
                   7258:                               bgp_show_type_prefix_list);
                   7259: }
                   7260: 
                   7261: ALIAS (show_bgp_prefix_list, 
                   7262:        show_bgp_ipv6_prefix_list_cmd,
                   7263:        "show bgp ipv6 prefix-list WORD",
                   7264:        SHOW_STR
                   7265:        BGP_STR
                   7266:        "Address family\n"
                   7267:        "Display routes conforming to the prefix-list\n"
                   7268:        "IPv6 prefix-list name\n")
                   7269: 
                   7270: /* old command */
                   7271: DEFUN (show_ipv6_bgp_prefix_list, 
                   7272:        show_ipv6_bgp_prefix_list_cmd,
                   7273:        "show ipv6 bgp prefix-list WORD",
                   7274:        SHOW_STR
                   7275:        IPV6_STR
                   7276:        BGP_STR
                   7277:        "Display routes matching the prefix-list\n"
                   7278:        "IPv6 prefix-list name\n")
                   7279: {
                   7280:   return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
                   7281:                               bgp_show_type_prefix_list);
                   7282: }
                   7283: 
                   7284: /* old command */
                   7285: DEFUN (show_ipv6_mbgp_prefix_list, 
                   7286:        show_ipv6_mbgp_prefix_list_cmd,
                   7287:        "show ipv6 mbgp prefix-list WORD",
                   7288:        SHOW_STR
                   7289:        IPV6_STR
                   7290:        MBGP_STR
                   7291:        "Display routes matching the prefix-list\n"
                   7292:        "IPv6 prefix-list name\n")
                   7293: {
                   7294:   return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
                   7295:                               bgp_show_type_prefix_list);
                   7296: }
                   7297: #endif /* HAVE_IPV6 */
                   7298: 
                   7299: static int
                   7300: bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
                   7301:                      safi_t safi, enum bgp_show_type type)
                   7302: {
                   7303:   struct as_list *as_list;
                   7304: 
                   7305:   as_list = as_list_lookup (filter);
                   7306:   if (as_list == NULL)
                   7307:     {
                   7308:       vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);       
                   7309:       return CMD_WARNING;
                   7310:     }
                   7311: 
                   7312:   return bgp_show (vty, NULL, afi, safi, type, as_list);
                   7313: }
                   7314: 
                   7315: DEFUN (show_ip_bgp_filter_list, 
                   7316:        show_ip_bgp_filter_list_cmd,
                   7317:        "show ip bgp filter-list WORD",
                   7318:        SHOW_STR
                   7319:        IP_STR
                   7320:        BGP_STR
                   7321:        "Display routes conforming to the filter-list\n"
                   7322:        "Regular expression access list name\n")
                   7323: {
                   7324:   return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
                   7325:                               bgp_show_type_filter_list);
                   7326: }
                   7327: 
                   7328: DEFUN (show_ip_bgp_flap_filter_list, 
                   7329:        show_ip_bgp_flap_filter_list_cmd,
                   7330:        "show ip bgp flap-statistics filter-list WORD",
                   7331:        SHOW_STR
                   7332:        IP_STR
                   7333:        BGP_STR
                   7334:        "Display flap statistics of routes\n"
                   7335:        "Display routes conforming to the filter-list\n"
                   7336:        "Regular expression access list name\n")
                   7337: {
                   7338:   return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
                   7339:                               bgp_show_type_flap_filter_list);
                   7340: }
                   7341: 
                   7342: DEFUN (show_ip_bgp_ipv4_filter_list, 
                   7343:        show_ip_bgp_ipv4_filter_list_cmd,
                   7344:        "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
                   7345:        SHOW_STR
                   7346:        IP_STR
                   7347:        BGP_STR
                   7348:        "Address family\n"
                   7349:        "Address Family modifier\n"
                   7350:        "Address Family modifier\n"
                   7351:        "Display routes conforming to the filter-list\n"
                   7352:        "Regular expression access list name\n")
                   7353: {
                   7354:   if (strncmp (argv[0], "m", 1) == 0)
                   7355:     return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
                   7356:                                 bgp_show_type_filter_list);
                   7357:   
                   7358:   return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
                   7359:                               bgp_show_type_filter_list);
                   7360: }
                   7361: 
                   7362: #ifdef HAVE_IPV6
                   7363: DEFUN (show_bgp_filter_list, 
                   7364:        show_bgp_filter_list_cmd,
                   7365:        "show bgp filter-list WORD",
                   7366:        SHOW_STR
                   7367:        BGP_STR
                   7368:        "Display routes conforming to the filter-list\n"
                   7369:        "Regular expression access list name\n")
                   7370: {
                   7371:   return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
                   7372:                               bgp_show_type_filter_list);
                   7373: }
                   7374: 
                   7375: ALIAS (show_bgp_filter_list, 
                   7376:        show_bgp_ipv6_filter_list_cmd,
                   7377:        "show bgp ipv6 filter-list WORD",
                   7378:        SHOW_STR
                   7379:        BGP_STR
                   7380:        "Address family\n"
                   7381:        "Display routes conforming to the filter-list\n"
                   7382:        "Regular expression access list name\n")
                   7383: 
                   7384: /* old command */
                   7385: DEFUN (show_ipv6_bgp_filter_list, 
                   7386:        show_ipv6_bgp_filter_list_cmd,
                   7387:        "show ipv6 bgp filter-list WORD",
                   7388:        SHOW_STR
                   7389:        IPV6_STR
                   7390:        BGP_STR
                   7391:        "Display routes conforming to the filter-list\n"
                   7392:        "Regular expression access list name\n")
                   7393: {
                   7394:   return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
                   7395:                               bgp_show_type_filter_list);
                   7396: }
                   7397: 
                   7398: /* old command */
                   7399: DEFUN (show_ipv6_mbgp_filter_list, 
                   7400:        show_ipv6_mbgp_filter_list_cmd,
                   7401:        "show ipv6 mbgp filter-list WORD",
                   7402:        SHOW_STR
                   7403:        IPV6_STR
                   7404:        MBGP_STR
                   7405:        "Display routes conforming to the filter-list\n"
                   7406:        "Regular expression access list name\n")
                   7407: {
                   7408:   return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
                   7409:                               bgp_show_type_filter_list);
                   7410: }
                   7411: #endif /* HAVE_IPV6 */
                   7412: 
                   7413: static int
                   7414: bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
                   7415:                    safi_t safi, enum bgp_show_type type)
                   7416: {
                   7417:   struct route_map *rmap;
                   7418: 
                   7419:   rmap = route_map_lookup_by_name (rmap_str);
                   7420:   if (! rmap)
                   7421:     {
                   7422:       vty_out (vty, "%% %s is not a valid route-map name%s",
                   7423:               rmap_str, VTY_NEWLINE);      
                   7424:       return CMD_WARNING;
                   7425:     }
                   7426: 
                   7427:   return bgp_show (vty, NULL, afi, safi, type, rmap);
                   7428: }
                   7429: 
                   7430: DEFUN (show_ip_bgp_route_map, 
                   7431:        show_ip_bgp_route_map_cmd,
                   7432:        "show ip bgp route-map WORD",
                   7433:        SHOW_STR
                   7434:        IP_STR
                   7435:        BGP_STR
                   7436:        "Display routes matching the route-map\n"
                   7437:        "A route-map to match on\n")
                   7438: {
                   7439:   return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
                   7440:                             bgp_show_type_route_map);
                   7441: }
                   7442: 
                   7443: DEFUN (show_ip_bgp_flap_route_map, 
                   7444:        show_ip_bgp_flap_route_map_cmd,
                   7445:        "show ip bgp flap-statistics route-map WORD",
                   7446:        SHOW_STR
                   7447:        IP_STR
                   7448:        BGP_STR
                   7449:        "Display flap statistics of routes\n"
                   7450:        "Display routes matching the route-map\n"
                   7451:        "A route-map to match on\n")
                   7452: {
                   7453:   return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
                   7454:                             bgp_show_type_flap_route_map);
                   7455: }
                   7456: 
                   7457: DEFUN (show_ip_bgp_ipv4_route_map, 
                   7458:        show_ip_bgp_ipv4_route_map_cmd,
                   7459:        "show ip bgp ipv4 (unicast|multicast) route-map WORD",
                   7460:        SHOW_STR
                   7461:        IP_STR
                   7462:        BGP_STR
                   7463:        "Address family\n"
                   7464:        "Address Family modifier\n"
                   7465:        "Address Family modifier\n"
                   7466:        "Display routes matching the route-map\n"
                   7467:        "A route-map to match on\n")
                   7468: {
                   7469:   if (strncmp (argv[0], "m", 1) == 0)
                   7470:     return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
                   7471:                               bgp_show_type_route_map);
                   7472: 
                   7473:   return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
                   7474:                             bgp_show_type_route_map);
                   7475: }
                   7476: 
                   7477: DEFUN (show_bgp_route_map, 
                   7478:        show_bgp_route_map_cmd,
                   7479:        "show bgp route-map WORD",
                   7480:        SHOW_STR
                   7481:        BGP_STR
                   7482:        "Display routes matching the route-map\n"
                   7483:        "A route-map to match on\n")
                   7484: {
                   7485:   return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
                   7486:                             bgp_show_type_route_map);
                   7487: }
                   7488: 
                   7489: ALIAS (show_bgp_route_map, 
                   7490:        show_bgp_ipv6_route_map_cmd,
                   7491:        "show bgp ipv6 route-map WORD",
                   7492:        SHOW_STR
                   7493:        BGP_STR
                   7494:        "Address family\n"
                   7495:        "Display routes matching the route-map\n"
                   7496:        "A route-map to match on\n")
                   7497: 
                   7498: DEFUN (show_ip_bgp_cidr_only,
                   7499:        show_ip_bgp_cidr_only_cmd,
                   7500:        "show ip bgp cidr-only",
                   7501:        SHOW_STR
                   7502:        IP_STR
                   7503:        BGP_STR
                   7504:        "Display only routes with non-natural netmasks\n")
                   7505: {
                   7506:     return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
                   7507:                     bgp_show_type_cidr_only, NULL);
                   7508: }
                   7509: 
                   7510: DEFUN (show_ip_bgp_flap_cidr_only,
                   7511:        show_ip_bgp_flap_cidr_only_cmd,
                   7512:        "show ip bgp flap-statistics cidr-only",
                   7513:        SHOW_STR
                   7514:        IP_STR
                   7515:        BGP_STR
                   7516:        "Display flap statistics of routes\n"
                   7517:        "Display only routes with non-natural netmasks\n")
                   7518: {
                   7519:   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
                   7520:                   bgp_show_type_flap_cidr_only, NULL);
                   7521: }
                   7522: 
                   7523: DEFUN (show_ip_bgp_ipv4_cidr_only,
                   7524:        show_ip_bgp_ipv4_cidr_only_cmd,
                   7525:        "show ip bgp ipv4 (unicast|multicast) cidr-only",
                   7526:        SHOW_STR
                   7527:        IP_STR
                   7528:        BGP_STR
                   7529:        "Address family\n"
                   7530:        "Address Family modifier\n"
                   7531:        "Address Family modifier\n"
                   7532:        "Display only routes with non-natural netmasks\n")
                   7533: {
                   7534:   if (strncmp (argv[0], "m", 1) == 0)
                   7535:     return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
                   7536:                     bgp_show_type_cidr_only, NULL);
                   7537: 
                   7538:   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
                   7539:                     bgp_show_type_cidr_only, NULL);
                   7540: }
                   7541: 
                   7542: DEFUN (show_ip_bgp_community_all,
                   7543:        show_ip_bgp_community_all_cmd,
                   7544:        "show ip bgp community",
                   7545:        SHOW_STR
                   7546:        IP_STR
                   7547:        BGP_STR
                   7548:        "Display routes matching the communities\n")
                   7549: {
                   7550:   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
                   7551:                     bgp_show_type_community_all, NULL);
                   7552: }
                   7553: 
                   7554: DEFUN (show_ip_bgp_ipv4_community_all,
                   7555:        show_ip_bgp_ipv4_community_all_cmd,
                   7556:        "show ip bgp ipv4 (unicast|multicast) community",
                   7557:        SHOW_STR
                   7558:        IP_STR
                   7559:        BGP_STR
                   7560:        "Address family\n"
                   7561:        "Address Family modifier\n"
                   7562:        "Address Family modifier\n"
                   7563:        "Display routes matching the communities\n")
                   7564: {
                   7565:   if (strncmp (argv[0], "m", 1) == 0)
                   7566:     return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
                   7567:                     bgp_show_type_community_all, NULL);
                   7568:  
                   7569:   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
                   7570:                   bgp_show_type_community_all, NULL);
                   7571: }
                   7572: 
                   7573: #ifdef HAVE_IPV6
                   7574: DEFUN (show_bgp_community_all,
                   7575:        show_bgp_community_all_cmd,
                   7576:        "show bgp community",
                   7577:        SHOW_STR
                   7578:        BGP_STR
                   7579:        "Display routes matching the communities\n")
                   7580: {
                   7581:   return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
                   7582:                   bgp_show_type_community_all, NULL);
                   7583: }
                   7584: 
                   7585: ALIAS (show_bgp_community_all,
                   7586:        show_bgp_ipv6_community_all_cmd,
                   7587:        "show bgp ipv6 community",
                   7588:        SHOW_STR
                   7589:        BGP_STR
                   7590:        "Address family\n"
                   7591:        "Display routes matching the communities\n")
                   7592: 
                   7593: /* old command */
                   7594: DEFUN (show_ipv6_bgp_community_all,
                   7595:        show_ipv6_bgp_community_all_cmd,
                   7596:        "show ipv6 bgp community",
                   7597:        SHOW_STR
                   7598:        IPV6_STR
                   7599:        BGP_STR
                   7600:        "Display routes matching the communities\n")
                   7601: {
                   7602:   return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
                   7603:                   bgp_show_type_community_all, NULL);
                   7604: }
                   7605: 
                   7606: /* old command */
                   7607: DEFUN (show_ipv6_mbgp_community_all,
                   7608:        show_ipv6_mbgp_community_all_cmd,
                   7609:        "show ipv6 mbgp community",
                   7610:        SHOW_STR
                   7611:        IPV6_STR
                   7612:        MBGP_STR
                   7613:        "Display routes matching the communities\n")
                   7614: {
                   7615:   return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
                   7616:                   bgp_show_type_community_all, NULL);
                   7617: }
                   7618: #endif /* HAVE_IPV6 */
                   7619: 
                   7620: static int
                   7621: bgp_show_community (struct vty *vty, const char *view_name, int argc,
                   7622:                    const char **argv, int exact, afi_t afi, safi_t safi)
                   7623: {
                   7624:   struct community *com;
                   7625:   struct buffer *b;
                   7626:   struct bgp *bgp;
                   7627:   int i;
                   7628:   char *str;
                   7629:   int first = 0;
                   7630: 
                   7631:   /* BGP structure lookup */
                   7632:   if (view_name)
                   7633:     {
                   7634:       bgp = bgp_lookup_by_name (view_name);
                   7635:       if (bgp == NULL)
                   7636:        {
                   7637:          vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
                   7638:          return CMD_WARNING;
                   7639:        }
                   7640:     }
                   7641:   else
                   7642:     {
                   7643:       bgp = bgp_get_default ();
                   7644:       if (bgp == NULL)
                   7645:        {
                   7646:          vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
                   7647:          return CMD_WARNING;
                   7648:        }
                   7649:     }
                   7650: 
                   7651:   b = buffer_new (1024);
                   7652:   for (i = 0; i < argc; i++)
                   7653:     {
                   7654:       if (first)
                   7655:         buffer_putc (b, ' ');
                   7656:       else
                   7657:        {
                   7658:          if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
                   7659:            continue;
                   7660:          first = 1;
                   7661:        }
                   7662:       
                   7663:       buffer_putstr (b, argv[i]);
                   7664:     }
                   7665:   buffer_putc (b, '\0');
                   7666: 
                   7667:   str = buffer_getstr (b);
                   7668:   buffer_free (b);
                   7669: 
                   7670:   com = community_str2com (str);
                   7671:   XFREE (MTYPE_TMP, str);
                   7672:   if (! com)
                   7673:     {
                   7674:       vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
                   7675:       return CMD_WARNING;
                   7676:     }
                   7677: 
                   7678:   return bgp_show (vty, bgp, afi, safi,
                   7679:                    (exact ? bgp_show_type_community_exact :
                   7680:                            bgp_show_type_community), com);
                   7681: }
                   7682: 
                   7683: DEFUN (show_ip_bgp_community,
                   7684:        show_ip_bgp_community_cmd,
                   7685:        "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
                   7686:        SHOW_STR
                   7687:        IP_STR
                   7688:        BGP_STR
                   7689:        "Display routes matching the communities\n"
                   7690:        "community number\n"
                   7691:        "Do not send outside local AS (well-known community)\n"
                   7692:        "Do not advertise to any peer (well-known community)\n"
                   7693:        "Do not export to next AS (well-known community)\n")
                   7694: {
                   7695:   return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
                   7696: }
                   7697: 
                   7698: ALIAS (show_ip_bgp_community,
                   7699:        show_ip_bgp_community2_cmd,
                   7700:        "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
                   7701:        SHOW_STR
                   7702:        IP_STR
                   7703:        BGP_STR
                   7704:        "Display routes matching the communities\n"
                   7705:        "community number\n"
                   7706:        "Do not send outside local AS (well-known community)\n"
                   7707:        "Do not advertise to any peer (well-known community)\n"
                   7708:        "Do not export to next AS (well-known community)\n"
                   7709:        "community number\n"
                   7710:        "Do not send outside local AS (well-known community)\n"
                   7711:        "Do not advertise to any peer (well-known community)\n"
                   7712:        "Do not export to next AS (well-known community)\n")
                   7713:        
                   7714: ALIAS (show_ip_bgp_community,
                   7715:        show_ip_bgp_community3_cmd,
                   7716:        "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)",
                   7717:        SHOW_STR
                   7718:        IP_STR
                   7719:        BGP_STR
                   7720:        "Display routes matching the communities\n"
                   7721:        "community number\n"
                   7722:        "Do not send outside local AS (well-known community)\n"
                   7723:        "Do not advertise to any peer (well-known community)\n"
                   7724:        "Do not export to next AS (well-known community)\n"
                   7725:        "community number\n"
                   7726:        "Do not send outside local AS (well-known community)\n"
                   7727:        "Do not advertise to any peer (well-known community)\n"
                   7728:        "Do not export to next AS (well-known community)\n"
                   7729:        "community number\n"
                   7730:        "Do not send outside local AS (well-known community)\n"
                   7731:        "Do not advertise to any peer (well-known community)\n"
                   7732:        "Do not export to next AS (well-known community)\n")
                   7733:        
                   7734: ALIAS (show_ip_bgp_community,
                   7735:        show_ip_bgp_community4_cmd,
                   7736:        "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)",
                   7737:        SHOW_STR
                   7738:        IP_STR
                   7739:        BGP_STR
                   7740:        "Display routes matching the communities\n"
                   7741:        "community number\n"
                   7742:        "Do not send outside local AS (well-known community)\n"
                   7743:        "Do not advertise to any peer (well-known community)\n"
                   7744:        "Do not export to next AS (well-known community)\n"
                   7745:        "community number\n"
                   7746:        "Do not send outside local AS (well-known community)\n"
                   7747:        "Do not advertise to any peer (well-known community)\n"
                   7748:        "Do not export to next AS (well-known community)\n"
                   7749:        "community number\n"
                   7750:        "Do not send outside local AS (well-known community)\n"
                   7751:        "Do not advertise to any peer (well-known community)\n"
                   7752:        "Do not export to next AS (well-known community)\n"
                   7753:        "community number\n"
                   7754:        "Do not send outside local AS (well-known community)\n"
                   7755:        "Do not advertise to any peer (well-known community)\n"
                   7756:        "Do not export to next AS (well-known community)\n")
                   7757: 
                   7758: DEFUN (show_ip_bgp_ipv4_community,
                   7759:        show_ip_bgp_ipv4_community_cmd,
                   7760:        "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
                   7761:        SHOW_STR
                   7762:        IP_STR
                   7763:        BGP_STR
                   7764:        "Address family\n"
                   7765:        "Address Family modifier\n"
                   7766:        "Address Family modifier\n"
                   7767:        "Display routes matching the communities\n"
                   7768:        "community number\n"
                   7769:        "Do not send outside local AS (well-known community)\n"
                   7770:        "Do not advertise to any peer (well-known community)\n"
                   7771:        "Do not export to next AS (well-known community)\n")
                   7772: {
                   7773:   if (strncmp (argv[0], "m", 1) == 0)
                   7774:     return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
                   7775:  
                   7776:   return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
                   7777: }
                   7778: 
                   7779: ALIAS (show_ip_bgp_ipv4_community,
                   7780:        show_ip_bgp_ipv4_community2_cmd,
                   7781:        "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
                   7782:        SHOW_STR
                   7783:        IP_STR
                   7784:        BGP_STR
                   7785:        "Address family\n"
                   7786:        "Address Family modifier\n"
                   7787:        "Address Family modifier\n"
                   7788:        "Display routes matching the communities\n"
                   7789:        "community number\n"
                   7790:        "Do not send outside local AS (well-known community)\n"
                   7791:        "Do not advertise to any peer (well-known community)\n"
                   7792:        "Do not export to next AS (well-known community)\n"
                   7793:        "community number\n"
                   7794:        "Do not send outside local AS (well-known community)\n"
                   7795:        "Do not advertise to any peer (well-known community)\n"
                   7796:        "Do not export to next AS (well-known community)\n")
                   7797:        
                   7798: ALIAS (show_ip_bgp_ipv4_community,
                   7799:        show_ip_bgp_ipv4_community3_cmd,
                   7800:        "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)",
                   7801:        SHOW_STR
                   7802:        IP_STR
                   7803:        BGP_STR
                   7804:        "Address family\n"
                   7805:        "Address Family modifier\n"
                   7806:        "Address Family modifier\n"
                   7807:        "Display routes matching the communities\n"
                   7808:        "community number\n"
                   7809:        "Do not send outside local AS (well-known community)\n"
                   7810:        "Do not advertise to any peer (well-known community)\n"
                   7811:        "Do not export to next AS (well-known community)\n"
                   7812:        "community number\n"
                   7813:        "Do not send outside local AS (well-known community)\n"
                   7814:        "Do not advertise to any peer (well-known community)\n"
                   7815:        "Do not export to next AS (well-known community)\n"
                   7816:        "community number\n"
                   7817:        "Do not send outside local AS (well-known community)\n"
                   7818:        "Do not advertise to any peer (well-known community)\n"
                   7819:        "Do not export to next AS (well-known community)\n")
                   7820:        
                   7821: ALIAS (show_ip_bgp_ipv4_community,
                   7822:        show_ip_bgp_ipv4_community4_cmd,
                   7823:        "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)",
                   7824:        SHOW_STR
                   7825:        IP_STR
                   7826:        BGP_STR
                   7827:        "Address family\n"
                   7828:        "Address Family modifier\n"
                   7829:        "Address Family modifier\n"
                   7830:        "Display routes matching the communities\n"
                   7831:        "community number\n"
                   7832:        "Do not send outside local AS (well-known community)\n"
                   7833:        "Do not advertise to any peer (well-known community)\n"
                   7834:        "Do not export to next AS (well-known community)\n"
                   7835:        "community number\n"
                   7836:        "Do not send outside local AS (well-known community)\n"
                   7837:        "Do not advertise to any peer (well-known community)\n"
                   7838:        "Do not export to next AS (well-known community)\n"
                   7839:        "community number\n"
                   7840:        "Do not send outside local AS (well-known community)\n"
                   7841:        "Do not advertise to any peer (well-known community)\n"
                   7842:        "Do not export to next AS (well-known community)\n"
                   7843:        "community number\n"
                   7844:        "Do not send outside local AS (well-known community)\n"
                   7845:        "Do not advertise to any peer (well-known community)\n"
                   7846:        "Do not export to next AS (well-known community)\n")
                   7847: 
                   7848: DEFUN (show_bgp_view_afi_safi_community_all,
                   7849:        show_bgp_view_afi_safi_community_all_cmd,
                   7850: #ifdef HAVE_IPV6
                   7851:        "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
                   7852: #else
                   7853:        "show bgp view WORD ipv4 (unicast|multicast) community",
                   7854: #endif
                   7855:        SHOW_STR
                   7856:        BGP_STR
                   7857:        "BGP view\n"
                   7858:        "BGP view name\n"
                   7859:        "Address family\n"
                   7860: #ifdef HAVE_IPV6
                   7861:        "Address family\n"
                   7862: #endif
                   7863:        "Address Family modifier\n"
                   7864:        "Address Family modifier\n"
                   7865:        "Display routes containing communities\n")
                   7866: {
                   7867:   int afi;
                   7868:   int safi;
                   7869:   struct bgp *bgp;
                   7870: 
                   7871:   /* BGP structure lookup. */
                   7872:   bgp = bgp_lookup_by_name (argv[0]);
                   7873:   if (bgp == NULL)
                   7874:     {
                   7875:       vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
                   7876:       return CMD_WARNING;
                   7877:     }
                   7878: 
                   7879: #ifdef HAVE_IPV6
                   7880:   afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
                   7881:   safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   7882: #else
                   7883:   afi = AFI_IP;
                   7884:   safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   7885: #endif
                   7886:   return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
                   7887: }
                   7888: 
                   7889: DEFUN (show_bgp_view_afi_safi_community,
                   7890:        show_bgp_view_afi_safi_community_cmd,
                   7891: #ifdef HAVE_IPV6
                   7892:        "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
                   7893: #else
                   7894:        "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
                   7895: #endif
                   7896:        SHOW_STR
                   7897:        BGP_STR
                   7898:        "BGP view\n"
                   7899:        "BGP view name\n"
                   7900:        "Address family\n"
                   7901: #ifdef HAVE_IPV6
                   7902:        "Address family\n"
                   7903: #endif
                   7904:        "Address family modifier\n"
                   7905:        "Address family modifier\n"
                   7906:        "Display routes matching the communities\n"
                   7907:        "community number\n"
                   7908:        "Do not send outside local AS (well-known community)\n"
                   7909:        "Do not advertise to any peer (well-known community)\n"
                   7910:        "Do not export to next AS (well-known community)\n")
                   7911: {
                   7912:   int afi;
                   7913:   int safi;
                   7914: 
                   7915: #ifdef HAVE_IPV6
                   7916:   afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
                   7917:   safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   7918:   return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
                   7919: #else
                   7920:   afi = AFI_IP;
                   7921:   safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   7922:   return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
                   7923: #endif
                   7924: }
                   7925: 
                   7926: ALIAS (show_bgp_view_afi_safi_community,
                   7927:        show_bgp_view_afi_safi_community2_cmd,
                   7928: #ifdef HAVE_IPV6
                   7929:        "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
                   7930: #else
                   7931:        "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
                   7932: #endif
                   7933:        SHOW_STR
                   7934:        BGP_STR
                   7935:        "BGP view\n"
                   7936:        "BGP view name\n"
                   7937:        "Address family\n"
                   7938: #ifdef HAVE_IPV6
                   7939:        "Address family\n"
                   7940: #endif
                   7941:        "Address family modifier\n"
                   7942:        "Address family modifier\n"
                   7943:        "Display routes matching the communities\n"
                   7944:        "community number\n"
                   7945:        "Do not send outside local AS (well-known community)\n"
                   7946:        "Do not advertise to any peer (well-known community)\n"
                   7947:        "Do not export to next AS (well-known community)\n"
                   7948:        "community number\n"
                   7949:        "Do not send outside local AS (well-known community)\n"
                   7950:        "Do not advertise to any peer (well-known community)\n"
                   7951:        "Do not export to next AS (well-known community)\n")
                   7952: 
                   7953: ALIAS (show_bgp_view_afi_safi_community,
                   7954:        show_bgp_view_afi_safi_community3_cmd,
                   7955: #ifdef HAVE_IPV6
                   7956:        "show bgp view WORD (ipv4|ipv6) (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)",
                   7957: #else
                   7958:        "show bgp view WORD 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)",
                   7959: #endif
                   7960:        SHOW_STR
                   7961:        BGP_STR
                   7962:        "BGP view\n"
                   7963:        "BGP view name\n"
                   7964:        "Address family\n"
                   7965: #ifdef HAVE_IPV6
                   7966:        "Address family\n"
                   7967: #endif
                   7968:        "Address family modifier\n"
                   7969:        "Address family modifier\n"
                   7970:        "Display routes matching the communities\n"
                   7971:        "community number\n"
                   7972:        "Do not send outside local AS (well-known community)\n"
                   7973:        "Do not advertise to any peer (well-known community)\n"
                   7974:        "Do not export to next AS (well-known community)\n"
                   7975:        "community number\n"
                   7976:        "Do not send outside local AS (well-known community)\n"
                   7977:        "Do not advertise to any peer (well-known community)\n"
                   7978:        "Do not export to next AS (well-known community)\n"
                   7979:        "community number\n"
                   7980:        "Do not send outside local AS (well-known community)\n"
                   7981:        "Do not advertise to any peer (well-known community)\n"
                   7982:        "Do not export to next AS (well-known community)\n")
                   7983: 
                   7984: ALIAS (show_bgp_view_afi_safi_community,
                   7985:        show_bgp_view_afi_safi_community4_cmd,
                   7986: #ifdef HAVE_IPV6
                   7987:        "show bgp view WORD (ipv4|ipv6) (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)",
                   7988: #else
                   7989:        "show bgp view WORD 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)",
                   7990: #endif
                   7991:        SHOW_STR
                   7992:        BGP_STR
                   7993:        "BGP view\n"
                   7994:        "BGP view name\n"
                   7995:        "Address family\n"
                   7996: #ifdef HAVE_IPV6
                   7997:        "Address family\n"
                   7998: #endif
                   7999:        "Address family modifier\n"
                   8000:        "Address family modifier\n"
                   8001:        "Display routes matching the communities\n"
                   8002:        "community number\n"
                   8003:        "Do not send outside local AS (well-known community)\n"
                   8004:        "Do not advertise to any peer (well-known community)\n"
                   8005:        "Do not export to next AS (well-known community)\n"
                   8006:        "community number\n"
                   8007:        "Do not send outside local AS (well-known community)\n"
                   8008:        "Do not advertise to any peer (well-known community)\n"
                   8009:        "Do not export to next AS (well-known community)\n"
                   8010:        "community number\n"
                   8011:        "Do not send outside local AS (well-known community)\n"
                   8012:        "Do not advertise to any peer (well-known community)\n"
                   8013:        "Do not export to next AS (well-known community)\n"
                   8014:        "community number\n"
                   8015:        "Do not send outside local AS (well-known community)\n"
                   8016:        "Do not advertise to any peer (well-known community)\n"
                   8017:        "Do not export to next AS (well-known community)\n")
                   8018: 
                   8019: DEFUN (show_ip_bgp_community_exact,
                   8020:        show_ip_bgp_community_exact_cmd,
                   8021:        "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
                   8022:        SHOW_STR
                   8023:        IP_STR
                   8024:        BGP_STR
                   8025:        "Display routes matching the communities\n"
                   8026:        "community number\n"
                   8027:        "Do not send outside local AS (well-known community)\n"
                   8028:        "Do not advertise to any peer (well-known community)\n"
                   8029:        "Do not export to next AS (well-known community)\n"
                   8030:        "Exact match of the communities")
                   8031: {
                   8032:   return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
                   8033: }
                   8034: 
                   8035: ALIAS (show_ip_bgp_community_exact,
                   8036:        show_ip_bgp_community2_exact_cmd,
                   8037:        "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
                   8038:        SHOW_STR
                   8039:        IP_STR
                   8040:        BGP_STR
                   8041:        "Display routes matching the communities\n"
                   8042:        "community number\n"
                   8043:        "Do not send outside local AS (well-known community)\n"
                   8044:        "Do not advertise to any peer (well-known community)\n"
                   8045:        "Do not export to next AS (well-known community)\n"
                   8046:        "community number\n"
                   8047:        "Do not send outside local AS (well-known community)\n"
                   8048:        "Do not advertise to any peer (well-known community)\n"
                   8049:        "Do not export to next AS (well-known community)\n"
                   8050:        "Exact match of the communities")
                   8051: 
                   8052: ALIAS (show_ip_bgp_community_exact,
                   8053:        show_ip_bgp_community3_exact_cmd,
                   8054:        "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",
                   8055:        SHOW_STR
                   8056:        IP_STR
                   8057:        BGP_STR
                   8058:        "Display routes matching the communities\n"
                   8059:        "community number\n"
                   8060:        "Do not send outside local AS (well-known community)\n"
                   8061:        "Do not advertise to any peer (well-known community)\n"
                   8062:        "Do not export to next AS (well-known community)\n"
                   8063:        "community number\n"
                   8064:        "Do not send outside local AS (well-known community)\n"
                   8065:        "Do not advertise to any peer (well-known community)\n"
                   8066:        "Do not export to next AS (well-known community)\n"
                   8067:        "community number\n"
                   8068:        "Do not send outside local AS (well-known community)\n"
                   8069:        "Do not advertise to any peer (well-known community)\n"
                   8070:        "Do not export to next AS (well-known community)\n"
                   8071:        "Exact match of the communities")
                   8072: 
                   8073: ALIAS (show_ip_bgp_community_exact,
                   8074:        show_ip_bgp_community4_exact_cmd,
                   8075:        "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",
                   8076:        SHOW_STR
                   8077:        IP_STR
                   8078:        BGP_STR
                   8079:        "Display routes matching the communities\n"
                   8080:        "community number\n"
                   8081:        "Do not send outside local AS (well-known community)\n"
                   8082:        "Do not advertise to any peer (well-known community)\n"
                   8083:        "Do not export to next AS (well-known community)\n"
                   8084:        "community number\n"
                   8085:        "Do not send outside local AS (well-known community)\n"
                   8086:        "Do not advertise to any peer (well-known community)\n"
                   8087:        "Do not export to next AS (well-known community)\n"
                   8088:        "community number\n"
                   8089:        "Do not send outside local AS (well-known community)\n"
                   8090:        "Do not advertise to any peer (well-known community)\n"
                   8091:        "Do not export to next AS (well-known community)\n"
                   8092:        "community number\n"
                   8093:        "Do not send outside local AS (well-known community)\n"
                   8094:        "Do not advertise to any peer (well-known community)\n"
                   8095:        "Do not export to next AS (well-known community)\n"
                   8096:        "Exact match of the communities")
                   8097: 
                   8098: DEFUN (show_ip_bgp_ipv4_community_exact,
                   8099:        show_ip_bgp_ipv4_community_exact_cmd,
                   8100:        "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
                   8101:        SHOW_STR
                   8102:        IP_STR
                   8103:        BGP_STR
                   8104:        "Address family\n"
                   8105:        "Address Family modifier\n"
                   8106:        "Address Family modifier\n"
                   8107:        "Display routes matching the communities\n"
                   8108:        "community number\n"
                   8109:        "Do not send outside local AS (well-known community)\n"
                   8110:        "Do not advertise to any peer (well-known community)\n"
                   8111:        "Do not export to next AS (well-known community)\n"
                   8112:        "Exact match of the communities")
                   8113: {
                   8114:   if (strncmp (argv[0], "m", 1) == 0)
                   8115:     return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
                   8116:  
                   8117:   return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
                   8118: }
                   8119: 
                   8120: ALIAS (show_ip_bgp_ipv4_community_exact,
                   8121:        show_ip_bgp_ipv4_community2_exact_cmd,
                   8122:        "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",
                   8123:        SHOW_STR
                   8124:        IP_STR
                   8125:        BGP_STR
                   8126:        "Address family\n"
                   8127:        "Address Family modifier\n"
                   8128:        "Address Family modifier\n"
                   8129:        "Display routes matching the communities\n"
                   8130:        "community number\n"
                   8131:        "Do not send outside local AS (well-known community)\n"
                   8132:        "Do not advertise to any peer (well-known community)\n"
                   8133:        "Do not export to next AS (well-known community)\n"
                   8134:        "community number\n"
                   8135:        "Do not send outside local AS (well-known community)\n"
                   8136:        "Do not advertise to any peer (well-known community)\n"
                   8137:        "Do not export to next AS (well-known community)\n"
                   8138:        "Exact match of the communities")
                   8139: 
                   8140: ALIAS (show_ip_bgp_ipv4_community_exact,
                   8141:        show_ip_bgp_ipv4_community3_exact_cmd,
                   8142:        "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",
                   8143:        SHOW_STR
                   8144:        IP_STR
                   8145:        BGP_STR
                   8146:        "Address family\n"
                   8147:        "Address Family modifier\n"
                   8148:        "Address Family modifier\n"
                   8149:        "Display routes matching the communities\n"
                   8150:        "community number\n"
                   8151:        "Do not send outside local AS (well-known community)\n"
                   8152:        "Do not advertise to any peer (well-known community)\n"
                   8153:        "Do not export to next AS (well-known community)\n"
                   8154:        "community number\n"
                   8155:        "Do not send outside local AS (well-known community)\n"
                   8156:        "Do not advertise to any peer (well-known community)\n"
                   8157:        "Do not export to next AS (well-known community)\n"
                   8158:        "community number\n"
                   8159:        "Do not send outside local AS (well-known community)\n"
                   8160:        "Do not advertise to any peer (well-known community)\n"
                   8161:        "Do not export to next AS (well-known community)\n"
                   8162:        "Exact match of the communities")
                   8163:        
                   8164: ALIAS (show_ip_bgp_ipv4_community_exact,
                   8165:        show_ip_bgp_ipv4_community4_exact_cmd,
                   8166:        "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",
                   8167:        SHOW_STR
                   8168:        IP_STR
                   8169:        BGP_STR
                   8170:        "Address family\n"
                   8171:        "Address Family modifier\n"
                   8172:        "Address Family modifier\n"
                   8173:        "Display routes matching the communities\n"
                   8174:        "community number\n"
                   8175:        "Do not send outside local AS (well-known community)\n"
                   8176:        "Do not advertise to any peer (well-known community)\n"
                   8177:        "Do not export to next AS (well-known community)\n"
                   8178:        "community number\n"
                   8179:        "Do not send outside local AS (well-known community)\n"
                   8180:        "Do not advertise to any peer (well-known community)\n"
                   8181:        "Do not export to next AS (well-known community)\n"
                   8182:        "community number\n"
                   8183:        "Do not send outside local AS (well-known community)\n"
                   8184:        "Do not advertise to any peer (well-known community)\n"
                   8185:        "Do not export to next AS (well-known community)\n"
                   8186:        "community number\n"
                   8187:        "Do not send outside local AS (well-known community)\n"
                   8188:        "Do not advertise to any peer (well-known community)\n"
                   8189:        "Do not export to next AS (well-known community)\n"
                   8190:        "Exact match of the communities")
                   8191: 
                   8192: #ifdef HAVE_IPV6
                   8193: DEFUN (show_bgp_community,
                   8194:        show_bgp_community_cmd,
                   8195:        "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
                   8196:        SHOW_STR
                   8197:        BGP_STR
                   8198:        "Display routes matching the communities\n"
                   8199:        "community number\n"
                   8200:        "Do not send outside local AS (well-known community)\n"
                   8201:        "Do not advertise to any peer (well-known community)\n"
                   8202:        "Do not export to next AS (well-known community)\n")
                   8203: {
                   8204:   return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
                   8205: }
                   8206: 
                   8207: ALIAS (show_bgp_community,
                   8208:        show_bgp_ipv6_community_cmd,
                   8209:        "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
                   8210:        SHOW_STR
                   8211:        BGP_STR
                   8212:        "Address family\n"
                   8213:        "Display routes matching the communities\n"
                   8214:        "community number\n"
                   8215:        "Do not send outside local AS (well-known community)\n"
                   8216:        "Do not advertise to any peer (well-known community)\n"
                   8217:        "Do not export to next AS (well-known community)\n")
                   8218: 
                   8219: ALIAS (show_bgp_community,
                   8220:        show_bgp_community2_cmd,
                   8221:        "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
                   8222:        SHOW_STR
                   8223:        BGP_STR
                   8224:        "Display routes matching the communities\n"
                   8225:        "community number\n"
                   8226:        "Do not send outside local AS (well-known community)\n"
                   8227:        "Do not advertise to any peer (well-known community)\n"
                   8228:        "Do not export to next AS (well-known community)\n"
                   8229:        "community number\n"
                   8230:        "Do not send outside local AS (well-known community)\n"
                   8231:        "Do not advertise to any peer (well-known community)\n"
                   8232:        "Do not export to next AS (well-known community)\n")
                   8233: 
                   8234: ALIAS (show_bgp_community,
                   8235:        show_bgp_ipv6_community2_cmd,
                   8236:        "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
                   8237:        SHOW_STR
                   8238:        BGP_STR
                   8239:        "Address family\n"
                   8240:        "Display routes matching the communities\n"
                   8241:        "community number\n"
                   8242:        "Do not send outside local AS (well-known community)\n"
                   8243:        "Do not advertise to any peer (well-known community)\n"
                   8244:        "Do not export to next AS (well-known community)\n"
                   8245:        "community number\n"
                   8246:        "Do not send outside local AS (well-known community)\n"
                   8247:        "Do not advertise to any peer (well-known community)\n"
                   8248:        "Do not export to next AS (well-known community)\n")
                   8249:        
                   8250: ALIAS (show_bgp_community,
                   8251:        show_bgp_community3_cmd,
                   8252:        "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)",
                   8253:        SHOW_STR
                   8254:        BGP_STR
                   8255:        "Display routes matching the communities\n"
                   8256:        "community number\n"
                   8257:        "Do not send outside local AS (well-known community)\n"
                   8258:        "Do not advertise to any peer (well-known community)\n"
                   8259:        "Do not export to next AS (well-known community)\n"
                   8260:        "community number\n"
                   8261:        "Do not send outside local AS (well-known community)\n"
                   8262:        "Do not advertise to any peer (well-known community)\n"
                   8263:        "Do not export to next AS (well-known community)\n"
                   8264:        "community number\n"
                   8265:        "Do not send outside local AS (well-known community)\n"
                   8266:        "Do not advertise to any peer (well-known community)\n"
                   8267:        "Do not export to next AS (well-known community)\n")
                   8268: 
                   8269: ALIAS (show_bgp_community,
                   8270:        show_bgp_ipv6_community3_cmd,
                   8271:        "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)",
                   8272:        SHOW_STR
                   8273:        BGP_STR
                   8274:        "Address family\n"
                   8275:        "Display routes matching the communities\n"
                   8276:        "community number\n"
                   8277:        "Do not send outside local AS (well-known community)\n"
                   8278:        "Do not advertise to any peer (well-known community)\n"
                   8279:        "Do not export to next AS (well-known community)\n"
                   8280:        "community number\n"
                   8281:        "Do not send outside local AS (well-known community)\n"
                   8282:        "Do not advertise to any peer (well-known community)\n"
                   8283:        "Do not export to next AS (well-known community)\n"
                   8284:        "community number\n"
                   8285:        "Do not send outside local AS (well-known community)\n"
                   8286:        "Do not advertise to any peer (well-known community)\n"
                   8287:        "Do not export to next AS (well-known community)\n")
                   8288: 
                   8289: ALIAS (show_bgp_community,
                   8290:        show_bgp_community4_cmd,
                   8291:        "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)",
                   8292:        SHOW_STR
                   8293:        BGP_STR
                   8294:        "Display routes matching the communities\n"
                   8295:        "community number\n"
                   8296:        "Do not send outside local AS (well-known community)\n"
                   8297:        "Do not advertise to any peer (well-known community)\n"
                   8298:        "Do not export to next AS (well-known community)\n"
                   8299:        "community number\n"
                   8300:        "Do not send outside local AS (well-known community)\n"
                   8301:        "Do not advertise to any peer (well-known community)\n"
                   8302:        "Do not export to next AS (well-known community)\n"
                   8303:        "community number\n"
                   8304:        "Do not send outside local AS (well-known community)\n"
                   8305:        "Do not advertise to any peer (well-known community)\n"
                   8306:        "Do not export to next AS (well-known community)\n"
                   8307:        "community number\n"
                   8308:        "Do not send outside local AS (well-known community)\n"
                   8309:        "Do not advertise to any peer (well-known community)\n"
                   8310:        "Do not export to next AS (well-known community)\n")
                   8311: 
                   8312: ALIAS (show_bgp_community,
                   8313:        show_bgp_ipv6_community4_cmd,
                   8314:        "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)",
                   8315:        SHOW_STR
                   8316:        BGP_STR
                   8317:        "Address family\n"
                   8318:        "Display routes matching the communities\n"
                   8319:        "community number\n"
                   8320:        "Do not send outside local AS (well-known community)\n"
                   8321:        "Do not advertise to any peer (well-known community)\n"
                   8322:        "Do not export to next AS (well-known community)\n"
                   8323:        "community number\n"
                   8324:        "Do not send outside local AS (well-known community)\n"
                   8325:        "Do not advertise to any peer (well-known community)\n"
                   8326:        "Do not export to next AS (well-known community)\n"
                   8327:        "community number\n"
                   8328:        "Do not send outside local AS (well-known community)\n"
                   8329:        "Do not advertise to any peer (well-known community)\n"
                   8330:        "Do not export to next AS (well-known community)\n"
                   8331:        "community number\n"
                   8332:        "Do not send outside local AS (well-known community)\n"
                   8333:        "Do not advertise to any peer (well-known community)\n"
                   8334:        "Do not export to next AS (well-known community)\n")
                   8335: 
                   8336: /* old command */
                   8337: DEFUN (show_ipv6_bgp_community,
                   8338:        show_ipv6_bgp_community_cmd,
                   8339:        "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
                   8340:        SHOW_STR
                   8341:        IPV6_STR
                   8342:        BGP_STR
                   8343:        "Display routes matching the communities\n"
                   8344:        "community number\n"
                   8345:        "Do not send outside local AS (well-known community)\n"
                   8346:        "Do not advertise to any peer (well-known community)\n"
                   8347:        "Do not export to next AS (well-known community)\n")
                   8348: {
                   8349:   return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
                   8350: }
                   8351: 
                   8352: /* old command */
                   8353: ALIAS (show_ipv6_bgp_community,
                   8354:        show_ipv6_bgp_community2_cmd,
                   8355:        "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
                   8356:        SHOW_STR
                   8357:        IPV6_STR
                   8358:        BGP_STR
                   8359:        "Display routes matching the communities\n"
                   8360:        "community number\n"
                   8361:        "Do not send outside local AS (well-known community)\n"
                   8362:        "Do not advertise to any peer (well-known community)\n"
                   8363:        "Do not export to next AS (well-known community)\n"
                   8364:        "community number\n"
                   8365:        "Do not send outside local AS (well-known community)\n"
                   8366:        "Do not advertise to any peer (well-known community)\n"
                   8367:        "Do not export to next AS (well-known community)\n")
                   8368: 
                   8369: /* old command */
                   8370: ALIAS (show_ipv6_bgp_community,
                   8371:        show_ipv6_bgp_community3_cmd,
                   8372:        "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)",
                   8373:        SHOW_STR
                   8374:        IPV6_STR
                   8375:        BGP_STR
                   8376:        "Display routes matching the communities\n"
                   8377:        "community number\n"
                   8378:        "Do not send outside local AS (well-known community)\n"
                   8379:        "Do not advertise to any peer (well-known community)\n"
                   8380:        "Do not export to next AS (well-known community)\n"
                   8381:        "community number\n"
                   8382:        "Do not send outside local AS (well-known community)\n"
                   8383:        "Do not advertise to any peer (well-known community)\n"
                   8384:        "Do not export to next AS (well-known community)\n"
                   8385:        "community number\n"
                   8386:        "Do not send outside local AS (well-known community)\n"
                   8387:        "Do not advertise to any peer (well-known community)\n"
                   8388:        "Do not export to next AS (well-known community)\n")
                   8389: 
                   8390: /* old command */
                   8391: ALIAS (show_ipv6_bgp_community,
                   8392:        show_ipv6_bgp_community4_cmd,
                   8393:        "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)",
                   8394:        SHOW_STR
                   8395:        IPV6_STR
                   8396:        BGP_STR
                   8397:        "Display routes matching the communities\n"
                   8398:        "community number\n"
                   8399:        "Do not send outside local AS (well-known community)\n"
                   8400:        "Do not advertise to any peer (well-known community)\n"
                   8401:        "Do not export to next AS (well-known community)\n"
                   8402:        "community number\n"
                   8403:        "Do not send outside local AS (well-known community)\n"
                   8404:        "Do not advertise to any peer (well-known community)\n"
                   8405:        "Do not export to next AS (well-known community)\n"
                   8406:        "community number\n"
                   8407:        "Do not send outside local AS (well-known community)\n"
                   8408:        "Do not advertise to any peer (well-known community)\n"
                   8409:        "Do not export to next AS (well-known community)\n"
                   8410:        "community number\n"
                   8411:        "Do not send outside local AS (well-known community)\n"
                   8412:        "Do not advertise to any peer (well-known community)\n"
                   8413:        "Do not export to next AS (well-known community)\n")
                   8414: 
                   8415: DEFUN (show_bgp_community_exact,
                   8416:        show_bgp_community_exact_cmd,
                   8417:        "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
                   8418:        SHOW_STR
                   8419:        BGP_STR
                   8420:        "Display routes matching the communities\n"
                   8421:        "community number\n"
                   8422:        "Do not send outside local AS (well-known community)\n"
                   8423:        "Do not advertise to any peer (well-known community)\n"
                   8424:        "Do not export to next AS (well-known community)\n"
                   8425:        "Exact match of the communities")
                   8426: {
                   8427:   return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
                   8428: }
                   8429: 
                   8430: ALIAS (show_bgp_community_exact,
                   8431:        show_bgp_ipv6_community_exact_cmd,
                   8432:        "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
                   8433:        SHOW_STR
                   8434:        BGP_STR
                   8435:        "Address family\n"
                   8436:        "Display routes matching the communities\n"
                   8437:        "community number\n"
                   8438:        "Do not send outside local AS (well-known community)\n"
                   8439:        "Do not advertise to any peer (well-known community)\n"
                   8440:        "Do not export to next AS (well-known community)\n"
                   8441:        "Exact match of the communities")
                   8442: 
                   8443: ALIAS (show_bgp_community_exact,
                   8444:        show_bgp_community2_exact_cmd,
                   8445:        "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
                   8446:        SHOW_STR
                   8447:        BGP_STR
                   8448:        "Display routes matching the communities\n"
                   8449:        "community number\n"
                   8450:        "Do not send outside local AS (well-known community)\n"
                   8451:        "Do not advertise to any peer (well-known community)\n"
                   8452:        "Do not export to next AS (well-known community)\n"
                   8453:        "community number\n"
                   8454:        "Do not send outside local AS (well-known community)\n"
                   8455:        "Do not advertise to any peer (well-known community)\n"
                   8456:        "Do not export to next AS (well-known community)\n"
                   8457:        "Exact match of the communities")
                   8458: 
                   8459: ALIAS (show_bgp_community_exact,
                   8460:        show_bgp_ipv6_community2_exact_cmd,
                   8461:        "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
                   8462:        SHOW_STR
                   8463:        BGP_STR
                   8464:        "Address family\n"
                   8465:        "Display routes matching the communities\n"
                   8466:        "community number\n"
                   8467:        "Do not send outside local AS (well-known community)\n"
                   8468:        "Do not advertise to any peer (well-known community)\n"
                   8469:        "Do not export to next AS (well-known community)\n"
                   8470:        "community number\n"
                   8471:        "Do not send outside local AS (well-known community)\n"
                   8472:        "Do not advertise to any peer (well-known community)\n"
                   8473:        "Do not export to next AS (well-known community)\n"
                   8474:        "Exact match of the communities")
                   8475: 
                   8476: ALIAS (show_bgp_community_exact,
                   8477:        show_bgp_community3_exact_cmd,
                   8478:        "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",
                   8479:        SHOW_STR
                   8480:        BGP_STR
                   8481:        "Display routes matching the communities\n"
                   8482:        "community number\n"
                   8483:        "Do not send outside local AS (well-known community)\n"
                   8484:        "Do not advertise to any peer (well-known community)\n"
                   8485:        "Do not export to next AS (well-known community)\n"
                   8486:        "community number\n"
                   8487:        "Do not send outside local AS (well-known community)\n"
                   8488:        "Do not advertise to any peer (well-known community)\n"
                   8489:        "Do not export to next AS (well-known community)\n"
                   8490:        "community number\n"
                   8491:        "Do not send outside local AS (well-known community)\n"
                   8492:        "Do not advertise to any peer (well-known community)\n"
                   8493:        "Do not export to next AS (well-known community)\n"
                   8494:        "Exact match of the communities")
                   8495: 
                   8496: ALIAS (show_bgp_community_exact,
                   8497:        show_bgp_ipv6_community3_exact_cmd,
                   8498:        "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",
                   8499:        SHOW_STR
                   8500:        BGP_STR
                   8501:        "Address family\n"
                   8502:        "Display routes matching the communities\n"
                   8503:        "community number\n"
                   8504:        "Do not send outside local AS (well-known community)\n"
                   8505:        "Do not advertise to any peer (well-known community)\n"
                   8506:        "Do not export to next AS (well-known community)\n"
                   8507:        "community number\n"
                   8508:        "Do not send outside local AS (well-known community)\n"
                   8509:        "Do not advertise to any peer (well-known community)\n"
                   8510:        "Do not export to next AS (well-known community)\n"
                   8511:        "community number\n"
                   8512:        "Do not send outside local AS (well-known community)\n"
                   8513:        "Do not advertise to any peer (well-known community)\n"
                   8514:        "Do not export to next AS (well-known community)\n"
                   8515:        "Exact match of the communities")
                   8516: 
                   8517: ALIAS (show_bgp_community_exact,
                   8518:        show_bgp_community4_exact_cmd,
                   8519:        "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",
                   8520:        SHOW_STR
                   8521:        BGP_STR
                   8522:        "Display routes matching the communities\n"
                   8523:        "community number\n"
                   8524:        "Do not send outside local AS (well-known community)\n"
                   8525:        "Do not advertise to any peer (well-known community)\n"
                   8526:        "Do not export to next AS (well-known community)\n"
                   8527:        "community number\n"
                   8528:        "Do not send outside local AS (well-known community)\n"
                   8529:        "Do not advertise to any peer (well-known community)\n"
                   8530:        "Do not export to next AS (well-known community)\n"
                   8531:        "community number\n"
                   8532:        "Do not send outside local AS (well-known community)\n"
                   8533:        "Do not advertise to any peer (well-known community)\n"
                   8534:        "Do not export to next AS (well-known community)\n"
                   8535:        "community number\n"
                   8536:        "Do not send outside local AS (well-known community)\n"
                   8537:        "Do not advertise to any peer (well-known community)\n"
                   8538:        "Do not export to next AS (well-known community)\n"
                   8539:        "Exact match of the communities")
                   8540:  
                   8541: ALIAS (show_bgp_community_exact,
                   8542:        show_bgp_ipv6_community4_exact_cmd,
                   8543:        "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",
                   8544:        SHOW_STR
                   8545:        BGP_STR
                   8546:        "Address family\n"
                   8547:        "Display routes matching the communities\n"
                   8548:        "community number\n"
                   8549:        "Do not send outside local AS (well-known community)\n"
                   8550:        "Do not advertise to any peer (well-known community)\n"
                   8551:        "Do not export to next AS (well-known community)\n"
                   8552:        "community number\n"
                   8553:        "Do not send outside local AS (well-known community)\n"
                   8554:        "Do not advertise to any peer (well-known community)\n"
                   8555:        "Do not export to next AS (well-known community)\n"
                   8556:        "community number\n"
                   8557:        "Do not send outside local AS (well-known community)\n"
                   8558:        "Do not advertise to any peer (well-known community)\n"
                   8559:        "Do not export to next AS (well-known community)\n"
                   8560:        "community number\n"
                   8561:        "Do not send outside local AS (well-known community)\n"
                   8562:        "Do not advertise to any peer (well-known community)\n"
                   8563:        "Do not export to next AS (well-known community)\n"
                   8564:        "Exact match of the communities")
                   8565: 
                   8566: /* old command */
                   8567: DEFUN (show_ipv6_bgp_community_exact,
                   8568:        show_ipv6_bgp_community_exact_cmd,
                   8569:        "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
                   8570:        SHOW_STR
                   8571:        IPV6_STR
                   8572:        BGP_STR
                   8573:        "Display routes matching the communities\n"
                   8574:        "community number\n"
                   8575:        "Do not send outside local AS (well-known community)\n"
                   8576:        "Do not advertise to any peer (well-known community)\n"
                   8577:        "Do not export to next AS (well-known community)\n"
                   8578:        "Exact match of the communities")
                   8579: {
                   8580:   return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
                   8581: }
                   8582: 
                   8583: /* old command */
                   8584: ALIAS (show_ipv6_bgp_community_exact,
                   8585:        show_ipv6_bgp_community2_exact_cmd,
                   8586:        "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
                   8587:        SHOW_STR
                   8588:        IPV6_STR
                   8589:        BGP_STR
                   8590:        "Display routes matching the communities\n"
                   8591:        "community number\n"
                   8592:        "Do not send outside local AS (well-known community)\n"
                   8593:        "Do not advertise to any peer (well-known community)\n"
                   8594:        "Do not export to next AS (well-known community)\n"
                   8595:        "community number\n"
                   8596:        "Do not send outside local AS (well-known community)\n"
                   8597:        "Do not advertise to any peer (well-known community)\n"
                   8598:        "Do not export to next AS (well-known community)\n"
                   8599:        "Exact match of the communities")
                   8600: 
                   8601: /* old command */
                   8602: ALIAS (show_ipv6_bgp_community_exact,
                   8603:        show_ipv6_bgp_community3_exact_cmd,
                   8604:        "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",
                   8605:        SHOW_STR
                   8606:        IPV6_STR
                   8607:        BGP_STR
                   8608:        "Display routes matching the communities\n"
                   8609:        "community number\n"
                   8610:        "Do not send outside local AS (well-known community)\n"
                   8611:        "Do not advertise to any peer (well-known community)\n"
                   8612:        "Do not export to next AS (well-known community)\n"
                   8613:        "community number\n"
                   8614:        "Do not send outside local AS (well-known community)\n"
                   8615:        "Do not advertise to any peer (well-known community)\n"
                   8616:        "Do not export to next AS (well-known community)\n"
                   8617:        "community number\n"
                   8618:        "Do not send outside local AS (well-known community)\n"
                   8619:        "Do not advertise to any peer (well-known community)\n"
                   8620:        "Do not export to next AS (well-known community)\n"
                   8621:        "Exact match of the communities")
                   8622: 
                   8623: /* old command */
                   8624: ALIAS (show_ipv6_bgp_community_exact,
                   8625:        show_ipv6_bgp_community4_exact_cmd,
                   8626:        "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",
                   8627:        SHOW_STR
                   8628:        IPV6_STR
                   8629:        BGP_STR
                   8630:        "Display routes matching the communities\n"
                   8631:        "community number\n"
                   8632:        "Do not send outside local AS (well-known community)\n"
                   8633:        "Do not advertise to any peer (well-known community)\n"
                   8634:        "Do not export to next AS (well-known community)\n"
                   8635:        "community number\n"
                   8636:        "Do not send outside local AS (well-known community)\n"
                   8637:        "Do not advertise to any peer (well-known community)\n"
                   8638:        "Do not export to next AS (well-known community)\n"
                   8639:        "community number\n"
                   8640:        "Do not send outside local AS (well-known community)\n"
                   8641:        "Do not advertise to any peer (well-known community)\n"
                   8642:        "Do not export to next AS (well-known community)\n"
                   8643:        "community number\n"
                   8644:        "Do not send outside local AS (well-known community)\n"
                   8645:        "Do not advertise to any peer (well-known community)\n"
                   8646:        "Do not export to next AS (well-known community)\n"
                   8647:        "Exact match of the communities")
                   8648:  
                   8649: /* old command */
                   8650: DEFUN (show_ipv6_mbgp_community,
                   8651:        show_ipv6_mbgp_community_cmd,
                   8652:        "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
                   8653:        SHOW_STR
                   8654:        IPV6_STR
                   8655:        MBGP_STR
                   8656:        "Display routes matching the communities\n"
                   8657:        "community number\n"
                   8658:        "Do not send outside local AS (well-known community)\n"
                   8659:        "Do not advertise to any peer (well-known community)\n"
                   8660:        "Do not export to next AS (well-known community)\n")
                   8661: {
                   8662:   return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
                   8663: }
                   8664: 
                   8665: /* old command */
                   8666: ALIAS (show_ipv6_mbgp_community,
                   8667:        show_ipv6_mbgp_community2_cmd,
                   8668:        "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
                   8669:        SHOW_STR
                   8670:        IPV6_STR
                   8671:        MBGP_STR
                   8672:        "Display routes matching the communities\n"
                   8673:        "community number\n"
                   8674:        "Do not send outside local AS (well-known community)\n"
                   8675:        "Do not advertise to any peer (well-known community)\n"
                   8676:        "Do not export to next AS (well-known community)\n"
                   8677:        "community number\n"
                   8678:        "Do not send outside local AS (well-known community)\n"
                   8679:        "Do not advertise to any peer (well-known community)\n"
                   8680:        "Do not export to next AS (well-known community)\n")
                   8681: 
                   8682: /* old command */
                   8683: ALIAS (show_ipv6_mbgp_community,
                   8684:        show_ipv6_mbgp_community3_cmd,
                   8685:        "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)",
                   8686:        SHOW_STR
                   8687:        IPV6_STR
                   8688:        MBGP_STR
                   8689:        "Display routes matching the communities\n"
                   8690:        "community number\n"
                   8691:        "Do not send outside local AS (well-known community)\n"
                   8692:        "Do not advertise to any peer (well-known community)\n"
                   8693:        "Do not export to next AS (well-known community)\n"
                   8694:        "community number\n"
                   8695:        "Do not send outside local AS (well-known community)\n"
                   8696:        "Do not advertise to any peer (well-known community)\n"
                   8697:        "Do not export to next AS (well-known community)\n"
                   8698:        "community number\n"
                   8699:        "Do not send outside local AS (well-known community)\n"
                   8700:        "Do not advertise to any peer (well-known community)\n"
                   8701:        "Do not export to next AS (well-known community)\n")
                   8702: 
                   8703: /* old command */
                   8704: ALIAS (show_ipv6_mbgp_community,
                   8705:        show_ipv6_mbgp_community4_cmd,
                   8706:        "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)",
                   8707:        SHOW_STR
                   8708:        IPV6_STR
                   8709:        MBGP_STR
                   8710:        "Display routes matching the communities\n"
                   8711:        "community number\n"
                   8712:        "Do not send outside local AS (well-known community)\n"
                   8713:        "Do not advertise to any peer (well-known community)\n"
                   8714:        "Do not export to next AS (well-known community)\n"
                   8715:        "community number\n"
                   8716:        "Do not send outside local AS (well-known community)\n"
                   8717:        "Do not advertise to any peer (well-known community)\n"
                   8718:        "Do not export to next AS (well-known community)\n"
                   8719:        "community number\n"
                   8720:        "Do not send outside local AS (well-known community)\n"
                   8721:        "Do not advertise to any peer (well-known community)\n"
                   8722:        "Do not export to next AS (well-known community)\n"
                   8723:        "community number\n"
                   8724:        "Do not send outside local AS (well-known community)\n"
                   8725:        "Do not advertise to any peer (well-known community)\n"
                   8726:        "Do not export to next AS (well-known community)\n")
                   8727: 
                   8728: /* old command */
                   8729: DEFUN (show_ipv6_mbgp_community_exact,
                   8730:        show_ipv6_mbgp_community_exact_cmd,
                   8731:        "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
                   8732:        SHOW_STR
                   8733:        IPV6_STR
                   8734:        MBGP_STR
                   8735:        "Display routes matching the communities\n"
                   8736:        "community number\n"
                   8737:        "Do not send outside local AS (well-known community)\n"
                   8738:        "Do not advertise to any peer (well-known community)\n"
                   8739:        "Do not export to next AS (well-known community)\n"
                   8740:        "Exact match of the communities")
                   8741: {
                   8742:   return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
                   8743: }
                   8744: 
                   8745: /* old command */
                   8746: ALIAS (show_ipv6_mbgp_community_exact,
                   8747:        show_ipv6_mbgp_community2_exact_cmd,
                   8748:        "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
                   8749:        SHOW_STR
                   8750:        IPV6_STR
                   8751:        MBGP_STR
                   8752:        "Display routes matching the communities\n"
                   8753:        "community number\n"
                   8754:        "Do not send outside local AS (well-known community)\n"
                   8755:        "Do not advertise to any peer (well-known community)\n"
                   8756:        "Do not export to next AS (well-known community)\n"
                   8757:        "community number\n"
                   8758:        "Do not send outside local AS (well-known community)\n"
                   8759:        "Do not advertise to any peer (well-known community)\n"
                   8760:        "Do not export to next AS (well-known community)\n"
                   8761:        "Exact match of the communities")
                   8762: 
                   8763: /* old command */
                   8764: ALIAS (show_ipv6_mbgp_community_exact,
                   8765:        show_ipv6_mbgp_community3_exact_cmd,
                   8766:        "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",
                   8767:        SHOW_STR
                   8768:        IPV6_STR
                   8769:        MBGP_STR
                   8770:        "Display routes matching the communities\n"
                   8771:        "community number\n"
                   8772:        "Do not send outside local AS (well-known community)\n"
                   8773:        "Do not advertise to any peer (well-known community)\n"
                   8774:        "Do not export to next AS (well-known community)\n"
                   8775:        "community number\n"
                   8776:        "Do not send outside local AS (well-known community)\n"
                   8777:        "Do not advertise to any peer (well-known community)\n"
                   8778:        "Do not export to next AS (well-known community)\n"
                   8779:        "community number\n"
                   8780:        "Do not send outside local AS (well-known community)\n"
                   8781:        "Do not advertise to any peer (well-known community)\n"
                   8782:        "Do not export to next AS (well-known community)\n"
                   8783:        "Exact match of the communities")
                   8784: 
                   8785: /* old command */
                   8786: ALIAS (show_ipv6_mbgp_community_exact,
                   8787:        show_ipv6_mbgp_community4_exact_cmd,
                   8788:        "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",
                   8789:        SHOW_STR
                   8790:        IPV6_STR
                   8791:        MBGP_STR
                   8792:        "Display routes matching the communities\n"
                   8793:        "community number\n"
                   8794:        "Do not send outside local AS (well-known community)\n"
                   8795:        "Do not advertise to any peer (well-known community)\n"
                   8796:        "Do not export to next AS (well-known community)\n"
                   8797:        "community number\n"
                   8798:        "Do not send outside local AS (well-known community)\n"
                   8799:        "Do not advertise to any peer (well-known community)\n"
                   8800:        "Do not export to next AS (well-known community)\n"
                   8801:        "community number\n"
                   8802:        "Do not send outside local AS (well-known community)\n"
                   8803:        "Do not advertise to any peer (well-known community)\n"
                   8804:        "Do not export to next AS (well-known community)\n"
                   8805:        "community number\n"
                   8806:        "Do not send outside local AS (well-known community)\n"
                   8807:        "Do not advertise to any peer (well-known community)\n"
                   8808:        "Do not export to next AS (well-known community)\n"
                   8809:        "Exact match of the communities")
                   8810: #endif /* HAVE_IPV6 */
                   8811: 
                   8812: static int
                   8813: bgp_show_community_list (struct vty *vty, const char *com, int exact,
                   8814:                         afi_t afi, safi_t safi)
                   8815: {
                   8816:   struct community_list *list;
                   8817: 
                   8818:   list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
                   8819:   if (list == NULL)
                   8820:     {
                   8821:       vty_out (vty, "%% %s is not a valid community-list name%s", com,
                   8822:               VTY_NEWLINE);
                   8823:       return CMD_WARNING;
                   8824:     }
                   8825: 
                   8826:   return bgp_show (vty, NULL, afi, safi,
                   8827:                    (exact ? bgp_show_type_community_list_exact :
                   8828:                            bgp_show_type_community_list), list);
                   8829: }
                   8830: 
                   8831: DEFUN (show_ip_bgp_community_list,
                   8832:        show_ip_bgp_community_list_cmd,
                   8833:        "show ip bgp community-list (<1-500>|WORD)",
                   8834:        SHOW_STR
                   8835:        IP_STR
                   8836:        BGP_STR
                   8837:        "Display routes matching the community-list\n"
                   8838:        "community-list number\n"
                   8839:        "community-list name\n")
                   8840: {
                   8841:   return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
                   8842: }
                   8843: 
                   8844: DEFUN (show_ip_bgp_ipv4_community_list,
                   8845:        show_ip_bgp_ipv4_community_list_cmd,
                   8846:        "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
                   8847:        SHOW_STR
                   8848:        IP_STR
                   8849:        BGP_STR
                   8850:        "Address family\n"
                   8851:        "Address Family modifier\n"
                   8852:        "Address Family modifier\n"
                   8853:        "Display routes matching the community-list\n"
                   8854:        "community-list number\n"
                   8855:        "community-list name\n")
                   8856: {
                   8857:   if (strncmp (argv[0], "m", 1) == 0)
                   8858:     return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
                   8859:   
                   8860:   return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
                   8861: }
                   8862: 
                   8863: DEFUN (show_ip_bgp_community_list_exact,
                   8864:        show_ip_bgp_community_list_exact_cmd,
                   8865:        "show ip bgp community-list (<1-500>|WORD) exact-match",
                   8866:        SHOW_STR
                   8867:        IP_STR
                   8868:        BGP_STR
                   8869:        "Display routes matching the community-list\n"
                   8870:        "community-list number\n"
                   8871:        "community-list name\n"
                   8872:        "Exact match of the communities\n")
                   8873: {
                   8874:   return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
                   8875: }
                   8876: 
                   8877: DEFUN (show_ip_bgp_ipv4_community_list_exact,
                   8878:        show_ip_bgp_ipv4_community_list_exact_cmd,
                   8879:        "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
                   8880:        SHOW_STR
                   8881:        IP_STR
                   8882:        BGP_STR
                   8883:        "Address family\n"
                   8884:        "Address Family modifier\n"
                   8885:        "Address Family modifier\n"
                   8886:        "Display routes matching the community-list\n"
                   8887:        "community-list number\n"
                   8888:        "community-list name\n"
                   8889:        "Exact match of the communities\n")
                   8890: {
                   8891:   if (strncmp (argv[0], "m", 1) == 0)
                   8892:     return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
                   8893:  
                   8894:   return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
                   8895: }
                   8896: 
                   8897: #ifdef HAVE_IPV6
                   8898: DEFUN (show_bgp_community_list,
                   8899:        show_bgp_community_list_cmd,
                   8900:        "show bgp community-list (<1-500>|WORD)",
                   8901:        SHOW_STR
                   8902:        BGP_STR
                   8903:        "Display routes matching the community-list\n"
                   8904:        "community-list number\n"
                   8905:        "community-list name\n")
                   8906: {
                   8907:   return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
                   8908: }
                   8909: 
                   8910: ALIAS (show_bgp_community_list,
                   8911:        show_bgp_ipv6_community_list_cmd,
                   8912:        "show bgp ipv6 community-list (<1-500>|WORD)",
                   8913:        SHOW_STR
                   8914:        BGP_STR
                   8915:        "Address family\n"
                   8916:        "Display routes matching the community-list\n"
                   8917:        "community-list number\n"
                   8918:        "community-list name\n")
                   8919: 
                   8920: /* old command */
                   8921: DEFUN (show_ipv6_bgp_community_list,
                   8922:        show_ipv6_bgp_community_list_cmd,
                   8923:        "show ipv6 bgp community-list WORD",
                   8924:        SHOW_STR
                   8925:        IPV6_STR
                   8926:        BGP_STR
                   8927:        "Display routes matching the community-list\n"
                   8928:        "community-list name\n")
                   8929: {
                   8930:   return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
                   8931: }
                   8932: 
                   8933: /* old command */
                   8934: DEFUN (show_ipv6_mbgp_community_list,
                   8935:        show_ipv6_mbgp_community_list_cmd,
                   8936:        "show ipv6 mbgp community-list WORD",
                   8937:        SHOW_STR
                   8938:        IPV6_STR
                   8939:        MBGP_STR
                   8940:        "Display routes matching the community-list\n"
                   8941:        "community-list name\n")
                   8942: {
                   8943:   return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
                   8944: }
                   8945: 
                   8946: DEFUN (show_bgp_community_list_exact,
                   8947:        show_bgp_community_list_exact_cmd,
                   8948:        "show bgp community-list (<1-500>|WORD) exact-match",
                   8949:        SHOW_STR
                   8950:        BGP_STR
                   8951:        "Display routes matching the community-list\n"
                   8952:        "community-list number\n"
                   8953:        "community-list name\n"
                   8954:        "Exact match of the communities\n")
                   8955: {
                   8956:   return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
                   8957: }
                   8958: 
                   8959: ALIAS (show_bgp_community_list_exact,
                   8960:        show_bgp_ipv6_community_list_exact_cmd,
                   8961:        "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
                   8962:        SHOW_STR
                   8963:        BGP_STR
                   8964:        "Address family\n"
                   8965:        "Display routes matching the community-list\n"
                   8966:        "community-list number\n"
                   8967:        "community-list name\n"
                   8968:        "Exact match of the communities\n")
                   8969: 
                   8970: /* old command */
                   8971: DEFUN (show_ipv6_bgp_community_list_exact,
                   8972:        show_ipv6_bgp_community_list_exact_cmd,
                   8973:        "show ipv6 bgp community-list WORD exact-match",
                   8974:        SHOW_STR
                   8975:        IPV6_STR
                   8976:        BGP_STR
                   8977:        "Display routes matching the community-list\n"
                   8978:        "community-list name\n"
                   8979:        "Exact match of the communities\n")
                   8980: {
                   8981:   return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
                   8982: }
                   8983: 
                   8984: /* old command */
                   8985: DEFUN (show_ipv6_mbgp_community_list_exact,
                   8986:        show_ipv6_mbgp_community_list_exact_cmd,
                   8987:        "show ipv6 mbgp community-list WORD exact-match",
                   8988:        SHOW_STR
                   8989:        IPV6_STR
                   8990:        MBGP_STR
                   8991:        "Display routes matching the community-list\n"
                   8992:        "community-list name\n"
                   8993:        "Exact match of the communities\n")
                   8994: {
                   8995:   return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
                   8996: }
                   8997: #endif /* HAVE_IPV6 */
                   8998: 
                   8999: static int
                   9000: bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
                   9001:                        safi_t safi, enum bgp_show_type type)
                   9002: {
                   9003:   int ret;
                   9004:   struct prefix *p;
                   9005: 
                   9006:   p = prefix_new();
                   9007: 
                   9008:   ret = str2prefix (prefix, p);
                   9009:   if (! ret)
                   9010:     {
                   9011:       vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
                   9012:       return CMD_WARNING;
                   9013:     }
                   9014: 
                   9015:   ret = bgp_show (vty, NULL, afi, safi, type, p);
                   9016:   prefix_free(p);
                   9017:   return ret;
                   9018: }
                   9019: 
                   9020: DEFUN (show_ip_bgp_prefix_longer,
                   9021:        show_ip_bgp_prefix_longer_cmd,
                   9022:        "show ip bgp A.B.C.D/M longer-prefixes",
                   9023:        SHOW_STR
                   9024:        IP_STR
                   9025:        BGP_STR
                   9026:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
                   9027:        "Display route and more specific routes\n")
                   9028: {
                   9029:   return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
                   9030:                                 bgp_show_type_prefix_longer);
                   9031: }
                   9032: 
                   9033: DEFUN (show_ip_bgp_flap_prefix_longer,
                   9034:        show_ip_bgp_flap_prefix_longer_cmd,
                   9035:        "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
                   9036:        SHOW_STR
                   9037:        IP_STR
                   9038:        BGP_STR
                   9039:        "Display flap statistics of routes\n"
                   9040:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
                   9041:        "Display route and more specific routes\n")
                   9042: {
                   9043:   return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
                   9044:                                 bgp_show_type_flap_prefix_longer);
                   9045: }
                   9046: 
                   9047: DEFUN (show_ip_bgp_ipv4_prefix_longer,
                   9048:        show_ip_bgp_ipv4_prefix_longer_cmd,
                   9049:        "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
                   9050:        SHOW_STR
                   9051:        IP_STR
                   9052:        BGP_STR
                   9053:        "Address family\n"
                   9054:        "Address Family modifier\n"
                   9055:        "Address Family modifier\n"
                   9056:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
                   9057:        "Display route and more specific routes\n")
                   9058: {
                   9059:   if (strncmp (argv[0], "m", 1) == 0)
                   9060:     return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
                   9061:                                   bgp_show_type_prefix_longer);
                   9062: 
                   9063:   return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
                   9064:                                 bgp_show_type_prefix_longer);
                   9065: }
                   9066: 
                   9067: DEFUN (show_ip_bgp_flap_address,
                   9068:        show_ip_bgp_flap_address_cmd,
                   9069:        "show ip bgp flap-statistics A.B.C.D",
                   9070:        SHOW_STR
                   9071:        IP_STR
                   9072:        BGP_STR
                   9073:        "Display flap statistics of routes\n"
                   9074:        "Network in the BGP routing table to display\n")
                   9075: {
                   9076:   return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
                   9077:                                 bgp_show_type_flap_address);
                   9078: }
                   9079: 
                   9080: DEFUN (show_ip_bgp_flap_prefix,
                   9081:        show_ip_bgp_flap_prefix_cmd,
                   9082:        "show ip bgp flap-statistics A.B.C.D/M",
                   9083:        SHOW_STR
                   9084:        IP_STR
                   9085:        BGP_STR
                   9086:        "Display flap statistics of routes\n"
                   9087:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
                   9088: {
                   9089:   return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
                   9090:                                 bgp_show_type_flap_prefix);
                   9091: }
                   9092: #ifdef HAVE_IPV6
                   9093: DEFUN (show_bgp_prefix_longer,
                   9094:        show_bgp_prefix_longer_cmd,
                   9095:        "show bgp X:X::X:X/M longer-prefixes",
                   9096:        SHOW_STR
                   9097:        BGP_STR
                   9098:        "IPv6 prefix <network>/<length>\n"
                   9099:        "Display route and more specific routes\n")
                   9100: {
                   9101:   return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
                   9102:                                 bgp_show_type_prefix_longer);
                   9103: }
                   9104: 
                   9105: ALIAS (show_bgp_prefix_longer,
                   9106:        show_bgp_ipv6_prefix_longer_cmd,
                   9107:        "show bgp ipv6 X:X::X:X/M longer-prefixes",
                   9108:        SHOW_STR
                   9109:        BGP_STR
                   9110:        "Address family\n"
                   9111:        "IPv6 prefix <network>/<length>\n"
                   9112:        "Display route and more specific routes\n")
                   9113: 
                   9114: /* old command */
                   9115: DEFUN (show_ipv6_bgp_prefix_longer,
                   9116:        show_ipv6_bgp_prefix_longer_cmd,
                   9117:        "show ipv6 bgp X:X::X:X/M longer-prefixes",
                   9118:        SHOW_STR
                   9119:        IPV6_STR
                   9120:        BGP_STR
                   9121:        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
                   9122:        "Display route and more specific routes\n")
                   9123: {
                   9124:   return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
                   9125:                                 bgp_show_type_prefix_longer);
                   9126: }
                   9127: 
                   9128: /* old command */
                   9129: DEFUN (show_ipv6_mbgp_prefix_longer,
                   9130:        show_ipv6_mbgp_prefix_longer_cmd,
                   9131:        "show ipv6 mbgp X:X::X:X/M longer-prefixes",
                   9132:        SHOW_STR
                   9133:        IPV6_STR
                   9134:        MBGP_STR
                   9135:        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
                   9136:        "Display route and more specific routes\n")
                   9137: {
                   9138:   return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
                   9139:                                 bgp_show_type_prefix_longer);
                   9140: }
                   9141: #endif /* HAVE_IPV6 */
                   9142: 
                   9143: static struct peer *
                   9144: peer_lookup_in_view (struct vty *vty, const char *view_name, 
                   9145:                      const char *ip_str)
                   9146: {
                   9147:   int ret;
                   9148:   struct bgp *bgp;
                   9149:   struct peer *peer;
                   9150:   union sockunion su;
                   9151: 
                   9152:   /* BGP structure lookup. */
                   9153:   if (view_name)
                   9154:     {
                   9155:       bgp = bgp_lookup_by_name (view_name);
                   9156:       if (! bgp)
                   9157:         {
                   9158:           vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
                   9159:           return NULL;
                   9160:         }      
                   9161:     }
                   9162:   else
                   9163:     {
                   9164:       bgp = bgp_get_default ();
                   9165:       if (! bgp)
                   9166:         {
                   9167:           vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
                   9168:           return NULL;
                   9169:         }
                   9170:     }
                   9171: 
                   9172:   /* Get peer sockunion. */  
                   9173:   ret = str2sockunion (ip_str, &su);
                   9174:   if (ret < 0)
                   9175:     {
                   9176:       vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
                   9177:       return NULL;
                   9178:     }
                   9179: 
                   9180:   /* Peer structure lookup. */
                   9181:   peer = peer_lookup (bgp, &su);
                   9182:   if (! peer)
                   9183:     {
                   9184:       vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
                   9185:       return NULL;
                   9186:     }
                   9187:   
                   9188:   return peer;
                   9189: }
                   9190: 
                   9191: enum bgp_stats
                   9192: {
                   9193:   BGP_STATS_MAXBITLEN = 0,
                   9194:   BGP_STATS_RIB,
                   9195:   BGP_STATS_PREFIXES,
                   9196:   BGP_STATS_TOTPLEN,
                   9197:   BGP_STATS_UNAGGREGATEABLE,
                   9198:   BGP_STATS_MAX_AGGREGATEABLE,
                   9199:   BGP_STATS_AGGREGATES,
                   9200:   BGP_STATS_SPACE,
                   9201:   BGP_STATS_ASPATH_COUNT,
                   9202:   BGP_STATS_ASPATH_MAXHOPS,
                   9203:   BGP_STATS_ASPATH_TOTHOPS,
                   9204:   BGP_STATS_ASPATH_MAXSIZE,
                   9205:   BGP_STATS_ASPATH_TOTSIZE,
                   9206:   BGP_STATS_ASN_HIGHEST,
                   9207:   BGP_STATS_MAX,
                   9208: };
                   9209: 
                   9210: static const char *table_stats_strs[] =
                   9211: {
                   9212:   [BGP_STATS_PREFIXES]            = "Total Prefixes",
                   9213:   [BGP_STATS_TOTPLEN]             = "Average prefix length",
                   9214:   [BGP_STATS_RIB]                 = "Total Advertisements",
                   9215:   [BGP_STATS_UNAGGREGATEABLE]     = "Unaggregateable prefixes",
                   9216:   [BGP_STATS_MAX_AGGREGATEABLE]   = "Maximum aggregateable prefixes",
                   9217:   [BGP_STATS_AGGREGATES]          = "BGP Aggregate advertisements",
                   9218:   [BGP_STATS_SPACE]               = "Address space advertised",
                   9219:   [BGP_STATS_ASPATH_COUNT]        = "Advertisements with paths",
                   9220:   [BGP_STATS_ASPATH_MAXHOPS]      = "Longest AS-Path (hops)",
                   9221:   [BGP_STATS_ASPATH_MAXSIZE]      = "Largest AS-Path (bytes)",
                   9222:   [BGP_STATS_ASPATH_TOTHOPS]      = "Average AS-Path length (hops)",
                   9223:   [BGP_STATS_ASPATH_TOTSIZE]      = "Average AS-Path size (bytes)",
                   9224:   [BGP_STATS_ASN_HIGHEST]         = "Highest public ASN",
                   9225:   [BGP_STATS_MAX] = NULL,
                   9226: };
                   9227: 
                   9228: struct bgp_table_stats
                   9229: {
                   9230:   struct bgp_table *table;
                   9231:   unsigned long long counts[BGP_STATS_MAX];
                   9232: };
                   9233: 
                   9234: #if 0
                   9235: #define TALLY_SIGFIG 100000
                   9236: static unsigned long
                   9237: ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
                   9238: {
                   9239:   unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
                   9240:   unsigned long res = (newtot * TALLY_SIGFIG) / count;
                   9241:   unsigned long ret = newtot / count;
                   9242:   
                   9243:   if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
                   9244:     return ret + 1;
                   9245:   else
                   9246:     return ret;
                   9247: }
                   9248: #endif
                   9249: 
                   9250: static int
                   9251: bgp_table_stats_walker (struct thread *t)
                   9252: {
                   9253:   struct bgp_node *rn;
                   9254:   struct bgp_node *top;
                   9255:   struct bgp_table_stats *ts = THREAD_ARG (t);
                   9256:   unsigned int space = 0;
                   9257:   
                   9258:   if (!(top = bgp_table_top (ts->table)))
                   9259:     return 0;
                   9260: 
                   9261:   switch (top->p.family)
                   9262:     {
                   9263:       case AF_INET:
                   9264:         space = IPV4_MAX_BITLEN;
                   9265:         break;
                   9266:       case AF_INET6:
                   9267:         space = IPV6_MAX_BITLEN;
                   9268:         break;
                   9269:     }
                   9270:     
                   9271:   ts->counts[BGP_STATS_MAXBITLEN] = space;
                   9272: 
                   9273:   for (rn = top; rn; rn = bgp_route_next (rn))
                   9274:     {
                   9275:       struct bgp_info *ri;
                   9276:       struct bgp_node *prn = rn->parent;
                   9277:       unsigned int rinum = 0;
                   9278:       
                   9279:       if (rn == top)
                   9280:         continue;
                   9281:       
                   9282:       if (!rn->info)
                   9283:         continue;
                   9284:       
                   9285:       ts->counts[BGP_STATS_PREFIXES]++;
                   9286:       ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
                   9287: 
                   9288: #if 0
                   9289:       ts->counts[BGP_STATS_AVGPLEN]
                   9290:         = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
                   9291:                       ts->counts[BGP_STATS_AVGPLEN],
                   9292:                       rn->p.prefixlen);
                   9293: #endif
                   9294:       
                   9295:       /* check if the prefix is included by any other announcements */
                   9296:       while (prn && !prn->info)
                   9297:         prn = prn->parent;
                   9298:       
                   9299:       if (prn == NULL || prn == top)
                   9300:         {
                   9301:           ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
                   9302:           /* announced address space */
                   9303:           if (space)
                   9304:             ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
                   9305:         }
                   9306:       else if (prn->info)
                   9307:         ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
                   9308:       
                   9309:       for (ri = rn->info; ri; ri = ri->next)
                   9310:         {
                   9311:           rinum++;
                   9312:           ts->counts[BGP_STATS_RIB]++;
                   9313:           
                   9314:           if (ri->attr &&
                   9315:               (CHECK_FLAG (ri->attr->flag,
                   9316:                            ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
                   9317:             ts->counts[BGP_STATS_AGGREGATES]++;
                   9318:           
                   9319:           /* as-path stats */
                   9320:           if (ri->attr && ri->attr->aspath)
                   9321:             {
                   9322:               unsigned int hops = aspath_count_hops (ri->attr->aspath);
                   9323:               unsigned int size = aspath_size (ri->attr->aspath);
                   9324:               as_t highest = aspath_highest (ri->attr->aspath);
                   9325:               
                   9326:               ts->counts[BGP_STATS_ASPATH_COUNT]++;
                   9327:               
                   9328:               if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
                   9329:                 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
                   9330:               
                   9331:               if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
                   9332:                 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
                   9333:               
                   9334:               ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
                   9335:               ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
                   9336: #if 0
                   9337:               ts->counts[BGP_STATS_ASPATH_AVGHOPS] 
                   9338:                 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
                   9339:                               ts->counts[BGP_STATS_ASPATH_AVGHOPS],
                   9340:                               hops);
                   9341:               ts->counts[BGP_STATS_ASPATH_AVGSIZE]
                   9342:                 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
                   9343:                               ts->counts[BGP_STATS_ASPATH_AVGSIZE],
                   9344:                               size);
                   9345: #endif
                   9346:               if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
                   9347:                 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
                   9348:             }
                   9349:         }
                   9350:     }
                   9351:   return 0;
                   9352: }
                   9353: 
                   9354: static int
                   9355: bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
                   9356: {
                   9357:   struct bgp_table_stats ts;
                   9358:   unsigned int i;
                   9359:   
                   9360:   if (!bgp->rib[afi][safi])
                   9361:     {
                   9362:       vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
                   9363:       return CMD_WARNING;
                   9364:     }
                   9365:   
                   9366:   memset (&ts, 0, sizeof (ts));
                   9367:   ts.table = bgp->rib[afi][safi];
                   9368:   thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
                   9369: 
                   9370:   vty_out (vty, "BGP %s RIB statistics%s%s",
                   9371:            afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
                   9372:   
                   9373:   for (i = 0; i < BGP_STATS_MAX; i++)
                   9374:     {
                   9375:       if (!table_stats_strs[i])
                   9376:         continue;
                   9377:       
                   9378:       switch (i)
                   9379:         {
                   9380: #if 0
                   9381:           case BGP_STATS_ASPATH_AVGHOPS:
                   9382:           case BGP_STATS_ASPATH_AVGSIZE:
                   9383:           case BGP_STATS_AVGPLEN:
                   9384:             vty_out (vty, "%-30s: ", table_stats_strs[i]);
                   9385:             vty_out (vty, "%12.2f",
                   9386:                      (float)ts.counts[i] / (float)TALLY_SIGFIG);
                   9387:             break;
                   9388: #endif
                   9389:           case BGP_STATS_ASPATH_TOTHOPS:
                   9390:           case BGP_STATS_ASPATH_TOTSIZE:
                   9391:             vty_out (vty, "%-30s: ", table_stats_strs[i]);
                   9392:             vty_out (vty, "%12.2f",
                   9393:                      ts.counts[i] ?
                   9394:                      (float)ts.counts[i] / 
                   9395:                       (float)ts.counts[BGP_STATS_ASPATH_COUNT]
                   9396:                      : 0);
                   9397:             break;
                   9398:           case BGP_STATS_TOTPLEN:
                   9399:             vty_out (vty, "%-30s: ", table_stats_strs[i]);
                   9400:             vty_out (vty, "%12.2f",
                   9401:                      ts.counts[i] ?
                   9402:                      (float)ts.counts[i] / 
                   9403:                       (float)ts.counts[BGP_STATS_PREFIXES]
                   9404:                      : 0);
                   9405:             break;
                   9406:           case BGP_STATS_SPACE:
                   9407:             vty_out (vty, "%-30s: ", table_stats_strs[i]);
                   9408:             vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
                   9409:             if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
                   9410:               break;
                   9411:             vty_out (vty, "%30s: ", "%% announced ");
                   9412:             vty_out (vty, "%12.2f%s", 
                   9413:                      100 * (float)ts.counts[BGP_STATS_SPACE] / 
                   9414:                        (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
                   9415:                        VTY_NEWLINE);
                   9416:             vty_out (vty, "%30s: ", "/8 equivalent ");
                   9417:             vty_out (vty, "%12.2f%s", 
                   9418:                      (float)ts.counts[BGP_STATS_SPACE] / 
                   9419:                        (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
                   9420:                      VTY_NEWLINE);
                   9421:             if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
                   9422:               break;
                   9423:             vty_out (vty, "%30s: ", "/24 equivalent ");
                   9424:             vty_out (vty, "%12.2f", 
                   9425:                      (float)ts.counts[BGP_STATS_SPACE] / 
                   9426:                        (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
                   9427:             break;
                   9428:           default:
                   9429:             vty_out (vty, "%-30s: ", table_stats_strs[i]);
                   9430:             vty_out (vty, "%12llu", ts.counts[i]);
                   9431:         }
                   9432:         
                   9433:       vty_out (vty, "%s", VTY_NEWLINE);
                   9434:     }
                   9435:   return CMD_SUCCESS;
                   9436: }
                   9437: 
                   9438: static int
                   9439: bgp_table_stats_vty (struct vty *vty, const char *name,
                   9440:                      const char *afi_str, const char *safi_str)
                   9441: {
                   9442:   struct bgp *bgp;
                   9443:   afi_t afi;
                   9444:   safi_t safi;
                   9445:   
                   9446:  if (name)
                   9447:     bgp = bgp_lookup_by_name (name);
                   9448:   else
                   9449:     bgp = bgp_get_default ();
                   9450: 
                   9451:   if (!bgp)
                   9452:     {
                   9453:       vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
                   9454:       return CMD_WARNING;
                   9455:     }
                   9456:   if (strncmp (afi_str, "ipv", 3) == 0)
                   9457:     {
                   9458:       if (strncmp (afi_str, "ipv4", 4) == 0)
                   9459:         afi = AFI_IP;
                   9460:       else if (strncmp (afi_str, "ipv6", 4) == 0)
                   9461:         afi = AFI_IP6;
                   9462:       else
                   9463:         {
                   9464:           vty_out (vty, "%% Invalid address family %s%s",
                   9465:                    afi_str, VTY_NEWLINE);
                   9466:           return CMD_WARNING;
                   9467:         }
                   9468:       if (strncmp (safi_str, "m", 1) == 0)
                   9469:         safi = SAFI_MULTICAST;
                   9470:       else if (strncmp (safi_str, "u", 1) == 0)
                   9471:         safi = SAFI_UNICAST;
1.1.1.2 ! misho    9472:       else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
        !          9473:         safi = SAFI_MPLS_LABELED_VPN;
1.1       misho    9474:       else
                   9475:         {
                   9476:           vty_out (vty, "%% Invalid subsequent address family %s%s",
                   9477:                    safi_str, VTY_NEWLINE);
                   9478:           return CMD_WARNING;
                   9479:         }
                   9480:     }
                   9481:   else
                   9482:     {
                   9483:       vty_out (vty, "%% Invalid address family %s%s",
                   9484:                afi_str, VTY_NEWLINE);
                   9485:       return CMD_WARNING;
                   9486:     }
                   9487: 
                   9488:   return bgp_table_stats (vty, bgp, afi, safi);
                   9489: }
                   9490: 
                   9491: DEFUN (show_bgp_statistics,
                   9492:        show_bgp_statistics_cmd,
                   9493:        "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
                   9494:        SHOW_STR
                   9495:        BGP_STR
                   9496:        "Address family\n"
                   9497:        "Address family\n"
                   9498:        "Address Family modifier\n"
                   9499:        "Address Family modifier\n"
                   9500:        "BGP RIB advertisement statistics\n")
                   9501: {
                   9502:   return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
                   9503: }
                   9504: 
                   9505: ALIAS (show_bgp_statistics,
                   9506:        show_bgp_statistics_vpnv4_cmd,
                   9507:        "show bgp (ipv4) (vpnv4) statistics",
                   9508:        SHOW_STR
                   9509:        BGP_STR
                   9510:        "Address family\n"
                   9511:        "Address Family modifier\n"
                   9512:        "BGP RIB advertisement statistics\n")
                   9513: 
                   9514: DEFUN (show_bgp_statistics_view,
                   9515:        show_bgp_statistics_view_cmd,
                   9516:        "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
                   9517:        SHOW_STR
                   9518:        BGP_STR
                   9519:        "BGP view\n"
                   9520:        "Address family\n"
                   9521:        "Address family\n"
                   9522:        "Address Family modifier\n"
                   9523:        "Address Family modifier\n"
                   9524:        "BGP RIB advertisement statistics\n")
                   9525: {
                   9526:   return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
                   9527: }
                   9528: 
                   9529: ALIAS (show_bgp_statistics_view,
                   9530:        show_bgp_statistics_view_vpnv4_cmd,
                   9531:        "show bgp view WORD (ipv4) (vpnv4) statistics",
                   9532:        SHOW_STR
                   9533:        BGP_STR
                   9534:        "BGP view\n"
                   9535:        "Address family\n"
                   9536:        "Address Family modifier\n"
                   9537:        "BGP RIB advertisement statistics\n")
                   9538: 
                   9539: enum bgp_pcounts
                   9540: {
                   9541:   PCOUNT_ADJ_IN = 0,
                   9542:   PCOUNT_DAMPED,
                   9543:   PCOUNT_REMOVED,
                   9544:   PCOUNT_HISTORY,
                   9545:   PCOUNT_STALE,
                   9546:   PCOUNT_VALID,
                   9547:   PCOUNT_ALL,
                   9548:   PCOUNT_COUNTED,
                   9549:   PCOUNT_PFCNT, /* the figure we display to users */
                   9550:   PCOUNT_MAX,
                   9551: };
                   9552: 
                   9553: static const char *pcount_strs[] =
                   9554: {
                   9555:   [PCOUNT_ADJ_IN]  = "Adj-in",
                   9556:   [PCOUNT_DAMPED]  = "Damped",
                   9557:   [PCOUNT_REMOVED] = "Removed",
                   9558:   [PCOUNT_HISTORY] = "History",
                   9559:   [PCOUNT_STALE]   = "Stale",
                   9560:   [PCOUNT_VALID]   = "Valid",
                   9561:   [PCOUNT_ALL]     = "All RIB",
                   9562:   [PCOUNT_COUNTED] = "PfxCt counted",
                   9563:   [PCOUNT_PFCNT]   = "Useable",
                   9564:   [PCOUNT_MAX]     = NULL,
                   9565: };
                   9566: 
                   9567: struct peer_pcounts
                   9568: {
                   9569:   unsigned int count[PCOUNT_MAX];
                   9570:   const struct peer *peer;
                   9571:   const struct bgp_table *table;
                   9572: };
                   9573: 
                   9574: static int
                   9575: bgp_peer_count_walker (struct thread *t)
                   9576: {
                   9577:   struct bgp_node *rn;
                   9578:   struct peer_pcounts *pc = THREAD_ARG (t);
                   9579:   const struct peer *peer = pc->peer;
                   9580:   
                   9581:   for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
                   9582:     {
                   9583:       struct bgp_adj_in *ain;
                   9584:       struct bgp_info *ri;
                   9585:       
                   9586:       for (ain = rn->adj_in; ain; ain = ain->next)
                   9587:         if (ain->peer == peer)
                   9588:           pc->count[PCOUNT_ADJ_IN]++;
                   9589: 
                   9590:       for (ri = rn->info; ri; ri = ri->next)
                   9591:         {
                   9592:           char buf[SU_ADDRSTRLEN];
                   9593:           
                   9594:           if (ri->peer != peer)
                   9595:             continue;
                   9596:           
                   9597:           pc->count[PCOUNT_ALL]++;
                   9598:           
                   9599:           if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
                   9600:             pc->count[PCOUNT_DAMPED]++;
                   9601:           if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
                   9602:             pc->count[PCOUNT_HISTORY]++;
                   9603:           if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
                   9604:             pc->count[PCOUNT_REMOVED]++;
                   9605:           if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
                   9606:             pc->count[PCOUNT_STALE]++;
                   9607:           if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
                   9608:             pc->count[PCOUNT_VALID]++;
                   9609:           if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
                   9610:             pc->count[PCOUNT_PFCNT]++;
                   9611:           
                   9612:           if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
                   9613:             {
                   9614:               pc->count[PCOUNT_COUNTED]++;
                   9615:               if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
                   9616:                 plog_warn (peer->log,
                   9617:                            "%s [pcount] %s/%d is counted but flags 0x%x",
                   9618:                            peer->host,
                   9619:                            inet_ntop(rn->p.family, &rn->p.u.prefix,
                   9620:                                      buf, SU_ADDRSTRLEN),
                   9621:                            rn->p.prefixlen,
                   9622:                            ri->flags);
                   9623:             }
                   9624:           else
                   9625:             {
                   9626:               if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
                   9627:                 plog_warn (peer->log,
                   9628:                            "%s [pcount] %s/%d not counted but flags 0x%x",
                   9629:                            peer->host,
                   9630:                            inet_ntop(rn->p.family, &rn->p.u.prefix,
                   9631:                                      buf, SU_ADDRSTRLEN),
                   9632:                            rn->p.prefixlen,
                   9633:                            ri->flags);
                   9634:             }
                   9635:         }
                   9636:     }
                   9637:   return 0;
                   9638: }
                   9639: 
                   9640: static int
                   9641: bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
                   9642: {
                   9643:   struct peer_pcounts pcounts = { .peer = peer };
                   9644:   unsigned int i;
                   9645:   
                   9646:   if (!peer || !peer->bgp || !peer->afc[afi][safi]
                   9647:       || !peer->bgp->rib[afi][safi])
                   9648:     {
                   9649:       vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
                   9650:       return CMD_WARNING;
                   9651:     }
                   9652:   
                   9653:   memset (&pcounts, 0, sizeof(pcounts));
                   9654:   pcounts.peer = peer;
                   9655:   pcounts.table = peer->bgp->rib[afi][safi];
                   9656:   
                   9657:   /* in-place call via thread subsystem so as to record execution time
                   9658:    * stats for the thread-walk (i.e. ensure this can't be blamed on
                   9659:    * on just vty_read()).
                   9660:    */
                   9661:   thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
                   9662:   
                   9663:   vty_out (vty, "Prefix counts for %s, %s%s", 
                   9664:            peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
                   9665:   vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
                   9666:   vty_out (vty, "%sCounts from RIB table walk:%s%s", 
                   9667:            VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
                   9668: 
                   9669:   for (i = 0; i < PCOUNT_MAX; i++)
                   9670:       vty_out (vty, "%20s: %-10d%s",
                   9671:                pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
                   9672: 
                   9673:   if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
                   9674:     {
                   9675:       vty_out (vty, "%s [pcount] PfxCt drift!%s",
                   9676:                peer->host, VTY_NEWLINE);
                   9677:       vty_out (vty, "Please report this bug, with the above command output%s",
                   9678:               VTY_NEWLINE);
                   9679:     }
                   9680:                
                   9681:   return CMD_SUCCESS;
                   9682: }
                   9683: 
                   9684: DEFUN (show_ip_bgp_neighbor_prefix_counts,
                   9685:        show_ip_bgp_neighbor_prefix_counts_cmd,
                   9686:        "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
                   9687:        SHOW_STR
                   9688:        IP_STR
                   9689:        BGP_STR
                   9690:        "Detailed information on TCP and BGP neighbor connections\n"
                   9691:        "Neighbor to display information about\n"
                   9692:        "Neighbor to display information about\n"
                   9693:        "Display detailed prefix count information\n")
                   9694: {
                   9695:   struct peer *peer;
                   9696: 
                   9697:   peer = peer_lookup_in_view (vty, NULL, argv[0]);  
                   9698:   if (! peer) 
                   9699:     return CMD_WARNING;
                   9700:  
                   9701:   return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
                   9702: }
                   9703: 
                   9704: DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
                   9705:        show_bgp_ipv6_neighbor_prefix_counts_cmd,
                   9706:        "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
                   9707:        SHOW_STR
                   9708:        BGP_STR
                   9709:        "Address family\n"
                   9710:        "Detailed information on TCP and BGP neighbor connections\n"
                   9711:        "Neighbor to display information about\n"
                   9712:        "Neighbor to display information about\n"
                   9713:        "Display detailed prefix count information\n")
                   9714: {
                   9715:   struct peer *peer;
                   9716: 
                   9717:   peer = peer_lookup_in_view (vty, NULL, argv[0]);  
                   9718:   if (! peer) 
                   9719:     return CMD_WARNING;
                   9720:  
                   9721:   return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
                   9722: }
                   9723: 
                   9724: DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
                   9725:        show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
                   9726:        "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
                   9727:        SHOW_STR
                   9728:        IP_STR
                   9729:        BGP_STR
                   9730:        "Address family\n"
                   9731:        "Address Family modifier\n"
                   9732:        "Address Family modifier\n"
                   9733:        "Detailed information on TCP and BGP neighbor connections\n"
                   9734:        "Neighbor to display information about\n"
                   9735:        "Neighbor to display information about\n"
                   9736:        "Display detailed prefix count information\n")
                   9737: {
                   9738:   struct peer *peer;
                   9739: 
                   9740:   peer = peer_lookup_in_view (vty, NULL, argv[1]);
                   9741:   if (! peer)
                   9742:     return CMD_WARNING;
                   9743: 
                   9744:   if (strncmp (argv[0], "m", 1) == 0)
                   9745:     return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
                   9746: 
                   9747:   return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
                   9748: }
                   9749: 
                   9750: DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
                   9751:        show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
                   9752:        "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
                   9753:        SHOW_STR
                   9754:        IP_STR
                   9755:        BGP_STR
                   9756:        "Address family\n"
                   9757:        "Address Family modifier\n"
                   9758:        "Address Family modifier\n"
                   9759:        "Detailed information on TCP and BGP neighbor connections\n"
                   9760:        "Neighbor to display information about\n"
                   9761:        "Neighbor to display information about\n"
                   9762:        "Display detailed prefix count information\n")
                   9763: {
                   9764:   struct peer *peer;
                   9765: 
                   9766:   peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   9767:   if (! peer)
                   9768:     return CMD_WARNING;
                   9769:   
                   9770:   return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
                   9771: }
                   9772: 
                   9773: 
                   9774: static void
                   9775: show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
                   9776:                int in)
                   9777: {
                   9778:   struct bgp_table *table;
                   9779:   struct bgp_adj_in *ain;
                   9780:   struct bgp_adj_out *adj;
                   9781:   unsigned long output_count;
                   9782:   struct bgp_node *rn;
                   9783:   int header1 = 1;
                   9784:   struct bgp *bgp;
                   9785:   int header2 = 1;
                   9786: 
                   9787:   bgp = peer->bgp;
                   9788: 
                   9789:   if (! bgp)
                   9790:     return;
                   9791: 
                   9792:   table = bgp->rib[afi][safi];
                   9793: 
                   9794:   output_count = 0;
                   9795:        
                   9796:   if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
                   9797:                          PEER_STATUS_DEFAULT_ORIGINATE))
                   9798:     {
                   9799:       vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
                   9800:       vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
                   9801:       vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
                   9802: 
                   9803:       vty_out (vty, "Originating default network 0.0.0.0%s%s",
                   9804:               VTY_NEWLINE, VTY_NEWLINE);
                   9805:       header1 = 0;
                   9806:     }
                   9807: 
                   9808:   for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
                   9809:     if (in)
                   9810:       {
                   9811:        for (ain = rn->adj_in; ain; ain = ain->next)
                   9812:          if (ain->peer == peer)
                   9813:            {
                   9814:              if (header1)
                   9815:                {
                   9816:                  vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
                   9817:                  vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
                   9818:                  vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
                   9819:                  header1 = 0;
                   9820:                }
                   9821:              if (header2)
                   9822:                {
                   9823:                  vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
                   9824:                  header2 = 0;
                   9825:                }
                   9826:              if (ain->attr)
                   9827:                { 
                   9828:                  route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
                   9829:                  output_count++;
                   9830:                }
                   9831:            }
                   9832:       }
                   9833:     else
                   9834:       {
                   9835:        for (adj = rn->adj_out; adj; adj = adj->next)
                   9836:          if (adj->peer == peer)
                   9837:            {
                   9838:              if (header1)
                   9839:                {
                   9840:                  vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
                   9841:                  vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
                   9842:                  vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
                   9843:                  header1 = 0;
                   9844:                }
                   9845:              if (header2)
                   9846:                {
                   9847:                  vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
                   9848:                  header2 = 0;
                   9849:                }
                   9850:              if (adj->attr)
                   9851:                {       
                   9852:                  route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
                   9853:                  output_count++;
                   9854:                }
                   9855:            }
                   9856:       }
                   9857:   
                   9858:   if (output_count != 0)
                   9859:     vty_out (vty, "%sTotal number of prefixes %ld%s",
                   9860:             VTY_NEWLINE, output_count, VTY_NEWLINE);
                   9861: }
                   9862: 
                   9863: static int
                   9864: peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
                   9865: {    
                   9866:   if (! peer || ! peer->afc[afi][safi])
                   9867:     {
                   9868:       vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
                   9869:       return CMD_WARNING;
                   9870:     }
                   9871: 
                   9872:   if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
                   9873:     {
                   9874:       vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
                   9875:               VTY_NEWLINE);
                   9876:       return CMD_WARNING;
                   9877:     }
                   9878: 
                   9879:   show_adj_route (vty, peer, afi, safi, in);
                   9880: 
                   9881:   return CMD_SUCCESS;
                   9882: }
                   9883: 
                   9884: DEFUN (show_ip_bgp_view_neighbor_advertised_route,
                   9885:        show_ip_bgp_view_neighbor_advertised_route_cmd,
                   9886:        "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
                   9887:        SHOW_STR
                   9888:        IP_STR
                   9889:        BGP_STR
                   9890:        "BGP view\n"
                   9891:        "View name\n"
                   9892:        "Detailed information on TCP and BGP neighbor connections\n"
                   9893:        "Neighbor to display information about\n"
                   9894:        "Neighbor to display information about\n"
                   9895:        "Display the routes advertised to a BGP neighbor\n")
                   9896: {
                   9897:   struct peer *peer;
                   9898: 
                   9899:   if (argc == 2)
                   9900:     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
                   9901:   else
                   9902:     peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   9903: 
                   9904:   if (! peer) 
                   9905:     return CMD_WARNING;
                   9906:  
                   9907:   return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
                   9908: }
                   9909: 
                   9910: ALIAS (show_ip_bgp_view_neighbor_advertised_route,
                   9911:        show_ip_bgp_neighbor_advertised_route_cmd,
                   9912:        "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
                   9913:        SHOW_STR
                   9914:        IP_STR
                   9915:        BGP_STR
                   9916:        "Detailed information on TCP and BGP neighbor connections\n"
                   9917:        "Neighbor to display information about\n"
                   9918:        "Neighbor to display information about\n"
                   9919:        "Display the routes advertised to a BGP neighbor\n")
                   9920: 
                   9921: DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
                   9922:        show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
                   9923:        "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
                   9924:        SHOW_STR
                   9925:        IP_STR
                   9926:        BGP_STR
                   9927:        "Address family\n"
                   9928:        "Address Family modifier\n"
                   9929:        "Address Family modifier\n"
                   9930:        "Detailed information on TCP and BGP neighbor connections\n"
                   9931:        "Neighbor to display information about\n"
                   9932:        "Neighbor to display information about\n"
                   9933:        "Display the routes advertised to a BGP neighbor\n")
                   9934: {
                   9935:   struct peer *peer;
                   9936: 
                   9937:   peer = peer_lookup_in_view (vty, NULL, argv[1]);
                   9938:   if (! peer)
                   9939:     return CMD_WARNING;
                   9940: 
                   9941:   if (strncmp (argv[0], "m", 1) == 0)
                   9942:     return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
                   9943: 
                   9944:   return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
                   9945: }
                   9946: 
                   9947: #ifdef HAVE_IPV6
                   9948: DEFUN (show_bgp_view_neighbor_advertised_route,
                   9949:        show_bgp_view_neighbor_advertised_route_cmd,
                   9950:        "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
                   9951:        SHOW_STR
                   9952:        BGP_STR
                   9953:        "BGP view\n"
                   9954:        "View name\n"
                   9955:        "Detailed information on TCP and BGP neighbor connections\n"
                   9956:        "Neighbor to display information about\n"
                   9957:        "Neighbor to display information about\n"
                   9958:        "Display the routes advertised to a BGP neighbor\n")
                   9959: {
                   9960:   struct peer *peer;
                   9961: 
                   9962:   if (argc == 2)
                   9963:     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
                   9964:   else
                   9965:     peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   9966: 
                   9967:   if (! peer)
                   9968:     return CMD_WARNING;    
                   9969: 
                   9970:   return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
                   9971: }
                   9972: 
                   9973: ALIAS (show_bgp_view_neighbor_advertised_route,
                   9974:        show_bgp_view_ipv6_neighbor_advertised_route_cmd,
                   9975:        "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
                   9976:        SHOW_STR
                   9977:        BGP_STR
                   9978:        "BGP view\n"
                   9979:        "View name\n"
                   9980:        "Address family\n"
                   9981:        "Detailed information on TCP and BGP neighbor connections\n"
                   9982:        "Neighbor to display information about\n"
                   9983:        "Neighbor to display information about\n"
                   9984:        "Display the routes advertised to a BGP neighbor\n")
                   9985: 
                   9986: DEFUN (show_bgp_view_neighbor_received_routes,
                   9987:        show_bgp_view_neighbor_received_routes_cmd,
                   9988:        "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
                   9989:        SHOW_STR
                   9990:        BGP_STR
                   9991:        "BGP view\n"
                   9992:        "View name\n"
                   9993:        "Detailed information on TCP and BGP neighbor connections\n"
                   9994:        "Neighbor to display information about\n"
                   9995:        "Neighbor to display information about\n"
                   9996:        "Display the received routes from neighbor\n")
                   9997: {
                   9998:   struct peer *peer;
                   9999: 
                   10000:   if (argc == 2)
                   10001:     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
                   10002:   else
                   10003:     peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   10004: 
                   10005:   if (! peer)
                   10006:     return CMD_WARNING;
                   10007: 
                   10008:   return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
                   10009: }
                   10010: 
                   10011: ALIAS (show_bgp_view_neighbor_received_routes,
                   10012:        show_bgp_view_ipv6_neighbor_received_routes_cmd,
                   10013:        "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
                   10014:        SHOW_STR
                   10015:        BGP_STR
                   10016:        "BGP view\n"
                   10017:        "View name\n"
                   10018:        "Address family\n"
                   10019:        "Detailed information on TCP and BGP neighbor connections\n"
                   10020:        "Neighbor to display information about\n"
                   10021:        "Neighbor to display information about\n"
                   10022:        "Display the received routes from neighbor\n")
                   10023: 
                   10024: ALIAS (show_bgp_view_neighbor_advertised_route,
                   10025:        show_bgp_neighbor_advertised_route_cmd,
                   10026:        "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
                   10027:        SHOW_STR
                   10028:        BGP_STR
                   10029:        "Detailed information on TCP and BGP neighbor connections\n"
                   10030:        "Neighbor to display information about\n"
                   10031:        "Neighbor to display information about\n"
                   10032:        "Display the routes advertised to a BGP neighbor\n")
                   10033:        
                   10034: ALIAS (show_bgp_view_neighbor_advertised_route,
                   10035:        show_bgp_ipv6_neighbor_advertised_route_cmd,
                   10036:        "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
                   10037:        SHOW_STR
                   10038:        BGP_STR
                   10039:        "Address family\n"
                   10040:        "Detailed information on TCP and BGP neighbor connections\n"
                   10041:        "Neighbor to display information about\n"
                   10042:        "Neighbor to display information about\n"
                   10043:        "Display the routes advertised to a BGP neighbor\n")
                   10044: 
                   10045: /* old command */
                   10046: ALIAS (show_bgp_view_neighbor_advertised_route,
                   10047:        ipv6_bgp_neighbor_advertised_route_cmd,
                   10048:        "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
                   10049:        SHOW_STR
                   10050:        IPV6_STR
                   10051:        BGP_STR
                   10052:        "Detailed information on TCP and BGP neighbor connections\n"
                   10053:        "Neighbor to display information about\n"
                   10054:        "Neighbor to display information about\n"
                   10055:        "Display the routes advertised to a BGP neighbor\n")
                   10056:   
                   10057: /* old command */
                   10058: DEFUN (ipv6_mbgp_neighbor_advertised_route,
                   10059:        ipv6_mbgp_neighbor_advertised_route_cmd,
                   10060:        "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
                   10061:        SHOW_STR
                   10062:        IPV6_STR
                   10063:        MBGP_STR
                   10064:        "Detailed information on TCP and BGP neighbor connections\n"
                   10065:        "Neighbor to display information about\n"
                   10066:        "Neighbor to display information about\n"
                   10067:        "Display the routes advertised to a BGP neighbor\n")
                   10068: {
                   10069:   struct peer *peer;
                   10070: 
                   10071:   peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   10072:   if (! peer)
                   10073:     return CMD_WARNING;  
                   10074: 
                   10075:   return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
                   10076: }
                   10077: #endif /* HAVE_IPV6 */
                   10078: 
                   10079: DEFUN (show_ip_bgp_view_neighbor_received_routes,
                   10080:        show_ip_bgp_view_neighbor_received_routes_cmd,
                   10081:        "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
                   10082:        SHOW_STR
                   10083:        IP_STR
                   10084:        BGP_STR
                   10085:        "BGP view\n"
                   10086:        "View name\n"
                   10087:        "Detailed information on TCP and BGP neighbor connections\n"
                   10088:        "Neighbor to display information about\n"
                   10089:        "Neighbor to display information about\n"
                   10090:        "Display the received routes from neighbor\n")
                   10091: {
                   10092:   struct peer *peer;
                   10093: 
                   10094:   if (argc == 2)
                   10095:     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
                   10096:   else
                   10097:     peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   10098: 
                   10099:   if (! peer)
                   10100:     return CMD_WARNING;
                   10101: 
                   10102:   return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
                   10103: }
                   10104: 
                   10105: ALIAS (show_ip_bgp_view_neighbor_received_routes,
                   10106:        show_ip_bgp_neighbor_received_routes_cmd,
                   10107:        "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
                   10108:        SHOW_STR
                   10109:        IP_STR
                   10110:        BGP_STR
                   10111:        "Detailed information on TCP and BGP neighbor connections\n"
                   10112:        "Neighbor to display information about\n"
                   10113:        "Neighbor to display information about\n"
                   10114:        "Display the received routes from neighbor\n")
                   10115: 
                   10116: DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
                   10117:        show_ip_bgp_ipv4_neighbor_received_routes_cmd,
                   10118:        "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
                   10119:        SHOW_STR
                   10120:        IP_STR
                   10121:        BGP_STR
                   10122:        "Address family\n"
                   10123:        "Address Family modifier\n"
                   10124:        "Address Family modifier\n"
                   10125:        "Detailed information on TCP and BGP neighbor connections\n"
                   10126:        "Neighbor to display information about\n"
                   10127:        "Neighbor to display information about\n"
                   10128:        "Display the received routes from neighbor\n")
                   10129: {
                   10130:   struct peer *peer;
                   10131: 
                   10132:   peer = peer_lookup_in_view (vty, NULL, argv[1]);
                   10133:   if (! peer)
                   10134:     return CMD_WARNING;
                   10135:   
                   10136:   if (strncmp (argv[0], "m", 1) == 0)
                   10137:     return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
                   10138: 
                   10139:   return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
                   10140: }
                   10141: 
                   10142: DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
                   10143:        show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
                   10144: #ifdef HAVE_IPV6
                   10145:        "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
                   10146: #else
                   10147:        "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
                   10148: #endif
                   10149:        SHOW_STR
                   10150:        BGP_STR
                   10151:        "BGP view\n"
                   10152:        "BGP view name\n"
                   10153:        "Address family\n"
                   10154: #ifdef HAVE_IPV6
                   10155:        "Address family\n"
                   10156: #endif
                   10157:        "Address family modifier\n"
                   10158:        "Address family modifier\n"
                   10159:        "Detailed information on TCP and BGP neighbor connections\n"
                   10160:        "Neighbor to display information about\n"
                   10161:        "Neighbor to display information about\n"
                   10162:        "Display the advertised routes to neighbor\n"
                   10163:        "Display the received routes from neighbor\n")
                   10164: {
                   10165:   int afi;
                   10166:   int safi;
                   10167:   int in;
                   10168:   struct peer *peer;
                   10169: 
                   10170: #ifdef HAVE_IPV6
                   10171:     peer = peer_lookup_in_view (vty, argv[0], argv[3]);
                   10172: #else
                   10173:     peer = peer_lookup_in_view (vty, argv[0], argv[2]);
                   10174: #endif
                   10175: 
                   10176:   if (! peer)
                   10177:     return CMD_WARNING;
                   10178: 
                   10179: #ifdef HAVE_IPV6
                   10180:   afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
                   10181:   safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   10182:   in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
                   10183: #else
                   10184:   afi = AFI_IP;
                   10185:   safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   10186:   in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
                   10187: #endif
                   10188: 
                   10189:   return peer_adj_routes (vty, peer, afi, safi, in);
                   10190: }
                   10191: 
                   10192: DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
                   10193:        show_ip_bgp_neighbor_received_prefix_filter_cmd,
                   10194:        "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
                   10195:        SHOW_STR
                   10196:        IP_STR
                   10197:        BGP_STR
                   10198:        "Detailed information on TCP and BGP neighbor connections\n"
                   10199:        "Neighbor to display information about\n"
                   10200:        "Neighbor to display information about\n"
                   10201:        "Display information received from a BGP neighbor\n"
                   10202:        "Display the prefixlist filter\n")
                   10203: {
                   10204:   char name[BUFSIZ];
                   10205:   union sockunion *su;
                   10206:   struct peer *peer;
                   10207:   int count;
                   10208: 
                   10209:   su = sockunion_str2su (argv[0]);
                   10210:   if (su == NULL)
                   10211:     return CMD_WARNING;
                   10212: 
                   10213:   peer = peer_lookup (NULL, su);
                   10214:   if (! peer)
                   10215:     return CMD_WARNING;
                   10216: 
                   10217:   sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
                   10218:   count =  prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
                   10219:   if (count)
                   10220:     {
                   10221:       vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
                   10222:       prefix_bgp_show_prefix_list (vty, AFI_IP, name);
                   10223:     }
                   10224: 
                   10225:   return CMD_SUCCESS;
                   10226: }
                   10227: 
                   10228: DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
                   10229:        show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
                   10230:        "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
                   10231:        SHOW_STR
                   10232:        IP_STR
                   10233:        BGP_STR
                   10234:        "Address family\n"
                   10235:        "Address Family modifier\n"
                   10236:        "Address Family modifier\n"
                   10237:        "Detailed information on TCP and BGP neighbor connections\n"
                   10238:        "Neighbor to display information about\n"
                   10239:        "Neighbor to display information about\n"
                   10240:        "Display information received from a BGP neighbor\n"
                   10241:        "Display the prefixlist filter\n")
                   10242: {
                   10243:   char name[BUFSIZ];
                   10244:   union sockunion *su;
                   10245:   struct peer *peer;
                   10246:   int count;
                   10247: 
                   10248:   su = sockunion_str2su (argv[1]);
                   10249:   if (su == NULL)
                   10250:     return CMD_WARNING;
                   10251: 
                   10252:   peer = peer_lookup (NULL, su);
                   10253:   if (! peer)
                   10254:     return CMD_WARNING;
                   10255: 
                   10256:   if (strncmp (argv[0], "m", 1) == 0)
                   10257:     {
                   10258:       sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
                   10259:       count =  prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
                   10260:       if (count)
                   10261:        {
                   10262:          vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
                   10263:          prefix_bgp_show_prefix_list (vty, AFI_IP, name);
                   10264:        }
                   10265:     }
                   10266:   else 
                   10267:     {
                   10268:       sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
                   10269:       count =  prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
                   10270:       if (count)
                   10271:        {
                   10272:          vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
                   10273:          prefix_bgp_show_prefix_list (vty, AFI_IP, name);
                   10274:        }
                   10275:     }
                   10276: 
                   10277:   return CMD_SUCCESS;
                   10278: }
                   10279: 
                   10280: 
                   10281: #ifdef HAVE_IPV6
                   10282: ALIAS (show_bgp_view_neighbor_received_routes,
                   10283:        show_bgp_neighbor_received_routes_cmd,
                   10284:        "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
                   10285:        SHOW_STR
                   10286:        BGP_STR
                   10287:        "Detailed information on TCP and BGP neighbor connections\n"
                   10288:        "Neighbor to display information about\n"
                   10289:        "Neighbor to display information about\n"
                   10290:        "Display the received routes from neighbor\n")
                   10291: 
                   10292: ALIAS (show_bgp_view_neighbor_received_routes,
                   10293:        show_bgp_ipv6_neighbor_received_routes_cmd,
                   10294:        "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
                   10295:        SHOW_STR
                   10296:        BGP_STR
                   10297:        "Address family\n"
                   10298:        "Detailed information on TCP and BGP neighbor connections\n"
                   10299:        "Neighbor to display information about\n"
                   10300:        "Neighbor to display information about\n"
                   10301:        "Display the received routes from neighbor\n")
                   10302: 
                   10303: DEFUN (show_bgp_neighbor_received_prefix_filter,
                   10304:        show_bgp_neighbor_received_prefix_filter_cmd,
                   10305:        "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
                   10306:        SHOW_STR
                   10307:        BGP_STR
                   10308:        "Detailed information on TCP and BGP neighbor connections\n"
                   10309:        "Neighbor to display information about\n"
                   10310:        "Neighbor to display information about\n"
                   10311:        "Display information received from a BGP neighbor\n"
                   10312:        "Display the prefixlist filter\n")
                   10313: {
                   10314:   char name[BUFSIZ];
                   10315:   union sockunion *su;
                   10316:   struct peer *peer;
                   10317:   int count;
                   10318: 
                   10319:   su = sockunion_str2su (argv[0]);
                   10320:   if (su == NULL)
                   10321:     return CMD_WARNING;
                   10322: 
                   10323:   peer = peer_lookup (NULL, su);
                   10324:   if (! peer)
                   10325:     return CMD_WARNING;
                   10326: 
                   10327:   sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
                   10328:   count =  prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
                   10329:   if (count)
                   10330:     {
                   10331:       vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
                   10332:       prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
                   10333:     }
                   10334: 
                   10335:   return CMD_SUCCESS;
                   10336: }
                   10337: 
                   10338: ALIAS (show_bgp_neighbor_received_prefix_filter,
                   10339:        show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
                   10340:        "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
                   10341:        SHOW_STR
                   10342:        BGP_STR
                   10343:        "Address family\n"
                   10344:        "Detailed information on TCP and BGP neighbor connections\n"
                   10345:        "Neighbor to display information about\n"
                   10346:        "Neighbor to display information about\n"
                   10347:        "Display information received from a BGP neighbor\n"
                   10348:        "Display the prefixlist filter\n")
                   10349: 
                   10350: /* old command */
                   10351: ALIAS (show_bgp_view_neighbor_received_routes,
                   10352:        ipv6_bgp_neighbor_received_routes_cmd,
                   10353:        "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
                   10354:        SHOW_STR
                   10355:        IPV6_STR
                   10356:        BGP_STR
                   10357:        "Detailed information on TCP and BGP neighbor connections\n"
                   10358:        "Neighbor to display information about\n"
                   10359:        "Neighbor to display information about\n"
                   10360:        "Display the received routes from neighbor\n")
                   10361: 
                   10362: /* old command */
                   10363: DEFUN (ipv6_mbgp_neighbor_received_routes,
                   10364:        ipv6_mbgp_neighbor_received_routes_cmd,
                   10365:        "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
                   10366:        SHOW_STR
                   10367:        IPV6_STR
                   10368:        MBGP_STR
                   10369:        "Detailed information on TCP and BGP neighbor connections\n"
                   10370:        "Neighbor to display information about\n"
                   10371:        "Neighbor to display information about\n"
                   10372:        "Display the received routes from neighbor\n")
                   10373: {
                   10374:   struct peer *peer;
                   10375: 
                   10376:   peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   10377:   if (! peer)
                   10378:     return CMD_WARNING;
                   10379: 
                   10380:   return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
                   10381: }
                   10382: 
                   10383: DEFUN (show_bgp_view_neighbor_received_prefix_filter,
                   10384:        show_bgp_view_neighbor_received_prefix_filter_cmd,
                   10385:        "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
                   10386:        SHOW_STR
                   10387:        BGP_STR
                   10388:        "BGP view\n"
                   10389:        "View name\n"
                   10390:        "Detailed information on TCP and BGP neighbor connections\n"
                   10391:        "Neighbor to display information about\n"
                   10392:        "Neighbor to display information about\n"
                   10393:        "Display information received from a BGP neighbor\n"
                   10394:        "Display the prefixlist filter\n")
                   10395: {
                   10396:   char name[BUFSIZ];
                   10397:   union sockunion *su;
                   10398:   struct peer *peer;
                   10399:   struct bgp *bgp;
                   10400:   int count;
                   10401: 
                   10402:   /* BGP structure lookup. */
                   10403:   bgp = bgp_lookup_by_name (argv[0]);
                   10404:   if (bgp == NULL)
                   10405:   {  
                   10406:          vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
                   10407:          return CMD_WARNING;
                   10408:        }
                   10409:   
                   10410:   su = sockunion_str2su (argv[1]);
                   10411:   if (su == NULL)
                   10412:     return CMD_WARNING;
                   10413: 
                   10414:   peer = peer_lookup (bgp, su);
                   10415:   if (! peer)
                   10416:     return CMD_WARNING;
                   10417: 
                   10418:   sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
                   10419:   count =  prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
                   10420:   if (count)
                   10421:     {
                   10422:       vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
                   10423:       prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
                   10424:     }
                   10425: 
                   10426:   return CMD_SUCCESS;
                   10427: }
                   10428: 
                   10429: ALIAS (show_bgp_view_neighbor_received_prefix_filter,
                   10430:        show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
                   10431:        "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
                   10432:        SHOW_STR
                   10433:        BGP_STR
                   10434:        "BGP view\n"
                   10435:        "View name\n"
                   10436:        "Address family\n"
                   10437:        "Detailed information on TCP and BGP neighbor connections\n"
                   10438:        "Neighbor to display information about\n"
                   10439:        "Neighbor to display information about\n"
                   10440:        "Display information received from a BGP neighbor\n"
                   10441:        "Display the prefixlist filter\n")
                   10442: #endif /* HAVE_IPV6 */
                   10443: 
                   10444: static int
                   10445: bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
                   10446:                         safi_t safi, enum bgp_show_type type)
                   10447: {
                   10448:   if (! peer || ! peer->afc[afi][safi])
                   10449:     {
                   10450:       vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
                   10451:       return CMD_WARNING;
                   10452:     }
                   10453:  
                   10454:   return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
                   10455: }
                   10456: 
                   10457: DEFUN (show_ip_bgp_neighbor_routes,
                   10458:        show_ip_bgp_neighbor_routes_cmd,
                   10459:        "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
                   10460:        SHOW_STR
                   10461:        IP_STR
                   10462:        BGP_STR
                   10463:        "Detailed information on TCP and BGP neighbor connections\n"
                   10464:        "Neighbor to display information about\n"
                   10465:        "Neighbor to display information about\n"
                   10466:        "Display routes learned from neighbor\n")
                   10467: {
                   10468:   struct peer *peer;
                   10469: 
                   10470:   peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   10471:   if (! peer)
                   10472:     return CMD_WARNING;
                   10473:     
                   10474:   return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
                   10475:                                  bgp_show_type_neighbor);
                   10476: }
                   10477: 
                   10478: DEFUN (show_ip_bgp_neighbor_flap,
                   10479:        show_ip_bgp_neighbor_flap_cmd,
                   10480:        "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
                   10481:        SHOW_STR
                   10482:        IP_STR
                   10483:        BGP_STR
                   10484:        "Detailed information on TCP and BGP neighbor connections\n"
                   10485:        "Neighbor to display information about\n"
                   10486:        "Neighbor to display information about\n"
                   10487:        "Display flap statistics of the routes learned from neighbor\n")
                   10488: {
                   10489:   struct peer *peer;
                   10490: 
                   10491:   peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   10492:   if (! peer)
                   10493:     return CMD_WARNING;
                   10494:     
                   10495:   return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
                   10496:                                  bgp_show_type_flap_neighbor);
                   10497: }
                   10498: 
                   10499: DEFUN (show_ip_bgp_neighbor_damp,
                   10500:        show_ip_bgp_neighbor_damp_cmd,
                   10501:        "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
                   10502:        SHOW_STR
                   10503:        IP_STR
                   10504:        BGP_STR
                   10505:        "Detailed information on TCP and BGP neighbor connections\n"
                   10506:        "Neighbor to display information about\n"
                   10507:        "Neighbor to display information about\n"
                   10508:        "Display the dampened routes received from neighbor\n")
                   10509: {
                   10510:   struct peer *peer;
                   10511: 
                   10512:   peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   10513:   if (! peer)
                   10514:     return CMD_WARNING;
                   10515:     
                   10516:   return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
                   10517:                                  bgp_show_type_damp_neighbor);
                   10518: }
                   10519: 
                   10520: DEFUN (show_ip_bgp_ipv4_neighbor_routes,
                   10521:        show_ip_bgp_ipv4_neighbor_routes_cmd,
                   10522:        "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
                   10523:        SHOW_STR
                   10524:        IP_STR
                   10525:        BGP_STR
                   10526:        "Address family\n"
                   10527:        "Address Family modifier\n"
                   10528:        "Address Family modifier\n"
                   10529:        "Detailed information on TCP and BGP neighbor connections\n"
                   10530:        "Neighbor to display information about\n"
                   10531:        "Neighbor to display information about\n"
                   10532:        "Display routes learned from neighbor\n")
                   10533: {
                   10534:   struct peer *peer;
                   10535: 
                   10536:   peer = peer_lookup_in_view (vty, NULL, argv[1]);
                   10537:   if (! peer)
                   10538:     return CMD_WARNING;
                   10539:  
                   10540:   if (strncmp (argv[0], "m", 1) == 0)
                   10541:     return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
                   10542:                                    bgp_show_type_neighbor);
                   10543: 
                   10544:   return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
                   10545:                                  bgp_show_type_neighbor);
                   10546: }
                   10547: 
                   10548: DEFUN (show_ip_bgp_view_rsclient,
                   10549:        show_ip_bgp_view_rsclient_cmd,
                   10550:        "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
                   10551:        SHOW_STR
                   10552:        IP_STR
                   10553:        BGP_STR
                   10554:        "BGP view\n"
                   10555:        "BGP view name\n"
                   10556:        "Information about Route Server Client\n"
                   10557:        NEIGHBOR_ADDR_STR)
                   10558: {
                   10559:   struct bgp_table *table;
                   10560:   struct peer *peer;
                   10561: 
                   10562:   if (argc == 2)
                   10563:     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
                   10564:   else
                   10565:     peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   10566: 
                   10567:   if (! peer)
                   10568:     return CMD_WARNING;
                   10569: 
                   10570:   if (! peer->afc[AFI_IP][SAFI_UNICAST])
                   10571:     {
                   10572:       vty_out (vty, "%% Activate the neighbor for the address family first%s",
                   10573:             VTY_NEWLINE);
                   10574:       return CMD_WARNING;
                   10575:     }
                   10576: 
                   10577:   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
                   10578:               PEER_FLAG_RSERVER_CLIENT))
                   10579:     {
                   10580:       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
                   10581:             VTY_NEWLINE);
                   10582:       return CMD_WARNING;
                   10583:     }
                   10584: 
                   10585:   table = peer->rib[AFI_IP][SAFI_UNICAST];
                   10586: 
                   10587:   return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
                   10588: }
                   10589: 
                   10590: ALIAS (show_ip_bgp_view_rsclient,
                   10591:        show_ip_bgp_rsclient_cmd,
                   10592:        "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
                   10593:        SHOW_STR
                   10594:        IP_STR
                   10595:        BGP_STR
                   10596:        "Information about Route Server Client\n"
                   10597:        NEIGHBOR_ADDR_STR)
                   10598: 
                   10599: DEFUN (show_bgp_view_ipv4_safi_rsclient,
                   10600:        show_bgp_view_ipv4_safi_rsclient_cmd,
                   10601:        "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
                   10602:        SHOW_STR
                   10603:        BGP_STR
                   10604:        "BGP view\n"
                   10605:        "BGP view name\n"
                   10606:        "Address family\n"
                   10607:        "Address Family modifier\n"
                   10608:        "Address Family modifier\n"
                   10609:        "Information about Route Server Client\n"
                   10610:        NEIGHBOR_ADDR_STR)
                   10611: {
                   10612:   struct bgp_table *table;
                   10613:   struct peer *peer;
                   10614:   safi_t safi;
                   10615: 
                   10616:   if (argc == 3) {
                   10617:     peer = peer_lookup_in_view (vty, argv[0], argv[2]);
                   10618:     safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   10619:   } else {
                   10620:     peer = peer_lookup_in_view (vty, NULL, argv[1]);
                   10621:     safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   10622:   }
                   10623: 
                   10624:   if (! peer)
                   10625:     return CMD_WARNING;
                   10626: 
                   10627:   if (! peer->afc[AFI_IP][safi])
                   10628:     {
                   10629:       vty_out (vty, "%% Activate the neighbor for the address family first%s",
                   10630:             VTY_NEWLINE);
                   10631:       return CMD_WARNING;
                   10632:     }
                   10633: 
                   10634:   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
                   10635:               PEER_FLAG_RSERVER_CLIENT))
                   10636:     {
                   10637:       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
                   10638:             VTY_NEWLINE);
                   10639:       return CMD_WARNING;
                   10640:     }
                   10641: 
                   10642:   table = peer->rib[AFI_IP][safi];
                   10643: 
                   10644:   return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
                   10645: }
                   10646: 
                   10647: ALIAS (show_bgp_view_ipv4_safi_rsclient,
                   10648:        show_bgp_ipv4_safi_rsclient_cmd,
                   10649:        "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
                   10650:        SHOW_STR
                   10651:        BGP_STR
                   10652:        "Address family\n"
                   10653:        "Address Family modifier\n"
                   10654:        "Address Family modifier\n"
                   10655:        "Information about Route Server Client\n"
                   10656:        NEIGHBOR_ADDR_STR)
                   10657: 
                   10658: DEFUN (show_ip_bgp_view_rsclient_route,
                   10659:        show_ip_bgp_view_rsclient_route_cmd,
                   10660:        "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
                   10661:        SHOW_STR
                   10662:        IP_STR
                   10663:        BGP_STR
                   10664:        "BGP view\n"
                   10665:        "BGP view name\n"
                   10666:        "Information about Route Server Client\n"
                   10667:        NEIGHBOR_ADDR_STR
                   10668:        "Network in the BGP routing table to display\n")
                   10669: {
                   10670:   struct bgp *bgp;
                   10671:   struct peer *peer;
                   10672: 
                   10673:   /* BGP structure lookup. */
                   10674:   if (argc == 3)
                   10675:     {
                   10676:       bgp = bgp_lookup_by_name (argv[0]);
                   10677:       if (bgp == NULL)
                   10678:        {
                   10679:          vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
                   10680:          return CMD_WARNING;
                   10681:        }
                   10682:     }
                   10683:   else
                   10684:     {
                   10685:       bgp = bgp_get_default ();
                   10686:       if (bgp == NULL)
                   10687:        {
                   10688:          vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
                   10689:          return CMD_WARNING;
                   10690:        }
                   10691:     }
                   10692: 
                   10693:   if (argc == 3)
                   10694:     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
                   10695:   else
                   10696:     peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   10697: 
                   10698:   if (! peer)
                   10699:     return CMD_WARNING;
                   10700: 
                   10701:   if (! peer->afc[AFI_IP][SAFI_UNICAST])
                   10702:     {
                   10703:       vty_out (vty, "%% Activate the neighbor for the address family first%s",
                   10704:             VTY_NEWLINE);
                   10705:       return CMD_WARNING;
                   10706: }
                   10707: 
                   10708:   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
                   10709:               PEER_FLAG_RSERVER_CLIENT))
                   10710:     {
                   10711:       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
                   10712:             VTY_NEWLINE);
                   10713:       return CMD_WARNING;
                   10714:     }
                   10715:  
                   10716:   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST], 
                   10717:                                   (argc == 3) ? argv[2] : argv[1],
                   10718:                                   AFI_IP, SAFI_UNICAST, NULL, 0);
                   10719: }
                   10720: 
                   10721: ALIAS (show_ip_bgp_view_rsclient_route,
                   10722:        show_ip_bgp_rsclient_route_cmd,
                   10723:        "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
                   10724:        SHOW_STR
                   10725:        IP_STR
                   10726:        BGP_STR
                   10727:        "Information about Route Server Client\n"
                   10728:        NEIGHBOR_ADDR_STR
                   10729:        "Network in the BGP routing table to display\n")
                   10730: 
                   10731: DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
                   10732:        show_bgp_view_ipv4_safi_rsclient_route_cmd,
                   10733:        "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
                   10734:        SHOW_STR
                   10735:        BGP_STR
                   10736:        "BGP view\n"
                   10737:        "BGP view name\n"
                   10738:        "Address family\n"
                   10739:        "Address Family modifier\n"
                   10740:        "Address Family modifier\n"
                   10741:        "Information about Route Server Client\n"
                   10742:        NEIGHBOR_ADDR_STR
                   10743:        "Network in the BGP routing table to display\n")
                   10744: {
                   10745:   struct bgp *bgp;
                   10746:   struct peer *peer;
                   10747:   safi_t safi;
                   10748: 
                   10749:   /* BGP structure lookup. */
                   10750:   if (argc == 4)
                   10751:     {
                   10752:       bgp = bgp_lookup_by_name (argv[0]);
                   10753:       if (bgp == NULL)
                   10754:        {
                   10755:          vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
                   10756:          return CMD_WARNING;
                   10757:        }
                   10758:     }
                   10759:   else
                   10760:     {
                   10761:       bgp = bgp_get_default ();
                   10762:       if (bgp == NULL)
                   10763:        {
                   10764:          vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
                   10765:          return CMD_WARNING;
                   10766:        }
                   10767:     }
                   10768: 
                   10769:   if (argc == 4) {
                   10770:     peer = peer_lookup_in_view (vty, argv[0], argv[2]);
                   10771:     safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   10772:   } else {
                   10773:     peer = peer_lookup_in_view (vty, NULL, argv[1]);
                   10774:     safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   10775:   }
                   10776: 
                   10777:   if (! peer)
                   10778:     return CMD_WARNING;
                   10779: 
                   10780:   if (! peer->afc[AFI_IP][safi])
                   10781:     {
                   10782:       vty_out (vty, "%% Activate the neighbor for the address family first%s",
                   10783:             VTY_NEWLINE);
                   10784:       return CMD_WARNING;
                   10785: }
                   10786: 
                   10787:   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
                   10788:               PEER_FLAG_RSERVER_CLIENT))
                   10789:     {
                   10790:       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
                   10791:             VTY_NEWLINE);
                   10792:       return CMD_WARNING;
                   10793:     }
                   10794: 
                   10795:   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
                   10796:                                   (argc == 4) ? argv[3] : argv[2],
                   10797:                                   AFI_IP, safi, NULL, 0);
                   10798: }
                   10799: 
                   10800: ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
                   10801:        show_bgp_ipv4_safi_rsclient_route_cmd,
                   10802:        "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
                   10803:        SHOW_STR
                   10804:        BGP_STR
                   10805:        "Address family\n"
                   10806:        "Address Family modifier\n"
                   10807:        "Address Family modifier\n"
                   10808:        "Information about Route Server Client\n"
                   10809:        NEIGHBOR_ADDR_STR
                   10810:        "Network in the BGP routing table to display\n")
                   10811: 
                   10812: DEFUN (show_ip_bgp_view_rsclient_prefix,
                   10813:        show_ip_bgp_view_rsclient_prefix_cmd,
                   10814:        "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
                   10815:        SHOW_STR
                   10816:        IP_STR
                   10817:        BGP_STR
                   10818:        "BGP view\n"
                   10819:        "BGP view name\n"
                   10820:        "Information about Route Server Client\n"
                   10821:        NEIGHBOR_ADDR_STR
                   10822:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
                   10823: {
                   10824:   struct bgp *bgp;
                   10825:   struct peer *peer;
                   10826: 
                   10827:   /* BGP structure lookup. */
                   10828:   if (argc == 3)
                   10829:     {
                   10830:       bgp = bgp_lookup_by_name (argv[0]);
                   10831:       if (bgp == NULL)
                   10832:        {
                   10833:          vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
                   10834:          return CMD_WARNING;
                   10835:        }
                   10836:     }
                   10837:   else
                   10838:     {
                   10839:       bgp = bgp_get_default ();
                   10840:       if (bgp == NULL)
                   10841:        {
                   10842:          vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
                   10843:          return CMD_WARNING;
                   10844:        }
                   10845:     }
                   10846: 
                   10847:   if (argc == 3)
                   10848:     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
                   10849:   else
                   10850:   peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   10851: 
                   10852:   if (! peer)
                   10853:     return CMD_WARNING;
                   10854:     
                   10855:   if (! peer->afc[AFI_IP][SAFI_UNICAST])
                   10856:     {
                   10857:       vty_out (vty, "%% Activate the neighbor for the address family first%s",
                   10858:             VTY_NEWLINE);
                   10859:       return CMD_WARNING;
                   10860: }
                   10861: 
                   10862:   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
                   10863:               PEER_FLAG_RSERVER_CLIENT))
                   10864: {
                   10865:       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
                   10866:             VTY_NEWLINE);
                   10867:     return CMD_WARNING;
                   10868:     }
                   10869:     
                   10870:   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST], 
                   10871:                                   (argc == 3) ? argv[2] : argv[1],
                   10872:                                   AFI_IP, SAFI_UNICAST, NULL, 1);
                   10873: }
                   10874: 
                   10875: ALIAS (show_ip_bgp_view_rsclient_prefix,
                   10876:        show_ip_bgp_rsclient_prefix_cmd,
                   10877:        "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
                   10878:        SHOW_STR
                   10879:        IP_STR
                   10880:        BGP_STR
                   10881:        "Information about Route Server Client\n"
                   10882:        NEIGHBOR_ADDR_STR
                   10883:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
                   10884: 
                   10885: DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
                   10886:        show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
                   10887:        "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
                   10888:        SHOW_STR
                   10889:        BGP_STR
                   10890:        "BGP view\n"
                   10891:        "BGP view name\n"
                   10892:        "Address family\n"
                   10893:        "Address Family modifier\n"
                   10894:        "Address Family modifier\n"
                   10895:        "Information about Route Server Client\n"
                   10896:        NEIGHBOR_ADDR_STR
                   10897:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
                   10898: {
                   10899:   struct bgp *bgp;
                   10900:   struct peer *peer;
                   10901:   safi_t safi;
                   10902: 
                   10903:   /* BGP structure lookup. */
                   10904:   if (argc == 4)
                   10905:     {
                   10906:       bgp = bgp_lookup_by_name (argv[0]);
                   10907:       if (bgp == NULL)
                   10908:        {
                   10909:          vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
                   10910:          return CMD_WARNING;
                   10911:        }
                   10912:     }
                   10913:   else
                   10914:     {
                   10915:       bgp = bgp_get_default ();
                   10916:       if (bgp == NULL)
                   10917:        {
                   10918:          vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
                   10919:          return CMD_WARNING;
                   10920:        }
                   10921:     }
                   10922: 
                   10923:   if (argc == 4) {
                   10924:     peer = peer_lookup_in_view (vty, argv[0], argv[2]);
                   10925:     safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   10926:   } else {
                   10927:     peer = peer_lookup_in_view (vty, NULL, argv[1]);
                   10928:     safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   10929:   }
                   10930: 
                   10931:   if (! peer)
                   10932:     return CMD_WARNING;
                   10933: 
                   10934:   if (! peer->afc[AFI_IP][safi])
                   10935:     {
                   10936:       vty_out (vty, "%% Activate the neighbor for the address family first%s",
                   10937:             VTY_NEWLINE);
                   10938:       return CMD_WARNING;
                   10939: }
                   10940: 
                   10941:   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
                   10942:               PEER_FLAG_RSERVER_CLIENT))
                   10943: {
                   10944:       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
                   10945:             VTY_NEWLINE);
                   10946:     return CMD_WARNING;
                   10947:     }
                   10948: 
                   10949:   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
                   10950:                                   (argc == 4) ? argv[3] : argv[2],
                   10951:                                   AFI_IP, safi, NULL, 1);
                   10952: }
                   10953: 
                   10954: ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
                   10955:        show_bgp_ipv4_safi_rsclient_prefix_cmd,
                   10956:        "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
                   10957:        SHOW_STR
                   10958:        BGP_STR
                   10959:        "Address family\n"
                   10960:        "Address Family modifier\n"
                   10961:        "Address Family modifier\n"
                   10962:        "Information about Route Server Client\n"
                   10963:        NEIGHBOR_ADDR_STR
                   10964:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
                   10965: 
                   10966: #ifdef HAVE_IPV6
                   10967: DEFUN (show_bgp_view_neighbor_routes,
                   10968:        show_bgp_view_neighbor_routes_cmd,
                   10969:        "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
                   10970:        SHOW_STR
                   10971:        BGP_STR
                   10972:        "BGP view\n"
                   10973:        "BGP view name\n"
                   10974:        "Detailed information on TCP and BGP neighbor connections\n"
                   10975:        "Neighbor to display information about\n"
                   10976:        "Neighbor to display information about\n"
                   10977:        "Display routes learned from neighbor\n")
                   10978: {
                   10979:   struct peer *peer;
                   10980: 
                   10981:   if (argc == 2)
                   10982:     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
                   10983:   else
                   10984:     peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   10985:    
                   10986:   if (! peer)
                   10987:     return CMD_WARNING;
                   10988: 
                   10989:   return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
                   10990:                                  bgp_show_type_neighbor);
                   10991: }
                   10992: 
                   10993: ALIAS (show_bgp_view_neighbor_routes,
                   10994:        show_bgp_view_ipv6_neighbor_routes_cmd,
                   10995:        "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
                   10996:        SHOW_STR
                   10997:        BGP_STR
                   10998:        "BGP view\n"
                   10999:        "BGP view name\n"
                   11000:        "Address family\n"
                   11001:        "Detailed information on TCP and BGP neighbor connections\n"
                   11002:        "Neighbor to display information about\n"
                   11003:        "Neighbor to display information about\n"
                   11004:        "Display routes learned from neighbor\n")
                   11005: 
                   11006: DEFUN (show_bgp_view_neighbor_damp,
                   11007:        show_bgp_view_neighbor_damp_cmd,
                   11008:        "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
                   11009:        SHOW_STR
                   11010:        BGP_STR
                   11011:        "BGP view\n"
                   11012:        "BGP view name\n"
                   11013:        "Detailed information on TCP and BGP neighbor connections\n"
                   11014:        "Neighbor to display information about\n"
                   11015:        "Neighbor to display information about\n"
                   11016:        "Display the dampened routes received from neighbor\n")
                   11017: {
                   11018:   struct peer *peer;
                   11019: 
                   11020:   if (argc == 2)
                   11021:     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
                   11022:   else
                   11023:     peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   11024: 
                   11025:   if (! peer)
                   11026:     return CMD_WARNING;
                   11027: 
                   11028:   return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
                   11029:                                  bgp_show_type_damp_neighbor);
                   11030: }
                   11031: 
                   11032: ALIAS (show_bgp_view_neighbor_damp,
                   11033:        show_bgp_view_ipv6_neighbor_damp_cmd,
                   11034:        "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
                   11035:        SHOW_STR
                   11036:        BGP_STR
                   11037:        "BGP view\n"
                   11038:        "BGP view name\n"
                   11039:        "Address family\n"
                   11040:        "Detailed information on TCP and BGP neighbor connections\n"
                   11041:        "Neighbor to display information about\n"
                   11042:        "Neighbor to display information about\n"
                   11043:        "Display the dampened routes received from neighbor\n")
                   11044: 
                   11045: DEFUN (show_bgp_view_neighbor_flap,
                   11046:        show_bgp_view_neighbor_flap_cmd,
                   11047:        "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
                   11048:        SHOW_STR
                   11049:        BGP_STR
                   11050:        "BGP view\n"
                   11051:        "BGP view name\n"
                   11052:        "Detailed information on TCP and BGP neighbor connections\n"
                   11053:        "Neighbor to display information about\n"
                   11054:        "Neighbor to display information about\n"
                   11055:        "Display flap statistics of the routes learned from neighbor\n")
                   11056: {
                   11057:   struct peer *peer;
                   11058: 
                   11059:   if (argc == 2)
                   11060:     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
                   11061:   else
                   11062:     peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   11063: 
                   11064:   if (! peer)
                   11065:     return CMD_WARNING;
                   11066: 
                   11067:   return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
                   11068:                                  bgp_show_type_flap_neighbor);
                   11069: }
                   11070: 
                   11071: ALIAS (show_bgp_view_neighbor_flap,
                   11072:        show_bgp_view_ipv6_neighbor_flap_cmd,
                   11073:        "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
                   11074:        SHOW_STR
                   11075:        BGP_STR
                   11076:        "BGP view\n"
                   11077:        "BGP view name\n"
                   11078:        "Address family\n"
                   11079:        "Detailed information on TCP and BGP neighbor connections\n"
                   11080:        "Neighbor to display information about\n"
                   11081:        "Neighbor to display information about\n"
                   11082:        "Display flap statistics of the routes learned from neighbor\n")
                   11083:        
                   11084: ALIAS (show_bgp_view_neighbor_routes,
                   11085:        show_bgp_neighbor_routes_cmd,
                   11086:        "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
                   11087:        SHOW_STR
                   11088:        BGP_STR
                   11089:        "Detailed information on TCP and BGP neighbor connections\n"
                   11090:        "Neighbor to display information about\n"
                   11091:        "Neighbor to display information about\n"
                   11092:        "Display routes learned from neighbor\n")
                   11093: 
                   11094: 
                   11095: ALIAS (show_bgp_view_neighbor_routes,
                   11096:        show_bgp_ipv6_neighbor_routes_cmd,
                   11097:        "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
                   11098:        SHOW_STR
                   11099:        BGP_STR
                   11100:        "Address family\n"
                   11101:        "Detailed information on TCP and BGP neighbor connections\n"
                   11102:        "Neighbor to display information about\n"
                   11103:        "Neighbor to display information about\n"
                   11104:        "Display routes learned from neighbor\n")
                   11105: 
                   11106: /* old command */
                   11107: ALIAS (show_bgp_view_neighbor_routes,
                   11108:        ipv6_bgp_neighbor_routes_cmd,
                   11109:        "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
                   11110:        SHOW_STR
                   11111:        IPV6_STR
                   11112:        BGP_STR
                   11113:        "Detailed information on TCP and BGP neighbor connections\n"
                   11114:        "Neighbor to display information about\n"
                   11115:        "Neighbor to display information about\n"
                   11116:        "Display routes learned from neighbor\n")
                   11117: 
                   11118: /* old command */
                   11119: DEFUN (ipv6_mbgp_neighbor_routes,
                   11120:        ipv6_mbgp_neighbor_routes_cmd,
                   11121:        "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
                   11122:        SHOW_STR
                   11123:        IPV6_STR
                   11124:        MBGP_STR
                   11125:        "Detailed information on TCP and BGP neighbor connections\n"
                   11126:        "Neighbor to display information about\n"
                   11127:        "Neighbor to display information about\n"
                   11128:        "Display routes learned from neighbor\n")
                   11129: {
                   11130:   struct peer *peer;
                   11131: 
                   11132:   peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   11133:   if (! peer)
                   11134:     return CMD_WARNING;
                   11135:  
                   11136:   return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
                   11137:                                  bgp_show_type_neighbor);
                   11138: }
                   11139: 
                   11140: ALIAS (show_bgp_view_neighbor_flap,
                   11141:        show_bgp_neighbor_flap_cmd,
                   11142:        "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
                   11143:        SHOW_STR
                   11144:        BGP_STR
                   11145:        "Detailed information on TCP and BGP neighbor connections\n"
                   11146:        "Neighbor to display information about\n"
                   11147:        "Neighbor to display information about\n"
                   11148:        "Display flap statistics of the routes learned from neighbor\n")
                   11149: 
                   11150: ALIAS (show_bgp_view_neighbor_flap,
                   11151:        show_bgp_ipv6_neighbor_flap_cmd,
                   11152:        "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
                   11153:        SHOW_STR
                   11154:        BGP_STR
                   11155:        "Address family\n"
                   11156:        "Detailed information on TCP and BGP neighbor connections\n"
                   11157:        "Neighbor to display information about\n"
                   11158:        "Neighbor to display information about\n"
                   11159:        "Display flap statistics of the routes learned from neighbor\n")
                   11160: 
                   11161: ALIAS (show_bgp_view_neighbor_damp,
                   11162:        show_bgp_neighbor_damp_cmd,
                   11163:        "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
                   11164:        SHOW_STR
                   11165:        BGP_STR
                   11166:        "Detailed information on TCP and BGP neighbor connections\n"
                   11167:        "Neighbor to display information about\n"
                   11168:        "Neighbor to display information about\n"
                   11169:        "Display the dampened routes received from neighbor\n")
                   11170: 
                   11171: ALIAS (show_bgp_view_neighbor_damp,
                   11172:        show_bgp_ipv6_neighbor_damp_cmd,
                   11173:        "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
                   11174:        SHOW_STR
                   11175:        BGP_STR
                   11176:        "Address family\n"
                   11177:        "Detailed information on TCP and BGP neighbor connections\n"
                   11178:        "Neighbor to display information about\n"
                   11179:        "Neighbor to display information about\n"
                   11180:        "Display the dampened routes received from neighbor\n")
                   11181: 
                   11182: DEFUN (show_bgp_view_rsclient,
                   11183:        show_bgp_view_rsclient_cmd,
                   11184:        "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
                   11185:        SHOW_STR
                   11186:        BGP_STR
                   11187:        "BGP view\n"
                   11188:        "BGP view name\n"
                   11189:        "Information about Route Server Client\n"
                   11190:        NEIGHBOR_ADDR_STR)
                   11191: {
                   11192:   struct bgp_table *table;
                   11193:   struct peer *peer;
                   11194: 
                   11195:   if (argc == 2)
                   11196:     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
                   11197:   else
                   11198:     peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   11199: 
                   11200:   if (! peer)
                   11201:     return CMD_WARNING;
                   11202: 
                   11203:   if (! peer->afc[AFI_IP6][SAFI_UNICAST])
                   11204:     {
                   11205:       vty_out (vty, "%% Activate the neighbor for the address family first%s",
                   11206:             VTY_NEWLINE);
                   11207:       return CMD_WARNING;
                   11208:     }
                   11209: 
                   11210:   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
                   11211:               PEER_FLAG_RSERVER_CLIENT))
                   11212:     {
                   11213:       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
                   11214:             VTY_NEWLINE);
                   11215:       return CMD_WARNING;
                   11216:     }
                   11217: 
                   11218:   table = peer->rib[AFI_IP6][SAFI_UNICAST];
                   11219: 
                   11220:   return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
                   11221: }
                   11222: 
                   11223: ALIAS (show_bgp_view_rsclient,
                   11224:        show_bgp_rsclient_cmd,
                   11225:        "show bgp rsclient (A.B.C.D|X:X::X:X)",
                   11226:        SHOW_STR
                   11227:        BGP_STR
                   11228:        "Information about Route Server Client\n"
                   11229:        NEIGHBOR_ADDR_STR)
                   11230: 
                   11231: DEFUN (show_bgp_view_ipv6_safi_rsclient,
                   11232:        show_bgp_view_ipv6_safi_rsclient_cmd,
                   11233:        "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
                   11234:        SHOW_STR
                   11235:        BGP_STR
                   11236:        "BGP view\n"
                   11237:        "BGP view name\n"
                   11238:        "Address family\n"
                   11239:        "Address Family modifier\n"
                   11240:        "Address Family modifier\n"
                   11241:        "Information about Route Server Client\n"
                   11242:        NEIGHBOR_ADDR_STR)
                   11243: {
                   11244:   struct bgp_table *table;
                   11245:   struct peer *peer;
                   11246:   safi_t safi;
                   11247: 
                   11248:   if (argc == 3) {
                   11249:     peer = peer_lookup_in_view (vty, argv[0], argv[2]);
                   11250:     safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   11251:   } else {
                   11252:     peer = peer_lookup_in_view (vty, NULL, argv[1]);
                   11253:     safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   11254:   }
                   11255: 
                   11256:   if (! peer)
                   11257:     return CMD_WARNING;
                   11258: 
                   11259:   if (! peer->afc[AFI_IP6][safi])
                   11260:     {
                   11261:       vty_out (vty, "%% Activate the neighbor for the address family first%s",
                   11262:             VTY_NEWLINE);
                   11263:       return CMD_WARNING;
                   11264:     }
                   11265: 
                   11266:   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
                   11267:               PEER_FLAG_RSERVER_CLIENT))
                   11268:     {
                   11269:       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
                   11270:             VTY_NEWLINE);
                   11271:       return CMD_WARNING;
                   11272:     }
                   11273: 
                   11274:   table = peer->rib[AFI_IP6][safi];
                   11275: 
                   11276:   return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
                   11277: }
                   11278: 
                   11279: ALIAS (show_bgp_view_ipv6_safi_rsclient,
                   11280:        show_bgp_ipv6_safi_rsclient_cmd,
                   11281:        "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
                   11282:        SHOW_STR
                   11283:        BGP_STR
                   11284:        "Address family\n"
                   11285:        "Address Family modifier\n"
                   11286:        "Address Family modifier\n"
                   11287:        "Information about Route Server Client\n"
                   11288:        NEIGHBOR_ADDR_STR)
                   11289: 
                   11290: DEFUN (show_bgp_view_rsclient_route,
                   11291:        show_bgp_view_rsclient_route_cmd,
                   11292:        "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
                   11293:        SHOW_STR
                   11294:        BGP_STR
                   11295:        "BGP view\n"
                   11296:        "BGP view name\n"
                   11297:        "Information about Route Server Client\n"
                   11298:        NEIGHBOR_ADDR_STR
                   11299:        "Network in the BGP routing table to display\n")
                   11300: {
                   11301:   struct bgp *bgp;
                   11302:   struct peer *peer;
                   11303: 
                   11304:   /* BGP structure lookup. */
                   11305:   if (argc == 3)
                   11306:     {
                   11307:       bgp = bgp_lookup_by_name (argv[0]);
                   11308:       if (bgp == NULL)
                   11309:         {
                   11310:           vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
                   11311:           return CMD_WARNING;
                   11312:         }
                   11313:     }
                   11314:   else
                   11315:     {
                   11316:       bgp = bgp_get_default ();
                   11317:       if (bgp == NULL)
                   11318:         {
                   11319:           vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
                   11320:           return CMD_WARNING;
                   11321:         }
                   11322:     }
                   11323: 
                   11324:   if (argc == 3)
                   11325:     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
                   11326:   else
                   11327:     peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   11328: 
                   11329:   if (! peer)
                   11330:     return CMD_WARNING;
                   11331: 
                   11332:   if (! peer->afc[AFI_IP6][SAFI_UNICAST])
                   11333:     {
                   11334:       vty_out (vty, "%% Activate the neighbor for the address family first%s",
                   11335:             VTY_NEWLINE);
                   11336:       return CMD_WARNING;
                   11337:     }
                   11338: 
                   11339:   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
                   11340:               PEER_FLAG_RSERVER_CLIENT))
                   11341:     {
                   11342:       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
                   11343:             VTY_NEWLINE);
                   11344:       return CMD_WARNING;
                   11345:     }
                   11346: 
                   11347:   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
                   11348:                                   (argc == 3) ? argv[2] : argv[1],
                   11349:                                   AFI_IP6, SAFI_UNICAST, NULL, 0);
                   11350: }
                   11351: 
                   11352: ALIAS (show_bgp_view_rsclient_route,
                   11353:        show_bgp_rsclient_route_cmd,
                   11354:        "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
                   11355:        SHOW_STR
                   11356:        BGP_STR
                   11357:        "Information about Route Server Client\n"
                   11358:        NEIGHBOR_ADDR_STR
                   11359:        "Network in the BGP routing table to display\n")
                   11360: 
                   11361: DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
                   11362:        show_bgp_view_ipv6_safi_rsclient_route_cmd,
                   11363:        "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
                   11364:        SHOW_STR
                   11365:        BGP_STR
                   11366:        "BGP view\n"
                   11367:        "BGP view name\n"
                   11368:        "Address family\n"
                   11369:        "Address Family modifier\n"
                   11370:        "Address Family modifier\n"
                   11371:        "Information about Route Server Client\n"
                   11372:        NEIGHBOR_ADDR_STR
                   11373:        "Network in the BGP routing table to display\n")
                   11374: {
                   11375:   struct bgp *bgp;
                   11376:   struct peer *peer;
                   11377:   safi_t safi;
                   11378: 
                   11379:   /* BGP structure lookup. */
                   11380:   if (argc == 4)
                   11381:     {
                   11382:       bgp = bgp_lookup_by_name (argv[0]);
                   11383:       if (bgp == NULL)
                   11384:        {
                   11385:          vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
                   11386:          return CMD_WARNING;
                   11387:        }
                   11388:     }
                   11389:   else
                   11390:     {
                   11391:       bgp = bgp_get_default ();
                   11392:       if (bgp == NULL)
                   11393:        {
                   11394:          vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
                   11395:          return CMD_WARNING;
                   11396:        }
                   11397:     }
                   11398: 
                   11399:   if (argc == 4) {
                   11400:     peer = peer_lookup_in_view (vty, argv[0], argv[2]);
                   11401:     safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   11402:   } else {
                   11403:     peer = peer_lookup_in_view (vty, NULL, argv[1]);
                   11404:     safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   11405:   }
                   11406: 
                   11407:   if (! peer)
                   11408:     return CMD_WARNING;
                   11409: 
                   11410:   if (! peer->afc[AFI_IP6][safi])
                   11411:     {
                   11412:       vty_out (vty, "%% Activate the neighbor for the address family first%s",
                   11413:             VTY_NEWLINE);
                   11414:       return CMD_WARNING;
                   11415: }
                   11416: 
                   11417:   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
                   11418:               PEER_FLAG_RSERVER_CLIENT))
                   11419:     {
                   11420:       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
                   11421:             VTY_NEWLINE);
                   11422:       return CMD_WARNING;
                   11423:     }
                   11424: 
                   11425:   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
                   11426:                                   (argc == 4) ? argv[3] : argv[2],
                   11427:                                   AFI_IP6, safi, NULL, 0);
                   11428: }
                   11429: 
                   11430: ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
                   11431:        show_bgp_ipv6_safi_rsclient_route_cmd,
                   11432:        "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
                   11433:        SHOW_STR
                   11434:        BGP_STR
                   11435:        "Address family\n"
                   11436:        "Address Family modifier\n"
                   11437:        "Address Family modifier\n"
                   11438:        "Information about Route Server Client\n"
                   11439:        NEIGHBOR_ADDR_STR
                   11440:        "Network in the BGP routing table to display\n")
                   11441: 
                   11442: DEFUN (show_bgp_view_rsclient_prefix,
                   11443:        show_bgp_view_rsclient_prefix_cmd,
                   11444:        "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
                   11445:        SHOW_STR
                   11446:        BGP_STR
                   11447:        "BGP view\n"
                   11448:        "BGP view name\n"
                   11449:        "Information about Route Server Client\n"
                   11450:        NEIGHBOR_ADDR_STR
                   11451:        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
                   11452: {
                   11453:   struct bgp *bgp;
                   11454:   struct peer *peer;
                   11455: 
                   11456:   /* BGP structure lookup. */
                   11457:   if (argc == 3)
                   11458:     {
                   11459:       bgp = bgp_lookup_by_name (argv[0]);
                   11460:       if (bgp == NULL)
                   11461:         {
                   11462:           vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
                   11463:           return CMD_WARNING;
                   11464:         }
                   11465:     }
                   11466:   else
                   11467:     {
                   11468:       bgp = bgp_get_default ();
                   11469:       if (bgp == NULL)
                   11470:         {
                   11471:           vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
                   11472:           return CMD_WARNING;
                   11473:         }
                   11474:     }
                   11475: 
                   11476:   if (argc == 3)
                   11477:     peer = peer_lookup_in_view (vty, argv[0], argv[1]);
                   11478:   else
                   11479:     peer = peer_lookup_in_view (vty, NULL, argv[0]);
                   11480: 
                   11481:   if (! peer)
                   11482:     return CMD_WARNING;
                   11483: 
                   11484:   if (! peer->afc[AFI_IP6][SAFI_UNICAST])
                   11485:     {
                   11486:       vty_out (vty, "%% Activate the neighbor for the address family first%s",
                   11487:             VTY_NEWLINE);
                   11488:       return CMD_WARNING;
                   11489:     }
                   11490: 
                   11491:   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
                   11492:               PEER_FLAG_RSERVER_CLIENT))
                   11493:     {
                   11494:       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
                   11495:             VTY_NEWLINE);
                   11496:       return CMD_WARNING;
                   11497:     }
                   11498: 
                   11499:   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
                   11500:                                   (argc == 3) ? argv[2] : argv[1],
                   11501:                                   AFI_IP6, SAFI_UNICAST, NULL, 1);
                   11502: }
                   11503: 
                   11504: ALIAS (show_bgp_view_rsclient_prefix,
                   11505:        show_bgp_rsclient_prefix_cmd,
                   11506:        "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
                   11507:        SHOW_STR
                   11508:        BGP_STR
                   11509:        "Information about Route Server Client\n"
                   11510:        NEIGHBOR_ADDR_STR
                   11511:        "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
                   11512: 
                   11513: DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
                   11514:        show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
                   11515:        "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
                   11516:        SHOW_STR
                   11517:        BGP_STR
                   11518:        "BGP view\n"
                   11519:        "BGP view name\n"
                   11520:        "Address family\n"
                   11521:        "Address Family modifier\n"
                   11522:        "Address Family modifier\n"
                   11523:        "Information about Route Server Client\n"
                   11524:        NEIGHBOR_ADDR_STR
                   11525:        "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
                   11526: {
                   11527:   struct bgp *bgp;
                   11528:   struct peer *peer;
                   11529:   safi_t safi;
                   11530: 
                   11531:   /* BGP structure lookup. */
                   11532:   if (argc == 4)
                   11533:     {
                   11534:       bgp = bgp_lookup_by_name (argv[0]);
                   11535:       if (bgp == NULL)
                   11536:        {
                   11537:          vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
                   11538:          return CMD_WARNING;
                   11539:        }
                   11540:     }
                   11541:   else
                   11542:     {
                   11543:       bgp = bgp_get_default ();
                   11544:       if (bgp == NULL)
                   11545:        {
                   11546:          vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
                   11547:          return CMD_WARNING;
                   11548:        }
                   11549:     }
                   11550: 
                   11551:   if (argc == 4) {
                   11552:     peer = peer_lookup_in_view (vty, argv[0], argv[2]);
                   11553:     safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   11554:   } else {
                   11555:     peer = peer_lookup_in_view (vty, NULL, argv[1]);
                   11556:     safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
                   11557:   }
                   11558: 
                   11559:   if (! peer)
                   11560:     return CMD_WARNING;
                   11561: 
                   11562:   if (! peer->afc[AFI_IP6][safi])
                   11563:     {
                   11564:       vty_out (vty, "%% Activate the neighbor for the address family first%s",
                   11565:             VTY_NEWLINE);
                   11566:       return CMD_WARNING;
                   11567: }
                   11568: 
                   11569:   if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
                   11570:               PEER_FLAG_RSERVER_CLIENT))
                   11571: {
                   11572:       vty_out (vty, "%% Neighbor is not a Route-Server client%s",
                   11573:             VTY_NEWLINE);
                   11574:     return CMD_WARNING;
                   11575:     }
                   11576: 
                   11577:   return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
                   11578:                                   (argc == 4) ? argv[3] : argv[2],
                   11579:                                   AFI_IP6, safi, NULL, 1);
                   11580: }
                   11581: 
                   11582: ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
                   11583:        show_bgp_ipv6_safi_rsclient_prefix_cmd,
                   11584:        "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
                   11585:        SHOW_STR
                   11586:        BGP_STR
                   11587:        "Address family\n"
                   11588:        "Address Family modifier\n"
                   11589:        "Address Family modifier\n"
                   11590:        "Information about Route Server Client\n"
                   11591:        NEIGHBOR_ADDR_STR
                   11592:        "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
                   11593: 
                   11594: #endif /* HAVE_IPV6 */
                   11595: 
                   11596: struct bgp_table *bgp_distance_table;
                   11597: 
                   11598: struct bgp_distance
                   11599: {
                   11600:   /* Distance value for the IP source prefix. */
                   11601:   u_char distance;
                   11602: 
                   11603:   /* Name of the access-list to be matched. */
                   11604:   char *access_list;
                   11605: };
                   11606: 
                   11607: static struct bgp_distance *
                   11608: bgp_distance_new (void)
                   11609: {
                   11610:   return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
                   11611: }
                   11612: 
                   11613: static void
                   11614: bgp_distance_free (struct bgp_distance *bdistance)
                   11615: {
                   11616:   XFREE (MTYPE_BGP_DISTANCE, bdistance);
                   11617: }
                   11618: 
                   11619: static int
                   11620: bgp_distance_set (struct vty *vty, const char *distance_str, 
                   11621:                   const char *ip_str, const char *access_list_str)
                   11622: {
                   11623:   int ret;
                   11624:   struct prefix_ipv4 p;
                   11625:   u_char distance;
                   11626:   struct bgp_node *rn;
                   11627:   struct bgp_distance *bdistance;
                   11628: 
                   11629:   ret = str2prefix_ipv4 (ip_str, &p);
                   11630:   if (ret == 0)
                   11631:     {
                   11632:       vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
                   11633:       return CMD_WARNING;
                   11634:     }
                   11635: 
                   11636:   distance = atoi (distance_str);
                   11637: 
                   11638:   /* Get BGP distance node. */
                   11639:   rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
                   11640:   if (rn->info)
                   11641:     {
                   11642:       bdistance = rn->info;
                   11643:       bgp_unlock_node (rn);
                   11644:     }
                   11645:   else
                   11646:     {
                   11647:       bdistance = bgp_distance_new ();
                   11648:       rn->info = bdistance;
                   11649:     }
                   11650: 
                   11651:   /* Set distance value. */
                   11652:   bdistance->distance = distance;
                   11653: 
                   11654:   /* Reset access-list configuration. */
                   11655:   if (bdistance->access_list)
                   11656:     {
                   11657:       free (bdistance->access_list);
                   11658:       bdistance->access_list = NULL;
                   11659:     }
                   11660:   if (access_list_str)
                   11661:     bdistance->access_list = strdup (access_list_str);
                   11662: 
                   11663:   return CMD_SUCCESS;
                   11664: }
                   11665: 
                   11666: static int
                   11667: bgp_distance_unset (struct vty *vty, const char *distance_str, 
                   11668:                     const char *ip_str, const char *access_list_str)
                   11669: {
                   11670:   int ret;
                   11671:   struct prefix_ipv4 p;
                   11672:   u_char distance;
                   11673:   struct bgp_node *rn;
                   11674:   struct bgp_distance *bdistance;
                   11675: 
                   11676:   ret = str2prefix_ipv4 (ip_str, &p);
                   11677:   if (ret == 0)
                   11678:     {
                   11679:       vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
                   11680:       return CMD_WARNING;
                   11681:     }
                   11682: 
                   11683:   distance = atoi (distance_str);
                   11684: 
                   11685:   rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
                   11686:   if (! rn)
                   11687:     {
                   11688:       vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
                   11689:       return CMD_WARNING;
                   11690:     }
                   11691: 
                   11692:   bdistance = rn->info;
                   11693: 
                   11694:   if (bdistance->access_list)
                   11695:     free (bdistance->access_list);
                   11696:   bgp_distance_free (bdistance);
                   11697: 
                   11698:   rn->info = NULL;
                   11699:   bgp_unlock_node (rn);
                   11700:   bgp_unlock_node (rn);
                   11701: 
                   11702:   return CMD_SUCCESS;
                   11703: }
                   11704: 
                   11705: /* Apply BGP information to distance method. */
                   11706: u_char
                   11707: bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
                   11708: {
                   11709:   struct bgp_node *rn;
                   11710:   struct prefix_ipv4 q;
                   11711:   struct peer *peer;
                   11712:   struct bgp_distance *bdistance;
                   11713:   struct access_list *alist;
                   11714:   struct bgp_static *bgp_static;
                   11715: 
                   11716:   if (! bgp)
                   11717:     return 0;
                   11718: 
                   11719:   if (p->family != AF_INET)
                   11720:     return 0;
                   11721: 
                   11722:   peer = rinfo->peer;
                   11723: 
                   11724:   if (peer->su.sa.sa_family != AF_INET)
                   11725:     return 0;
                   11726: 
                   11727:   memset (&q, 0, sizeof (struct prefix_ipv4));
                   11728:   q.family = AF_INET;
                   11729:   q.prefix = peer->su.sin.sin_addr;
                   11730:   q.prefixlen = IPV4_MAX_BITLEN;
                   11731: 
                   11732:   /* Check source address. */
                   11733:   rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
                   11734:   if (rn)
                   11735:     {
                   11736:       bdistance = rn->info;
                   11737:       bgp_unlock_node (rn);
                   11738: 
                   11739:       if (bdistance->access_list)
                   11740:        {
                   11741:          alist = access_list_lookup (AFI_IP, bdistance->access_list);
                   11742:          if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
                   11743:            return bdistance->distance;
                   11744:        }
                   11745:       else
                   11746:        return bdistance->distance;
                   11747:     }
                   11748: 
                   11749:   /* Backdoor check. */
                   11750:   rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
                   11751:   if (rn)
                   11752:     {
                   11753:       bgp_static = rn->info;
                   11754:       bgp_unlock_node (rn);
                   11755: 
                   11756:       if (bgp_static->backdoor)
                   11757:        {
                   11758:          if (bgp->distance_local)
                   11759:            return bgp->distance_local;
                   11760:          else
                   11761:            return ZEBRA_IBGP_DISTANCE_DEFAULT;
                   11762:        }
                   11763:     }
                   11764: 
                   11765:   if (peer_sort (peer) == BGP_PEER_EBGP)
                   11766:     {
                   11767:       if (bgp->distance_ebgp)
                   11768:        return bgp->distance_ebgp;
                   11769:       return ZEBRA_EBGP_DISTANCE_DEFAULT;
                   11770:     }
                   11771:   else
                   11772:     {
                   11773:       if (bgp->distance_ibgp)
                   11774:        return bgp->distance_ibgp;
                   11775:       return ZEBRA_IBGP_DISTANCE_DEFAULT;
                   11776:     }
                   11777: }
                   11778: 
                   11779: DEFUN (bgp_distance,
                   11780:        bgp_distance_cmd,
                   11781:        "distance bgp <1-255> <1-255> <1-255>",
                   11782:        "Define an administrative distance\n"
                   11783:        "BGP distance\n"
                   11784:        "Distance for routes external to the AS\n"
                   11785:        "Distance for routes internal to the AS\n"
                   11786:        "Distance for local routes\n")
                   11787: {
                   11788:   struct bgp *bgp;
                   11789: 
                   11790:   bgp = vty->index;
                   11791: 
                   11792:   bgp->distance_ebgp = atoi (argv[0]);
                   11793:   bgp->distance_ibgp = atoi (argv[1]);
                   11794:   bgp->distance_local = atoi (argv[2]);
                   11795:   return CMD_SUCCESS;
                   11796: }
                   11797: 
                   11798: DEFUN (no_bgp_distance,
                   11799:        no_bgp_distance_cmd,
                   11800:        "no distance bgp <1-255> <1-255> <1-255>",
                   11801:        NO_STR
                   11802:        "Define an administrative distance\n"
                   11803:        "BGP distance\n"
                   11804:        "Distance for routes external to the AS\n"
                   11805:        "Distance for routes internal to the AS\n"
                   11806:        "Distance for local routes\n")
                   11807: {
                   11808:   struct bgp *bgp;
                   11809: 
                   11810:   bgp = vty->index;
                   11811: 
                   11812:   bgp->distance_ebgp= 0;
                   11813:   bgp->distance_ibgp = 0;
                   11814:   bgp->distance_local = 0;
                   11815:   return CMD_SUCCESS;
                   11816: }
                   11817: 
                   11818: ALIAS (no_bgp_distance,
                   11819:        no_bgp_distance2_cmd,
                   11820:        "no distance bgp",
                   11821:        NO_STR
                   11822:        "Define an administrative distance\n"
                   11823:        "BGP distance\n")
                   11824: 
                   11825: DEFUN (bgp_distance_source,
                   11826:        bgp_distance_source_cmd,
                   11827:        "distance <1-255> A.B.C.D/M",
                   11828:        "Define an administrative distance\n"
                   11829:        "Administrative distance\n"
                   11830:        "IP source prefix\n")
                   11831: {
                   11832:   bgp_distance_set (vty, argv[0], argv[1], NULL);
                   11833:   return CMD_SUCCESS;
                   11834: }
                   11835: 
                   11836: DEFUN (no_bgp_distance_source,
                   11837:        no_bgp_distance_source_cmd,
                   11838:        "no distance <1-255> A.B.C.D/M",
                   11839:        NO_STR
                   11840:        "Define an administrative distance\n"
                   11841:        "Administrative distance\n"
                   11842:        "IP source prefix\n")
                   11843: {
                   11844:   bgp_distance_unset (vty, argv[0], argv[1], NULL);
                   11845:   return CMD_SUCCESS;
                   11846: }
                   11847: 
                   11848: DEFUN (bgp_distance_source_access_list,
                   11849:        bgp_distance_source_access_list_cmd,
                   11850:        "distance <1-255> A.B.C.D/M WORD",
                   11851:        "Define an administrative distance\n"
                   11852:        "Administrative distance\n"
                   11853:        "IP source prefix\n"
                   11854:        "Access list name\n")
                   11855: {
                   11856:   bgp_distance_set (vty, argv[0], argv[1], argv[2]);
                   11857:   return CMD_SUCCESS;
                   11858: }
                   11859: 
                   11860: DEFUN (no_bgp_distance_source_access_list,
                   11861:        no_bgp_distance_source_access_list_cmd,
                   11862:        "no distance <1-255> A.B.C.D/M WORD",
                   11863:        NO_STR
                   11864:        "Define an administrative distance\n"
                   11865:        "Administrative distance\n"
                   11866:        "IP source prefix\n"
                   11867:        "Access list name\n")
                   11868: {
                   11869:   bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
                   11870:   return CMD_SUCCESS;
                   11871: }
                   11872: 
                   11873: DEFUN (bgp_damp_set,
                   11874:        bgp_damp_set_cmd,
                   11875:        "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
                   11876:        "BGP Specific commands\n"
                   11877:        "Enable route-flap dampening\n"
                   11878:        "Half-life time for the penalty\n"
                   11879:        "Value to start reusing a route\n"
                   11880:        "Value to start suppressing a route\n"
                   11881:        "Maximum duration to suppress a stable route\n")
                   11882: {
                   11883:   struct bgp *bgp;
                   11884:   int half = DEFAULT_HALF_LIFE * 60;
                   11885:   int reuse = DEFAULT_REUSE;
                   11886:   int suppress = DEFAULT_SUPPRESS;
                   11887:   int max = 4 * half;
                   11888: 
                   11889:   if (argc == 4)
                   11890:     {
                   11891:       half = atoi (argv[0]) * 60;
                   11892:       reuse = atoi (argv[1]);
                   11893:       suppress = atoi (argv[2]);
                   11894:       max = atoi (argv[3]) * 60;
                   11895:     }
                   11896:   else if (argc == 1)
                   11897:     {
                   11898:       half = atoi (argv[0]) * 60;
                   11899:       max = 4 * half;
                   11900:     }
                   11901: 
                   11902:   bgp = vty->index;
                   11903:   return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
                   11904:                          half, reuse, suppress, max);
                   11905: }
                   11906: 
                   11907: ALIAS (bgp_damp_set,
                   11908:        bgp_damp_set2_cmd,
                   11909:        "bgp dampening <1-45>",
                   11910:        "BGP Specific commands\n"
                   11911:        "Enable route-flap dampening\n"
                   11912:        "Half-life time for the penalty\n")
                   11913: 
                   11914: ALIAS (bgp_damp_set,
                   11915:        bgp_damp_set3_cmd,
                   11916:        "bgp dampening",
                   11917:        "BGP Specific commands\n"
                   11918:        "Enable route-flap dampening\n")
                   11919: 
                   11920: DEFUN (bgp_damp_unset,
                   11921:        bgp_damp_unset_cmd,
                   11922:        "no bgp dampening",
                   11923:        NO_STR
                   11924:        "BGP Specific commands\n"
                   11925:        "Enable route-flap dampening\n")
                   11926: {
                   11927:   struct bgp *bgp;
                   11928: 
                   11929:   bgp = vty->index;
                   11930:   return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
                   11931: }
                   11932: 
                   11933: ALIAS (bgp_damp_unset,
                   11934:        bgp_damp_unset2_cmd,
                   11935:        "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
                   11936:        NO_STR
                   11937:        "BGP Specific commands\n"
                   11938:        "Enable route-flap dampening\n"
                   11939:        "Half-life time for the penalty\n"
                   11940:        "Value to start reusing a route\n"
                   11941:        "Value to start suppressing a route\n"
                   11942:        "Maximum duration to suppress a stable route\n")
                   11943: 
                   11944: DEFUN (show_ip_bgp_dampened_paths,
                   11945:        show_ip_bgp_dampened_paths_cmd,
                   11946:        "show ip bgp dampened-paths",
                   11947:        SHOW_STR
                   11948:        IP_STR
                   11949:        BGP_STR
                   11950:        "Display paths suppressed due to dampening\n")
                   11951: {
                   11952:   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
                   11953:                    NULL);
                   11954: }
                   11955: 
                   11956: DEFUN (show_ip_bgp_flap_statistics,
                   11957:        show_ip_bgp_flap_statistics_cmd,
                   11958:        "show ip bgp flap-statistics",
                   11959:        SHOW_STR
                   11960:        IP_STR
                   11961:        BGP_STR
                   11962:        "Display flap statistics of routes\n")
                   11963: {
                   11964:   return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
                   11965:                    bgp_show_type_flap_statistics, NULL);
                   11966: }
                   11967: 
                   11968: /* Display specified route of BGP table. */
                   11969: static int
                   11970: bgp_clear_damp_route (struct vty *vty, const char *view_name, 
                   11971:                       const char *ip_str, afi_t afi, safi_t safi, 
                   11972:                       struct prefix_rd *prd, int prefix_check)
                   11973: {
                   11974:   int ret;
                   11975:   struct prefix match;
                   11976:   struct bgp_node *rn;
                   11977:   struct bgp_node *rm;
                   11978:   struct bgp_info *ri;
                   11979:   struct bgp_info *ri_temp;
                   11980:   struct bgp *bgp;
                   11981:   struct bgp_table *table;
                   11982: 
                   11983:   /* BGP structure lookup. */
                   11984:   if (view_name)
                   11985:     {
                   11986:       bgp = bgp_lookup_by_name (view_name);
                   11987:       if (bgp == NULL)
                   11988:        {
                   11989:          vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
                   11990:          return CMD_WARNING;
                   11991:        }
                   11992:     }
                   11993:   else
                   11994:     {
                   11995:       bgp = bgp_get_default ();
                   11996:       if (bgp == NULL)
                   11997:        {
                   11998:          vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
                   11999:          return CMD_WARNING;
                   12000:        }
                   12001:     }
                   12002: 
                   12003:   /* Check IP address argument. */
                   12004:   ret = str2prefix (ip_str, &match);
                   12005:   if (! ret)
                   12006:     {
                   12007:       vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
                   12008:       return CMD_WARNING;
                   12009:     }
                   12010: 
                   12011:   match.family = afi2family (afi);
                   12012: 
                   12013:   if (safi == SAFI_MPLS_VPN)
                   12014:     {
                   12015:       for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
                   12016:         {
                   12017:           if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
                   12018:             continue;
                   12019: 
                   12020:          if ((table = rn->info) != NULL)
                   12021:            if ((rm = bgp_node_match (table, &match)) != NULL)
                   12022:               {
                   12023:                 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
                   12024:                   {
                   12025:                     ri = rm->info;
                   12026:                     while (ri)
                   12027:                       {
                   12028:                         if (ri->extra && ri->extra->damp_info)
                   12029:                           {
                   12030:                             ri_temp = ri->next;
                   12031:                             bgp_damp_info_free (ri->extra->damp_info, 1);
                   12032:                             ri = ri_temp;
                   12033:                           }
                   12034:                         else
                   12035:                           ri = ri->next;
                   12036:                       }
                   12037:                   }
                   12038: 
                   12039:                 bgp_unlock_node (rm);
                   12040:               }
                   12041:         }
                   12042:     }
                   12043:   else
                   12044:     {
                   12045:       if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
                   12046:         {
                   12047:           if (! prefix_check || rn->p.prefixlen == match.prefixlen)
                   12048:             {
                   12049:               ri = rn->info;
                   12050:               while (ri)
                   12051:                 {
                   12052:                   if (ri->extra && ri->extra->damp_info)
                   12053:                     {
                   12054:                       ri_temp = ri->next;
                   12055:                       bgp_damp_info_free (ri->extra->damp_info, 1);
                   12056:                       ri = ri_temp;
                   12057:                     }
                   12058:                   else
                   12059:                     ri = ri->next;
                   12060:                 }
                   12061:             }
                   12062: 
                   12063:           bgp_unlock_node (rn);
                   12064:         }
                   12065:     }
                   12066: 
                   12067:   return CMD_SUCCESS;
                   12068: }
                   12069: 
                   12070: DEFUN (clear_ip_bgp_dampening,
                   12071:        clear_ip_bgp_dampening_cmd,
                   12072:        "clear ip bgp dampening",
                   12073:        CLEAR_STR
                   12074:        IP_STR
                   12075:        BGP_STR
                   12076:        "Clear route flap dampening information\n")
                   12077: {
                   12078:   bgp_damp_info_clean ();
                   12079:   return CMD_SUCCESS;
                   12080: }
                   12081: 
                   12082: DEFUN (clear_ip_bgp_dampening_prefix,
                   12083:        clear_ip_bgp_dampening_prefix_cmd,
                   12084:        "clear ip bgp dampening A.B.C.D/M",
                   12085:        CLEAR_STR
                   12086:        IP_STR
                   12087:        BGP_STR
                   12088:        "Clear route flap dampening information\n"
                   12089:        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
                   12090: {
                   12091:   return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
                   12092:                               SAFI_UNICAST, NULL, 1);
                   12093: }
                   12094: 
                   12095: DEFUN (clear_ip_bgp_dampening_address,
                   12096:        clear_ip_bgp_dampening_address_cmd,
                   12097:        "clear ip bgp dampening A.B.C.D",
                   12098:        CLEAR_STR
                   12099:        IP_STR
                   12100:        BGP_STR
                   12101:        "Clear route flap dampening information\n"
                   12102:        "Network to clear damping information\n")
                   12103: {
                   12104:   return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
                   12105:                               SAFI_UNICAST, NULL, 0);
                   12106: }
                   12107: 
                   12108: DEFUN (clear_ip_bgp_dampening_address_mask,
                   12109:        clear_ip_bgp_dampening_address_mask_cmd,
                   12110:        "clear ip bgp dampening A.B.C.D A.B.C.D",
                   12111:        CLEAR_STR
                   12112:        IP_STR
                   12113:        BGP_STR
                   12114:        "Clear route flap dampening information\n"
                   12115:        "Network to clear damping information\n"
                   12116:        "Network mask\n")
                   12117: {
                   12118:   int ret;
                   12119:   char prefix_str[BUFSIZ];
                   12120: 
                   12121:   ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
                   12122:   if (! ret)
                   12123:     {
                   12124:       vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
                   12125:       return CMD_WARNING;
                   12126:     }
                   12127: 
                   12128:   return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
                   12129:                               SAFI_UNICAST, NULL, 0);
                   12130: }
                   12131: 
                   12132: static int
                   12133: bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
                   12134:                                afi_t afi, safi_t safi, int *write)
                   12135: {
                   12136:   struct bgp_node *prn;
                   12137:   struct bgp_node *rn;
                   12138:   struct bgp_table *table;
                   12139:   struct prefix *p;
                   12140:   struct prefix_rd *prd;
                   12141:   struct bgp_static *bgp_static;
                   12142:   u_int32_t label;
                   12143:   char buf[SU_ADDRSTRLEN];
                   12144:   char rdbuf[RD_ADDRSTRLEN];
                   12145:   
                   12146:   /* Network configuration. */
                   12147:   for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
                   12148:     if ((table = prn->info) != NULL)
                   12149:       for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) 
                   12150:        if ((bgp_static = rn->info) != NULL)
                   12151:          {
                   12152:            p = &rn->p;
                   12153:            prd = (struct prefix_rd *) &prn->p;
                   12154: 
                   12155:            /* "address-family" display.  */
                   12156:            bgp_config_write_family_header (vty, afi, safi, write);
                   12157: 
                   12158:            /* "network" configuration display.  */
                   12159:            prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
                   12160:            label = decode_label (bgp_static->tag);
                   12161: 
                   12162:            vty_out (vty, " network %s/%d rd %s tag %d",
                   12163:                     inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), 
                   12164:                     p->prefixlen,
                   12165:                     rdbuf, label);
                   12166:            vty_out (vty, "%s", VTY_NEWLINE);
                   12167:          }
                   12168:   return 0;
                   12169: }
                   12170: 
                   12171: /* Configuration of static route announcement and aggregate
                   12172:    information. */
                   12173: int
                   12174: bgp_config_write_network (struct vty *vty, struct bgp *bgp,
                   12175:                          afi_t afi, safi_t safi, int *write)
                   12176: {
                   12177:   struct bgp_node *rn;
                   12178:   struct prefix *p;
                   12179:   struct bgp_static *bgp_static;
                   12180:   struct bgp_aggregate *bgp_aggregate;
                   12181:   char buf[SU_ADDRSTRLEN];
                   12182:   
                   12183:   if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
                   12184:     return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
                   12185: 
                   12186:   /* Network configuration. */
                   12187:   for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn)) 
                   12188:     if ((bgp_static = rn->info) != NULL)
                   12189:       {
                   12190:        p = &rn->p;
                   12191: 
                   12192:        /* "address-family" display.  */
                   12193:        bgp_config_write_family_header (vty, afi, safi, write);
                   12194: 
                   12195:        /* "network" configuration display.  */
                   12196:        if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
                   12197:          {
                   12198:            u_int32_t destination; 
                   12199:            struct in_addr netmask;
                   12200: 
                   12201:            destination = ntohl (p->u.prefix4.s_addr);
                   12202:            masklen2ip (p->prefixlen, &netmask);
                   12203:            vty_out (vty, " network %s",
                   12204:                     inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
                   12205: 
                   12206:            if ((IN_CLASSC (destination) && p->prefixlen == 24)
                   12207:                || (IN_CLASSB (destination) && p->prefixlen == 16)
                   12208:                || (IN_CLASSA (destination) && p->prefixlen == 8)
                   12209:                || p->u.prefix4.s_addr == 0)
                   12210:              {
                   12211:                /* Natural mask is not display. */
                   12212:              }
                   12213:            else
                   12214:              vty_out (vty, " mask %s", inet_ntoa (netmask));
                   12215:          }
                   12216:        else
                   12217:          {
                   12218:            vty_out (vty, " network %s/%d",
                   12219:                     inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), 
                   12220:                     p->prefixlen);
                   12221:          }
                   12222: 
                   12223:        if (bgp_static->rmap.name)
                   12224:          vty_out (vty, " route-map %s", bgp_static->rmap.name);
                   12225:        else 
                   12226:          {
                   12227:            if (bgp_static->backdoor)
                   12228:              vty_out (vty, " backdoor");
                   12229:           }
                   12230: 
                   12231:        vty_out (vty, "%s", VTY_NEWLINE);
                   12232:       }
                   12233: 
                   12234:   /* Aggregate-address configuration. */
                   12235:   for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
                   12236:     if ((bgp_aggregate = rn->info) != NULL)
                   12237:       {
                   12238:        p = &rn->p;
                   12239: 
                   12240:        /* "address-family" display.  */
                   12241:        bgp_config_write_family_header (vty, afi, safi, write);
                   12242: 
                   12243:        if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
                   12244:          {
                   12245:            struct in_addr netmask;
                   12246: 
                   12247:            masklen2ip (p->prefixlen, &netmask);
                   12248:            vty_out (vty, " aggregate-address %s %s",
                   12249:                     inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   12250:                     inet_ntoa (netmask));
                   12251:          }
                   12252:        else
                   12253:          {
                   12254:            vty_out (vty, " aggregate-address %s/%d",
                   12255:                     inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
                   12256:                     p->prefixlen);
                   12257:          }
                   12258: 
                   12259:        if (bgp_aggregate->as_set)
                   12260:          vty_out (vty, " as-set");
                   12261:        
                   12262:        if (bgp_aggregate->summary_only)
                   12263:          vty_out (vty, " summary-only");
                   12264: 
                   12265:        vty_out (vty, "%s", VTY_NEWLINE);
                   12266:       }
                   12267: 
                   12268:   return 0;
                   12269: }
                   12270: 
                   12271: int
                   12272: bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
                   12273: {
                   12274:   struct bgp_node *rn;
                   12275:   struct bgp_distance *bdistance;
                   12276: 
                   12277:   /* Distance configuration. */
                   12278:   if (bgp->distance_ebgp
                   12279:       && bgp->distance_ibgp
                   12280:       && bgp->distance_local
                   12281:       && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
                   12282:          || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
                   12283:          || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
                   12284:     vty_out (vty, " distance bgp %d %d %d%s",
                   12285:             bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
                   12286:             VTY_NEWLINE);
                   12287:   
                   12288:   for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
                   12289:     if ((bdistance = rn->info) != NULL)
                   12290:       {
                   12291:        vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
                   12292:                 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
                   12293:                 bdistance->access_list ? bdistance->access_list : "",
                   12294:                 VTY_NEWLINE);
                   12295:       }
                   12296: 
                   12297:   return 0;
                   12298: }
                   12299: 
                   12300: /* Allocate routing table structure and install commands. */
                   12301: void
                   12302: bgp_route_init (void)
                   12303: {
                   12304:   /* Init BGP distance table. */
                   12305:   bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
                   12306: 
                   12307:   /* IPv4 BGP commands. */
                   12308:   install_element (BGP_NODE, &bgp_network_cmd);
                   12309:   install_element (BGP_NODE, &bgp_network_mask_cmd);
                   12310:   install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
                   12311:   install_element (BGP_NODE, &bgp_network_route_map_cmd);
                   12312:   install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
                   12313:   install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
                   12314:   install_element (BGP_NODE, &bgp_network_backdoor_cmd);
                   12315:   install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
                   12316:   install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
                   12317:   install_element (BGP_NODE, &no_bgp_network_cmd);
                   12318:   install_element (BGP_NODE, &no_bgp_network_mask_cmd);
                   12319:   install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
                   12320:   install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
                   12321:   install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
                   12322:   install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
                   12323:   install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
                   12324:   install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
                   12325:   install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
                   12326: 
                   12327:   install_element (BGP_NODE, &aggregate_address_cmd);
                   12328:   install_element (BGP_NODE, &aggregate_address_mask_cmd);
                   12329:   install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
                   12330:   install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
                   12331:   install_element (BGP_NODE, &aggregate_address_as_set_cmd);
                   12332:   install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
                   12333:   install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
                   12334:   install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
                   12335:   install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
                   12336:   install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
                   12337:   install_element (BGP_NODE, &no_aggregate_address_cmd);
                   12338:   install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
                   12339:   install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
                   12340:   install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
                   12341:   install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
                   12342:   install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
                   12343:   install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
                   12344:   install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
                   12345:   install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
                   12346:   install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
                   12347: 
                   12348:   /* IPv4 unicast configuration.  */
                   12349:   install_element (BGP_IPV4_NODE, &bgp_network_cmd);
                   12350:   install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
                   12351:   install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
                   12352:   install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
                   12353:   install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
                   12354:   install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
                   12355:   install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
                   12356:   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
                   12357:   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
                   12358:   install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
                   12359:   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
                   12360:   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
                   12361:   
                   12362:   install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
                   12363:   install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
                   12364:   install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
                   12365:   install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
                   12366:   install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
                   12367:   install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
                   12368:   install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
                   12369:   install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
                   12370:   install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
                   12371:   install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
                   12372:   install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
                   12373:   install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
                   12374:   install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
                   12375:   install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
                   12376:   install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
                   12377:   install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
                   12378:   install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
                   12379:   install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
                   12380:   install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
                   12381:   install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
                   12382: 
                   12383:   /* IPv4 multicast configuration.  */
                   12384:   install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
                   12385:   install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
                   12386:   install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
                   12387:   install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
                   12388:   install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
                   12389:   install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
                   12390:   install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
                   12391:   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
                   12392:   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
                   12393:   install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
                   12394:   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
                   12395:   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
                   12396:   install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
                   12397:   install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
                   12398:   install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
                   12399:   install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
                   12400:   install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
                   12401:   install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
                   12402:   install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
                   12403:   install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
                   12404:   install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
                   12405:   install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
                   12406:   install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
                   12407:   install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
                   12408:   install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
                   12409:   install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
                   12410:   install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
                   12411:   install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
                   12412:   install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
                   12413:   install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
                   12414:   install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
                   12415:   install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
                   12416: 
                   12417:   install_element (VIEW_NODE, &show_ip_bgp_cmd);
                   12418:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
                   12419:   install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
                   12420:   install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
                   12421:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
                   12422:   install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
                   12423:   install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
                   12424:   install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
                   12425:   install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
                   12426:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
                   12427:   install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
                   12428:   install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
                   12429:   install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
                   12430:   install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
                   12431:   install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
                   12432:   install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
                   12433:   install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
                   12434:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
                   12435:   install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
                   12436:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
                   12437:   install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
                   12438:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
                   12439:   install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
                   12440:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
                   12441:   install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
                   12442:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
                   12443:   install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
                   12444:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
                   12445:   install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
                   12446:   install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
                   12447:   install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
                   12448:   install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
                   12449:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
                   12450:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
                   12451:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
                   12452:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
                   12453:   install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
                   12454:   install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
                   12455:   install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
                   12456:   install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
                   12457:   install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
                   12458:   install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
                   12459:   install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
                   12460:   install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
                   12461:   install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
                   12462:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
                   12463:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
                   12464:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
                   12465:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
                   12466:   install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
                   12467:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
                   12468:   install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
                   12469:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
                   12470:   install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
                   12471:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
                   12472:   install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
                   12473:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
                   12474:   install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
                   12475:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
                   12476:   install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
                   12477:   install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
                   12478:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
                   12479:   install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
                   12480:   install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
                   12481:   install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
                   12482:   install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
                   12483:   install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
                   12484:   install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
                   12485:   install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
                   12486:   install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
                   12487:   install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
                   12488:   install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
                   12489:   install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
                   12490:   install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
                   12491:   install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
                   12492:   install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
                   12493:   install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
                   12494:   install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
                   12495:   install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
                   12496:   install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
                   12497:   install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
                   12498:   install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
                   12499:   install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
                   12500:   install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
                   12501:   install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
                   12502:   install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
                   12503:   install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
                   12504:   install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
                   12505:   install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
                   12506:   install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
                   12507:   
                   12508:   /* Restricted node: VIEW_NODE - (set of dangerous commands) */
                   12509:   install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
                   12510:   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
                   12511:   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
                   12512:   install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
                   12513:   install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
                   12514:   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
                   12515:   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
                   12516:   install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
                   12517:   install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
                   12518:   install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
                   12519:   install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
                   12520:   install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
                   12521:   install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
                   12522:   install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
                   12523:   install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
                   12524:   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
                   12525:   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
                   12526:   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
                   12527:   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
                   12528:   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
                   12529:   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
                   12530:   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
                   12531:   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
                   12532:   install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
                   12533:   install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
                   12534:   install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
                   12535:   install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
                   12536:   install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
                   12537:   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
                   12538:   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
                   12539:   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
                   12540:   install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
                   12541:   install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
                   12542:   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
                   12543:   install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
                   12544:   install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
                   12545:   install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
                   12546:   install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
                   12547:   install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
                   12548:   install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
                   12549: 
                   12550:   install_element (ENABLE_NODE, &show_ip_bgp_cmd);
                   12551:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
                   12552:   install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
                   12553:   install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
                   12554:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
                   12555:   install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
                   12556:   install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
                   12557:   install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
                   12558:   install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
                   12559:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
                   12560:   install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
                   12561:   install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
                   12562:   install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
                   12563:   install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
                   12564:   install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
                   12565:   install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
                   12566:   install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
                   12567:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
                   12568:   install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
                   12569:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
                   12570:   install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
                   12571:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
                   12572:   install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
                   12573:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
                   12574:   install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
                   12575:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
                   12576:   install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
                   12577:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
                   12578:   install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
                   12579:   install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
                   12580:   install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
                   12581:   install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
                   12582:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
                   12583:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
                   12584:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
                   12585:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
                   12586:   install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
                   12587:   install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
                   12588:   install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
                   12589:   install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
                   12590:   install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
                   12591:   install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
                   12592:   install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
                   12593:   install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
                   12594:   install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
                   12595:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
                   12596:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
                   12597:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
                   12598:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
                   12599:   install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
                   12600:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
                   12601:   install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
                   12602:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
                   12603:   install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
                   12604:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
                   12605:   install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
                   12606:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
                   12607:   install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
                   12608:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
                   12609:   install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
                   12610:   install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
                   12611:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
                   12612:   install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
                   12613:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
                   12614:   install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
                   12615:   install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
                   12616:   install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
                   12617:   install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
                   12618:   install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
                   12619:   install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
                   12620:   install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
                   12621:   install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
                   12622:   install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
                   12623:   install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
                   12624:   install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
                   12625:   install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
                   12626:   install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
                   12627:   install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
                   12628:   install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
                   12629:   install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
                   12630:   install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
                   12631:   install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
                   12632:   install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
                   12633:   install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
                   12634:   install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
                   12635:   install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
                   12636:   install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
                   12637:   install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
                   12638:   install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
                   12639:   install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
                   12640: 
                   12641:  /* BGP dampening clear commands */
                   12642:   install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
                   12643:   install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
                   12644:   install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
                   12645:   install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
                   12646: 
                   12647:   /* prefix count */
                   12648:   install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
                   12649:   install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
                   12650:   install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
                   12651: #ifdef HAVE_IPV6
                   12652:   install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
                   12653: 
                   12654:   /* New config IPv6 BGP commands.  */
                   12655:   install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
                   12656:   install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
                   12657:   install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
                   12658:   install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
                   12659: 
                   12660:   install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
                   12661:   install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
                   12662:   install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
                   12663:   install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
                   12664: 
1.1.1.2 ! misho    12665:   install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
        !          12666:   install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
        !          12667: 
1.1       misho    12668:   /* Old config IPv6 BGP commands.  */
                   12669:   install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
                   12670:   install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
                   12671: 
                   12672:   install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
                   12673:   install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
                   12674:   install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
                   12675:   install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
                   12676: 
                   12677:   install_element (VIEW_NODE, &show_bgp_cmd);
                   12678:   install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
                   12679:   install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
                   12680:   install_element (VIEW_NODE, &show_bgp_route_cmd);
                   12681:   install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
                   12682:   install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
                   12683:   install_element (VIEW_NODE, &show_bgp_prefix_cmd);
                   12684:   install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
                   12685:   install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
                   12686:   install_element (VIEW_NODE, &show_bgp_regexp_cmd);
                   12687:   install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
                   12688:   install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
                   12689:   install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
                   12690:   install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
                   12691:   install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
                   12692:   install_element (VIEW_NODE, &show_bgp_route_map_cmd);
                   12693:   install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
                   12694:   install_element (VIEW_NODE, &show_bgp_community_all_cmd);
                   12695:   install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
                   12696:   install_element (VIEW_NODE, &show_bgp_community_cmd);
                   12697:   install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
                   12698:   install_element (VIEW_NODE, &show_bgp_community2_cmd);
                   12699:   install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
                   12700:   install_element (VIEW_NODE, &show_bgp_community3_cmd);
                   12701:   install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
                   12702:   install_element (VIEW_NODE, &show_bgp_community4_cmd);
                   12703:   install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
                   12704:   install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
                   12705:   install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
                   12706:   install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
                   12707:   install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
                   12708:   install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
                   12709:   install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
                   12710:   install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
                   12711:   install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
                   12712:   install_element (VIEW_NODE, &show_bgp_community_list_cmd);
                   12713:   install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
                   12714:   install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
                   12715:   install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
                   12716:   install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
                   12717:   install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
                   12718:   install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
                   12719:   install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
                   12720:   install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
                   12721:   install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
                   12722:   install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
                   12723:   install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
                   12724:   install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
                   12725:   install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
                   12726:   install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
                   12727:   install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
                   12728:   install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
                   12729:   install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
                   12730:   install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
                   12731:   install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
                   12732:   install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
                   12733:   install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
                   12734:   install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
                   12735:   install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
                   12736:   install_element (VIEW_NODE, &show_bgp_view_cmd);
                   12737:   install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
                   12738:   install_element (VIEW_NODE, &show_bgp_view_route_cmd);
                   12739:   install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
                   12740:   install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
                   12741:   install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
                   12742:   install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
                   12743:   install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
                   12744:   install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
                   12745:   install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
                   12746:   install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
                   12747:   install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
                   12748:   install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
                   12749:   install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
                   12750:   install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
                   12751:   install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
                   12752:   install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
                   12753:   install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd); 
                   12754:   install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
                   12755:   install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
                   12756:   install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
                   12757:   install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
                   12758:   install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
                   12759:   install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
                   12760:   
                   12761:   /* Restricted:
                   12762:    * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev) 
                   12763:    */
                   12764:   install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
                   12765:   install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
                   12766:   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
                   12767:   install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
                   12768:   install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
                   12769:   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
                   12770:   install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
                   12771:   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
                   12772:   install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
                   12773:   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
                   12774:   install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
                   12775:   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
                   12776:   install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
                   12777:   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
                   12778:   install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
                   12779:   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
                   12780:   install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
                   12781:   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
                   12782:   install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
                   12783:   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
                   12784:   install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
                   12785:   install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
                   12786:   install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
                   12787:   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
                   12788:   install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
                   12789:   install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
                   12790:   install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
                   12791:   install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
                   12792:   install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
                   12793:   install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
                   12794:   install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
                   12795:   install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
                   12796:   install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
                   12797:   install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
                   12798:   install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
                   12799:   install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
                   12800: 
                   12801:   install_element (ENABLE_NODE, &show_bgp_cmd);
                   12802:   install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
                   12803:   install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
                   12804:   install_element (ENABLE_NODE, &show_bgp_route_cmd);
                   12805:   install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
                   12806:   install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
                   12807:   install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
                   12808:   install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
                   12809:   install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
                   12810:   install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
                   12811:   install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
                   12812:   install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
                   12813:   install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
                   12814:   install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
                   12815:   install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
                   12816:   install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
                   12817:   install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
                   12818:   install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
                   12819:   install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
                   12820:   install_element (ENABLE_NODE, &show_bgp_community_cmd);
                   12821:   install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
                   12822:   install_element (ENABLE_NODE, &show_bgp_community2_cmd);
                   12823:   install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
                   12824:   install_element (ENABLE_NODE, &show_bgp_community3_cmd);
                   12825:   install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
                   12826:   install_element (ENABLE_NODE, &show_bgp_community4_cmd);
                   12827:   install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
                   12828:   install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
                   12829:   install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
                   12830:   install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
                   12831:   install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
                   12832:   install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
                   12833:   install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
                   12834:   install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
                   12835:   install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
                   12836:   install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
                   12837:   install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
                   12838:   install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
                   12839:   install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
                   12840:   install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
                   12841:   install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
                   12842:   install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
                   12843:   install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
                   12844:   install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
                   12845:   install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
                   12846:   install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
                   12847:   install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
                   12848:   install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
                   12849:   install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
                   12850:   install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
                   12851:   install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
                   12852:   install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
                   12853:   install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
                   12854:   install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
                   12855:   install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
                   12856:   install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
                   12857:   install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
                   12858:   install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
                   12859:   install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
                   12860:   install_element (ENABLE_NODE, &show_bgp_view_cmd);
                   12861:   install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
                   12862:   install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
                   12863:   install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
                   12864:   install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
                   12865:   install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
                   12866:   install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
                   12867:   install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
                   12868:   install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
                   12869:   install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
                   12870:   install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
                   12871:   install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
                   12872:   install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
                   12873:   install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
                   12874:   install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
                   12875:   install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
                   12876:   install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
                   12877:   install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
                   12878:   install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
                   12879:   install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
                   12880:   install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
                   12881:   install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
                   12882:   install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
                   12883:   install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
                   12884:   
                   12885:   /* Statistics */
                   12886:   install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
                   12887:   install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
                   12888:   install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
                   12889:   install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
                   12890:   
                   12891:   /* old command */
                   12892:   install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
                   12893:   install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
                   12894:   install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
                   12895:   install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
                   12896:   install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
                   12897:   install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
                   12898:   install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
                   12899:   install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
                   12900:   install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
                   12901:   install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
                   12902:   install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
                   12903:   install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
                   12904:   install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
                   12905:   install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
                   12906:   install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
                   12907:   install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
                   12908:   install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
                   12909:   install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
                   12910:   install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
                   12911:   install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
                   12912:   install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
                   12913:   install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
                   12914:   install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
                   12915:   install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
                   12916:   install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
                   12917:   install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
                   12918:   install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
                   12919:   install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
                   12920:   install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
                   12921:   install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
                   12922:   install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
                   12923:   install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
                   12924:   install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
                   12925:   install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
                   12926:   install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
                   12927:   install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
                   12928:   
                   12929:   /* old command */
                   12930:   install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
                   12931:   install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
                   12932:   install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
                   12933:   install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
                   12934:   install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
                   12935:   install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
                   12936:   install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
                   12937:   install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
                   12938:   install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
                   12939:   install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
                   12940:   install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
                   12941:   install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
                   12942:   install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
                   12943:   install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
                   12944:   install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
                   12945:   install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
                   12946:   install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
                   12947:   install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
                   12948:   install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
                   12949:   install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
                   12950:   install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
                   12951:   install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
                   12952:   install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
                   12953:   install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
                   12954:   install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
                   12955:   install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
                   12956:   install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
                   12957:   install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
                   12958:   install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
                   12959:   install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
                   12960:   install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
                   12961:   install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
                   12962:   install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
                   12963:   install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
                   12964:   install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
                   12965:   install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
                   12966: 
                   12967:   /* old command */
                   12968:   install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
                   12969:   install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
                   12970:   install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
                   12971:   install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
                   12972: 
                   12973:   /* old command */
                   12974:   install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
                   12975:   install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
                   12976:   install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
                   12977:   install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
                   12978: 
                   12979:   /* old command */
                   12980:   install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
                   12981:   install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
                   12982:   install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
                   12983:   install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
                   12984: #endif /* HAVE_IPV6 */
                   12985: 
                   12986:   install_element (BGP_NODE, &bgp_distance_cmd);
                   12987:   install_element (BGP_NODE, &no_bgp_distance_cmd);
                   12988:   install_element (BGP_NODE, &no_bgp_distance2_cmd);
                   12989:   install_element (BGP_NODE, &bgp_distance_source_cmd);
                   12990:   install_element (BGP_NODE, &no_bgp_distance_source_cmd);
                   12991:   install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
                   12992:   install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
                   12993: 
                   12994:   install_element (BGP_NODE, &bgp_damp_set_cmd);
                   12995:   install_element (BGP_NODE, &bgp_damp_set2_cmd);
                   12996:   install_element (BGP_NODE, &bgp_damp_set3_cmd);
                   12997:   install_element (BGP_NODE, &bgp_damp_unset_cmd);
                   12998:   install_element (BGP_NODE, &bgp_damp_unset2_cmd);
                   12999:   install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
                   13000:   install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
                   13001:   install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
                   13002:   install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
                   13003:   install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
                   13004:   
                   13005:   /* Deprecated AS-Pathlimit commands */
                   13006:   install_element (BGP_NODE, &bgp_network_ttl_cmd);
                   13007:   install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
                   13008:   install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
                   13009:   install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
                   13010:   install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
                   13011:   install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
                   13012:   
                   13013:   install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
                   13014:   install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
                   13015:   install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
                   13016:   install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
                   13017:   install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
                   13018:   install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
                   13019:   
                   13020:   install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
                   13021:   install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
                   13022:   install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
                   13023:   install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
                   13024:   install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
                   13025:   install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
                   13026:   
                   13027:   install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
                   13028:   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
                   13029:   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
                   13030:   install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
                   13031:   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
                   13032:   install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
                   13033:   
                   13034:   install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
                   13035:   install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
                   13036:   install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
                   13037:   install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
                   13038:   install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
                   13039:   install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
                   13040:   
                   13041:   install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
                   13042:   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
                   13043:   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
                   13044:   install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
                   13045:   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
                   13046:   install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
                   13047: 
                   13048: #ifdef HAVE_IPV6
                   13049:   install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
                   13050:   install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
                   13051: #endif
                   13052: }
                   13053: 
                   13054: void
                   13055: bgp_route_finish (void)
                   13056: {
                   13057:   bgp_table_unlock (bgp_distance_table);
                   13058:   bgp_distance_table = NULL;
                   13059: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>