Skip to content

Commit 65ed96e

Browse files
committed
inet/dhcp: reset network config on dhcp offer
1 parent a829579 commit 65ed96e

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

api/net/inet.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace net {
8383
typename IPV::addr nmask,
8484
typename IPV::addr gateway,
8585
typename IPV::addr dnssrv = IPV::ADDR_ANY) = 0;
86-
86+
virtual void reset_config() = 0;
8787

8888
using dhcp_timeout_func = delegate<void(bool timed_out)>;
8989
virtual void negotiate_dhcp(double timeout = 10.0, dhcp_timeout_func = nullptr) = 0;

api/net/inet4.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ namespace net {
168168
INFO2("DNS Server: \t%s", dns_server.str().c_str());
169169
}
170170

171+
virtual void
172+
reset_config() override
173+
{
174+
this->ip4_addr_ = IP4::ADDR_ANY;
175+
this->gateway_ = IP4::ADDR_ANY;
176+
this->netmask_ = IP4::ADDR_ANY;
177+
}
178+
171179
// register a callback for receiving signal on free packet-buffers
172180
virtual void
173181
on_transmit_queue_available(transmit_avail_delg del) override {

src/net/dhcp/dh4client.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,14 @@ namespace net
259259
socket.bcast(IP4::ADDR_ANY, DHCP_DEST_PORT, packet, packetlen);
260260

261261
socket.on_read(
262-
[this, &socket] (IP4::addr, UDP::port_t port,
262+
[this, &socket] (IP4::addr addr, UDP::port_t port,
263263
const char* data, size_t len)
264264
{
265265
if (port == DHCP_DEST_PORT)
266266
{
267267
// we have got a DHCP Offer
268-
debug("Received possible DHCP OFFER from %s:%d\n",
269-
addr.str().c_str(), DHCP_DEST_PORT);
268+
MYINFO("Received possible DHCP OFFER from %s",
269+
addr.str().c_str());
270270
this->offer(socket, data, len);
271271
}
272272
});
@@ -369,6 +369,10 @@ namespace net
369369
if (console_spam)
370370
MYINFO("DNS SERVER: \t%s", this->dns_server.str().c_str());
371371

372+
// Remove any existing IP config to be able to receive on broadcast
373+
stack.reset_config();
374+
375+
372376
// we can accept the offer now by requesting the IP!
373377
this->request(sock, server_id);
374378
}

0 commit comments

Comments
 (0)