ha: Improve distribution of pool addresses over segments
authorTobias Brunner <tobias@strongswan.org>
Tue, 20 Nov 2018 11:50:05 +0000 (12:50 +0100)
committerTobias Brunner <tobias@strongswan.org>
Fri, 7 Dec 2018 09:12:14 +0000 (10:12 +0100)
This is particularly important for higher number of segments, but even
with small numbers there is a significant difference.  For instance,
with 4 segments the fourth segment had no IPs assigned with the old
code, no matter how large the pool, because none of the eight bits used
for the segment check hashed/mapped to it.

src/libcharon/plugins/ha/ha_attribute.c

index 34d6efc..224e223 100644 (file)
@@ -159,13 +159,13 @@ static pool_t* get_pool(private_ha_attribute_t *this, char *name)
 }
 
 /**
- * Check if we are responsible for a bit in our bitmask
+ * Check if we are responsible for an offset
  */
-static bool responsible_for(private_ha_attribute_t *this, int bit)
+static bool responsible_for(private_ha_attribute_t *this, int offset)
 {
        u_int segment;
 
-       segment = this->kernel->get_segment_int(this->kernel, bit);
+       segment = this->kernel->get_segment_int(this->kernel, offset);
        return this->segments->is_active(this->segments, segment);
 }
 
@@ -175,7 +175,7 @@ METHOD(attribute_provider_t, acquire_address, host_t*,
 {
        enumerator_t *enumerator;
        pool_t *pool = NULL;
-       int offset = -1, byte, bit;
+       int offset = -1, tmp_offset, byte, bit;
        host_t *address;
        char *name;
 
@@ -199,10 +199,11 @@ METHOD(attribute_provider_t, acquire_address, host_t*,
                        {
                                for (bit = 0; bit < 8; bit++)
                                {
+                                       tmp_offset = byte * 8 + bit;
                                        if (!(pool->mask[byte] & 1 << bit) &&
-                                               responsible_for(this, bit))
+                                               responsible_for(this, tmp_offset))
                                        {
-                                               offset = byte * 8 + bit;
+                                               offset = tmp_offset;
                                                pool->mask[byte] |= 1 << bit;
                                                break;
                                        }