Merge branch 'ha-pool-offset'

Ensure an even distribution of a pool's addresses among all segments.

Fixes #2828.
This commit is contained in:
Tobias Brunner
2018-12-07 10:16:21 +01:00
3 changed files with 21 additions and 6 deletions
+7 -6
View 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 = offset % this->segments->count(this->segments) + 1;
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;
}
+7
View File
@@ -433,6 +433,12 @@ METHOD(ha_segments_t, is_active, bool,
return (this->active & SEGMENTS_BIT(segment)) != 0;
}
METHOD(ha_segments_t, count, u_int,
private_ha_segments_t *this)
{
return this->count;
}
METHOD(ha_segments_t, destroy, void,
private_ha_segments_t *this)
{
@@ -459,6 +465,7 @@ ha_segments_t *ha_segments_create(ha_socket_t *socket, ha_kernel_t *kernel,
.deactivate = _deactivate,
.handle_status = _handle_status,
.is_active = _is_active,
.count = _count,
.destroy = _destroy,
},
.socket = socket,
+7
View File
@@ -82,6 +82,13 @@ struct ha_segments_t {
*/
bool (*is_active)(ha_segments_t *this, u_int segment);
/**
* Return the number of segments
*
* @return number of segments
*/
u_int (*count)(ha_segments_t *this);
/**
* Destroy a ha_segments_t.
*/