Esempio n. 1
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;
}
Esempio n. 2
0
IPSET * ipset_copy( IPSET *ipsp )
{
    int family;
    IPSET * newset = NULL;
    CIDRBLOCK *cbp;
    CIDRBLOCK6 *cbp6;

    if(ipsp)
    {
        family = ipset_family( ipsp );
        newset = ipset_new(family) ;

        if( family == IPV4_FAMILY )
        {
            for(cbp =(CIDRBLOCK*)sflist_first( &ipsp->cidr_list );
                cbp !=NULL;
                cbp =(CIDRBLOCK*)sflist_next( &ipsp->cidr_list ) )
            {
                ipset_add(newset, &cbp->ip, &cbp->mask, &cbp->portset, cbp->notflag, family);
            }

        }
        else
        {
            for(cbp6 =(CIDRBLOCK6*)sflist_first( &ipsp->cidr_list );
                cbp6 !=NULL;
                cbp6 =(CIDRBLOCK6*)sflist_next( &ipsp->cidr_list ) )
            {
                ipset_add(newset, &cbp6->ip, &cbp6->mask, &cbp6->portset, cbp6->notflag, family);
            }

        }
    }

    return newset;
}