Beispiel #1
0
void CleanupTag(void)
{
    if (ssn_tag_cache_ptr)
    {
        sfxhash_delete(ssn_tag_cache_ptr);
    }

    if (host_tag_cache_ptr)
    {
        sfxhash_delete(host_tag_cache_ptr);
    }
}
Beispiel #2
0
void sfthd_free(THD_STRUCT *thd)
{
    if (thd == NULL)
        return;

#ifndef CRIPPLE
    if (thd->ip_nodes != NULL)
        sfxhash_delete(thd->ip_nodes);

    if (thd->ip_gnodes != NULL)
        sfxhash_delete(thd->ip_gnodes);
#endif

    free(thd);
}
Beispiel #3
0
void file_resume_block_cleanup(void)
{
    if (fileHash)
    {
        sfxhash_delete(fileHash);
        fileHash = NULL;
    }
}
Beispiel #4
0
/**
**  Cleanup the portscan infrastructure.
*/
void ps_cleanup(void)
{
    if (portscan_hash != NULL)
    {
        sfxhash_delete(portscan_hash);
        portscan_hash = NULL;
    }
}
Beispiel #5
0
void SFRF_Delete (void)
{
    if ( !rf_hash )
        return;

    sfxhash_delete(rf_hash);
    rf_hash = NULL;
}
Beispiel #6
0
/* Release file cache */
void file_cache_free( FileCache *fileCache )
{
    if (fileCache)
    {
        sfxhash_delete(fileCache->hashTable);
        free(fileCache);
    }
}
Beispiel #7
0
void detection_filter_cleanup(void)
{

    if (detection_filter_hash == NULL)
        return;

    sfxhash_delete(detection_filter_hash);
    detection_filter_hash = NULL;
}
Beispiel #8
0
int server_stats_destroy(SERVER_STATS *ssp)
{
    if(!ssp)
    {
        return FLOW_ENULL;
    }
    
    sfxhash_delete(ssp->ipv4_table);
    ipset_free(ssp->ipv4_watch);

    return FLOW_SUCCESS;
}
Beispiel #9
0
int flowcache_destroy(FLOWCACHE *flowcachep)
{
    if(!flowcachep)
    {
        return FLOW_ENULL;
    }

    sfxhash_delete(flowcachep->ipv4_table);

    flowcachep->ipv4_table = NULL;
    
    return FLOW_SUCCESS;
}
Beispiel #10
0
int scoreboard_destroy(SCOREBOARD *sbp)
{
    if(!sbp || !sbp->ipv4_table)
    {
        return FLOW_ENULL;
    }

    sfxhash_delete(sbp->ipv4_table);

    sbp->ipv4_table = NULL;
    
    return FLOW_SUCCESS;    
}
int DeleteLWSessionCache(Stream5SessionCache *sessionCache)
{
    int retCount = 0;

    if (!sessionCache)
        return 0;

    retCount = PurgeLWSessionCache(sessionCache);

    sfxhash_delete(sessionCache->hashTable);
    free(sessionCache);

    return retCount;
}
Beispiel #12
0
void FreeFlowStats(SFFLOW *sfFlow)
{
    if (sfFlow->pktLenCnt != NULL)
    {
        free(sfFlow->pktLenCnt);
        sfFlow->pktLenCnt = NULL;
    }

    if (sfFlow->portTcpSrc != NULL)
    {
        free(sfFlow->portTcpSrc);
        sfFlow->portTcpSrc = NULL;
    }

    if (sfFlow->portTcpDst != NULL)
    {
        free(sfFlow->portTcpDst);
        sfFlow->portTcpDst = NULL;
    }

    if (sfFlow->portUdpSrc != NULL)
    {
        free(sfFlow->portUdpSrc);
        sfFlow->portUdpSrc = NULL;
    }

    if (sfFlow->portUdpDst != NULL)
    {
        free(sfFlow->portUdpDst);
        sfFlow->portUdpDst = NULL;
    }

    if (sfFlow->typeIcmp != NULL)
    {
        free(sfFlow->typeIcmp);
        sfFlow->typeIcmp = NULL;
    }

    if (sfFlow->ipMap != NULL)
    {
        sfxhash_delete(sfFlow->ipMap);
        sfFlow->ipMap = NULL;
    }
}
Beispiel #13
0
/** 
 * Initialize the server stats structure
 *
 * If we do not specify a watchnet, then we have no use for this
 * structure
 * 
 * @param ssp server stats structure to initialize
 * @param watchnet what network we're watching for information
 * @param rows how many rows the underlying table should use
 * @param memcap what our total memory limit is
 * 
 * @return FLOW_SUCCESS on success
 */
int server_stats_init(SERVER_STATS *ssp, IPSET *watchnetv4,
                      unsigned int rows, int memcap)
{
    if(!ssp || !watchnetv4)
        return FLOW_ENULL;

    server_stats_init_entry();
    
    memset(ssp, 0, sizeof(SERVER_STATS));

    
    if(ipset_family(watchnetv4) != IPV4_FAMILY)
    {
        return FLOW_EINVALID;
    }

    /* what size should we do? */
    ssp->ipv4_table = sfxhash_new(rows,               /* # of rows in HT*/
                                  sizeof(SERVER_KEY), /* size of the key  */
                                  sizeof(u_int32_t),   /* data size */
                                  memcap,            /* how much memory is alloted */
                                  1,                 /* auto recover nodes */
                                  NULL,              /* autorecovery function */
                                  NULL,              /* free function for the data */
                                  1);                /* recycle old nodes */

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

    ssp->ipv4_watch = ipset_copy(watchnetv4);
    
    if(!ssp->ipv4_watch)
    {
        sfxhash_delete(ssp->ipv4_table);        
        return FLOW_ENOMEM;
    }

    return FLOW_SUCCESS;
}
Beispiel #14
0
THD_STRUCT * sfthd_new(unsigned lbytes, unsigned gbytes)
{
    THD_STRUCT * thd;

    /* Create the THD struct */
    thd = (THD_STRUCT *)SnortAlloc(sizeof(THD_STRUCT));

#ifndef CRIPPLE
    /* Create hash table for all of the local IP Nodes */
    thd->ip_nodes = sfthd_local_new(lbytes);
    if( !thd->ip_nodes )
    {
#ifdef THD_DEBUG
        printf("Could not allocate the sfxhash table\n");
#endif
        free(thd);
        return NULL;
    }

    if ( gbytes == 0 )
        return thd;

    /* Create hash table for all of the global IP Nodes */
    thd->ip_gnodes = sfthd_global_new(gbytes);
    if( !thd->ip_gnodes )
    {
#ifdef THD_DEBUG
        printf("Could not allocate the sfxhash table\n");
#endif
        sfxhash_delete(thd->ip_nodes);
        free(thd);
        return NULL;
    }
#endif

    return thd;
}
void DetectionHashTableFree(SFXHASH *doht)
{
    if (doht != NULL)
        sfxhash_delete(doht);
}
Beispiel #16
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;
}
Beispiel #17
0
/*
 *       Hash test program : use 'sfxhash 1000 50000' to stress the Auto_NodeRecover feature
 */
int main ( int argc, char ** argv )
{
    int             i;
    SFXHASH      * t;
    SFXHASH_NODE * n;
    char            strkey[256], strdata[256], * p;
    int             num = 100;
    int             mem = 0;

    memset(strkey,0,20);
    memset(strdata,0,20);

    if( argc > 1 )
    {
        num = atoi(argv[1]);
    }

    if( argc > 2 )
    {
        mem = atoi(argv[2]);
    }

    /* Create a Hash Table */
    t = sfxhash_new( 100,        /* one row per element in table, when possible */
                     20,        /* key size :  padded with zeros */ 
                     20,        /* data size:  padded with zeros */ 
                     mem,       /* max bytes,  0=no max */  
                     1,         /* enable AutoNodeRecovery */
                     anrfree,   /* provide a function to let user know we want to kill a node */
                     usrfree, /* provide a function to release user memory */
                     1);      /* Recycle nodes */
    if(!t)
    {
        printf("Low Memory!\n");
        exit(0);
    }
    /* Add Nodes to the Hash Table */
    for(i=0;i<num;i++) 
    {
        snprintf(strkey, sizeof(strkey), "KeyWord%5.5d",i+1);
        strkey[sizeof(strkey) - 1] = '\0';
        snprintf(strdata, sizeof(strdata), "KeyWord%5.5d",i+1);
        strdata[sizeof(strdata) - 1] = '\0';
        //strupr(strdata);
        sfxhash_add( t, strkey  /* user key */ ,  strdata /* user data */ );
    }  

    /* Find and Display Nodes in the Hash Table */
    printf("\n** FIND KEY TEST\n");
    for(i=0;i<num;i++) 
    {
        snprintf(strkey, sizeof(strkey) - 1, "KeyWord%5.5d",i+1);
        strkey[sizeof(strkey) - 1] = '\0';

        p = (char*) sfxhash_find( t, strkey );

        if(p)printf("Hash-key=%*s, data=%*s\n", strlen(strkey),strkey, strlen(strkey), p );
    }  

    /* Show memcap memory */
    printf("\n...******\n");
    sfmemcap_showmem(&t->mc);
    printf("...******\n");

    /* Display All Nodes in the Hash Table findfirst/findnext */
    printf("\n...FINDFIRST / FINDNEXT TEST\n");
    for( n  = sfxhash_findfirst(t); 
         n != 0; 
         n  = sfxhash_findnext(t) )
    {
        printf("hash-findfirst/next: n=%x, key=%s, data=%s\n", n, n->key, n->data );

        /*
          remove node we are looking at, this is first/next safe.
        */
        if( sfxhash_remove(t,n->key) ) 
        {
            printf("...ERROR: Could not remove the key node!\n");
        }
        else  
        {
            printf("...key node removed\n");
        }
    }

    printf("...Auto-Node-Recovery: %d recycle attempts, %d completions.\n",t->anr_tries,t->anr_count);

    /* Free the table and it's user data */
    printf("...sfxhash_delete\n");

    sfxhash_delete( t );
   
    printf("\nnormal pgm finish\n\n");

    return 0;
}