示例#1
0
SFXHASH * DetectionHashTableNew(void)
{
    SFXHASH *doht = sfxhash_new(HASH_RULE_OPTIONS,
                                sizeof(detection_option_key_t),
                                0,      /* Data size == 0, just store the ptr */
                                0,      /* Memcap */
                                0,      /* Auto node recovery */
                                NULL,   /* Auto free function */
                                detection_hash_free_func,   /* User free function */
                                1);     /* Recycle nodes */


    if (doht == NULL)
        FatalError("Failed to create rule detection option hash table");

    sfxhash_set_keyops(doht, detection_option_hash_func,
                       detection_option_key_compare_func);

    return doht;
}
示例#2
0
int flowcache_init(FLOWCACHE *flowcachep, unsigned int rows,
                   int memcap, int datasize, FLOWHASHID hashid)
{
    int ret;
    int real_datasize = 0;
    
    if(!flowcachep)
    {
        return FLOW_ENULL;
    }

    if(datasize < 0)
    {
        return FLOW_ENULL;
    }

    if(memcap <= (int)(datasize + sizeof(FLOW) + sizeof(SFXHASH_NODE)))
    {
        /* come on man, you gotta give me enough memory to store 1. */
        return FLOW_EINVALID;
    }

    if(rows < 1)
        return FLOW_EINVALID;

    /* zero out the struct for all the additional data strctures */
    memset(flowcachep, 0, sizeof(FLOWCACHE));

    /*
    **  If we have a datasize, then we need to decrement by 1 because
    **  the FLOWDATA already has one byte.
    */
    if(datasize)
    {
        real_datasize = datasize - 1;
    }

    /*
    **  datasize-1 because there is already 1 byte in the FLOWDATA
    **  structure.
    */
    flowcachep->ipv4_table =
        sfxhash_new(rows,                         /* # of nodes in HT*/
                    sizeof(FLOWKEY),              /* size of the key  */
                    sizeof(FLOW) + real_datasize, /* data size */
                    memcap,                       /* max memory */
                    1,                            /* auto recover nodes */
                    flowcache_anrfree,            /* autorecovery function */
                    flowcache_usrfree,            /* data free function*/
                    1);                           /* recycle old nodes */

    if(flowcachep->ipv4_table == NULL)
    {
        return FLOW_ENOMEM;
    }

    /* set our hash function to something that understands ipv4 flowkeys */
    switch(hashid)
    {
    case HASH1:
        ret = sfxhash_set_keyops(flowcachep->ipv4_table,
                                 flowkey_hashfcn1,
                                 flowkeycmp_fcn);
        break;
    case HASH2:
        ret = sfxhash_set_keyops(flowcachep->ipv4_table,
                                 flowkey_hashfcn2,
                                 flowkeycmp_fcn);
        break;
    default:
        ret = FLOW_EINVALID;
    }

    /* if setting the hash function or setting the comparison function fails,
       abort */
    if(ret != 0)
    {
        sfxhash_delete(flowcachep->ipv4_table);
        return FLOW_BADJUJU;
    }

    flowcachep->max_flowbits_bytes = (unsigned int)datasize;

    return FLOW_SUCCESS;
}