--- 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]].