/** ** Initialize the server_lookup structure. ** ** We need to initialize the server_lookup structure for the server ** configuration access. Don't want a NULL pointer flying around, when ** we have to look for server configs. ** ** @param ServerLookup pointer to the pointer of the server lookup structure. ** ** @return integer ** ** @retval HI_SUCCESS function successful. ** @retval HI_MEM_ALLOC_FAIL memory allocation failed */ int hi_ui_server_lookup_init(SERVER_LOOKUP **ServerLookup) { #ifdef SUP_IP6 *ServerLookup = sfrt_new(DIR_16_4x4_16x5_4x4, IPv6, HI_UI_CONFIG_MAX_SERVERS, 20); #else *ServerLookup = sfrt_new(DIR_16x2, IPv4, HI_UI_CONFIG_MAX_SERVERS, 20); #endif if(*ServerLookup == NULL) { return HI_MEM_ALLOC_FAIL; } return HI_SUCCESS; }
int ftpp_ui_client_lookup_init(CLIENT_LOOKUP **ClientLookup) { #ifdef SUP_IP6 *ClientLookup = sfrt_new(DIR_16_4x4_16x5_4x4, IPv6, FTPP_UI_CONFIG_MAX_CLIENTS, 20); #else *ClientLookup = sfrt_new(DIR_16x2, IPv4, FTPP_UI_CONFIG_MAX_CLIENTS, 20); #endif if(*ClientLookup == NULL) { return FTPP_MEM_ALLOC_FAIL; } return FTPP_SUCCESS; }
/** ** Initialize the server_lookup structure. ** ** We need to initialize the server_lookup structure for the server ** configuration access. Don't want a NULL pointer flying around, when ** we have to look for server configs. ** ** @param ServerLookup pointer to the pointer of the server lookup structure. ** ** @return integer ** ** @retval HI_SUCCESS function successful. ** @retval HI_MEM_ALLOC_FAIL memory allocation failed */ int hi_ui_server_lookup_init(SERVER_LOOKUP **ServerLookup) { *ServerLookup = sfrt_new(DIR_16_4x4_16x5_4x4, IPv6, HI_UI_CONFIG_MAX_SERVERS, 20); if(*ServerLookup == NULL) { return HI_MEM_ALLOC_FAIL; } return HI_SUCCESS; }
static void IpListInit(uint32_t maxEntries, ReputationConfig *config) { if (config->iplist == NULL) { #ifdef SUP_IP6 /*DIR_16x7_4x4 for performance, but memory usage is high *Use DIR_8x16 worst case IPV4 5K, IPV6 15K (bytes) *Use DIR_16x7_4x4 worst case IPV4 500, IPV6 2.5M */ config->iplist = sfrt_new(DIR_8x16, IPv6, maxEntries, config->memcap); #else config->iplist = sfrt_new(DIR_8x4, IPv4, maxEntries, config->memcap); #endif if (config->iplist == NULL) { DynamicPreprocessorFatalMessage("%s(%d): Failed to create IP list.\n", *(_dpd.config_file), *(_dpd.config_line)); return; } } }
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; }