int CleanHashTable(SFXHASH *table, u_int32_t thetime, Session *save_me, int memCheck) { Session *idx; u_int32_t pruned = 0; u_int32_t timeout = s4data.timeout; if (thetime != 0) { char got_one; idx = (Session *) sfxhash_lru(table); if(idx == NULL) { return 0; } do { got_one = 0; if(idx == save_me) { SFXHASH_NODE *lastNode = sfxhash_lru_node(table); sfxhash_gmovetofront(table, lastNode); lastNode = sfxhash_lru_node(table); if ((lastNode) && (lastNode->data != idx)) { idx = (Session *)lastNode->data; continue; } else { return pruned; } } timeout = s4data.timeout; if(idx->drop_traffic) { /* If we're dropping traffic on the session, keep * it around longer. */ timeout = s4data.timeout * 2; } if((idx->last_session_time+timeout) < thetime) { Session *savidx = idx; if(sfxhash_count(table) > 1) { DEBUG_WRAP(DebugMessage(DEBUG_STREAM, "pruning stale session\n");); DeleteSession(savidx, thetime, SESSION_CLOSED_TIMEDOUT); idx = (Session *) sfxhash_lru(table); pruned++; got_one = 1; }
int PruneLWSessionCache(Stream5SessionCache *sessionCache, uint32_t thetime, Stream5LWSession *save_me, int memCheck) { Stream5LWSession *idx; uint32_t pruned = 0; if (thetime != 0) { /* Pruning, look for sessions that have time'd out */ char got_one; idx = (Stream5LWSession *) sfxhash_lru(sessionCache->hashTable); if(idx == NULL) { return 0; } do { got_one = 0; if(idx == save_me) { SFXHASH_NODE *lastNode = sfxhash_lru_node(sessionCache->hashTable); sfxhash_gmovetofront(sessionCache->hashTable, lastNode); lastNode = sfxhash_lru_node(sessionCache->hashTable); if ((lastNode) && (lastNode->data != idx)) { idx = (Stream5LWSession *)lastNode->data; continue; } else { sessionCache->prunes += pruned; return pruned; } } if((idx->last_data_seen+sessionCache->timeout) < thetime) { Stream5LWSession *savidx = idx; if(sfxhash_count(sessionCache->hashTable) > 1) { DEBUG_WRAP(DebugMessage(DEBUG_STREAM, "pruning stale session\n");); savidx->session_flags |= SSNFLAG_TIMEDOUT; DeleteLWSession(sessionCache, savidx, "stale/timeout"); idx = (Stream5LWSession *) sfxhash_lru(sessionCache->hashTable); pruned++; got_one = 1; }
/* Prune file entries based on LRU */ static int pruneFileCache(FileCache *fileCache, FileEntry *file) { SFXHASH_NODE *lru_node = NULL; int pruned = 0; int mustdie = fileCache->cleanup_files; while (pruned < mustdie && (sfxhash_count(fileCache->hashTable) > 0)) { if ((lru_node = sfxhash_lru_node(fileCache->hashTable)) != NULL) { if (lru_node->data == file) break; if (sfxhash_free_node(fileCache->hashTable, lru_node) != SFXHASH_OK) { LogMessage("WARNING: failed to remove file entry from hash.\n"); } pruned++; } } fileCache->status.prunes += pruned; return pruned; }