From d77cc49b71f00c55f161fccfb99a74020418bdd4 Mon Sep 17 00:00:00 2001 From: Richard Peters Date: Sat, 26 Oct 2024 07:50:42 +0200 Subject: [PATCH 1/2] fix: when a DHCP lease is obtained, stop autoip to avoid that it overwrites the IP address after conflict resolution --- src/core/ipv4/autoip.c | 5 +++++ src/core/ipv4/dhcp.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index 461a00533..e0511ea4b 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -343,6 +343,11 @@ autoip_stop(struct netif *netif) LWIP_ASSERT_CORE_LOCKED(); if (autoip != NULL) { + /* Stop and remove acd */ + if (autoip->state != AUTOIP_STATE_OFF) { + acd_stop(&autoip->acd); + acd_remove(netif, &autoip->acd); + } autoip->state = AUTOIP_STATE_OFF; if (ip4_addr_islinklocal(netif_ip4_addr(netif))) { netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4); diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index 12e00683d..6201055d3 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -1143,6 +1143,11 @@ dhcp_bind(struct netif *netif) to ensure the callback can use dhcp_supplied_address() */ dhcp_set_state(dhcp, DHCP_STATE_BOUND); +#if LWIP_DHCP_AUTOIP_COOP + /* If autoip was started, stop it to avoid that it sets an ip address after conflict resolution */ + autoip_stop(netif); +#endif /* LWIP_DHCP_AUTOIP_COOP */ + netif_set_addr(netif, &dhcp->offered_ip_addr, &sn_mask, &gw_addr); /* interface is used by routing now that an address is set */ } From 2475a654c5775a54fb5f3fb01dfed23017628ac3 Mon Sep 17 00:00:00 2001 From: Richard Peters Date: Sat, 26 Oct 2024 20:51:24 +0200 Subject: [PATCH 2/2] Stop autoip when dhcp is stopped --- src/core/ipv4/dhcp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index 6201055d3..1dfb46244 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -1394,6 +1394,11 @@ dhcp_release_and_stop(struct netif *netif) dhcp_dec_pcb_refcount(); /* free DHCP PCB if not needed any more */ dhcp->pcb_allocated = 0; } + +#if LWIP_DHCP_AUTOIP_COOP + /* If autoip was started, stop it to avoid that it sets an ip address after conflict resolution */ + autoip_stop(netif); +#endif /* LWIP_DHCP_AUTOIP_COOP */ } /**