Skip to content

Commit 73bd6a0

Browse files
Send DHCP request on ::begin even if lease exists (#2977)
When a link comes up, we were only sending a DHCP request if the existing netif's ipaddress was 0. When a DHCP lease is acquired at first that IP is changed to the given address, and if we do another ::begin we wouldn't dhcp_start to send a new request and use the old one (until its lease expired). In the case of network changing (i.e. WiFiMulti on different nets or moving an Ethernet cable to another router) that old address would not be valid. Track if an IP address has been manually set and use that to determine if DHCP needs to be re-requested instead of looking at the old netif's ipaddress. Fixes #2974
1 parent f3df355 commit 73bd6a0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

libraries/lwIP_Ethernet/src/LwipIntfDev.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ class LwipIntfDev: public LwipIntf, public RawDev {
186186
SPIClass& _spiUnit;
187187
SPISettings _spiSettings = SPISettings(4000000, MSBFIRST, SPI_MODE0);
188188
netif _netif;
189+
bool _isDHCP = true;
189190

190191
uint16_t _mtu;
191192
int8_t _intrPin;
@@ -282,6 +283,8 @@ bool LwipIntfDev<RawDev>::config(const IPAddress& localIP, const IPAddress& gate
282283
return false;
283284
}
284285

286+
_isDHCP = (localIP.v4() == 0);
287+
285288
IPAddress realGateway, realNetmask, realDns1;
286289
if (!ipAddressReorder(localIP, gateway, netmask, dns1, realGateway, realNetmask, realDns1)) {
287290
return false;
@@ -389,7 +392,7 @@ bool LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu) {
389392
_phID = __addEthernetPacketHandler([this] { this->handlePackets(); });
390393
}
391394

392-
if (localIP().v4() == 0) {
395+
if (_isDHCP) {
393396
// IP not set, starting DHCP
394397
_netif.flags |= NETIF_FLAG_UP;
395398
switch (dhcp_start(&_netif)) {

0 commit comments

Comments
 (0)