From: Richard Maw Date: Tue, 6 Jun 2017 14:43:24 +0000 (+0100) Subject: networkd: Clean up pool addresses on link down X-Git-Tag: v234~91^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=410a7f15f0c6a96cd3b6a73f4a6465a5abfb9d0a;p=platform%2Fupstream%2Fsystemd.git 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. --- diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 69f3e12..fd81c14 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -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) {