[hipl-commit] [trunk] Rev 3622: fixed some more s6_addr32 errors by moving code and using s6_addr

  • From: Rene Hummen <rene.hummen@xxxxxxxxxxxxxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Fri, 12 Feb 2010 17:40:33 +0200

Committer: Rene Hummen <rene.hummen@xxxxxxxxxxxxxxxxx>
Date: Fri Feb 12 16:40:01 2010 +0100
Revision: 3622
Revision-id: rene.hummen@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: trunk

Log:
  fixed some more s6_addr32 errors by moving code and using s6_addr

Modified:
  M  hipd/hiprelay.c
  M  hipd/hiprelay.h
  M  lib/core/misc.h

=== modified file 'hipd/hiprelay.c'
--- hipd/hiprelay.c     2010-02-12 10:47:40 +0000
+++ hipd/hiprelay.c     2010-02-12 15:40:01 +0000
@@ -207,6 +207,43 @@
  */
 static unsigned long hip_relwl_hash(const hip_hit_t *hit);
 
+/**
+ * Returns a hash calculated over a HIT.
+ *
+ * @param  hit a HIT value over which the hash is calculated.
+ * @return a hash value.
+ */
+static inline unsigned long hip_hash_func(const hip_hit_t *hit)
+{
+    uint32_t bits_1st  = 0;
+    unsigned long hash = 0;
+
+    /* HITs are of the form: 2001:001x:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
+     * We have four groups of 32 bit sequences here, but the first 28 bits
+     * are constant and have no hash value. Therefore, we create a new
+     * replacement sequence for first 32 bit sequence. */
+
+    bits_1st  = (~hit->s6_addr[3]) << 28;
+    bits_1st |= hit->s6_addr[3] << 24;
+    bits_1st |= hit->s6_addr[7] << 16;
+    bits_1st |= hit->s6_addr[11] << 8;
+    bits_1st |= hit->s6_addr[15];
+
+    /* We calculate the hash by avalanching the bits. The avalanching
+     * ensures that we make use of all bits when dealing with 64 bits
+     * architectures. */
+    hash      =  (bits_1st ^ hit->s6_addr32[1]);
+    hash     ^= hash << 3;
+    hash     ^= (hit->s6_addr32[2] ^ hit->s6_addr32[3]);
+    hash     += hash >> 5;
+    hash     ^= hash << 4;
+    hash     += hash >> 17;
+    hash     ^= hash << 25;
+    hash     += hash >> 6;
+
+    return hash;
+}
+
 static int hip_relay_forward_response(const hip_common_t *r,
                                       const uint8_t type_hdr,
                                       const in6_addr_t *r_saddr,

=== modified file 'hipd/hiprelay.h'
--- hipd/hiprelay.h     2010-02-10 22:32:46 +0000
+++ hipd/hiprelay.h     2010-02-12 15:40:01 +0000
@@ -152,43 +152,6 @@
 void hip_relay_set_status(hip_relay_status_t status);
 
 /**
- * Returns a hash calculated over a HIT.
- *
- * @param  hit a HIT value over which the hash is calculated.
- * @return a hash value.
- */
-static inline unsigned long hip_hash_func(const hip_hit_t *hit)
-{
-    uint32_t bits_1st  = 0;
-    unsigned long hash = 0;
-
-    /* HITs are of the form: 2001:001x:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
-     * We have four groups of 32 bit sequences here, but the first 28 bits
-     * are constant and have no hash value. Therefore, we create a new
-     * replacement sequence for first 32 bit sequence. */
-
-    bits_1st  = (~hit->s6_addr[3]) << 28;
-    bits_1st |= hit->s6_addr[3] << 24;
-    bits_1st |= hit->s6_addr[7] << 16;
-    bits_1st |= hit->s6_addr[11] << 8;
-    bits_1st |= hit->s6_addr[15];
-
-    /* We calculate the hash by avalanching the bits. The avalanching
-     * ensures that we make use of all bits when dealing with 64 bits
-     * architectures. */
-    hash      =  (bits_1st ^ hit->s6_addr32[1]);
-    hash     ^= hash << 3;
-    hash     ^= (hit->s6_addr32[2] ^ hit->s6_addr32[3]);
-    hash     += hash >> 5;
-    hash     ^= hash << 4;
-    hash     += hash >> 17;
-    hash     ^= hash << 25;
-    hash     += hash >> 6;
-
-    return hash;
-}
-
-/**
  * Initializes the HIP relay / RVS. Initializes the HIP relay hashtable and
  * whitelist.
  */

=== modified file 'lib/core/misc.h'
--- lib/core/misc.h     2010-02-10 23:55:24 +0000
+++ lib/core/misc.h     2010-02-12 15:40:01 +0000
@@ -81,8 +81,10 @@
 
 static inline int ipv6_addr_any(const struct in6_addr *a)
 {
-    return (a->s6_addr32[0] | a->s6_addr32[1] |
-            a->s6_addr32[2] | a->s6_addr32[3]) == 0;
+    return (a->s6_addr[0] | a->s6_addr[1] | a->s6_addr[2] | a->s6_addr[3] |
+            a->s6_addr[4] |a->s6_addr[5] |a->s6_addr[6] |a->s6_addr[7] |
+            a->s6_addr[8] |a->s6_addr[9] |a->s6_addr[10] |a->s6_addr[11] |
+            a->s6_addr[12] |a->s6_addr[13] |a->s6_addr[14] |a->s6_addr[15]) == 
0;
 }
 
 int hip_opportunistic_ipv6_to_hit(const struct in6_addr *ip,

Other related posts:

  • » [hipl-commit] [trunk] Rev 3622: fixed some more s6_addr32 errors by moving code and using s6_addr - Rene Hummen