static void set_timer(void) { struct mipv6_bcache_entry *entry; unsigned long callback_time; DEBUG_FUNC(); entry = (struct mipv6_bcache_entry *) hashlist_get_first(bcache->entries); if (entry != NULL) { if (entry->callback_time == EXPIRE_INFINITE) { DEBUG((DBG_WARNING, "bcache.c: set_timer: expire at infinity, " "not setting a new timer")); } else { if (entry->br_callback_time > 0) callback_time = entry->br_callback_time; else if (entry->callback_time > jiffies) callback_time = entry->callback_time; else { DEBUG((DBG_WARNING, "bcache.c: set_timer: bcache timer attempted " "to schedule for a historical jiffies count!")); callback_time = jiffies+TIMERDELAY; } DEBUG((DBG_INFO, "bcache.c: set_timer: setting timer to now")); mod_timer(&bcache->callback_timer, callback_time); } } else { del_timer(&bcache->callback_timer); DEBUG((DBG_INFO, "bcache.c: set_timer: BC empty, not setting a new timer")); } return; }
int __exit mipv6_shutdown_bcache() { unsigned long flags; struct mipv6_bcache_entry *entry; DEBUG_FUNC(); write_lock_irqsave(&bcache->lock, flags); DEBUG((DBG_INFO, "mipv6_shutdown_bcache: Stopping the timer")); del_timer(&bcache->callback_timer); while ((entry = (struct mipv6_bcache_entry *) hashlist_get_first(bcache->entries)) != NULL) { DEBUG_FUNC(); /* hashlist_delete_first(bcache->entries); */ bcache_proxy_nd_rem(entry); hashlist_delete(bcache->entries, &entry->home_addr); mipv6_bcache_entry_free(entry); DEBUG_FUNC(); } hashlist_destroy(bcache->entries); mipv6_free_allocation_pool(bcache->entry_pool); #ifdef CONFIG_PROC_FS proc_net_remove("mip6_bcache"); #endif /* Lock must be released before freeing the memory. */ write_unlock_irqrestore(&bcache->lock, flags); kfree(bcache); return 0; }
int main() { UUID_HEAD * test_uuid; UUID_HEAD * test_uuid1; BYTE digest[DIGEST_SIZE]; int ret; // static unsigned char alloc_buffer[4096*(1+1+4+1+16+1+256)]; void * hash_head; // alloc_init(alloc_buffer); test_uuid=Calloc(sizeof(UUID_HEAD)); Memset(test_uuid->uuid,'A',DIGEST_SIZE); hash_head=init_hash_list(8,0,0); ret=hashlist_add_elem(hash_head,test_uuid); Memset(digest,'A',DIGEST_SIZE); test_uuid1=hashlist_find_elem(hash_head,digest); test_uuid=hashlist_get_first(hash_head); test_uuid1=hashlist_get_next(hash_head); test_uuid=hashlist_remove_elem(hash_head,digest); test_uuid1=hashlist_find_elem(hash_head,digest); // void * list_queue; // list_queue=init_list_queue(); // list_queue_put(list_queue,test_uuid); // list_queue_put(list_queue,test_uuid1); // void * temp; // ret=list_queue_get(list_queue,&temp); // ret=list_queue_get(list_queue,&temp); // ret=list_queue_get(list_queue,&temp); // free_list_queue(list_queue); Free(test_uuid); return 0; }
/* * Removes all expired entries */ static void expire(void) { struct mipv6_bcache_entry *entry; unsigned long now = jiffies; unsigned long flags; struct br_addrs { struct in6_addr daddr; struct in6_addr saddr; struct br_addrs *next; }; struct br_addrs *br_info = NULL; DEBUG_FUNC(); write_lock_irqsave(&bcache->lock, flags); while ((entry = (struct mipv6_bcache_entry *) hashlist_get_first(bcache->entries)) != NULL) { if (entry->callback_time <= now) { DEBUG((DBG_INFO, "expire(): an entry expired")); if (entry->type & HOME_REGISTRATION) { mipv6_tunnel_route_del(&entry->home_addr, &entry->coa, &entry->our_addr); mipv6_tunnel_del(&entry->coa, &entry->our_addr); bcache_proxy_nd_rem(entry); } hashlist_delete(bcache->entries, &entry->home_addr); mipv6_bcache_entry_free(entry); entry = NULL; } else if (entry->br_callback_time != 0 && entry->br_callback_time <= now && entry->type & !(HOME_REGISTRATION | TEMPORARY_ENTRY)) { if (now - entry->last_used < BCACHE_BR_SEND_THRESHOLD * HZ) { struct br_addrs *tmp; tmp = br_info; DEBUG((DBG_INFO, "bcache entry recently used. Sending BR.")); /* queue for sending */ br_info = kmalloc(sizeof(struct br_addrs), GFP_ATOMIC); if (br_info) { ipv6_addr_copy(&br_info->saddr, &entry->our_addr); ipv6_addr_copy(&br_info->daddr, &entry->home_addr); br_info->next = tmp; entry->last_br = now; } else { br_info = tmp; DEBUG((DBG_ERROR, "Out of memory")); } } entry->br_callback_time = 0; } else { break; } } write_unlock_irqrestore(&bcache->lock, flags); while (br_info) { struct br_addrs *tmp = br_info->next; if (mipv6_send_rq_option(&br_info->saddr, &br_info->daddr, 0, NULL) < 0) DEBUG((DBG_WARNING, "BR send for %x:%x:%x:%x:%x:%x:%x:%x failed", NIPV6ADDR(&br_info->daddr))); kfree(br_info); br_info = tmp; } return; }