Diff for /embedaddon/quagga/zebra/redistribute.c between versions 1.1.1.3 and 1.1.1.4

version 1.1.1.3, 2013/07/21 23:54:41 version 1.1.1.4, 2016/11/02 10:09:10
Line 30 Line 30
 #include "zclient.h"  #include "zclient.h"
 #include "linklist.h"  #include "linklist.h"
 #include "log.h"  #include "log.h"
   #include "vrf.h"
   
 #include "zebra/rib.h"  #include "zebra/rib.h"
 #include "zebra/zserv.h"  #include "zebra/zserv.h"
Line 67  zebra_check_addr (struct prefix *p) Line 68  zebra_check_addr (struct prefix *p)
   return 1;    return 1;
 }  }
   
static intint
 is_default (struct prefix *p)  is_default (struct prefix *p)
 {  {
   if (p->family == AF_INET)    if (p->family == AF_INET)
Line 85  is_default (struct prefix *p) Line 86  is_default (struct prefix *p)
 }  }
   
 static void  static void
zebra_redistribute_default (struct zserv *client)zebra_redistribute_default (struct zserv *client, vrf_id_t vrf_id)
 {  {
   struct prefix_ipv4 p;    struct prefix_ipv4 p;
   struct route_table *table;    struct route_table *table;
Line 101  zebra_redistribute_default (struct zserv *client) Line 102  zebra_redistribute_default (struct zserv *client)
   p.family = AF_INET;    p.family = AF_INET;
   
   /* Lookup table.  */    /* Lookup table.  */
  table = vrf_table (AFI_IP, SAFI_UNICAST, 0);  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
   if (table)    if (table)
     {      {
       rn = route_node_lookup (table, (struct prefix *)&p);        rn = route_node_lookup (table, (struct prefix *)&p);
Line 121  zebra_redistribute_default (struct zserv *client) Line 122  zebra_redistribute_default (struct zserv *client)
   p6.family = AF_INET6;    p6.family = AF_INET6;
   
   /* Lookup table.  */    /* Lookup table.  */
  table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
   if (table)    if (table)
     {      {
       rn = route_node_lookup (table, (struct prefix *)&p6);        rn = route_node_lookup (table, (struct prefix *)&p6);
Line 139  zebra_redistribute_default (struct zserv *client) Line 140  zebra_redistribute_default (struct zserv *client)
   
 /* Redistribute routes. */  /* Redistribute routes. */
 static void  static void
zebra_redistribute (struct zserv *client, int type)zebra_redistribute (struct zserv *client, int type, vrf_id_t vrf_id)
 {  {
   struct rib *newrib;    struct rib *newrib;
   struct route_table *table;    struct route_table *table;
   struct route_node *rn;    struct route_node *rn;
   
  table = vrf_table (AFI_IP, SAFI_UNICAST, 0);  table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id);
   if (table)    if (table)
     for (rn = route_top (table); rn; rn = route_next (rn))      for (rn = route_top (table); rn; rn = route_next (rn))
       RNODE_FOREACH_RIB (rn, newrib)        RNODE_FOREACH_RIB (rn, newrib)
        if (CHECK_FLAG (newrib->flags, ZEBRA_FLAG_SELECTED)         {
            && newrib->type == type           if (IS_ZEBRA_DEBUG_EVENT)
            && newrib->distance != DISTANCE_INFINITY            zlog_debug("%s: checking: selected=%d, type=%d, distance=%d, zebra_check_addr=%d",
            && zebra_check_addr (&rn->p))                       __func__, CHECK_FLAG (newrib->flags, ZEBRA_FLAG_SELECTED),
          zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, &rn->p, newrib);                       newrib->type, newrib->distance, zebra_check_addr (&rn->p));
            if (CHECK_FLAG (newrib->flags, ZEBRA_FLAG_SELECTED)
               && newrib->type == type
               && newrib->distance != DISTANCE_INFINITY
               && zebra_check_addr (&rn->p))
             zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, &rn->p, newrib);
         }
 
 #ifdef HAVE_IPV6  #ifdef HAVE_IPV6
  table = vrf_table (AFI_IP6, SAFI_UNICAST, 0);  table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id);
   if (table)    if (table)
     for (rn = route_top (table); rn; rn = route_next (rn))      for (rn = route_top (table); rn; rn = route_next (rn))
       RNODE_FOREACH_RIB (rn, newrib)        RNODE_FOREACH_RIB (rn, newrib)
Line 176  redistribute_add (struct prefix *p, struct rib *rib) Line 183  redistribute_add (struct prefix *p, struct rib *rib)
   
   for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client))    for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client))
     {      {
      if (is_default (p))      if ((is_default (p) &&
            vrf_bitmap_check (client->redist_default, rib->vrf_id))
           || vrf_bitmap_check (client->redist[rib->type], rib->vrf_id))
         {          {
           if (client->redist_default || client->redist[rib->type])  
             {  
               if (p->family == AF_INET)  
                 zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, p, rib);  
 #ifdef HAVE_IPV6  
               if (p->family == AF_INET6)  
                 zsend_route_multipath (ZEBRA_IPV6_ROUTE_ADD, client, p, rib);  
 #endif /* HAVE_IPV6 */      
             }  
         }  
       else if (client->redist[rib->type])  
         {  
           if (p->family == AF_INET)            if (p->family == AF_INET)
             zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, p, rib);              zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, p, rib);
 #ifdef HAVE_IPV6  #ifdef HAVE_IPV6
Line 212  redistribute_delete (struct prefix *p, struct rib *rib Line 209  redistribute_delete (struct prefix *p, struct rib *rib
   
   for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client))    for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client))
     {      {
      if (is_default (p))      if ((is_default (p) &&
            vrf_bitmap_check (client->redist_default, rib->vrf_id))
           || vrf_bitmap_check (client->redist[rib->type], rib->vrf_id))
         {          {
           if (client->redist_default || client->redist[rib->type])  
             {  
               if (p->family == AF_INET)  
                 zsend_route_multipath (ZEBRA_IPV4_ROUTE_DELETE, client, p,  
                                        rib);  
 #ifdef HAVE_IPV6  
               if (p->family == AF_INET6)  
                 zsend_route_multipath (ZEBRA_IPV6_ROUTE_DELETE, client, p,  
                                        rib);  
 #endif /* HAVE_IPV6 */  
             }  
         }  
       else if (client->redist[rib->type])  
         {  
           if (p->family == AF_INET)            if (p->family == AF_INET)
             zsend_route_multipath (ZEBRA_IPV4_ROUTE_DELETE, client, p, rib);              zsend_route_multipath (ZEBRA_IPV4_ROUTE_DELETE, client, p, rib);
 #ifdef HAVE_IPV6  #ifdef HAVE_IPV6
Line 239  redistribute_delete (struct prefix *p, struct rib *rib Line 224  redistribute_delete (struct prefix *p, struct rib *rib
 }  }
   
 void  void
zebra_redistribute_add (int command, struct zserv *client, int length)zebra_redistribute_add (int command, struct zserv *client, int length,
     vrf_id_t vrf_id)
 {  {
   int type;    int type;
   
Line 248  zebra_redistribute_add (int command, struct zserv *cli Line 234  zebra_redistribute_add (int command, struct zserv *cli
   if (type == 0 || type >= ZEBRA_ROUTE_MAX)    if (type == 0 || type >= ZEBRA_ROUTE_MAX)
     return;      return;
   
  if (! client->redist[type])  if (! vrf_bitmap_check (client->redist[type], vrf_id))
     {      {
      client->redist[type] = 1;      vrf_bitmap_set (client->redist[type], vrf_id);
      zebra_redistribute (client, type);      zebra_redistribute (client, type, vrf_id);
     }      }
 }  }
   
 void  void
zebra_redistribute_delete (int command, struct zserv *client, int length)zebra_redistribute_delete (int command, struct zserv *client, int length,
     vrf_id_t vrf_id)
 {  {
   int type;    int type;
   
Line 265  zebra_redistribute_delete (int command, struct zserv * Line 252  zebra_redistribute_delete (int command, struct zserv *
   if (type == 0 || type >= ZEBRA_ROUTE_MAX)    if (type == 0 || type >= ZEBRA_ROUTE_MAX)
     return;      return;
   
  client->redist[type] = 0;  vrf_bitmap_unset (client->redist[type], vrf_id);
 }  }
   
 void  void
zebra_redistribute_default_add (int command, struct zserv *client, int length)zebra_redistribute_default_add (int command, struct zserv *client, int length,
     vrf_id_t vrf_id)
 {  {
  client->redist_default = 1;  vrf_bitmap_set (client->redist_default, vrf_id);
  zebra_redistribute_default (client);  zebra_redistribute_default (client, vrf_id);
 }       }     
   
 void  void
 zebra_redistribute_default_delete (int command, struct zserv *client,  zebra_redistribute_default_delete (int command, struct zserv *client,
                                   int length)    int length, vrf_id_t vrf_id)
 {  {
  client->redist_default = 0;;  vrf_bitmap_unset (client->redist_default, vrf_id);
 }       }     
   
 /* Interface up information. */  /* Interface up information. */
Line 350  zebra_interface_address_add_update (struct interface * Line 338  zebra_interface_address_add_update (struct interface *
   
   if (IS_ZEBRA_DEBUG_EVENT)    if (IS_ZEBRA_DEBUG_EVENT)
     {      {
      char buf[INET6_ADDRSTRLEN];      char buf[PREFIX_STRLEN];
   
       p = ifc->address;        p = ifc->address;
      zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s/%d on %s",      zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s on %s",
                  inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN),                  prefix2str (p, buf, sizeof(buf)),
                  p->prefixlen, ifc->ifp->name);                  ifc->ifp->name);
     }      }
   
     if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
       zlog_warn("WARNING: advertising address to clients that is not yet usable.");
   
   router_id_add_address(ifc);    router_id_add_address(ifc);
   
   for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client))    for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client))
Line 376  zebra_interface_address_delete_update (struct interfac Line 367  zebra_interface_address_delete_update (struct interfac
   
   if (IS_ZEBRA_DEBUG_EVENT)    if (IS_ZEBRA_DEBUG_EVENT)
     {      {
      char buf[INET6_ADDRSTRLEN];      char buf[PREFIX_STRLEN];
   
       p = ifc->address;        p = ifc->address;
      zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s/%d on %s",      zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s on %s",
                  inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN),                  prefix2str (p, buf, sizeof(buf)),
                 p->prefixlen, ifc->ifp->name);                  ifc->ifp->name);
     }      }
   
   router_id_del_address(ifc);    router_id_del_address(ifc);

Removed from v.1.1.1.3  
changed lines
  Added in v.1.1.1.4


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