SchOS/.claude/memory/schunix-network-stack-choice.md
Nexoniarz 3182da3965 Carry project memory in the repo, with tools/memory-sync.sh
Claude Code keeps per-project memory at <home>/.claude/projects/<key>/,
where <key> is the project's absolute path with every separator and the
drive colon turned into a dash. That makes it both rename-fragile and
machine-specific, and this project has hit each of those once:

  - D:\DEV\Schunix -> D:\DEV\SchOS changed the key, and 43 memories were
    invisible until moved across by hand.
  - Development happens from Windows and from Linux, and each looks in a
    different place for the same checkout.

Committing .claude/memory/ fixes both -- git carries it across renames
and between hosts -- and `import` puts it wherever the local machine
expects. .claude/settings.local.json stays ignored: those are per-machine
permissions.

The colon maps to a dash rather than being dropped. Deleting it gives
D-DEV-SchOS, which matches nothing and silently finds zero memories; that
was the first attempt. On Git Bash the key comes from `cygpath -w`,
because Claude Code is a Windows program and sees D:\DEV\SchOS, not
/d/DEV/SchOS.
2026-08-09 14:27:22 +02:00

61 lines
2.9 KiB
Markdown

---
name: schunix-network-stack-choice
description: "Don't write TCP from scratch — and don't take NetBSD's either; the licence and porting evidence for lwIP vs FreeBSD."
metadata:
node_type: memory
type: project
originSessionId: 9d8a2aef-bcf0-47a0-96c6-f706efab4a95
modified: 2026-08-08T20:25:37.412Z
---
Decided 2026-08-08. Nexoniarz: "we should take FreeBSD or NetBSD and their
Network stuff because it's going to be hell making own TCP/IP." **Agreed on the
premise** — TCP is the one part of a network stack where writing it yourself is
a bad trade. It is not the packet format that is hard; it is congestion control,
retransmission, window management and twenty years of corner cases that only
appear against a real peer.
**But the source matters, and NetBSD is the wrong one.**
## The licence evidence (all verified, not assumed)
| | advertising clause? |
|---|---|
| NetBSD `sys/netinet/tcp_input.c`, `tcp_output.c` | **Yes** — the WIDE Project's 4-clause |
| FreeBSD `sys/netinet/tcp_input.c` | **No** — UC, Swinburne, FreeBSD Foundation, Juniper |
| lwIP | **No** — BSD-3, Swedish Institute of Computer Science |
The NetBSD clause belongs to **WIDE**, not Berkeley, so the 1999 rescission does
not reach it. Checked FreeBSD's file directly from `raw.githubusercontent.com`;
zero matches for "All advertising materials". Checked lwIP's `COPYING`; likewise
zero. This **reverses** the older assumption in `docs/roadmap.md` that NetBSD
was the intended starting point.
## The porting evidence, which matters more
FreeBSD's `sys/netinet` is not a library. `tcp_input.c` alone is 122 KB and
reaches into mbufs, `epoch(9)`, netisr, VNET, `uma(9)`, sockbufs, inpcb hash
tables and FreeBSD's locking. Taking it means porting FreeBSD's kernel
infrastructure first and finding the TCP underneath — the same conclusion
`docs/roadmap.md` §1 already reached about `sys/dev/usb`.
**lwIP was written for the situation Schunix is actually in:** a small OS with a
raw Ethernet driver and no infrastructure. Port layer is a handful of files, no
dependency on the host allocator or locking, and it brings ARP, IPv4, ICMP, UDP,
TCP, DHCP and DNS.
**Recommendation: lwIP first, FreeBSD as the reference to check against.**
## Practical notes
- Nexoniarz deleted the NetBSD checkout (`src-trunk/`) for space and said it can
be re-fetched. **Do not clone a whole BSD tree** — a sparse checkout of
`sys/net` and `sys/netinet` is all that has ever been needed, and the space
complaint was legitimate.
- One-file fetches from `raw.githubusercontent.com` are enough for a licence
check and cost nothing. That is how both findings above were made.
- Shell trap hit while doing this: `grep -c` **exits 1 when it finds zero
matches**, so `cmd && grep -c ... || echo "failed"` prints the failure message
on a perfectly successful run. Nearly reported "no network access" when the
fetch had worked.
- Whichever is chosen, it needs a `NOTICE` entry — see [[schunix-licensing]].