Skip to content

Networking Stack

kazah-png edited this page Jul 11, 2026 · 2 revisions

Networking Stack

Full in-kernel TCP/IP stack: RTL8139 → Ethernet → ARP → IP → ICMP/UDP/TCP → DNS/HTTP.

See also: Drivers, Shell, Architecture

RTL8139 driver (rtl8139.c)

PCI NIC, I/O + MMIO BARs, 4 TX descriptors, circular RX buffer, link detection.

ARP (arp.c)

16-entry cache with TTL. Sends "who has" broadcasts, handles replies, responds to requests.

IP (ip.c)

IPv4 send/receive with header checksum. Routes off-subnet via gateway, delivers loopback internally.

ICMP (icmp.c)

Responds to echo requests (type 8) with replies (type 0). ping CLI sends 4 requests with RTT/loss stats.

UDP (udp.c)

Raw datagram send + port-based listener registration.

TCP (tcp.c)

Full state machine: CLOSED → SYN_SENT → ESTABLISHED → FIN_WAIT → TIME_WAIT → CLOSED. 8 connections.

  • listen/accept: Passive open for TCP servers (NIC-side and loopback). NyxOS can serve HTTP to real external clients via QEMU hostfwd.
  • Server half-close: replies are sent from CLOSE_WAIT (the standard server pattern when the client FINs right after the request)
  • Retransmission (RTO): Exponential backoff 300 ms → 2400 ms cap, 5 retries max. Segments buffered verbatim for retransmit; cumulative ACK clears the buffer.
  • Loopback: 127.0.0.x via software ring (no NIC needed) — entire 3-way handshake, data, and teardown testable in-guest
  • Byte-order fixes v5.7.3-v5.7.4: IP checksum, TCP offset_flags/window/checksum, DNS qcount/flags, ARP sender/target IPs all stored in network byte order (was little-endian)

DHCP (dhcp.c)

DISCOVER → OFFER → REQUEST → ACK. Sets local_ip, netmask, gateway. Lease obtained from QEMU slirp (10.0.2.15). Uses busy-wait on port 0x80 for inter-packet delay.

DNS (dns.c)

Single A-record UDP query to configured server.

HTTP (http.c)

HTTP/1.1 GET with TCP, Host header, timeout-based receive. http_get() waits for handshake completion before sending.

Clone this wiki locally