networkd: Clean up pool addresses on link down

When the link comes up it assigns addresses
by checking whether the address is 0.0.0.0,
and if so pulling a new address range out of the pool.

If the addresses aren't removed from the pool when the link goes down
then the set of addresses allocated will grow
until all the local address ranges are exhausted,
while it gets a different IP address every time.

This patch frees the addresses when link config is dropped
to fix the address leak,
and on systems which can expect all interfaces to be brought up or down
in a deterministic order this conveniently makes use the same address each time.
This commit is contained in:
Richard Maw 2017-06-06 15:43:24 +01:00
parent 42d3bf86bb
commit 410a7f15f0
1 changed files with 10 additions and 1 deletions

View File

@ -2443,7 +2443,7 @@ static int link_drop_foreign_config(Link *link) {
}
static int link_drop_config(Link *link) {
Address *address;
Address *address, *pool_address;
Route *route;
Iterator i;
int r;
@ -2456,6 +2456,15 @@ static int link_drop_config(Link *link) {
r = address_remove(address, link, link_address_remove_handler);
if (r < 0)
return r;
/* If this address came from an address pool, clean up the pool */
LIST_FOREACH(addresses, pool_address, link->pool_addresses) {
if (address_equal(address, pool_address)) {
LIST_REMOVE(addresses, link->pool_addresses, pool_address);
address_free(pool_address);
break;
}
}
}
SET_FOREACH(route, link->routes, i) {