From a2cb756693229c7880d926d2cdde2f838c697415 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 17 Jul 2026 14:11:22 +0200 Subject: net: DHCP client - lease the IP at boot instead of hardcoding it The address is no longer baked in. net_init starts at 0.0.0.0; a DHCP client runs as the first thing on boot (init/shell forks it and waits), and only once it has a lease (or gives up) does the prompt appear. Kernel: - IP is configurable: 0.0.0.0 until leased; NET_SETIP op stores it. - 16-bit frame length. DHCP/BOOTP packets are ~272 bytes, over the old 255-byte frame cap, so net_slip_send takes a 16-bit length, net_pump assembles into a 320-byte buffer with a 16-bit wNetRxLen, and udp_send writes a 16-bit IP total. Payloads stay <=255 (kept small on purpose) so the per-protocol datalen math is unchanged. wNetTx/wNetRxBuf 256->320, SK_RXBUF 208->288. Userland: - c/dhcp.c: DISCOVER->OFFER->REQUEST->ACK over a UDP socket, then net_setip(); times out gracefully (shell still boots) if there's no server. sh.c runs it before the prompt. Bridge (self-contained DHCP server, no dnsmasq): - tunbridge.py + netboot intercept UDP->:67 and answer OFFER/ACK leasing 10.0.0.2 (gateway 10.0.0.1); everything else is bridged/NATed as before. Regression-tested ICMP/UDP/TCP after the 16-bit change. Verified end to end: dhcp: discovering dhcp: leased 10.0.0.2 /# ping 10.0.0.1 -> 4/4 (traffic from the leased address) --- include/gbos.inc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/gbos.inc') diff --git a/include/gbos.inc b/include/gbos.inc index 049a4bc..937d083 100644 --- a/include/gbos.inc +++ b/include/gbos.inc @@ -152,6 +152,7 @@ DEF NET_RECV EQU 3 ; NR_SOCK, NR_BUF, NR_LEN(max) -> A=len or $FF(timeout); DEF NET_CLOSE EQU 4 ; NR_SOCK DEF NET_BIND EQU 5 ; NR_SOCK, NR_PORT -> bind local port (UDP) DEF NET_POLL EQU 6 ; pump RX once (answer pings) -> A=0 +DEF NET_SETIP EQU 7 ; set our IPv4 address from NR_IP (DHCP) ; socket types DEF SOCK_ICMP EQU 1 DEF SOCK_UDP EQU 2 @@ -252,5 +253,6 @@ DEF PROG_CHAT EQU 25 DEF PROG_NETD EQU 26 DEF PROG_PING EQU 27 DEF PROG_NSLOOKUP EQU 28 +DEF PROG_DHCP EQU 29 ENDC -- cgit v1.3.1-sl0p