mirror of
https://github.com/strongswan/strongswan.git
synced 2025-12-05 00:01:49 -05:00
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.
This commit is contained in:
parent
872b9b3e8d
commit
a8f91cd466
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user