mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-25 16:52:29 +00:00
feat(net): real UDP transport, BSD datagram sockets, DNS resolver, DHCP client
Turn the networking stubs into a working transport/application stack on top of
the existing L2/L3 (Ethernet/ARP/IPv4/ICMP) core.
UDP (net/ipv4/udp.c)
- Port-demux table with bound receive handlers, pseudo-header checksum,
ephemeral-port allocation, limited-broadcast send (0.0.0.0 -> 255.255.255.255
for DHCP before the interface has an address), and rx/tx/drop counters.
- Wired into the IPv4 receive path (IP_PROTO_UDP dispatch in net/core/net.c).
BSD sockets (net/core/socket.c)
- Real SOCK_DGRAM sockets backed by UDP: bind installs a UDP handler that fills
a per-socket receive ring; send/sendto and recv/recvfrom move datagrams;
ephemeral auto-bind, connect() memorises the peer. Socket table + I/O stats
exposed for introspection.
DNS resolver (net/ipv4/dns.c)
- Builds and parses real A-record queries over UDP/53 (label encoding,
compression-pointer aware answer walk), cache-first with TTL, static-hosts
and dotted-quad fast paths, and a bounded timeout that degrades to fallback
instead of hanging.
DHCP client (net/ipv4/dhcp.c)
- Full DISCOVER/OFFER/REQUEST/ACK handshake over UDP broadcast, option parsing
(mask/router/dns/lease/server-id), applies the lease to the primary
interface, bounded timeouts keep the static config on no response.
Fix (net/ipv4/dns_cache.c): the cache stored IPs as 0xAABBCCDD numeric while the
rest of the stack uses network-byte-order-in-memory (ip_parse/ip_to_str), so a
resolved address came back byte-swapped (nslookup github.com -> 100.121.82.140).
Seeds and dump now use ip_parse/ip_to_str; verified 140.82.121.4.
Userland (lazybox): live ifconfig (real interface + NIC counters, loopback),
netstat with live UDP bindings and transport stats, new `sockstat`, richer
nslookup. Verified in QEMU: boot clean on x86_64/aarch64/armv8i, login as SUB,
ping/nslookup/dhclient/netstat/sockstat all run; DHCP/DNS wire replies are
blocked by the sandbox's slirp but time out cleanly and fall back as designed.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Fh5z6V7nGPbHvqVG5p4CXX
This commit is contained in:
1 parent
2c2e2d536e
commit
cd840d5799
10 files changed
+924
-57
No files matched your search
@@ -41,6 +41,18 @@ int sys_bind(int sockfd, const struct sockaddr_in* addr, size_t addrlen);
|
||||
int sys_connect(int sockfd, const struct sockaddr_in* addr, size_t addrlen);
|
||||
ssize_t sys_send(int sockfd, const void* buf, size_t len, int flags);
|
||||
ssize_t sys_recv(int sockfd, void* buf, size_t len, int flags);
|
||||
|
||||
// Address-carrying variants for connectionless (SOCK_DGRAM) use.
|
||||
ssize_t sys_sendto(int sockfd, const void* buf, size_t len, int flags,
|
||||
const struct sockaddr_in* dest, size_t addrlen);
|
||||
ssize_t sys_recvfrom(int sockfd, void* buf, size_t len, int flags,
|
||||
struct sockaddr_in* src, size_t* addrlen);
|
||||
|
||||
int sys_close_socket(int sockfd);
|
||||
|
||||
// Introspection for netstat / sockstat.
|
||||
int socket_get_count(void);
|
||||
const socket_t* socket_get(int idx);
|
||||
void socket_get_stats(uint64_t* tx_dgrams, uint64_t* rx_dgrams, uint64_t* drops);
|
||||
|
||||
#endif // _NET_SOCKET_H
|
||||
Reference in new issue
Block a user