Skip to content

Commit a8f91cd

Browse files
committed
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.
1 parent 872b9b3 commit a8f91cd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/libcharon/plugins/ha/ha_attribute.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ static pool_t* get_pool(private_ha_attribute_t *this, char *name)
159159
}
160160

161161
/**
162-
* Check if we are responsible for a bit in our bitmask
162+
* Check if we are responsible for an offset
163163
*/
164-
static bool responsible_for(private_ha_attribute_t *this, int bit)
164+
static bool responsible_for(private_ha_attribute_t *this, int offset)
165165
{
166166
u_int segment;
167167

168-
segment = this->kernel->get_segment_int(this->kernel, bit);
168+
segment = this->kernel->get_segment_int(this->kernel, offset);
169169
return this->segments->is_active(this->segments, segment);
170170
}
171171

@@ -175,7 +175,7 @@ METHOD(attribute_provider_t, acquire_address, host_t*,
175175
{
176176
enumerator_t *enumerator;
177177
pool_t *pool = NULL;
178-
int offset = -1, byte, bit;
178+
int offset = -1, tmp_offset, byte, bit;
179179
host_t *address;
180180
char *name;
181181

@@ -199,10 +199,11 @@ METHOD(attribute_provider_t, acquire_address, host_t*,
199199
{
200200
for (bit = 0; bit < 8; bit++)
201201
{
202+
tmp_offset = byte * 8 + bit;
202203
if (!(pool->mask[byte] & 1 << bit) &&
203-
responsible_for(this, bit))
204+
responsible_for(this, tmp_offset))
204205
{
205-
offset = byte * 8 + bit;
206+
offset = tmp_offset;
206207
pool->mask[byte] |= 1 << bit;
207208
break;
208209
}

0 commit comments

Comments
 (0)