コード例 #1
0
/**
 * \brief Destroy threshold context hash tables
 *
 * \param de_ctx Dectection Context
 *
 */
void ThresholdContextDestroy(DetectEngineCtx *de_ctx)
{
    HashListTableFree(de_ctx->ths_ctx.threshold_hash_table_dst);
    HashListTableFree(de_ctx->ths_ctx.threshold_hash_table_src);
    HashListTableFree(de_ctx->ths_ctx.threshold_hash_table_dst_ipv6);
    HashListTableFree(de_ctx->ths_ctx.threshold_hash_table_src_ipv6);
    if (de_ctx->ths_ctx.th_entry != NULL)
        SCFree(de_ctx->ths_ctx.th_entry);
}
コード例 #2
0
ファイル: util-hashlist.c プロジェクト: H5eye/suricata
static int HashListTableTestFull02 (void)
{
    int result = 0;
    HashListTable *ht = HashListTableInit(32, HashListTableGenericHash, NULL, NULL);
    if (ht == NULL)
        goto end;

    int r = HashListTableAdd(ht, "test", 4);
    if (r != 0)
        goto end;

    char *rp = HashListTableLookup(ht, "test", 4);
    if (rp == NULL)
        goto end;

    r = HashListTableRemove(ht, "test2", 5);
    if (r == 0)
        goto end;

    /* all is good! */
    result = 1;
end:
    if (ht != NULL) HashListTableFree(ht);
    return result;
}
コード例 #3
0
ファイル: util-hashlist.c プロジェクト: H5eye/suricata
static int HashListTableTestAdd03 (void)
{
    int result = 0;
    HashListTable *ht = HashListTableInit(32, HashListTableGenericHash, NULL, NULL);
    if (ht == NULL)
        goto end;

    int r = HashListTableAdd(ht, "test", 0);
    if (r != 0)
        goto end;

    if (ht->listhead == NULL) {
        printf("ht->listhead == NULL: ");
        goto end;
    }

    if (ht->listtail == NULL) {
        printf("ht->listtail == NULL: ");
        goto end;
    }

    /* all is good! */
    result = 1;
end:
    if (ht != NULL) HashListTableFree(ht);
    return result;
}
コード例 #4
0
ファイル: util-hashlist.c プロジェクト: H5eye/suricata
static int HashListTableTestInit04 (void)
{
    HashListTable *ht = HashListTableInit(0, HashListTableGenericHash, NULL, NULL);
    if (ht == NULL)
        return 1;

    HashListTableFree(ht);
    return 0;
}
コード例 #5
0
ファイル: util-hashlist.c プロジェクト: H5eye/suricata
/* no hash function, so it should fail */
static int HashListTableTestInit02 (void)
{
    HashListTable *ht = HashListTableInit(1024, NULL, NULL, NULL);
    if (ht == NULL)
        return 1;

    HashListTableFree(ht);
    return 0;
}
コード例 #6
0
ファイル: detect-engine-mpm.c プロジェクト: banjoey/suricata
/**
 * \brief Frees the hash table - DetectEngineCtx->mpm_hash_table, allocated by
 *        MpmStoreInit() function.
 *
 * \param de_ctx Pointer to the detection engine context.
 */
void MpmStoreFree(DetectEngineCtx *de_ctx)
{
    if (de_ctx->mpm_hash_table == NULL)
        return;

    HashListTableFree(de_ctx->mpm_hash_table);
    de_ctx->mpm_hash_table = NULL;
    return;
}
コード例 #7
0
/**
 * \brief Frees the hash table - DetectEngineCtx->sgh_hash_table, allocated by
 *        SigGroupHeadHashInit() function.
 *
 * \param de_ctx Pointer to the detection engine context.
 */
void SigGroupHeadHashFree(DetectEngineCtx *de_ctx)
{
    if (de_ctx->sgh_hash_table == NULL)
        return;

    HashListTableFree(de_ctx->sgh_hash_table);
    de_ctx->sgh_hash_table = NULL;

    return;
}
コード例 #8
0
ファイル: util-hashlist.c プロジェクト: H5eye/suricata
static int HashListTableTestInit03 (void)
{
    int result = 0;
    HashListTable *ht = HashListTableInit(1024, HashListTableGenericHash, NULL, NULL);
    if (ht == NULL)
        return 0;

    if (ht->Hash == HashListTableGenericHash)
        result = 1;

    HashListTableFree(ht);
    return result;
}
コード例 #9
0
ファイル: util-hashlist.c プロジェクト: H5eye/suricata
static int HashListTableTestAdd02 (void)
{
    int result = 0;
    HashListTable *ht = HashListTableInit(32, HashListTableGenericHash, NULL, NULL);
    if (ht == NULL)
        goto end;

    int r = HashListTableAdd(ht, NULL, 4);
    if (r == 0)
        goto end;

    /* all is good! */
    result = 1;
end:
    if (ht != NULL) HashListTableFree(ht);
    return result;
}
コード例 #10
0
ファイル: util-hashlist.c プロジェクト: H5eye/suricata
static int HashListTableTestAdd04 (void)
{
    int result = 0;
    HashListTable *ht = HashListTableInit(32, HashListTableGenericHash, NULL, NULL);
    if (ht == NULL)
        goto end;

    int r = HashListTableAdd(ht, "test", 4);
    if (r != 0)
        goto end;

    char *rp = HashListTableLookup(ht, "test", 4);
    if (rp == NULL)
        goto end;

    HashListTableBucket *htb = HashListTableGetListHead(ht);
    if (htb == NULL) {
        printf("htb == NULL: ");
        goto end;
    }

    char *rp2 = HashListTableGetListData(htb);
    if (rp2 == NULL) {
        printf("rp2 == NULL: ");
        goto end;
    }

    if (rp != rp2) {
        printf("rp != rp2: ");
        goto end;
    }

    /* all is good! */
    result = 1;
end:
    if (ht != NULL) HashListTableFree(ht);
    return result;
}
コード例 #11
0
static int PrefilterSetupPacketHeaderCommon(SigGroupHead *sgh, int sm_type,
        void (*Set)(PrefilterPacketHeaderValue *v, void *),
        _Bool (*Compare)(PrefilterPacketHeaderValue v, void *),
        void (*Match)(DetectEngineThreadCtx *det_ctx,
                      Packet *p, const void *pectx),
        _Bool u8hash)
{
    Signature *s = NULL;
    uint32_t sig = 0;

    if (sgh == NULL)
        return 0;

    /* first count how many engines we will need */

    HashListTable *hash_table = HashListTableInit(4096,
            PrefilterPacketHeaderHashFunc,
            PrefilterPacketHeaderCompareFunc,
            PrefilterPacketHeaderFreeFunc);
    if (hash_table == NULL)
        return -1;

    for (sig = 0; sig < sgh->sig_cnt; sig++) {
        s = sgh->match_array[sig];
        if (s == NULL)
            continue;
        if (s->prefilter_sm == NULL || s->prefilter_sm->type != sm_type)
            continue;

        PrefilterPacketHeaderHashCtx ctx;
        memset(&ctx, 0, sizeof(ctx));
        Set(&ctx.v1, s->prefilter_sm->ctx);

        GetExtraMatch(s, &ctx.type, &ctx.value);

        PrefilterPacketHeaderHashCtx *rctx = HashListTableLookup(hash_table, (void *)&ctx, 0);
        if (rctx != 0) {
            rctx->cnt++;
        } else {
            PrefilterPacketHeaderHashCtx *actx = SCCalloc(1, sizeof(*actx));
            if (actx == NULL)
                goto error;

            Set(&actx->v1, s->prefilter_sm->ctx);
            actx->cnt = 1;
            actx->type = ctx.type;
            actx->value = ctx.value;

            int ret = HashListTableAdd(hash_table, actx, 0);
            if (ret != 0) {
                SCFree(actx);
                goto error;
            }
        }
    }

    if (u8hash == FALSE) {
        SetupSingle(hash_table, sgh, sm_type, Compare, Match);
    } else {
        SetupU8Hash(hash_table, sgh, sm_type, Set, Compare, Match);
    }

    HashListTableFree(hash_table);
    return 0;
error:
    HashListTableFree(hash_table);
    return -1;
}