diff --git a/man/networkctl.xml b/man/networkctl.xml
index 5a6ca5ab27..1a4553afd9 100644
--- a/man/networkctl.xml
+++ b/man/networkctl.xml
@@ -299,7 +299,10 @@ s - Service VLAN, m - Two-port MAC Relay (TPMR)
reconfigure
DEVICEā¦
- Reconfigure network interfaces. Takes interface name or index number.
+ Reconfigure network interfaces. Takes interface name or index number. Note that
+ this does not reload .netdev or .network
+ corresponding to the the specifed interface. So, if you edit config files, it is necessary to
+ call networkctl reload first to apply new settings.
diff --git a/src/libsystemd-network/sd-ipv4acd.c b/src/libsystemd-network/sd-ipv4acd.c
index d957202a68..af2b98f591 100644
--- a/src/libsystemd-network/sd-ipv4acd.c
+++ b/src/libsystemd-network/sd-ipv4acd.c
@@ -142,10 +142,17 @@ static void ipv4acd_client_notify(sd_ipv4acd *acd, int event) {
}
int sd_ipv4acd_stop(sd_ipv4acd *acd) {
+ IPv4ACDState old_state;
+
assert_return(acd, -EINVAL);
+ old_state = acd->state;
+
ipv4acd_reset(acd);
+ if (old_state == IPV4ACD_STATE_INIT)
+ return 0;
+
log_ipv4acd(acd, "STOPPED");
ipv4acd_client_notify(acd, SD_IPV4ACD_EVENT_STOP);
@@ -435,6 +442,15 @@ int sd_ipv4acd_set_address(sd_ipv4acd *acd, const struct in_addr *address) {
return 0;
}
+int sd_ipv4acd_get_address(sd_ipv4acd *acd, struct in_addr *address) {
+ assert_return(acd, -EINVAL);
+ assert_return(address, -EINVAL);
+
+ address->s_addr = acd->address;
+
+ return 0;
+}
+
int sd_ipv4acd_is_running(sd_ipv4acd *acd) {
assert_return(acd, false);
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
index ba03d36f20..8f5b08c079 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -22,19 +22,8 @@
static int dhcp4_update_address(Link *link, bool announce);
static int dhcp4_remove_all(Link *link);
-static int dhcp4_release_old_lease(Link *link, bool force);
-static int dhcp4_address_callback(Address *address) {
- assert(address);
- assert(address->link);
-
- /* Do not call this callback again. */
- address->callback = NULL;
-
- return dhcp4_release_old_lease(address->link, true);
-}
-
-static int dhcp4_release_old_lease(Link *link, bool force) {
+static int dhcp4_release_old_lease(Link *link) {
Route *route;
Iterator i;
int k, r = 0;
@@ -44,12 +33,6 @@ static int dhcp4_release_old_lease(Link *link, bool force) {
if (!link->dhcp_address_old && set_isempty(link->dhcp_routes_old))
return 0;
- if (!force && (link->dhcp_address && !address_is_ready(link->dhcp_address))) {
- log_link_debug(link, "New DHCPv4 address is not ready. The old lease will be removed later.");
- link->dhcp_address->callback = dhcp4_address_callback;
- return 0;
- }
-
log_link_debug(link, "Removing old DHCPv4 address and routes.");
link_dirty(link);
@@ -81,7 +64,7 @@ static void dhcp4_check_ready(Link *link) {
link->dhcp4_configured = true;
/* New address and routes are configured now. Let's release old lease. */
- r = dhcp4_release_old_lease(link, false);
+ r = dhcp4_release_old_lease(link);
if (r < 0) {
link_enter_failed(link);
return;
@@ -559,7 +542,7 @@ static int dhcp_lease_lost(Link *link) {
link->dhcp4_configured = false;
/* dhcp_lease_lost() may be called during renewing IP address. */
- k = dhcp4_release_old_lease(link, true);
+ k = dhcp4_release_old_lease(link);
if (k < 0)
r = k;
@@ -627,7 +610,7 @@ static void dhcp_address_on_acd(sd_ipv4acd *acd, int event, void *userdata) {
assert_not_reached("Invalid IPv4ACD event.");
}
- sd_ipv4acd_stop(acd);
+ (void) sd_ipv4acd_stop(acd);
return;
}
@@ -658,6 +641,7 @@ static int configure_dhcpv4_duplicate_address_detection(Link *link) {
static int dhcp4_start_acd(Link *link) {
union in_addr_union addr;
+ struct in_addr old;
int r;
if (!link->network->dhcp_send_decline)
@@ -666,12 +650,18 @@ static int dhcp4_start_acd(Link *link) {
if (!link->dhcp_lease)
return 0;
+ (void) sd_ipv4acd_stop(link->network->dhcp_acd);
+
link->dhcp4_address_bind = false;
r = sd_dhcp_lease_get_address(link->dhcp_lease, &addr.in);
if (r < 0)
return r;
+ r = sd_ipv4acd_get_address(link->network->dhcp_acd, &old);
+ if (r < 0)
+ return r;
+
r = sd_ipv4acd_set_address(link->network->dhcp_acd, &addr.in);
if (r < 0)
return r;
@@ -687,13 +677,41 @@ static int dhcp4_start_acd(Link *link) {
log_link_debug(link, "Starting IPv4ACD client. Probing DHCPv4 address %s", strna(pretty));
}
- r = sd_ipv4acd_start(link->network->dhcp_acd, true);
+ r = sd_ipv4acd_start(link->network->dhcp_acd, !in4_addr_equal(&addr.in, &old));
if (r < 0)
return r;
return 1;
}
+static int dhcp4_address_ready_callback(Address *address) {
+ Link *link;
+ int r;
+
+ assert(address);
+
+ link = address->link;
+
+ /* Do not call this again. */
+ address->callback = NULL;
+
+ r = link_set_dhcp_routes(link);
+ if (r < 0)
+ return r;
+
+ /* Reconfigure static routes as kernel may remove some routes when lease expires. */
+ r = link_request_set_routes(link);
+ if (r < 0)
+ return r;
+
+ r = dhcp4_start_acd(link);
+ if (r < 0)
+ return log_link_error_errno(link, r, "Failed to start IPv4ACD for DHCP4 adddress: %m");
+
+ dhcp4_check_ready(link);
+ return 0;
+}
+
static int dhcp4_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
@@ -710,27 +728,14 @@ static int dhcp4_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *
} else if (r >= 0)
(void) manager_rtnl_process_address(rtnl, m, link->manager);
- r = link_set_dhcp_routes(link);
- if (r < 0) {
- link_enter_failed(link);
- return 1;
- }
-
- /* Add back static routes since kernel removes while DHCPv4 address is removed from when lease expires */
- r = link_request_set_routes(link);
- if (r < 0) {
- link_enter_failed(link);
- return 1;
- }
-
- r = dhcp4_start_acd(link);
- if (r < 0) {
- log_link_error_errno(link, r, "Failed to start IPv4ACD for DHCP4 adddress: %m");
- link_enter_failed(link);
- return 1;
- }
-
- dhcp4_check_ready(link);
+ if (address_is_ready(link->dhcp_address)) {
+ r = dhcp4_address_ready_callback(link->dhcp_address);
+ if (r < 0) {
+ link_enter_failed(link);
+ return 1;
+ }
+ } else
+ link->dhcp_address->callback = dhcp4_address_ready_callback;
return 1;
}