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; }
/** * Get the least recently used flow from the cache * * @param flowcachep flow cache to operate on * @param flowp where to put the flow * * @return FLOW_SUCCESS on success */ static INLINE int flowcache_lru(FLOWCACHE *flowcachep, FLOW **flowpp) { if(!flowcachep || !flowpp) return FLOW_EINVALID; *flowpp = sfxhash_lru(flowcachep->ipv4_table); if(*flowpp == NULL) return FLOW_NOTFOUND; return FLOW_SUCCESS; }
/** * Get the least recently used flow from the cache * * @param sbp scoreboard to find * @param sepp score entry pointer to fill in * * @return FLOW_SUCCESS on sucess */ static INLINE int scoreboard_lru(SCOREBOARD *sbp, SCORE_ENTRY **sepp) { if(!sbp || !sepp) return FLOW_EINVALID; *sepp = sfxhash_lru(sbp->ipv4_table); if(*sepp == NULL) return FLOW_NOTFOUND; return FLOW_SUCCESS; }