|
|
|
|
@ -68,16 +68,6 @@ static uint32_t detect_siggroup_matcharray_free_cnt = 0;
|
|
|
|
|
|
|
|
|
|
void SigGroupHeadInitDataFree(SigGroupHeadInitData *sghid)
|
|
|
|
|
{
|
|
|
|
|
if (sghid->content_array != NULL) {
|
|
|
|
|
SCFree(sghid->content_array);
|
|
|
|
|
sghid->content_array = NULL;
|
|
|
|
|
sghid->content_size = 0;
|
|
|
|
|
}
|
|
|
|
|
if (sghid->uri_content_array != NULL) {
|
|
|
|
|
SCFree(sghid->uri_content_array);
|
|
|
|
|
sghid->uri_content_array = NULL;
|
|
|
|
|
sghid->uri_content_size = 0;
|
|
|
|
|
}
|
|
|
|
|
if (sghid->sig_array != NULL) {
|
|
|
|
|
SCFree(sghid->sig_array);
|
|
|
|
|
sghid->sig_array = NULL;
|
|
|
|
|
@ -340,258 +330,6 @@ void SigGroupHeadMpmHashFree(DetectEngineCtx *de_ctx)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief The hash function to be the used by the mpm uri SigGroupHead hash
|
|
|
|
|
* table - DetectEngineCtx->sgh_mpm_uri_hash_table.
|
|
|
|
|
*
|
|
|
|
|
* \param ht Pointer to the hash table.
|
|
|
|
|
* \param data Pointer to the SigGroupHead.
|
|
|
|
|
* \param datalen Not used in our case.
|
|
|
|
|
*
|
|
|
|
|
* \retval hash The generated hash value.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t SigGroupHeadMpmUriHashFunc(HashListTable *ht, void *data, uint16_t datalen)
|
|
|
|
|
{
|
|
|
|
|
SigGroupHead *sgh = (SigGroupHead *)data;
|
|
|
|
|
uint32_t hash = 0;
|
|
|
|
|
uint32_t b = 0;
|
|
|
|
|
|
|
|
|
|
for (b = 0; b < sgh->init->uri_content_size; b++)
|
|
|
|
|
hash += sgh->init->uri_content_array[b];
|
|
|
|
|
|
|
|
|
|
return hash % ht->array_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief The Compare function to be used by the mpm uri SigGroupHead hash
|
|
|
|
|
* table - DetectEngineCtx->sgh_mpm_uri_hash_table.
|
|
|
|
|
*
|
|
|
|
|
* \param data1 Pointer to the first SigGroupHead.
|
|
|
|
|
* \param len1 Not used.
|
|
|
|
|
* \param data2 Pointer to the second SigGroupHead.
|
|
|
|
|
* \param len2 Not used.
|
|
|
|
|
*
|
|
|
|
|
* \retval 1 If the 2 SigGroupHeads sent as args match.
|
|
|
|
|
* \retval 0 If the 2 SigGroupHeads sent as args do not match.
|
|
|
|
|
*/
|
|
|
|
|
char SigGroupHeadMpmUriCompareFunc(void *data1, uint16_t len1, void *data2,
|
|
|
|
|
uint16_t len2)
|
|
|
|
|
{
|
|
|
|
|
SigGroupHead *sgh1 = (SigGroupHead *)data1;
|
|
|
|
|
SigGroupHead *sgh2 = (SigGroupHead *)data2;
|
|
|
|
|
|
|
|
|
|
if (sgh1->init->uri_content_size != sgh2->init->uri_content_size)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (SCMemcmp(sgh1->init->uri_content_array, sgh2->init->uri_content_array,
|
|
|
|
|
sgh1->init->uri_content_size) != 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Initializes the mpm uri hash table to be used by the detection engine
|
|
|
|
|
* context.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
*
|
|
|
|
|
* \retval 0 On success.
|
|
|
|
|
* \retval -1 On failure.
|
|
|
|
|
*/
|
|
|
|
|
int SigGroupHeadMpmUriHashInit(DetectEngineCtx *de_ctx)
|
|
|
|
|
{
|
|
|
|
|
de_ctx->sgh_mpm_uri_hash_table = HashListTableInit(4096,
|
|
|
|
|
SigGroupHeadMpmUriHashFunc,
|
|
|
|
|
SigGroupHeadMpmUriCompareFunc,
|
|
|
|
|
NULL);
|
|
|
|
|
if (de_ctx->sgh_mpm_uri_hash_table == NULL)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Adds a SigGroupHead to the detection engine context SigGroupHead
|
|
|
|
|
* mpm uri hash table.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
* \param sgh Pointer to the SigGroupHead.
|
|
|
|
|
*
|
|
|
|
|
* \retval ret 0 on Successfully adding the argument sgh and -1 on failure.
|
|
|
|
|
*/
|
|
|
|
|
int SigGroupHeadMpmUriHashAdd(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
|
|
|
|
|
{
|
|
|
|
|
int ret = HashListTableAdd(de_ctx->sgh_mpm_uri_hash_table, (void *)sgh, 0);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Used to lookup a SigGroupHead from the detection engine context
|
|
|
|
|
* SigGroupHead mpm uri hash table.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
* \param sgh Pointer to the SigGroupHead.
|
|
|
|
|
*
|
|
|
|
|
* \retval rsgh On success a pointer to the SigGroupHead if the SigGroupHead is
|
|
|
|
|
* found in the hash table; NULL on failure.
|
|
|
|
|
*/
|
|
|
|
|
SigGroupHead *SigGroupHeadMpmUriHashLookup(DetectEngineCtx *de_ctx,
|
|
|
|
|
SigGroupHead *sgh)
|
|
|
|
|
{
|
|
|
|
|
SigGroupHead *rsgh = HashListTableLookup(de_ctx->sgh_mpm_uri_hash_table,
|
|
|
|
|
(void *)sgh, 0);
|
|
|
|
|
|
|
|
|
|
return rsgh;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Frees the hash table - DetectEngineCtx->sgh_mpm_uri_hash_table,
|
|
|
|
|
* allocated by SigGroupHeadMpmUriHashInit() function.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
*/
|
|
|
|
|
void SigGroupHeadMpmUriHashFree(DetectEngineCtx *de_ctx)
|
|
|
|
|
{
|
|
|
|
|
if (de_ctx->sgh_mpm_uri_hash_table == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
HashListTableFree(de_ctx->sgh_mpm_uri_hash_table);
|
|
|
|
|
de_ctx->sgh_mpm_uri_hash_table = NULL;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief The hash function to be the used by the mpm uri SigGroupHead hash
|
|
|
|
|
* table - DetectEngineCtx->sgh_mpm_uri_hash_table.
|
|
|
|
|
*
|
|
|
|
|
* \param ht Pointer to the hash table.
|
|
|
|
|
* \param data Pointer to the SigGroupHead.
|
|
|
|
|
* \param datalen Not used in our case.
|
|
|
|
|
*
|
|
|
|
|
* \retval hash The generated hash value.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t SigGroupHeadMpmStreamHashFunc(HashListTable *ht, void *data, uint16_t datalen)
|
|
|
|
|
{
|
|
|
|
|
SigGroupHead *sgh = (SigGroupHead *)data;
|
|
|
|
|
uint32_t hash = 0;
|
|
|
|
|
uint32_t b = 0;
|
|
|
|
|
|
|
|
|
|
for (b = 0; b < sgh->init->stream_content_size; b++)
|
|
|
|
|
hash += sgh->init->stream_content_array[b];
|
|
|
|
|
|
|
|
|
|
return hash % ht->array_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief The Compare function to be used by the mpm uri SigGroupHead hash
|
|
|
|
|
* table - DetectEngineCtx->sgh_mpm_uri_hash_table.
|
|
|
|
|
*
|
|
|
|
|
* \param data1 Pointer to the first SigGroupHead.
|
|
|
|
|
* \param len1 Not used.
|
|
|
|
|
* \param data2 Pointer to the second SigGroupHead.
|
|
|
|
|
* \param len2 Not used.
|
|
|
|
|
*
|
|
|
|
|
* \retval 1 If the 2 SigGroupHeads sent as args match.
|
|
|
|
|
* \retval 0 If the 2 SigGroupHeads sent as args do not match.
|
|
|
|
|
*/
|
|
|
|
|
char SigGroupHeadMpmStreamCompareFunc(void *data1, uint16_t len1, void *data2,
|
|
|
|
|
uint16_t len2)
|
|
|
|
|
{
|
|
|
|
|
SigGroupHead *sgh1 = (SigGroupHead *)data1;
|
|
|
|
|
SigGroupHead *sgh2 = (SigGroupHead *)data2;
|
|
|
|
|
|
|
|
|
|
if (sgh1->init->stream_content_size != sgh2->init->stream_content_size)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (SCMemcmp(sgh1->init->stream_content_array, sgh2->init->stream_content_array,
|
|
|
|
|
sgh1->init->stream_content_size) != 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Initializes the mpm uri hash table to be used by the detection engine
|
|
|
|
|
* context.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
*
|
|
|
|
|
* \retval 0 On success.
|
|
|
|
|
* \retval -1 On failure.
|
|
|
|
|
*/
|
|
|
|
|
int SigGroupHeadMpmStreamHashInit(DetectEngineCtx *de_ctx)
|
|
|
|
|
{
|
|
|
|
|
de_ctx->sgh_mpm_stream_hash_table = HashListTableInit(4096,
|
|
|
|
|
SigGroupHeadMpmStreamHashFunc, SigGroupHeadMpmStreamCompareFunc, NULL);
|
|
|
|
|
if (de_ctx->sgh_mpm_stream_hash_table == NULL)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Adds a SigGroupHead to the detection engine context SigGroupHead
|
|
|
|
|
* mpm uri hash table.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
* \param sgh Pointer to the SigGroupHead.
|
|
|
|
|
*
|
|
|
|
|
* \retval ret 0 on Successfully adding the argument sgh and -1 on failure.
|
|
|
|
|
*/
|
|
|
|
|
int SigGroupHeadMpmStreamHashAdd(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
|
|
|
|
|
{
|
|
|
|
|
int ret = HashListTableAdd(de_ctx->sgh_mpm_stream_hash_table, (void *)sgh, 0);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Used to lookup a SigGroupHead from the detection engine context
|
|
|
|
|
* SigGroupHead mpm uri hash table.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
* \param sgh Pointer to the SigGroupHead.
|
|
|
|
|
*
|
|
|
|
|
* \retval rsgh On success a pointer to the SigGroupHead if the SigGroupHead is
|
|
|
|
|
* found in the hash table; NULL on failure.
|
|
|
|
|
*/
|
|
|
|
|
SigGroupHead *SigGroupHeadMpmStreamHashLookup(DetectEngineCtx *de_ctx,
|
|
|
|
|
SigGroupHead *sgh)
|
|
|
|
|
{
|
|
|
|
|
SigGroupHead *rsgh = HashListTableLookup(de_ctx->sgh_mpm_stream_hash_table,
|
|
|
|
|
(void *)sgh, 0);
|
|
|
|
|
|
|
|
|
|
return rsgh;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Frees the hash table - DetectEngineCtx->sgh_mpm_uri_hash_table,
|
|
|
|
|
* allocated by SigGroupHeadMpmUriHashInit() function.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
*/
|
|
|
|
|
void SigGroupHeadMpmStreamHashFree(DetectEngineCtx *de_ctx)
|
|
|
|
|
{
|
|
|
|
|
if (de_ctx->sgh_mpm_stream_hash_table == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
HashListTableFree(de_ctx->sgh_mpm_stream_hash_table);
|
|
|
|
|
de_ctx->sgh_mpm_stream_hash_table = NULL;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief The hash function to be the used by the hash table -
|
|
|
|
|
* DetectEngineCtx->sgh_hash_table.
|
|
|
|
|
@ -806,88 +544,6 @@ void SigGroupHeadDPortHashFree(DetectEngineCtx *de_ctx)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Initializes the sport based SigGroupHead hash table to hold the
|
|
|
|
|
* SigGroupHeads. The hash table that would be initialized is
|
|
|
|
|
* DetectEngineCtx->sgh_sport_hash_table.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
*
|
|
|
|
|
* \retval 0 On success.
|
|
|
|
|
* \retval -1 On failure.
|
|
|
|
|
*/
|
|
|
|
|
int SigGroupHeadSPortHashInit(DetectEngineCtx *de_ctx)
|
|
|
|
|
{
|
|
|
|
|
de_ctx->sgh_sport_hash_table = HashListTableInit(4096,
|
|
|
|
|
SigGroupHeadHashFunc,
|
|
|
|
|
SigGroupHeadCompareFunc,
|
|
|
|
|
NULL);
|
|
|
|
|
if (de_ctx->sgh_sport_hash_table == NULL)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Adds a SigGroupHead to the detection engine context dport based
|
|
|
|
|
* SigGroupHead hash table(DetectEngineCtx->sgh_sport_hash_table).
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
* \param sgh Pointer to the SigGroupHead.
|
|
|
|
|
*
|
|
|
|
|
* \retval ret 0 on Successfully adding the argument sgh and -1 on failure.
|
|
|
|
|
*/
|
|
|
|
|
int SigGroupHeadSPortHashAdd(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
|
|
|
|
|
{
|
|
|
|
|
int ret = HashListTableAdd(de_ctx->sgh_sport_hash_table, (void *)sgh, 0);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SigGroupHeadSPortHashRemove(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
|
|
|
|
|
{
|
|
|
|
|
return HashListTableRemove(de_ctx->sgh_sport_hash_table, (void *)sgh, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Used to lookup a SigGroupHead hash from the detection engine ctx sport
|
|
|
|
|
* based SigGroupHead hash table(DetectEngineCtx->sgh_dport_hash_table).
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
* \param sgh Pointer to the SigGroupHead.
|
|
|
|
|
*
|
|
|
|
|
* \retval rsgh On success a pointer to the SigGroupHead if the SigGroupHead is
|
|
|
|
|
* found in the hash table; NULL on failure.
|
|
|
|
|
*/
|
|
|
|
|
SigGroupHead *SigGroupHeadSPortHashLookup(DetectEngineCtx *de_ctx,
|
|
|
|
|
SigGroupHead *sgh)
|
|
|
|
|
{
|
|
|
|
|
SigGroupHead *rsgh = HashListTableLookup(de_ctx->sgh_sport_hash_table,
|
|
|
|
|
(void *)sgh, 0);
|
|
|
|
|
|
|
|
|
|
return rsgh;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Frees the hash table - DetectEngineCtx->sgh_sport_hash_table,
|
|
|
|
|
* allocated by the SigGroupHeadSPortHashInit() function.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
*/
|
|
|
|
|
void SigGroupHeadSPortHashFree(DetectEngineCtx *de_ctx)
|
|
|
|
|
{
|
|
|
|
|
if (de_ctx->sgh_sport_hash_table == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
HashListTableFree(de_ctx->sgh_sport_hash_table);
|
|
|
|
|
de_ctx->sgh_sport_hash_table = NULL;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Used to free the signature array, content_array and uri_content_array
|
|
|
|
|
* members from the SigGroupHeads in the HashListTable.
|
|
|
|
|
@ -964,7 +620,6 @@ void SigGroupHeadFreeSigArrays(DetectEngineCtx *de_ctx)
|
|
|
|
|
{
|
|
|
|
|
SigGroupHeadFreeSigArraysHash2(de_ctx, de_ctx->sgh_hash_table);
|
|
|
|
|
SigGroupHeadFreeSigArraysHash(de_ctx, de_ctx->sgh_dport_hash_table);
|
|
|
|
|
SigGroupHeadFreeSigArraysHash(de_ctx, de_ctx->sgh_sport_hash_table);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
@ -987,14 +642,6 @@ void SigGroupHeadFreeMpmArrays(DetectEngineCtx *de_ctx)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (htb = HashListTableGetListHead(de_ctx->sgh_sport_hash_table); htb != NULL; htb = HashListTableGetListNext(htb)) {
|
|
|
|
|
sgh = (SigGroupHead *)HashListTableGetListData(htb);
|
|
|
|
|
if (sgh->init != NULL) {
|
|
|
|
|
SigGroupHeadInitDataFree(sgh->init);
|
|
|
|
|
sgh->init = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -1236,304 +883,6 @@ void SigGroupHeadPrintSigs(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
|
|
|
|
|
SCReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Helper function used to print the content ids of all the contents that
|
|
|
|
|
* have been added to the bitarray of this SigGroupHead.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
* \param sgh Pointer to the SigGroupHead.
|
|
|
|
|
*/
|
|
|
|
|
void SigGroupHeadPrintContent(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t i = 0;
|
|
|
|
|
|
|
|
|
|
SCLogDebug("Contents with the following content ids are present in this "
|
|
|
|
|
"SigGroupHead - ");
|
|
|
|
|
for (i = 0; i < DetectContentMaxId(de_ctx); i++) {
|
|
|
|
|
if (sgh->init->content_array[i / 8] & (1 << (i % 8)))
|
|
|
|
|
SCLogDebug("%" PRIu32, i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Helper function used to print the total no of contents that have
|
|
|
|
|
* been added to the bitarray for this SigGroupHead.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
* \param sgh Pointer to the SigGroupHead.
|
|
|
|
|
*/
|
|
|
|
|
void SigGroupHeadPrintContentCnt(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
uint32_t i = 0;
|
|
|
|
|
uint32_t cnt = 0;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < DetectContentMaxId(de_ctx); i++) {
|
|
|
|
|
if (sgh->init->content_array[i / 8] & (1 << (i % 8)))
|
|
|
|
|
cnt++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCLogDebug("Total contents added to the SigGroupHead content bitarray: "
|
|
|
|
|
"%" PRIu32, cnt);
|
|
|
|
|
|
|
|
|
|
SCReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Loads all the content ids from all the contents belonging to all the
|
|
|
|
|
* Signatures in this SigGroupHead, into a bitarray. A fast and an
|
|
|
|
|
* efficient way of comparing pattern sets.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
* \param sgh Pointer to the SigGroupHead.
|
|
|
|
|
*
|
|
|
|
|
* \retval 0 On success, i.e. on either the detection engine context being NULL
|
|
|
|
|
* or on successfully allocating memory and updating it with relevant
|
|
|
|
|
* data.
|
|
|
|
|
* \retval -1 On failure.
|
|
|
|
|
*/
|
|
|
|
|
int SigGroupHeadLoadContent(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
|
|
|
|
|
{
|
|
|
|
|
Signature *s = NULL;
|
|
|
|
|
SigMatch *sm = NULL;
|
|
|
|
|
uint32_t sig = 0;
|
|
|
|
|
DetectContentData *co = NULL;
|
|
|
|
|
|
|
|
|
|
if (sgh == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (DetectContentMaxId(de_ctx) == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
BUG_ON(sgh->init == NULL);
|
|
|
|
|
|
|
|
|
|
sgh->init->content_size = (DetectContentMaxId(de_ctx) / 8) + 1;
|
|
|
|
|
sgh->init->content_array = SCMalloc(sgh->init->content_size);
|
|
|
|
|
if (sgh->init->content_array == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
memset(sgh->init->content_array,0, sgh->init->content_size);
|
|
|
|
|
|
|
|
|
|
for (sig = 0; sig < sgh->sig_cnt; sig++) {
|
|
|
|
|
s = sgh->match_array[sig];
|
|
|
|
|
if (s == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (s->alproto != ALPROTO_UNKNOWN)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
sm = s->sm_lists[DETECT_SM_LIST_PMATCH];
|
|
|
|
|
if (sm == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
for ( ;sm != NULL; sm = sm->next) {
|
|
|
|
|
if (sm->type == DETECT_CONTENT) {
|
|
|
|
|
co = (DetectContentData *)sm->ctx;
|
|
|
|
|
|
|
|
|
|
sgh->init->content_array[co->id / 8] |= 1 << (co->id % 8);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Clears the memory allocated by SigGroupHeadLoadContent() for the
|
|
|
|
|
* bitarray to hold the content ids for a SigGroupHead.
|
|
|
|
|
*
|
|
|
|
|
* \param Pointer to the SigGroupHead whose content_array would to be cleared.
|
|
|
|
|
*
|
|
|
|
|
* \ret 0 Always.
|
|
|
|
|
*/
|
|
|
|
|
int SigGroupHeadClearContent(SigGroupHead *sh)
|
|
|
|
|
{
|
|
|
|
|
if (sh == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (sh->init->content_array != NULL) {
|
|
|
|
|
SCFree(sh->init->content_array);
|
|
|
|
|
sh->init->content_array = NULL;
|
|
|
|
|
sh->init->content_size = 0;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Loads all the uri content ids from all the uri contents belonging to
|
|
|
|
|
* all the Signatures in this SigGroupHead, into a bitarray. A fast and
|
|
|
|
|
* an efficient way of comparing pattern sets.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
* \param sgh Pointer to the SigGroupHead.
|
|
|
|
|
*
|
|
|
|
|
* \retval 0 On success, i.e. on either the detection engine context being NULL
|
|
|
|
|
* or on successfully allocating memory and updating it with relevant
|
|
|
|
|
* data.
|
|
|
|
|
* \retval -1 On failure.
|
|
|
|
|
*/
|
|
|
|
|
int SigGroupHeadLoadUricontent(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
|
|
|
|
|
{
|
|
|
|
|
Signature *s = NULL;
|
|
|
|
|
SigMatch *sm = NULL;
|
|
|
|
|
uint32_t sig = 0;
|
|
|
|
|
DetectContentData *co = NULL;
|
|
|
|
|
|
|
|
|
|
if (sgh == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (DetectUricontentMaxId(de_ctx) == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
BUG_ON(sgh->init == NULL);
|
|
|
|
|
|
|
|
|
|
sgh->init->uri_content_size = (DetectUricontentMaxId(de_ctx) / 8) + 1;
|
|
|
|
|
sgh->init->uri_content_array = SCMalloc(sgh->init->uri_content_size);
|
|
|
|
|
if (sgh->init->uri_content_array == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
memset(sgh->init->uri_content_array, 0, sgh->init->uri_content_size);
|
|
|
|
|
|
|
|
|
|
for (sig = 0; sig < sgh->sig_cnt; sig++) {
|
|
|
|
|
s = sgh->match_array[sig];
|
|
|
|
|
|
|
|
|
|
if (s == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
sm = s->sm_lists[DETECT_SM_LIST_UMATCH];
|
|
|
|
|
if (sm == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
for ( ;sm != NULL; sm = sm->next) {
|
|
|
|
|
if (sm->type == DETECT_CONTENT) {
|
|
|
|
|
co = (DetectContentData *)sm->ctx;
|
|
|
|
|
|
|
|
|
|
sgh->init->uri_content_array[co->id / 8] |= 1 << (co->id % 8);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Clears the memory allocated by SigGroupHeadLoadUriContent() for the
|
|
|
|
|
* bitarray to hold the uri content ids for a SigGroupHead.
|
|
|
|
|
*
|
|
|
|
|
* \param Pointer to the SigGroupHead whose uri_content_array would to be
|
|
|
|
|
* cleared.
|
|
|
|
|
*
|
|
|
|
|
* \retval 0 Always.
|
|
|
|
|
*/
|
|
|
|
|
int SigGroupHeadClearUricontent(SigGroupHead *sh)
|
|
|
|
|
{
|
|
|
|
|
if (sh == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (sh->init->uri_content_array != NULL) {
|
|
|
|
|
SCFree(sh->init->uri_content_array);
|
|
|
|
|
sh->init->uri_content_array = NULL;
|
|
|
|
|
sh->init->uri_content_size = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Loads all the content ids from all the contents belonging to all the
|
|
|
|
|
* Signatures in this SigGroupHead, into a bitarray. A fast and an
|
|
|
|
|
* efficient way of comparing pattern sets.
|
|
|
|
|
*
|
|
|
|
|
* \param de_ctx Pointer to the detection engine context.
|
|
|
|
|
* \param sgh Pointer to the SigGroupHead.
|
|
|
|
|
*
|
|
|
|
|
* \retval 0 On success, i.e. on either the detection engine context being NULL
|
|
|
|
|
* or on successfully allocating memory and updating it with relevant
|
|
|
|
|
* data.
|
|
|
|
|
* \retval -1 On failure.
|
|
|
|
|
*/
|
|
|
|
|
int SigGroupHeadLoadStreamContent(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
Signature *s = NULL;
|
|
|
|
|
SigMatch *sm = NULL;
|
|
|
|
|
uint32_t sig = 0;
|
|
|
|
|
DetectContentData *co = NULL;
|
|
|
|
|
|
|
|
|
|
if (sgh == NULL) {
|
|
|
|
|
SCReturnInt(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DetectContentMaxId(de_ctx) == 0) {
|
|
|
|
|
SCReturnInt(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BUG_ON(sgh->init == NULL);
|
|
|
|
|
|
|
|
|
|
sgh->init->stream_content_size = (DetectContentMaxId(de_ctx) / 8) + 1;
|
|
|
|
|
sgh->init->stream_content_array = SCMalloc(sgh->init->stream_content_size);
|
|
|
|
|
if (sgh->init->stream_content_array == NULL) {
|
|
|
|
|
SCReturnInt(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset(sgh->init->stream_content_array,0, sgh->init->stream_content_size);
|
|
|
|
|
|
|
|
|
|
for (sig = 0; sig < sgh->sig_cnt; sig++) {
|
|
|
|
|
s = sgh->match_array[sig];
|
|
|
|
|
|
|
|
|
|
SCLogDebug("s %"PRIu32, s->id);
|
|
|
|
|
|
|
|
|
|
if (s == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (SignatureHasPacketContent(s)) {
|
|
|
|
|
SCLogDebug("Sig has packet content");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sm = s->sm_lists[DETECT_SM_LIST_PMATCH];
|
|
|
|
|
if (sm == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
for ( ;sm != NULL; sm = sm->next) {
|
|
|
|
|
if (sm->type == DETECT_CONTENT) {
|
|
|
|
|
co = (DetectContentData *)sm->ctx;
|
|
|
|
|
|
|
|
|
|
sgh->init->stream_content_array[co->id / 8] |= 1 << (co->id % 8);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCReturnInt(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Clears the memory allocated by SigGroupHeadLoadContent() for the
|
|
|
|
|
* bitarray to hold the content ids for a SigGroupHead.
|
|
|
|
|
*
|
|
|
|
|
* \param Pointer to the SigGroupHead whose content_array would to be cleared.
|
|
|
|
|
*
|
|
|
|
|
* \ret 0 Always.
|
|
|
|
|
*/
|
|
|
|
|
int SigGroupHeadClearStreamContent(SigGroupHead *sh)
|
|
|
|
|
{
|
|
|
|
|
if (sh == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (sh->init->stream_content_array != NULL) {
|
|
|
|
|
SCFree(sh->init->stream_content_array);
|
|
|
|
|
sh->init->stream_content_array = NULL;
|
|
|
|
|
sh->init->stream_content_size = 0;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Create an array with all the internal ids of the sigs that this
|
|
|
|
|
* sig group head will check for.
|
|
|
|
|
@ -1865,28 +1214,6 @@ static int SigGroupHeadTest01(void)
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \test Check if a SigGroupHead mpm uri hash table is properly allocated and
|
|
|
|
|
* deallocated when calling SigGroupHeadMpmUriHashInit() and
|
|
|
|
|
* SigGroupHeadMpmUriHashFree() respectively.
|
|
|
|
|
*/
|
|
|
|
|
static int SigGroupHeadTest02(void)
|
|
|
|
|
{
|
|
|
|
|
int result = 1;
|
|
|
|
|
|
|
|
|
|
DetectEngineCtx de_ctx;
|
|
|
|
|
|
|
|
|
|
SigGroupHeadMpmUriHashInit(&de_ctx);
|
|
|
|
|
|
|
|
|
|
result &= (de_ctx.sgh_mpm_uri_hash_table != NULL);
|
|
|
|
|
|
|
|
|
|
SigGroupHeadMpmUriHashFree(&de_ctx);
|
|
|
|
|
|
|
|
|
|
result &= (de_ctx.sgh_mpm_uri_hash_table == NULL);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \test Check if a SigGroupHead hash table is properly allocated and
|
|
|
|
|
* deallocated when calling SigGroupHeadHashInit() and
|
|
|
|
|
@ -1931,28 +1258,6 @@ static int SigGroupHeadTest04(void)
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \test Check if a SigGroupHead dport hash table is properly allocated and
|
|
|
|
|
* deallocated when calling SigGroupHeadSPortHashInit() and
|
|
|
|
|
* SigGroupHeadSportHashFree() respectively.
|
|
|
|
|
*/
|
|
|
|
|
static int SigGroupHeadTest05(void)
|
|
|
|
|
{
|
|
|
|
|
int result = 1;
|
|
|
|
|
|
|
|
|
|
DetectEngineCtx de_ctx;
|
|
|
|
|
|
|
|
|
|
SigGroupHeadSPortHashInit(&de_ctx);
|
|
|
|
|
|
|
|
|
|
result &= (de_ctx.sgh_sport_hash_table != NULL);
|
|
|
|
|
|
|
|
|
|
SigGroupHeadSPortHashFree(&de_ctx);
|
|
|
|
|
|
|
|
|
|
result &= (de_ctx.sgh_sport_hash_table == NULL);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \test Check if a SigGroupHeadAppendSig() correctly appends a sid to a
|
|
|
|
|
* SigGroupHead() and SigGroupHeadContainsSigId() correctly indicates
|
|
|
|
|
@ -2416,10 +1721,8 @@ void SigGroupHeadRegisterTests(void)
|
|
|
|
|
{
|
|
|
|
|
#ifdef UNITTESTS
|
|
|
|
|
UtRegisterTest("SigGroupHeadTest01", SigGroupHeadTest01, 1);
|
|
|
|
|
UtRegisterTest("SigGroupHeadTest02", SigGroupHeadTest02, 1);
|
|
|
|
|
UtRegisterTest("SigGroupHeadTest03", SigGroupHeadTest03, 1);
|
|
|
|
|
UtRegisterTest("SigGroupHeadTest04", SigGroupHeadTest04, 1);
|
|
|
|
|
UtRegisterTest("SigGroupHeadTest05", SigGroupHeadTest05, 1);
|
|
|
|
|
UtRegisterTest("SigGroupHeadTest06", SigGroupHeadTest06, 1);
|
|
|
|
|
UtRegisterTest("SigGroupHeadTest07", SigGroupHeadTest07, 1);
|
|
|
|
|
UtRegisterTest("SigGroupHeadTest08", SigGroupHeadTest08, 1);
|
|
|
|
|
|