From: Tobias Brunner Date: Tue, 20 Nov 2018 11:50:05 +0000 (+0100) Subject: ha: Improve distribution of pool addresses over segments X-Git-Tag: 5.7.2dr4~8^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a8f91cd4666a1e37c464d1147e35b2cd6540ad80;p=thirdparty%2Fstrongswan.git ha: Improve distribution of pool addresses over segments 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. --- diff --git a/src/libcharon/plugins/ha/ha_attribute.c b/src/libcharon/plugins/ha/ha_attribute.c index 34d6efc480..224e223621 100644 --- a/src/libcharon/plugins/ha/ha_attribute.c +++ b/src/libcharon/plugins/ha/ha_attribute.c @@ -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; }