Diff for /embedaddon/quagga/ospf6d/ospf6_lsdb.c between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2012/02/21 17:26:12 version 1.1.1.2, 2016/11/02 10:09:12
Line 54  ospf6_lsdb_create (void *data) Line 54  ospf6_lsdb_create (void *data)
 void  void
 ospf6_lsdb_delete (struct ospf6_lsdb *lsdb)  ospf6_lsdb_delete (struct ospf6_lsdb *lsdb)
 {  {
  ospf6_lsdb_remove_all (lsdb);  if (lsdb != NULL)
  route_table_finish (lsdb->table);    {
  XFREE (MTYPE_OSPF6_LSDB, lsdb);      ospf6_lsdb_remove_all (lsdb);
       route_table_finish (lsdb->table);
       XFREE (MTYPE_OSPF6_LSDB, lsdb);
     }
 }  }
   
 static void  static void
Line 70  ospf6_lsdb_set_key (struct prefix_ipv6 *key, void *val Line 73  ospf6_lsdb_set_key (struct prefix_ipv6 *key, void *val
   key->prefixlen += len * 8;    key->prefixlen += len * 8;
 }  }
   
#ifndef NDEBUG#ifdef DEBUG
 static void  static void
 _lsdb_count_assert (struct ospf6_lsdb *lsdb)  _lsdb_count_assert (struct ospf6_lsdb *lsdb)
 {  {
Line 94  _lsdb_count_assert (struct ospf6_lsdb *lsdb) Line 97  _lsdb_count_assert (struct ospf6_lsdb *lsdb)
   assert (num == lsdb->count);    assert (num == lsdb->count);
 }  }
 #define ospf6_lsdb_count_assert(t) (_lsdb_count_assert (t))  #define ospf6_lsdb_count_assert(t) (_lsdb_count_assert (t))
#else /*NDEBUG*/#else /*DEBUG*/
 #define ospf6_lsdb_count_assert(t) ((void) 0)  #define ospf6_lsdb_count_assert(t) ((void) 0)
#endif /*NDEBUG*/#endif /*DEBUG*/
   
 void  void
 ospf6_lsdb_add (struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb)  ospf6_lsdb_add (struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb)
 {  {
   struct prefix_ipv6 key;    struct prefix_ipv6 key;
  struct route_node *current, *nextnode, *prevnode;  struct route_node *current;
  struct ospf6_lsa *next, *prev, *old = NULL;  struct ospf6_lsa *old = NULL;
   
   memset (&key, 0, sizeof (key));    memset (&key, 0, sizeof (key));
   ospf6_lsdb_set_key (&key, &lsa->header->type, sizeof (lsa->header->type));    ospf6_lsdb_set_key (&key, &lsa->header->type, sizeof (lsa->header->type));
Line 114  ospf6_lsdb_add (struct ospf6_lsa *lsa, struct ospf6_ls Line 117  ospf6_lsdb_add (struct ospf6_lsa *lsa, struct ospf6_ls
   current = route_node_get (lsdb->table, (struct prefix *) &key);    current = route_node_get (lsdb->table, (struct prefix *) &key);
   old = current->info;    old = current->info;
   current->info = lsa;    current->info = lsa;
     lsa->rn = current;
   ospf6_lsa_lock (lsa);    ospf6_lsa_lock (lsa);
   
  if (old)  if (!old)
     {      {
      if (old->prev)      lsdb->count++;
        old->prev->next = lsa; 
      if (old->next) 
        old->next->prev = lsa; 
      lsa->next = old->next; 
      lsa->prev = old->prev; 
    } 
  else 
    { 
      /* next link */ 
      nextnode = current; 
      route_lock_node (nextnode); 
      do { 
        nextnode = route_next (nextnode); 
      } while (nextnode && nextnode->info == NULL); 
      if (nextnode == NULL) 
        lsa->next = NULL; 
      else 
        { 
          next = nextnode->info; 
          lsa->next = next; 
          next->prev = lsa; 
          route_unlock_node (nextnode); 
        } 
   
      /* prev link */      if (OSPF6_LSA_IS_MAXAGE (lsa))
      prevnode = current;        {
      route_lock_node (prevnode);          if (lsdb->hook_remove)
      do {            (*lsdb->hook_remove) (lsa);
        prevnode = route_prev (prevnode);        }
      } while (prevnode && prevnode->info == NULL); 
      if (prevnode == NULL) 
        lsa->prev = NULL; 
       else        else
        {        {
          prev = prevnode->info;          if (lsdb->hook_add)
          lsa->prev = prev;            (*lsdb->hook_add) (lsa);
          prev->next = lsa;        }
          route_unlock_node (prevnode); 
        } 
 
      lsdb->count++; 
     }      }
  else
  if (old) 
     {      {
       if (OSPF6_LSA_IS_CHANGED (old, lsa))        if (OSPF6_LSA_IS_CHANGED (old, lsa))
         {          {
Line 187  ospf6_lsdb_add (struct ospf6_lsa *lsa, struct ospf6_ls Line 160  ospf6_lsdb_add (struct ospf6_lsa *lsa, struct ospf6_ls
                 (*lsdb->hook_add) (lsa);                  (*lsdb->hook_add) (lsa);
             }              }
         }          }
         ospf6_lsa_unlock (old);
     }      }
   else if (OSPF6_LSA_IS_MAXAGE (lsa))  
     {  
       if (lsdb->hook_remove)  
         (*lsdb->hook_remove) (lsa);  
     }  
   else  
     {  
       if (lsdb->hook_add)  
         (*lsdb->hook_add) (lsa);  
     }  
   
   if (old)  
     ospf6_lsa_unlock (old);  
   
   ospf6_lsdb_count_assert (lsdb);    ospf6_lsdb_count_assert (lsdb);
 }  }
   
Line 220  ospf6_lsdb_remove (struct ospf6_lsa *lsa, struct ospf6 Line 181  ospf6_lsdb_remove (struct ospf6_lsa *lsa, struct ospf6
   node = route_node_lookup (lsdb->table, (struct prefix *) &key);    node = route_node_lookup (lsdb->table, (struct prefix *) &key);
   assert (node && node->info == lsa);    assert (node && node->info == lsa);
   
   if (lsa->prev)  
     lsa->prev->next = lsa->next;  
   if (lsa->next)  
     lsa->next->prev = lsa->prev;  
   
   node->info = NULL;    node->info = NULL;
   lsdb->count--;    lsdb->count--;
   
   if (lsdb->hook_remove)    if (lsdb->hook_remove)
     (*lsdb->hook_remove) (lsa);      (*lsdb->hook_remove) (lsa);
   
     route_unlock_node (node);     /* to free the lookup lock */
     route_unlock_node (node);     /* to free the original lock */
   ospf6_lsa_unlock (lsa);    ospf6_lsa_unlock (lsa);
   route_unlock_node (node);  
   
   ospf6_lsdb_count_assert (lsdb);    ospf6_lsdb_count_assert (lsdb);
 }  }
Line 255  ospf6_lsdb_lookup (u_int16_t type, u_int32_t id, u_int Line 212  ospf6_lsdb_lookup (u_int16_t type, u_int32_t id, u_int
   node = route_node_lookup (lsdb->table, (struct prefix *) &key);    node = route_node_lookup (lsdb->table, (struct prefix *) &key);
   if (node == NULL || node->info == NULL)    if (node == NULL || node->info == NULL)
     return NULL;      return NULL;
   
     route_unlock_node (node);
   return (struct ospf6_lsa *) node->info;    return (struct ospf6_lsa *) node->info;
 }  }
   
Line 306  ospf6_lsdb_lookup_next (u_int16_t type, u_int32_t id,  Line 265  ospf6_lsdb_lookup_next (u_int16_t type, u_int32_t id, 
   
   if (prefix_same (&node->p, p))    if (prefix_same (&node->p, p))
     {      {
       struct route_node *prev = node;  
       struct ospf6_lsa *lsa_prev;  
       struct ospf6_lsa *lsa_next;  
   
       node = route_next (node);        node = route_next (node);
       while (node && node->info == NULL)        while (node && node->info == NULL)
         node = route_next (node);          node = route_next (node);
   
       lsa_prev = prev->info;  
       lsa_next = (node ? node->info : NULL);  
       assert (lsa_prev);  
       assert (lsa_prev->next == lsa_next);  
       if (lsa_next)  
         assert (lsa_next->prev == lsa_prev);  
       zlog_debug ("lsdb_lookup_next: assert OK with previous LSA");  
     }      }
   
   if (! node)    if (! node)
Line 346  ospf6_lsdb_head (struct ospf6_lsdb *lsdb) Line 293  ospf6_lsdb_head (struct ospf6_lsdb *lsdb)
   if (node == NULL)    if (node == NULL)
     return NULL;      return NULL;
   
   route_unlock_node (node);  
   if (node->info)    if (node->info)
     ospf6_lsa_lock ((struct ospf6_lsa *) node->info);      ospf6_lsa_lock ((struct ospf6_lsa *) node->info);
   return (struct ospf6_lsa *) node->info;    return (struct ospf6_lsa *) node->info;
Line 355  ospf6_lsdb_head (struct ospf6_lsdb *lsdb) Line 301  ospf6_lsdb_head (struct ospf6_lsdb *lsdb)
 struct ospf6_lsa *  struct ospf6_lsa *
 ospf6_lsdb_next (struct ospf6_lsa *lsa)  ospf6_lsdb_next (struct ospf6_lsa *lsa)
 {  {
  struct ospf6_lsa *next = lsa->next;  struct route_node *node = lsa->rn;
   struct ospf6_lsa *next = NULL;
   
  ospf6_lsa_unlock (lsa);  do {
  if (next)    node = route_next (node);
    ospf6_lsa_lock (next);  } while (node && node->info == NULL);
   
     if ((node != NULL) && (node->info != NULL))
       {
         next = node->info;
         ospf6_lsa_lock (next);
       }
   
     ospf6_lsa_unlock (lsa);
   return next;    return next;
 }  }
   
Line 390  ospf6_lsdb_type_router_head (u_int16_t type, u_int32_t Line 344  ospf6_lsdb_type_router_head (u_int16_t type, u_int32_t
   
   if (node == NULL)    if (node == NULL)
     return NULL;      return NULL;
   else  
     route_unlock_node (node);  
   
   if (! prefix_match ((struct prefix *) &key, &node->p))    if (! prefix_match ((struct prefix *) &key, &node->p))
     return NULL;      return NULL;
Line 406  struct ospf6_lsa * Line 358  struct ospf6_lsa *
 ospf6_lsdb_type_router_next (u_int16_t type, u_int32_t adv_router,  ospf6_lsdb_type_router_next (u_int16_t type, u_int32_t adv_router,
                              struct ospf6_lsa *lsa)                               struct ospf6_lsa *lsa)
 {  {
  struct ospf6_lsa *next = lsa->next;  struct ospf6_lsa *next = ospf6_lsdb_next(lsa);
   
   if (next)    if (next)
     {      {
       if (next->header->type != type ||        if (next->header->type != type ||
           next->header->adv_router != adv_router)            next->header->adv_router != adv_router)
        next = NULL;        {
           route_unlock_node (next->rn);
           ospf6_lsa_unlock (next);
           next = NULL;
         }
     }      }
   
   if (next)  
     ospf6_lsa_lock (next);  
   ospf6_lsa_unlock (lsa);  
   return next;    return next;
 }  }
   
Line 444  ospf6_lsdb_type_head (u_int16_t type, struct ospf6_lsd Line 397  ospf6_lsdb_type_head (u_int16_t type, struct ospf6_lsd
   
   if (node == NULL)    if (node == NULL)
     return NULL;      return NULL;
   else  
     route_unlock_node (node);  
   
   if (! prefix_match ((struct prefix *) &key, &node->p))    if (! prefix_match ((struct prefix *) &key, &node->p))
     return NULL;      return NULL;
Line 459  ospf6_lsdb_type_head (u_int16_t type, struct ospf6_lsd Line 410  ospf6_lsdb_type_head (u_int16_t type, struct ospf6_lsd
 struct ospf6_lsa *  struct ospf6_lsa *
 ospf6_lsdb_type_next (u_int16_t type, struct ospf6_lsa *lsa)  ospf6_lsdb_type_next (u_int16_t type, struct ospf6_lsa *lsa)
 {  {
  struct ospf6_lsa *next = lsa->next;  struct ospf6_lsa *next = ospf6_lsdb_next (lsa);
   
   if (next)    if (next)
     {      {
       if (next->header->type != type)        if (next->header->type != type)
        next = NULL;        {
           route_unlock_node (next->rn);
           ospf6_lsa_unlock (next);
           next = NULL;
         }
     }      }
   
   if (next)  
     ospf6_lsa_lock (next);  
   ospf6_lsa_unlock (lsa);  
   return next;    return next;
 }  }
   
Line 477  void Line 429  void
 ospf6_lsdb_remove_all (struct ospf6_lsdb *lsdb)  ospf6_lsdb_remove_all (struct ospf6_lsdb *lsdb)
 {  {
   struct ospf6_lsa *lsa;    struct ospf6_lsa *lsa;
   
     if (lsdb == NULL)
       return;
   
   for (lsa = ospf6_lsdb_head (lsdb); lsa; lsa = ospf6_lsdb_next (lsa))    for (lsa = ospf6_lsdb_head (lsdb); lsa; lsa = ospf6_lsdb_next (lsa))
     ospf6_lsdb_remove (lsa, lsdb);      ospf6_lsdb_remove (lsa, lsdb);
 }  }
   
 void  void
ospf6_lsdb_show (struct vty *vty, int level,ospf6_lsdb_lsa_unlock (struct ospf6_lsa *lsa)
 {
   if (lsa != NULL)
     {
       if (lsa->rn != NULL)
         route_unlock_node (lsa->rn);
       ospf6_lsa_unlock (lsa);
     }
 }
 
 int
 ospf6_lsdb_maxage_remover (struct ospf6_lsdb *lsdb)
 {
   int reschedule = 0;
   struct ospf6_lsa *lsa;
 
   for (lsa = ospf6_lsdb_head (lsdb); lsa; lsa = ospf6_lsdb_next (lsa))
     {
       if (! OSPF6_LSA_IS_MAXAGE (lsa))
         continue;
       if (lsa->retrans_count != 0)
         {
           reschedule = 1;
           continue;
         }
       if (IS_OSPF6_DEBUG_LSA_TYPE (lsa->header->type))
         zlog_debug ("Remove MaxAge %s", lsa->name);
       if (CHECK_FLAG(lsa->flag, OSPF6_LSA_SEQWRAPPED))
       {
         UNSET_FLAG(lsa->flag, OSPF6_LSA_SEQWRAPPED);
         /*
          * lsa->header->age = 0;
          */
         lsa->header->seqnum = htonl(OSPF_MAX_SEQUENCE_NUMBER + 1);
         ospf6_lsa_checksum (lsa->header);
 
         THREAD_OFF(lsa->refresh);
         thread_execute (master, ospf6_lsa_refresh, lsa, 0);
       } else {
         ospf6_lsdb_remove (lsa, lsdb);
       }
     }
 
   return (reschedule);
 }
 
 void
 ospf6_lsdb_show (struct vty *vty, enum ospf_lsdb_show_level level,
                  u_int16_t *type, u_int32_t *id, u_int32_t *adv_router,                   u_int16_t *type, u_int32_t *id, u_int32_t *adv_router,
                  struct ospf6_lsdb *lsdb)                   struct ospf6_lsdb *lsdb)
 {  {
   struct ospf6_lsa *lsa;    struct ospf6_lsa *lsa;
   void (*showfunc) (struct vty *, struct ospf6_lsa *) = NULL;    void (*showfunc) (struct vty *, struct ospf6_lsa *) = NULL;
   
  if (level == OSPF6_LSDB_SHOW_LEVEL_NORMAL)  switch (level)
    showfunc = ospf6_lsa_show_summary;  {
  else if (level == OSPF6_LSDB_SHOW_LEVEL_DETAIL)    case OSPF6_LSDB_SHOW_LEVEL_DETAIL:
    showfunc = ospf6_lsa_show;      showfunc = ospf6_lsa_show;
  else if (level == OSPF6_LSDB_SHOW_LEVEL_INTERNAL)      break;
    showfunc = ospf6_lsa_show_internal;    case OSPF6_LSDB_SHOW_LEVEL_INTERNAL:
  else if (level == OSPF6_LSDB_SHOW_LEVEL_DUMP)      showfunc = ospf6_lsa_show_internal;
    showfunc = ospf6_lsa_show_dump;      break;
    case OSPF6_LSDB_SHOW_LEVEL_DUMP:
       showfunc = ospf6_lsa_show_dump;
       break;
     case OSPF6_LSDB_SHOW_LEVEL_NORMAL:
     default:
       showfunc = ospf6_lsa_show_summary;
   }
   
   if (type && id && adv_router)    if (type && id && adv_router)
     {      {
       lsa = ospf6_lsdb_lookup (*type, *id, *adv_router, lsdb);        lsa = ospf6_lsdb_lookup (*type, *id, *adv_router, lsdb);
Line 551  ospf6_new_ls_id (u_int16_t type, u_int32_t adv_router, Line 561  ospf6_new_ls_id (u_int16_t type, u_int32_t adv_router,
         continue;          continue;
       if (ntohl (lsa->header->id) > id)        if (ntohl (lsa->header->id) > id)
       {        {
        ospf6_lsa_unlock (lsa);        ospf6_lsdb_lsa_unlock (lsa);
         break;          break;
       }        }
       id++;        id++;
Line 572  ospf6_new_ls_seqnum (u_int16_t type, u_int32_t id, u_i Line 582  ospf6_new_ls_seqnum (u_int16_t type, u_int32_t id, u_i
   /* if current database copy not found, return InitialSequenceNumber */    /* if current database copy not found, return InitialSequenceNumber */
   lsa = ospf6_lsdb_lookup (type, id, adv_router, lsdb);    lsa = ospf6_lsdb_lookup (type, id, adv_router, lsdb);
   if (lsa == NULL)    if (lsa == NULL)
    seqnum = INITIAL_SEQUENCE_NUMBER;    seqnum = OSPF_INITIAL_SEQUENCE_NUMBER;
   else    else
     seqnum = (signed long) ntohl (lsa->header->seqnum) + 1;      seqnum = (signed long) ntohl (lsa->header->seqnum) + 1;
   

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


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