Beispiel #1
0
/*
 * Function: ftpp_ui_client_lookup_add(CLIENT_LOOKUP *ClientLookup,
 *                                 sfcidr_t* Ip,
 *                                 FTP_CLIENT_PROTO_CONF *ClientConf)
 *
 * Purpose: Add a client configuration to the list.
 *          We add these keys like you would normally think to add
 *          them, because on low endian machines the least significant
 *          byte is compared first.  This is what we want to compare
 *          IPs backward, doesn't work on high endian machines, but oh
 *          well.  Our platform is Intel.
 *
 * Arguments: ClientLookup => a pointer to the lookup structure
 *            IP           => the ftp client address
 *            ClientConf   => a pointer to the client configuration structure
 *
 * Returns: int => return code indicating error or success
 *
 */
int ftpp_ui_client_lookup_add(
    CLIENT_LOOKUP *ClientLookup,
    sfcidr_t* Ip, FTP_CLIENT_PROTO_CONF *ClientConf)
{
    int iRet;

    if(!ClientLookup || !ClientConf)
    {
        return FTPP_INVALID_ARG;
    }

    iRet = sfrt_insert(Ip, (unsigned char)Ip->bits,
        (void *)ClientConf, RT_FAVOR_SPECIFIC, ClientLookup);

    if (iRet)
    {
        /*
         * This means the key has already been added.
         */
        if(iRet == 1)
        {
            return FTPP_NONFATAL_ERR;
        }
        else
        {
            return FTPP_MEM_ALLOC_FAIL;
        }
    }

    return FTPP_SUCCESS;
}
Beispiel #2
0
/**
**  Add a server configuration to the list.
**
**  We add these keys like you would normally think to add them, because
**  on low endian machines the least significant byte is compared first.
**  This is what we want to compare IPs backward, doesn't work on high
**  endian machines, but oh well.  Our platform is Intel.
**
**  @param ServerLookup a pointer to the lookup structure
**  @param Ip           the IP address of the server (the key)
**  @param ServerConf   a pointer to the server configuration
**
**  @return integer
**
**  @retval HI_SUCCESS        function successful
**  @retval HI_INVALID_ARG    invalid argument, most likely NULL pointer
**  @retval HI_MEM_ALLOC_FAIL memory allocation failed
**  @retval HI_NONFATAL_ERR   key is already in table, don't overwrite
**                            configuration.
*/
int hi_ui_server_lookup_add(SERVER_LOOKUP *ServerLookup, sfip_t *Ip,
                            HTTPINSPECT_CONF *ServerConf)
{
    int iRet;

    if(!ServerLookup || !ServerConf)
    {
        return HI_INVALID_ARG;
    }

#ifdef SUP_IP6
    iRet = sfrt_insert((void *)Ip, (unsigned char)Ip->bits, (void *)ServerConf, RT_FAVOR_SPECIFIC, ServerLookup);
#else
    iRet = sfrt_insert((void *)&(Ip->ip.u6_addr32[0]), (unsigned char)Ip->bits, (void *)ServerConf, RT_FAVOR_SPECIFIC, ServerLookup);
#endif
    if (iRet)
    {
        return HI_MEM_ALLOC_FAIL;
    }

    return HI_SUCCESS;
}
Beispiel #3
0
int main()
{
    table_t *dir;
    uint32_t ip_list[NUM_IPS];  /* entirely arbitrary */
    char data[NUM_DATA];     /* also entirely arbitrary */
    uint32_t index, val;

    for(index=0; index<NUM_IPS; index++)
    {
        ip_list[index] = (uint32_t)rand()%NUM_IPS;
        data[index%NUM_DATA] = index%26 + 65;    /* Random letter */
    }

    dir = sfrt_new(DIR_16x2, IPv4, NUM_IPS, 20);

    if(!dir)
    {
        printf("Failed to create DIR\n");
        return 1;
    }

    for(index=0; index < NUM_IPS; index++)
    {
        if(sfrt_insert(&ip_list[index], 32, &data[index%NUM_DATA],
                       RT_FAVOR_SPECIFIC, dir) != RT_SUCCESS)
        {
            printf("DIR Insertion failure\n");
            return 1;
        }

        printf("%d\t %x: %c -> %c\n", index, ip_list[index],
              data[index%NUM_DATA], *(uint32_t*)sfrt_lookup(&ip_list[index], dir));

    }

    for(index=0; index < NUM_IPS; index++)
    {
        val = *(uint32_t*)sfrt_lookup(&ip_list[index], dir);
        printf("\t@%d\t%x: %c.  originally:\t%c\n",
                            index, ip_list[index], val, data[index%NUM_DATA]);
    }

    printf("Usage: %d bytes\n", ((dir_table_t*)(dir->rt))->allocated);

    sfrt_free(dir);
    return 0;
}
/*
 * Function: ftpp_ui_server_lookup_add(SERVER_LOOKUP *ServerLookup,
 *                                 char *ip, int len,
 *                                 FTP_SERVER_PROTO_CONF *ServerConf)
 *
 * Purpose: Add a server configuration to the list.
 *          We add these keys like you would normally think to add
 *          them, because on low endian machines the least significant
 *          byte is compared first.  This is what we want to compare
 *          IPs backward, doesn't work on high endian machines, but oh
 *          well.  Our platform is Intel.
 *
 * Arguments: ServerLookup => a pointer to the lookup structure
 *            IP           => the ftp server address
 *            len          => Length of the address
 *            ServerConf   => a pointer to the server configuration structure
 *
 * Returns: int => return code indicating error or success
 *
 */
int ftpp_ui_server_lookup_add(
    SERVER_LOOKUP *ServerLookup, sfip_t* Ip, FTP_SERVER_PROTO_CONF *ServerConf )
{
    int iRet;

    if(!ServerLookup || !ServerConf)
    {
        return FTPP_INVALID_ARG;
    }

    iRet = sfrt_insert((void *)Ip, (unsigned char)Ip->bits, (void *)ServerConf, RT_FAVOR_SPECIFIC, ServerLookup);

    if (iRet)
    {
        return FTPP_MEM_ALLOC_FAIL;
    }

    return FTPP_SUCCESS;
}
Beispiel #5
0
static int AddIPtoList(sfip_t *ipAddr, void *info, ReputationConfig *config)
{
    int iRet;
    int iFinalRet = IP_INSERT_SUCCESS;
    /*This variable is used to check whether a more generic address
     * overrides specific address
     */
    uint32_t usageBeforeAdd;
    uint32_t usageAfterAdd;

#ifndef SUP_IP6
    if (ipAddr->family == AF_INET6)
    {
        return RT_INSERT_FAILURE;
    }
#endif
    if (ipAddr->family == AF_INET)
    {
        ipAddr->ip32[0] = ntohl(ipAddr->ip32[0]);
    }
    else if (ipAddr->family == AF_INET6)
    {
        int i;
        for(i = 0; i < 4 ; i++)
            ipAddr->ip32[i] = ntohl(ipAddr->ip32[i]);
    }
#ifdef DEBUG_MSGS

    if (NULL != sfrt_lookup((void *)ipAddr, config->iplist))
    {
        DebugMessage(DEBUG_REPUTATION, "Find address before insert: %s \n",sfip_to_str(ipAddr) );

    }
    else
    {
        DebugMessage(DEBUG_REPUTATION, "Can't find address before insert: %s \n",sfip_to_str(ipAddr) );

    }
#endif
    usageBeforeAdd =  sfrt_usage(config->iplist);

    /*Check whether the same or more generic address is already in the table*/
    if (NULL != sfrt_lookup((void *)ipAddr, config->iplist))
    {
        iFinalRet = IP_INSERT_DUPLICATE;
    }


#ifdef SUP_IP6
    iRet = sfrt_insert((void *)ipAddr, (unsigned char)ipAddr->bits, (void *)info, RT_FAVOR_TIME, config->iplist);
#else
    iRet = sfrt_insert((void *)&(ipAddr->ip.u6_addr32[0]), (unsigned char)ipAddr->bits, (void *)info, RT_FAVOR_TIME, config->iplist);
#endif

    if (RT_SUCCESS == iRet)
    {
        totalNumEntries++;
#ifdef DEBUG_MSGS

        DebugMessage(DEBUG_REPUTATION, "Number of entries input: %d, in table: %d \n",
                totalNumEntries,sfrt_num_entries(config->iplist) );
        DebugMessage(DEBUG_REPUTATION, "Memory allocated: %d \n",sfrt_usage(config->iplist) );
        if (NULL != sfrt_lookup((void *)ipAddr, config->iplist))
        {
            DebugMessage(DEBUG_REPUTATION, "Find address after insert: %s \n",sfip_to_str(ipAddr) );

        }
#endif
    }
    else if (MEM_ALLOC_FAILURE == iRet)
    {
        iFinalRet = IP_MEM_ALLOC_FAILURE;
        DEBUG_WRAP( DebugMessage(DEBUG_REPUTATION, "Insert error: %d for address: %s \n",iRet, sfip_to_str(ipAddr) ););