static switch_l3_hash_t *switch_l3_search_hash(switch_handle_t vrf, switch_ip_addr_t *ip_addr) { unsigned char key[SWITCH_L3_HASH_KEY_SIZE]; unsigned int len = 0; uint32_t hash = 0; switch_l3_hash_key_init(key, vrf, ip_addr, &len, &hash); switch_l3_hash_t *hash_entry = tommy_hashtable_search( &switch_l3_hash_table, switch_l3_hash_cmp, key, hash); return hash_entry; }
static switch_smac_entry_t * switch_smac_rewrite_search_entry(switch_mac_addr_t *mac) { switch_smac_entry_t *smac_entry = NULL; unsigned char key[ETH_LEN]; unsigned int len = 0; uint32_t hash; switch_smac_rewrite_hash_key_init(key, mac, &len, &hash); smac_entry = tommy_hashtable_search(&smac_rewrite_table, switch_smac_rewrite_hash_cmp, key, hash); return smac_entry; }
static switch_dmac_rewrite_t *switch_dmac_rewrite_search_hash( switch_mac_addr_t *mac) { unsigned char key[SWITCH_DMAC_REWRITE_HASH_KEY_SIZE]; unsigned int len = 0; uint32_t hash = 0; switch_dmac_rewrite_t *dmac_rewrite = NULL; switch_dmac_rewrite_hash_key_init(key, mac, &len, &hash); dmac_rewrite = tommy_hashtable_search( &switch_dmac_rewrite_table, switch_dmac_rewrite_hash_cmp, key, hash); return dmac_rewrite; }
switch_neighbor_dmac_t *switch_neighbor_dmac_search_hash( switch_handle_t bd_handle, switch_mac_addr_t *mac) { unsigned char key[SWITCH_NEIGHBOR_DMAC_HASH_KEY_SIZE]; unsigned int len = 0; uint32_t hash = 0; switch_neighbor_dmac_t *neighbor_dmac = NULL; switch_neighbor_dmac_hash_key_init(key, bd_handle, mac, &len, &hash); neighbor_dmac = tommy_hashtable_search( &switch_neighbor_dmac_table, switch_neighbor_dmac_hash_cmp, key, hash); return neighbor_dmac; }
switch_handle_t switch_api_nhop_handle_get(switch_nhop_key_t *nhop_key) { switch_spath_info_t *spath_info = NULL; unsigned char key[SWITCH_NHOP_HASH_KEY_SIZE]; uint32_t len = 0; uint32_t hash = 0; switch_nhop_hash_key_init(key, nhop_key, &len, &hash); spath_info = tommy_hashtable_search(&switch_nhop_hash_table, switch_nhop_hash_cmp, key, hash); if (!spath_info) { return SWITCH_API_INVALID_HANDLE; } return spath_info->nhop_handle; }
void* pcore_hash_search(phash_pool pool, const puint32 value) { if (!pool) { plog_error("%s(): Нет phash_pool!", __PRETTY_FUNCTION__); return NULL; } plog_dbg("%s(): Поиск в пуле 0x%08X значения '%d'", __PRETTY_FUNCTION__, pool, value); phash_object ret = NULL; switch (pool->type) { case PHASH_FAST_SEARCH: ret = tommy_hashdyn_search((tommy_hashdyn *)pool->hash_struct, compare_hash_uint32, &value, tommy_inthash_u32(value)); break; case PHASH_FAST_INSERT: default: ret = tommy_hashtable_search((tommy_hashtable *)pool->hash_struct, compare_hash_uint32, &value, tommy_inthash_u32(value)); break; } return ret->data; }
/* 0: found, 1: not found, insert 2: not found, do NOT insert */ int tcam_cache_lookup(tcam_cache_t *cache, uint8_t *key, void **data) { int acquired = pthread_mutex_trylock(&cache->lock); if(acquired){ *data = NULL; return 2; } uint32_t hash = hashlittle(key, cache->key_size, 0); cache_entry_t *entry = tommy_hashtable_search(&cache->hashtable, cmp, key, hash); int result; if(entry) { entry->last_access = time(NULL); *data = entry->data; result = 0; } else { *data = NULL; result = 1; } pthread_mutex_unlock(&cache->lock); return result; }