]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: don't remove ip address
authorTobias Jungel <tobias.jungel@bisdn.de>
Wed, 31 Oct 2018 12:33:54 +0000 (13:33 +0100)
committerTobias Jungel <tobias.jungel@bisdn.de>
Tue, 6 Nov 2018 12:26:37 +0000 (13:26 +0100)
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.

src/network/networkd-address.c
src/network/networkd-link.c

index 9cccf25cb928af77039d92cfdc7fe0684a58cac9..1f722aca529f04ba42ab1feaa852f010ac7edcbd 100644 (file)
@@ -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)
index c4923980e396b068d113a18ecc61c687de1ec0bb..6da881c1d310910b79ca1f79756e6f7fcd507d27 100644 (file)
@@ -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) {