Skip to content

Conversation

@ryanbreen
Copy link
Owner

Summary

  • Implement TCP socket syscalls (socket, bind, listen, accept, connect, shutdown) with working data transfer
  • Support loopback connections to 127.x.x.x addresses via internal routing
  • Add comprehensive test suite with 22 tests covering data transfer, shutdown semantics, error handling

Changes

Implementation:

  • TCP connection state machine (SynSent, SynReceived, Established, Closed)
  • Loopback optimization for 127.x.x.x addresses
  • EPIPE returned for writes after shutdown (POSIX compliance)
  • Backlog enforcement in listen()
  • Client address population in accept()

Test Coverage:

  • Basic syscalls: socket, bind, listen, connect, accept, shutdown
  • Data transfer: client→server, server→client, bidirectional
  • Large transfers: 256 bytes, MSS boundary (1460+ bytes)
  • Error handling: EADDRINUSE, ECONNREFUSED, ETIMEDOUT, EPIPE
  • Shutdown semantics: SHUT_RD, SHUT_WR, SHUT_RDWR
  • Backlog overflow rejection
  • Multi-cycle message exchange

Validation Results:

  • Technical Accuracy: A-
  • Intellectual Honesty: A
  • All 177 boot stages pass

Test plan

  • All 177 boot stages pass
  • TCP tests verify exact POSIX error codes
  • Tests can fail when bugs exist (no catch-all patterns)
  • Data verification is byte-exact

🤖 Generated with Claude Code

ryanbreen and others added 3 commits January 11, 2026 08:08
Add complete TCP socket support including:
- TCP state machine (SYN, SYN-ACK, ACK, FIN handshakes)
- Socket syscalls: socket(SOCK_STREAM), bind, listen, accept, connect, shutdown
- Data transfer via read/write on TcpConnection file descriptors
- Connection tracking with ConnectionId and TCP_CONNECTIONS table
- Port conflict detection (EADDRINUSE) for bind
- Blocking connect() that waits for TCP handshake completion

New files:
- kernel/src/net/tcp.rs: Full TCP implementation
- userspace/tests/tcp_socket_test.rs: 11-test validation suite
- userspace/tests/tcp_client_test.rs: Interactive TCP client (tcpclient command)
- run.sh: Convenience script for interactive mode

The tcp_client_test demonstrates end-to-end TCP by connecting to an external
host (10.0.2.2:18888 via QEMU SLIRP) and sending "Hello from Breenix!".

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The TCP loopback tests were failing because:
1. send_ipv4 only detected loopback for our own IP, not 127.x.x.x
2. handle_ipv4 dropped packets destined for 127.x.x.x
3. tcp_connect stored connections with remote_ip=127.0.0.1, but
   SYN-ACK replies came from our actual IP, causing lookup mismatch
4. sys_connect didn't drain loopback queue for local packets

Fixes:
- Accept 127.x.x.x as loopback in send_ipv4 and handle_ipv4
- Normalize loopback addresses to our IP in tcp_connect
- Drain loopback queue in connect wait loop

All 150 boot stages now pass including TCP tests.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…dation

Expand TCP test coverage from basic syscall tests to 22 comprehensive tests
covering data transfer, shutdown semantics, backlog enforcement, and error
handling with strict POSIX compliance.

Key changes:
- Add EPIPE errno and return it for writes after shutdown
- Add tests for bidirectional data, large transfers (256B, MSS boundary)
- Add backlog enforcement test that fails if limit not respected
- Add ECONNREFUSED/ETIMEDOUT test with specific error code checks
- Add client address verification in accept() with 0.0.0.0 failure check
- All tests require exact POSIX error codes, not generic failures

Validation: Technical Accuracy A-, Intellectual Honesty A, APPROVED

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ryanbreen ryanbreen merged commit 762d216 into main Jan 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants