Improve threshold hash table handling.

remotes/origin/master-1.0.x
Victor Julien 16 years ago
parent 8c8b8596c8
commit 6ab64706b0

@ -148,15 +148,23 @@ void ThresholdTimeoutRemove(DetectEngineCtx *de_ctx)
next = HashListTableGetListHead(de_ctx->ths_ctx.threshold_hash_table_src); next = HashListTableGetListHead(de_ctx->ths_ctx.threshold_hash_table_src);
while (next != NULL) { while (next != NULL) {
tsh = HashListTableGetListData(next); tsh = HashListTableGetListData(next);
if (tsh && ((tv.tv_sec - tsh->tv_sec1) > tsh->seconds)) { if (tsh && ((tv.tv_sec - tsh->tv_sec1) > tsh->seconds)) {
if (tsh->ipv == 4) {
if (tsh->type == TRACK_SRC) {
HashListTableRemove(de_ctx->ths_ctx.threshold_hash_table_src, tsh, sizeof(DetectThresholdData)); HashListTableRemove(de_ctx->ths_ctx.threshold_hash_table_src, tsh, sizeof(DetectThresholdData));
} else if (tsh->type == TRACK_DST) {
HashListTableRemove(de_ctx->ths_ctx.threshold_hash_table_dst, tsh, sizeof(DetectThresholdData)); HashListTableRemove(de_ctx->ths_ctx.threshold_hash_table_dst, tsh, sizeof(DetectThresholdData));
}
} else if (tsh->ipv == 6) {
if (tsh->type == TRACK_SRC) {
HashListTableRemove(de_ctx->ths_ctx.threshold_hash_table_src_ipv6, tsh, sizeof(DetectThresholdData)); HashListTableRemove(de_ctx->ths_ctx.threshold_hash_table_src_ipv6, tsh, sizeof(DetectThresholdData));
} else if (tsh->type == TRACK_DST) {
HashListTableRemove(de_ctx->ths_ctx.threshold_hash_table_dst_ipv6, tsh, sizeof(DetectThresholdData)); HashListTableRemove(de_ctx->ths_ctx.threshold_hash_table_dst_ipv6, tsh, sizeof(DetectThresholdData));
} }
}
}
next = HashListTableGetListNext(next); next = HashListTableGetListNext(next);
} }
@ -191,8 +199,8 @@ void ThresholdHashAdd(DetectEngineCtx *de_ctx, DetectThresholdData *tsh_ptr, Pac
} }
if(ret == -1) { if(ret == -1) {
SCLogError(SC_ERR_MEM_ALLOC, SCLogError(SC_ERR_THRESHOLD_HASH_ADD,
"Threshold: Failed to Add element into the hash table."); "failed to add element into the hash table");
} }
return; return;

@ -229,7 +229,7 @@ typedef struct ThresholdCtx_ {
HashListTable *threshold_hash_table_src; /**< Ipv4 src hash table */ HashListTable *threshold_hash_table_src; /**< Ipv4 src hash table */
HashListTable *threshold_hash_table_dst_ipv6; /**< Ipv6 dst hash table */ HashListTable *threshold_hash_table_dst_ipv6; /**< Ipv6 dst hash table */
HashListTable *threshold_hash_table_src_ipv6; /**< Ipv6 src hash table */ HashListTable *threshold_hash_table_src_ipv6; /**< Ipv6 src hash table */
pthread_mutex_t threshold_table_lock; /**< Mutex for hash table */ SCMutex threshold_table_lock; /**< Mutex for hash table */
} ThresholdCtx; } ThresholdCtx;
/** \brief main detection engine ctx */ /** \brief main detection engine ctx */

@ -61,6 +61,7 @@ const char * SCErrorToString(SCError err)
CASE_CODE (SC_ERR_UNIFIED2_ALERT_GENERIC_ERROR); CASE_CODE (SC_ERR_UNIFIED2_ALERT_GENERIC_ERROR);
CASE_CODE (SC_ERR_FWRITE); CASE_CODE (SC_ERR_FWRITE);
CASE_CODE (SC_ERR_FOPEN); CASE_CODE (SC_ERR_FOPEN);
CASE_CODE (SC_ERR_THRESHOLD_HASH_ADD);
default: default:
return "UNKNOWN_ERROR"; return "UNKNOWN_ERROR";
} }

@ -73,6 +73,7 @@ typedef enum {
SC_ERR_UNIFIED_ALERT_GENERIC_ERROR, SC_ERR_UNIFIED_ALERT_GENERIC_ERROR,
SC_ERR_UNIFIED2_ALERT_GENERIC_ERROR, SC_ERR_UNIFIED2_ALERT_GENERIC_ERROR,
SC_ERR_FWRITE, SC_ERR_FWRITE,
SC_ERR_THRESHOLD_HASH_ADD,
} SCError; } SCError;
const char *SCErrorToString(SCError); const char *SCErrorToString(SCError);

Loading…
Cancel
Save