From 64f2911bacdf7f9d11acfe0ae605cbab8ae733e3 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 12 Sep 2026 01:34:47 +0900 Subject: [PATCH] network: drop pending requests when a DHCP lease is lost or a client is stopped When a DHCP lease is lost or a client is stopped, there may exist requests not processed yet. We need to cancel them, otherwise an address or route requested by the lost lease may be configured later. (cherry picked from commit 830b60ae1fcd435b162b1fa7552609dd425fb6b7) --- src/network/networkd-dhcp-prefix-delegation.c | 4 ++++ src/network/networkd-dhcp4.c | 4 ++++ src/network/networkd-dhcp6.c | 4 ++++ src/network/networkd-ndisc.c | 3 +++ 4 files changed, 15 insertions(+) diff --git a/src/network/networkd-dhcp-prefix-delegation.c b/src/network/networkd-dhcp-prefix-delegation.c index 85c5233472..c5757ac8f2 100644 --- a/src/network/networkd-dhcp-prefix-delegation.c +++ b/src/network/networkd-dhcp-prefix-delegation.c @@ -271,6 +271,10 @@ int dhcp_pd_remove(Link *link, bool only_marked) { } } + if (!only_marked) + /* Also drop pending requests when the lease is lost or the client is stopped. */ + RET_GATHER(ret, link_drop_requests(link, NETWORK_CONFIG_SOURCE_DHCP_PD)); + return ret; } diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index 468c3eb920..bd5cf845a6 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -272,6 +272,10 @@ static int dhcp4_remove_address_and_routes(Link *link, bool only_marked) { RET_GATHER(ret, address_remove_and_cancel(address, link)); } + if (!only_marked) + /* Also drop pending requests when the lease is lost or the client is stopped. */ + RET_GATHER(ret, link_drop_requests(link, NETWORK_CONFIG_SOURCE_DHCP4)); + return ret; } diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index 799caeb15b..db3d9297c2 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -83,6 +83,10 @@ static int dhcp6_remove(Link *link, bool only_marked) { RET_GATHER(ret, address_remove_and_cancel(address, link)); } + if (!only_marked) + /* Also drop pending requests when the lease is lost or the client is stopped. */ + RET_GATHER(ret, link_drop_requests(link, NETWORK_CONFIG_SOURCE_DHCP6)); + return ret; } diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c index 4198a6d017..3476effb2f 100644 --- a/src/network/networkd-ndisc.c +++ b/src/network/networkd-ndisc.c @@ -3194,6 +3194,9 @@ int ndisc_stop(Link *link) { void ndisc_flush(Link *link) { assert(link); + /* First, drop pending requests. */ + (void) link_drop_requests(link, NETWORK_CONFIG_SOURCE_NDISC); + /* Remove all addresses, routes, RDNSS, DNSSL, DNR, and Captive Portal entries, without exception. */ (void) ndisc_drop_outdated(link, /* router= */ NULL, /* timestamp_usec= */ USEC_INFINITY); (void) ndisc_drop_redirect(link, /* router= */ NULL);