예제 #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;
}
예제 #2
0
//  -----------------------------
void test_ipset()
{
    int      i,k;
    IPSET  * ipset, * ipset6;
    IPSET  * ipset_copyp, * ipset6_copyp;

    unsigned ipaddress, mask;
    unsigned short mask6[8];
    unsigned short ipaddress6[8];
    unsigned port_lo, port_hi;
    PORTSET        portset;

    printf("IPSET testing\n");

    ipset  = ipset_new(IPV4_FAMILY);
    ipset6 = ipset_new(IPV6_FAMILY);

    srand( time(0) );

    for(i=0;i<MAXIP;i++)
    {
        if( i % 2 )
        {
            ipaddress = rand() * rand();
            mask = 0xffffff00;
            port_lo = rand();
            port_hi = rand() % 5 + port_lo;
            portset_init(&portset);
            portset_add(&portset, port_lo, port_hi);

            ipset_add( ipset, &ipaddress, &mask, &portset, 0, IPV4_FAMILY ); //class C cidr blocks

            if( !ipset_contains( ipset, &ipaddress, &port_lo, IPV4_FAMILY ) )
                printf("error with ipset_contains\n");
        }
        else
        {
            for(k=0;k<8;k++) ipaddress6[k] = (char) (rand() % (1<<16)); 

            for(k=0;k<8;k++) mask6[k] = 0xffff;

            port_lo = rand();
            port_hi = rand() % 5 + port_lo;
            portset_init(&portset);
            portset_add(&portset, port_lo, port_hi);

            ipset_add( ipset6, ipaddress6, mask6, &portset, 0, IPV6_FAMILY );

            if( !ipset_contains( ipset6, &ipaddress6, &port_lo, IPV6_FAMILY ) )
                printf("error with ipset6_contains\n");
        }

    }

    ipset_copyp = ipset_copy( ipset );
    ipset6_copyp = ipset_copy( ipset6 );


    printf("-----IP SET-----\n");
    ipset_print( ipset );
    printf("\n");

    printf("-----IP SET6-----\n");
    ipset_print( ipset6 );
    printf("\n");

    printf("-----IP SET COPY -----\n");
    ipset_print( ipset_copyp );
    printf("\n");

    printf("-----IP SET6 COPY -----\n");
    ipset_print( ipset6_copyp );
    printf("\n");

    printf("IP set testing completed\n");
}