diff options
author | Tobias Jungel <tobias.jungel@bisdn.de> | 2018-10-31 13:33:54 +0100 |
---|---|---|
committer | Tobias Jungel <tobias.jungel@bisdn.de> | 2018-11-06 13:26:37 +0100 |
commit | 30226d2718d9c3209ff779465ab62c3fb05b3f22 (patch) | |
tree | ef67f53cce4ce1555932cf80a775ca46e1c4c963 | |
parent | 8912a99cea2c05b66ba78809eef199d04c6b862e (diff) | |
download | systemd-30226d2718d9c3209ff779465ab62c3fb05b3f22.tar.gz systemd-30226d2718d9c3209ff779465ab62c3fb05b3f22.tar.bz2 systemd-30226d2718d9c3209ff779465ab62c3fb05b3f22.zip |
networkd: don't remove ip address
In case networkd is restarted this prevents a removal of an already existing IP
address that would be configured using networkd. With the proposed changes the
IP address will be kept on the interface without removing. This happens only on
physical hosts or VMs since networkd handles interface configuration slightly
different in containers.
-rw-r--r-- | src/network/networkd-address.c | 6 | ||||
-rw-r--r-- | src/network/networkd-link.c | 28 |
2 files changed, 31 insertions, 3 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index 9cccf25cb9..1f722aca52 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -428,6 +428,7 @@ int address_remove( sd_netlink_message_handler_t callback) { _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL; + _cleanup_free_ char *b = NULL; int r; assert(address); @@ -437,6 +438,11 @@ int address_remove( assert(link->manager); assert(link->manager->rtnl); + if (DEBUG_LOGGING) { + if (in_addr_to_string(address->family, &address->in_addr, &b) >= 0) + log_link_debug(link, "Removing address %s", b); + } + r = sd_rtnl_message_new_addr(link->manager->rtnl, &req, RTM_DELADDR, link->ifindex, address->family); if (r < 0) diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index c4923980e3..6da881c1d3 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -2618,6 +2618,22 @@ static int link_set_ipv6_mtu(Link *link) { return 0; } +static bool link_is_static_address_configured(Link *link, Address *address) { + Address *net_address; + + assert(link); + assert(address); + + if (!link->network) + return false; + + LIST_FOREACH(addresses, net_address, link->network->static_addresses) + if (address_equal(net_address, address)) + return true; + + return false; +} + static int link_drop_foreign_config(Link *link) { Address *address; Route *route; @@ -2629,9 +2645,15 @@ static int link_drop_foreign_config(Link *link) { if (address->family == AF_INET6 && in_addr_is_link_local(AF_INET6, &address->in_addr) == 1) continue; - r = address_remove(address, link, link_address_remove_handler); - if (r < 0) - return r; + if (link_is_static_address_configured(link, address)) { + r = address_add(link, address->family, &address->in_addr, address->prefixlen, NULL); + if (r < 0) + return log_link_error_errno(link, r, "Failed to add address: %m"); + } else { + r = address_remove(address, link, link_address_remove_handler); + if (r < 0) + return r; + } } SET_FOREACH(route, link->routes_foreign, i) { |