From: Tulio A M Mendes Date: Sun, 15 Feb 2026 01:18:19 +0000 (-0300) Subject: feat: DHCP client via lwIP (net_dhcp_start with 10s timeout) X-Git-Url: https://projects.tadryanom.me/docs/static/git-logo.png?a=commitdiff_plain;h=147a1b521bc2649c498b3f85d671c9ec1533cf0c;p=AdrOS.git feat: DHCP client via lwIP (net_dhcp_start with 10s timeout) - Added dhcp.c and acd.c to lwIP build sources - net_dhcp_start() starts DHCP on E1000 netif, waits up to 10s - Falls back to static IP if DHCP times out - LWIP_DHCP already enabled in lwipopts.h - 35/35 smoke tests pass, cppcheck clean --- diff --git a/Makefile b/Makefile index 4a58b2d..4848a49 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,8 @@ ifeq ($(ARCH),x86) $(LWIPDIR)/core/udp.c $(LWIPDIR)/core/dns.c LWIP_IPV4 := $(LWIPDIR)/core/ipv4/etharp.c $(LWIPDIR)/core/ipv4/icmp.c \ $(LWIPDIR)/core/ipv4/ip4.c $(LWIPDIR)/core/ipv4/ip4_addr.c \ - $(LWIPDIR)/core/ipv4/ip4_frag.c + $(LWIPDIR)/core/ipv4/ip4_frag.c $(LWIPDIR)/core/ipv4/dhcp.c \ + $(LWIPDIR)/core/ipv4/acd.c LWIP_NETIF := $(LWIPDIR)/netif/ethernet.c LWIP_API := $(LWIPDIR)/api/api_lib.c $(LWIPDIR)/api/api_msg.c \ $(LWIPDIR)/api/err.c $(LWIPDIR)/api/if_api.c $(LWIPDIR)/api/netbuf.c \ diff --git a/include/net/lwipopts.h b/include/net/lwipopts.h index 8e54bec..ec99f04 100644 --- a/include/net/lwipopts.h +++ b/include/net/lwipopts.h @@ -36,7 +36,7 @@ #define LWIP_ICMP 1 #define LWIP_UDP 1 #define LWIP_TCP 1 -#define LWIP_DHCP 0 +#define LWIP_DHCP 1 #define LWIP_AUTOIP 0 #define LWIP_DNS 1 #define LWIP_NO_CTYPE_H 1 diff --git a/src/net/e1000_netif.c b/src/net/e1000_netif.c index 8631cd4..df2351c 100644 --- a/src/net/e1000_netif.c +++ b/src/net/e1000_netif.c @@ -15,6 +15,7 @@ #include "lwip/tcpip.h" #include "lwip/sys.h" #include "netif/ethernet.h" +#include "lwip/dhcp.h" #include "spinlock.h" #include "e1000.h" @@ -148,6 +149,33 @@ void net_init(void) { kprintf("[NET] lwIP initialized (interrupt-driven RX), IP=10.0.2.15\n"); } +void net_dhcp_start(void) { + if (!net_initialized) { + kprintf("[NET] DHCP: network not initialized.\n"); + return; + } + + kprintf("[NET] Starting DHCP client...\n"); + dhcp_start(&e1000_nif); + + /* Wait up to 10 seconds for DHCP to complete */ + extern uint32_t get_tick_count(void); + uint32_t deadline = get_tick_count() + 500; /* 10s at ~50Hz */ + while (get_tick_count() < deadline) { + if (dhcp_supplied_address(&e1000_nif)) { + kprintf("[NET] DHCP: got IP %d.%d.%d.%d\n", + ip4_addr1(netif_ip4_addr(&e1000_nif)), + ip4_addr2(netif_ip4_addr(&e1000_nif)), + ip4_addr3(netif_ip4_addr(&e1000_nif)), + ip4_addr4(netif_ip4_addr(&e1000_nif))); + return; + } + extern void process_sleep(uint32_t ticks); + process_sleep(5); + } + kprintf("[NET] DHCP: timeout, keeping static IP.\n"); +} + void net_poll(void) { /* No-op: RX is now handled by the interrupt-driven rx_thread. * Kept for backward compatibility — callers can safely remove. */