hashlist: Move get_match() and sorting into a separate class

The main intention here is that we can change the hashtable_t
implementation without being impeded by the special requirements imposed
by get_match() and sorting the keys/items in buckets.
This commit is contained in:
Tobias Brunner
2020-07-20 13:50:11 +02:00
parent 4334f61284
commit d9944102f5
6 changed files with 386 additions and 224 deletions
@@ -323,7 +323,7 @@ struct private_kernel_pfroute_net_t
/**
* Map for IP addresses to iface_entry_t objects (addr_map_entry_t)
*/
hashtable_t *addrs;
hashlist_t *addrs;
/**
* List of tun devices we installed for virtual IPs
@@ -524,7 +524,7 @@ static void addr_map_entry_add(private_kernel_pfroute_net_t *this,
.addr = addr,
.iface = iface,
);
entry = this->addrs->put(this->addrs, entry, entry);
entry = this->addrs->ht.put(&this->addrs->ht, entry, entry);
free(entry);
}
@@ -541,7 +541,7 @@ static void addr_map_entry_remove(addr_entry_t *addr, iface_entry_t *iface,
.iface = iface,
};
entry = this->addrs->remove(this->addrs, &lookup);
entry = this->addrs->ht.remove(&this->addrs->ht, &lookup);
free(entry);
}
@@ -2013,7 +2013,6 @@ METHOD(kernel_net_t, destroy, void,
{
enumerator_t *enumerator;
route_entry_t *route;
addr_entry_t *addr;
enumerator = this->routes->create_enumerator(this->routes);
while (enumerator->enumerate(enumerator, NULL, (void**)&route))
@@ -2036,13 +2035,7 @@ METHOD(kernel_net_t, destroy, void,
this->net_changes->destroy(this->net_changes);
this->net_changes_lock->destroy(this->net_changes_lock);
enumerator = this->addrs->create_enumerator(this->addrs);
while (enumerator->enumerate(enumerator, NULL, (void**)&addr))
{
free(addr);
}
enumerator->destroy(enumerator);
this->addrs->destroy(this->addrs);
this->addrs->ht.destroy_function(&this->addrs->ht, (void*)free);
this->ifaces->destroy_function(this->ifaces, (void*)iface_entry_destroy);
this->tuns->destroy(this->tuns);
this->lock->destroy(this->lock);
@@ -2078,7 +2071,7 @@ kernel_pfroute_net_t *kernel_pfroute_net_create()
},
.pid = getpid(),
.ifaces = linked_list_create(),
.addrs = hashtable_create(
.addrs = hashlist_create(
(hashtable_hash_t)addr_map_entry_hash,
(hashtable_equals_t)addr_map_entry_equals, 16),
.routes = hashtable_create((hashtable_hash_t)route_entry_hash,