]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Properly hash pointers for hash tables where appropriate
authorTobias Brunner <tobias@strongswan.org>
Thu, 27 Mar 2014 10:37:16 +0000 (11:37 +0100)
committerTobias Brunner <tobias@strongswan.org>
Mon, 31 Mar 2014 12:32:44 +0000 (14:32 +0200)
Simply using the pointer is not optimal for our hash table
implementation, which simply masks the key to determine the bucket.

src/libcharon/plugins/dhcp/dhcp_provider.c
src/libcharon/plugins/eap_radius/eap_radius_forward.c
src/libcharon/plugins/ha/ha_cache.c
src/libstrongswan/credentials/cred_encoding.c

index e092771f42f0a1c161c9440c8a7a948efdeb335d..f5325b566418650dc2a6a033bd05c11944b621ad 100644 (file)
@@ -46,22 +46,6 @@ struct private_dhcp_provider_t {
        dhcp_socket_t *socket;
 };
 
-/**
- * Hashtable hash function
- */
-static u_int hash(void *key)
-{
-       return (uintptr_t)key;
-}
-
-/**
- * Hashtable equals function
- */
-static bool equals(void *a, void *b)
-{
-       return a == b;
-}
-
 /**
  * Hash ID and host to a key
  */
@@ -226,7 +210,8 @@ dhcp_provider_t *dhcp_provider_create(dhcp_socket_t *socket)
                },
                .socket = socket,
                .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
-               .transactions = hashtable_create(hash, equals, 8),
+               .transactions = hashtable_create(hashtable_hash_ptr,
+                                                                                hashtable_equals_ptr, 8),
        );
 
        return &this->public;
index b873e1d698964eeb31a87198228ca83c2a62aea7..54d52a98c416af2c5d20c50355f74691211e17ca 100644 (file)
@@ -73,22 +73,6 @@ typedef struct {
  */
 static private_eap_radius_forward_t *singleton = NULL;
 
-/**
- * Hashtable hash function
- */
-static u_int hash(uintptr_t key)
-{
-       return key;
-}
-
-/**
- * Hashtable equals function
- */
-static bool equals(uintptr_t a, uintptr_t b)
-{
-       return a == b;
-}
-
 /**
  * Free a queue entry
  */
@@ -442,10 +426,8 @@ eap_radius_forward_t *eap_radius_forward_create()
                .to_attr = parse_selector(lib->settings->get_str(lib->settings,
                                                        "%s.plugins.eap-radius.forward.radius_to_ike", "",
                                                        lib->ns)),
-               .from = hashtable_create((hashtable_hash_t)hash,
-                                               (hashtable_equals_t)equals, 8),
-               .to = hashtable_create((hashtable_hash_t)hash,
-                                               (hashtable_equals_t)equals, 8),
+               .from = hashtable_create(hashtable_hash_ptr, hashtable_equals_ptr, 8),
+               .to = hashtable_create(hashtable_hash_ptr, hashtable_equals_ptr, 8),
                .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
        );
 
index ce1afe6f9147c16da88efa05c5951e7b5bb047e2..60e75fc7e87be85c7fe8578239750145fb3bcb2e 100644 (file)
@@ -58,22 +58,6 @@ struct private_ha_cache_t {
        mutex_t *mutex;
 };
 
-/**
- * Hashtable hash function
- */
-static u_int hash(void *key)
-{
-       return (uintptr_t)key;
-}
-
-/**
- * Hashtable equals function
- */
-static bool equals(void *a, void *b)
-{
-       return a == b;
-}
-
 /**
  * Cache entry for an IKE_SA
  */
@@ -380,7 +364,7 @@ ha_cache_t *ha_cache_create(ha_kernel_t *kernel, ha_socket_t *socket,
                .count = count,
                .kernel = kernel,
                .socket = socket,
-               .cache = hashtable_create(hash, equals, 8),
+               .cache = hashtable_create(hashtable_hash_ptr, hashtable_equals_ptr, 8),
                .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
        );
 
index 53ac13cbb513ef21dcf67b2acdf75e51a0e11b79..303816391ad71473861de2658b648abd89689bcf 100644 (file)
@@ -94,22 +94,6 @@ bool cred_encoding_args(va_list args, ...)
        return !failed;
 }
 
-/**
- * hashtable hash() function
- */
-static u_int hash(void *key)
-{
-       return (uintptr_t)key;
-}
-
-/**
- * hashtable equals() function
- */
-static bool equals(void *key1, void *key2)
-{
-       return key1 == key2;
-}
-
 METHOD(cred_encoding_t, get_cache, bool,
        private_cred_encoding_t *this, cred_encoding_type_t type, void *cache,
        chunk_t *encoding)
@@ -289,7 +273,8 @@ cred_encoding_t *cred_encoding_create()
 
        for (type = 0; type < CRED_ENCODING_MAX; type++)
        {
-               this->cache[type] = hashtable_create(hash, equals, 8);
+               this->cache[type] = hashtable_create(hashtable_hash_ptr,
+                                                                                        hashtable_equals_ptr, 8);
        }
 
        return &this->public;