Networking Plan: Chaosnet Bridge (cbridge), libslirp Mux, Real Interface Tapping (TAP / PCAP / veth) & Windows L2
Status: Future / Proposed Design Plan (Tier 1, Priority #3) — Not yet implemented. See
docs/ROADMAP.mdfor overall sequencing anddocs/emulator/peripherals-and-backends.mdfor the current Intel 82586,libslirp, and Linux TAP/AF_PACKET implementation.
Target Emulator: C11 XL1200 Emulator (emu/) — Host Shell Only (zero changes to eth_82586.c or libivory_core ABI)
Reference Sources: docs/hardware-reference/05-xl1200-workstation-peripherals.md, genera-original/sys.sct/network/, emu/src/eth_82586.c, emu/src/eth_slirp.c, emu/src/eth_tap_linux.c
1. Executive Summary & Lean Design Philosophy
Today, ivory-xl1200 has a complete, OS-independent Intel 82586 LAN coprocessor (emu/src/eth_82586.c) wired exclusively via EthHostCallbacks (on_tx_frame / poll_rx_frame), backed by two host-shell implementations:
eth_slirp.c: Zero-privilege IPv4 TCP/UDP/ICMP NAT (libslirp) on Linux and Windows — but drops raw EtherType0x0804Chaosnet frames.eth_tap_linux.c: Linux-only/dev/net/tun(IFF_TAP | IFF_NO_PI) andAF_PACKET(SOCK_RAW) forveth/ NIC attachment — not yet exposed cleanly for pre-existing persistent TAP orveth/PCAP in theNetwork & SerialUI, and unavailable on Windows.
Rather than building and maintaining a complex in-emulator virtual L2 switch, this plan keeps the networking stack minimal, composable, and interoperable with existing real-world tools:
- Chaosnet Bridge Integration (
cbridge/CHUDP) +libslirpHybrid Multiplexer: Zero-privilege simultaneous Internet (IPv4 vialibslirp) + native Chaosnet (EtherType0x0804via externalcbridge/CHUDPUDP42042) on both Linux and Windows. - Real Interface Tapping on Linux:
- TAP (including pre-existing persistent interfaces): Clean support & UI/config for opening user-owned persistent TAPs (
ip tuntap add dev xl0 mode tap user $USER) with zero runtime root privileges. - PCAP &
AF_PACKET(veth/ bridge support): Unified dynamically-loadedlibpcap(eth_pcap.c) alongside zero-depAF_PACKET(--eth-veth), enabling reliable attachment to Linuxvethpairs and host bridges.
- TAP (including pre-existing persistent interfaces): Clean support & UI/config for opening user-owned persistent TAPs (
- Native Windows L2 Options: Dynamically-loaded Npcap (
wpcap.dll) sharingeth_pcap.c(zero mandatory runtime DLL dependency) plus optional TAP-Windows / WinTUN attachment. - macOS Notes (Lowest Priority): Documented ideas and entitlement requirements (
libpcap/bpf,vmnet.framework) deferred until macOS support is prioritized.
flowchart LR
NIC["Core: eth_82586.c<br/>(Pure ISO C11, Unchanged)<br/>EthHostCallbacks"]
MUX["Shell: eth_mux.c<br/>EtherType Splitter"]
SLIRP["eth_slirp.c<br/>IPv4 / ARP (0x0800, 0x0806)<br/>Zero-Priv NAT"]
CHAOS["eth_chaos_udp.c<br/>Chaosnet (0x0804)<br/>CHUDP / cbridge (UDP 42042)"]
TAP["eth_tap_linux.c<br/>Linux TAP (incl. pre-existing)<br/>& AF_PACKET (veth)"]
PCAP["eth_pcap.c (dlopen/LoadLibrary)<br/>Linux libpcap (veth/bridge)<br/>Windows Npcap (wpcap.dll)<br/>macOS libpcap (future)"]
NIC -->|"Hybrid mode"| MUX
MUX -->|"0x0800 / 0x0806"| SLIRP
MUX -->|"0x0804"| CHAOS
NIC -->|"Direct Linux L2"| TAP
NIC -->|"Direct PCAP / Npcap"| PCAP2. Core & Portability Invariants
- Zero Core Changes:
emu/src/eth_82586.candlibivory_core.so/.dllremain untouched (IVORY_CORE_ABI_VERSION == 4U). - No Mandatory New Runtime DLLs on Windows:
eth_pcap.cloadswpcap.dll(Windows Npcap) orlibpcap.so.1/libpcap.so(Linux) dynamically viaemu_dlopen/emu_dlsym(LoadLibraryA/GetProcAddress), soivory-xl1200.exeruns identically on machines without Npcap installed and prints a clear diagnostic if the user explicitly selects PCAP mode without Npcap. - Non-Blocking Poll Discipline: Every backend implements non-blocking
on_tx_frameandpoll_rx_frame(draining without stallingemu_thread), compatible withemu_os.h/ Winsock2 (WSAStartupalready initialized inemu_ipc.c).
3. Phase-by-Phase Technical Design
Phase 1: Chaosnet Bridge (cbridge / CHUDP) & libslirp Hybrid Multiplexer
A. Chaosnet-over-UDP Bridge Client (emu/src/eth_chaos_udp.c)
- Connects to a local or LAN
cbridgeinstance (the standard open-source Chaosnet bridge used across Symbolics, ITS, and CADR communities) using the CHUDP encapsulation protocol (UDP port42042by default, configurable ashost:port, e.g.127.0.0.1:42042). - TX Path (Guest →
cbridge):- Accepts Ethernet frames with EtherType
0x0804(len >= 14 + 16). - Strips the 14-byte Ethernet header, extracts the Chaosnet packet, prepends the 4-byte CHUDP header (
version = 1,function = 1,0, 0), and sends via non-blocking UDPsendto().
- Accepts Ethernet frames with EtherType
- RX Path (
cbridge→ Guest):- Non-blocking
recvfrom()validates the 4-byte CHUDP header, wraps the Chaosnet payload in a 14-byte Ethernet frame (dst = guest MACor broadcastff:ff:ff:ff:ff:ff,src = bridge synthetic MAC 08:00:05:cb:00:01,ethertype = 0x0804), and delivers it intoEth82586.
- Non-blocking
- Works identically on Linux (
POSIXsockets) and Windows (Winsock2) with zero elevated privileges.
B. Lightweight EtherType Multiplexer (emu/src/eth_mux.c, ~90 LOC)
- Wraps up to two child
EthHostCallbacks(ip_backend=libslirp,chaos_backend=eth_chaos_udp):on_tx_frame: inspectsuint16_t ethertype = (frame[12] << 8) | frame[13]:0x0804→ forwards tochaos_backend.0x0800(IPv4) /0x0806(ARP) /0x86DD(IPv6) → forwards toip_backend.
poll_rx_frame: round-robin pollschaos_backendandip_backend, wakingemu_threadcleanly.
- Result: One XL1200 instance gets both Internet TCP/IP (
libslirp) and native Genera Chaosnet (File Server, Namespace, ZMail, Telnet, Host-to-Host viacbridge) out of the box!
Phase 2: Linux Real Interface Tapping (Pre-Existing TAP & PCAP / veth)
A. Opening Pre-Existing Persistent TAP Interfaces (emu/src/eth_tap_linux.c)
eth_tap_linux_open_tap()already callsioctl(fd, TUNSETIFF, &ifr)withIFF_TAP | IFF_NO_PI, which on Linux automatically attaches to an existing user-owned persistent TAP (ip tuntap add dev xl0 mode tap user $USER && ip link set xl0 up) without requiringCAP_NET_ADMINat runtime.- Concrete polish needed:
- Detect & report clear actionable diagnostics on
EPERM/EBUSY(e.g., "interface 'xl0' busy or not owned by user; pre-create withip tuntap add dev xl0 mode tap user $USER"). - Expose persistent TAP cleanly in
Network & Serialworkbench UI and document a copy-pastesystemd-networkd/ip tuntap+ bridge setup snippet indocs/emulator/peripherals-and-backends.md.
- Detect & report clear actionable diagnostics on
B. Unified Dynamic PCAP Backend (emu/src/eth_pcap.c) for Linux veth & Bridges
- While
eth_tap_linux_open_packet()(--eth-veth <if>) already supports zero-dependencyAF_PACKET, adding a dynamically-loadedlibpcapbackend (--eth-pcap <ifname>) provides:- Cross-OS parity (
libpcap.soon Linux,wpcap.dllon Windows,libpcap.dylibon macOS). - Reliable Linux
vethpair attachment (ip link add veth-xl type veth peer name veth-host), immediate mode (pcap_set_immediate_mode(p, 1)), promiscuous capture (pcap_set_promisc(p, 1)), and incoming-only direction filtering (pcap_setdirection(p, PCAP_D_IN)) to prevent TX echo loops cleanly even on kernels/drivers withoutPACKET_IGNORE_OUTGOING. pcap_findalldevs()enumeration helper to populate an interface picker dropdown in theNetwork & Serialworkbench UI!
- Cross-OS parity (
Phase 3: Windows Native L2 Options
- Npcap (
wpcap.dll, Primary Windows L2 Path — viaeth_pcap.c):- Dynamically load
wpcap.dll(searching%SystemRoot%\System32\Npcap\wpcap.dllfirst viaSetDllDirectoryA/ explicit path so Npcap in WinPcap-compatible or native mode always resolves cleanly). - Uses
pcap_open_live/pcap_create+pcap_set_immediate_mode+pcap_setnonblock+pcap_sendpacket, plus MAC-source echo filter (dropping RX frames whose source MAC equals the guest'sia_addrsince Npcap on Windows ignoresPCAP_D_IN). - Supports tapping physical Ethernet NICs, Hyper-V virtual switches, and Npcap Loopback Adapter for host↔guest Chaosnet/IPv4!
- Dynamically load
- TAP-Windows / WinTUN (Secondary Windows Option —
emu/src/eth_tap_win.c, optional):- Opens an existing TAP-Windows6 (
OpenVPN TAP-WindowsNDIS6 L2 adapter,\\.\Global\{GUID}.tap) using overlappedReadFile/WriteFile+TAP_WIN_IOCTL_SET_MEDIA_STATUS, giving Windows users a pure L2 virtual NIC (carrying both IPv4 and Chaosnet0x0804) without needing a physical Ethernet link. (Note: WinTUN is L3-only IP and cannot carry EtherType0x0804Chaosnet frames, so TAP-Windows6 or Npcap is preferred for true L2.)
- Opens an existing TAP-Windows6 (
Phase 4: macOS Ideas & Requirements (Lowest Priority — Documentation Only for Now)
Target hardware note: Intel macOS (e.g., 2019 Intel MacBook Pro, x86_64-darwin) as well as future Apple Silicon (aarch64-darwin).
- Zero-Privilege Chaosnet + IPv4: Phase 1 (
libslirp+eth_chaos_udpcbridgemux) works unmodified on macOS via POSIX sockets. - L2 Interface Tapping Options on macOS:
libpcap(/dev/bpf*) viaeth_pcap.c: Ships built-in on macOS (/usr/lib/libpcap.A.dylib), supportsen0orfethfake-Ethernet pairs (ifconfig feth0 create), requireschmod/ChmodBPFgroup permissions on/dev/bpf*.vmnet.framework(VMNET_SHARED_MODE/VMNET_BRIDGED_MODE): Apple's native userspace L2 virtual NIC API (requirescom.apple.vm.networkingentitlement or rootsudo).- macOS TAP kexts (
tuntaposx) are deprecated on modern macOS (>= 11); prefercbridge+libslirporlibpcap/feth/vmnet.framework.
4. CLI, Config (define-machine) & Network & Serial UI
| Surface | New / Updated Options |
|---|---|
CLI (main.c) | --eth-chaos <host:port> (can combine with --eth-user to auto-enable eth_mux!), --eth-pcap <ifname>, --eth-list-ifs (lists available TAP/PCAP interfaces), existing --eth-tap <if> & --eth-veth <if> |
Config (emu_script.c) | :net '(:mode :user :cidr "10.0.2.0/24" :chaos "127.0.0.1:42042" :hostfwd (...)) or :net '(:mode :pcap :ifname "veth-xl") / :mode :tap / :mode :veth |
Workbench (ui_workbench.c) | Network & Serial window: mode selector (Off, User NAT (slirp), User NAT + Chaosnet, TAP (Linux/Win), PCAP / Npcap / veth), optional cbridge host:port field, and Refresh Interfaces button |
5. Verification & Acceptance Criteria
| Phase | Automated Tests | End-to-End Verification |
|---|---|---|
Phase 1: cbridge + libslirp Mux | Expand emu/tests/test_eth.c: loopback UDP mock cbridge verifying CHUDP 4-byte framing, EtherType 0x0804 → chaos and 0x0800/0x0806 → slirp demux, and clean RX round-robin on both Linux & Wine. | Live Genera 8.3 booted with --eth-user --eth-chaos 127.0.0.1:42042 running alongside real cbridge: verify both IPv4 (Show Host / Telnet) and Chaosnet (Show Host / Chaos contact) simultaneously. |
Phase 2: Linux TAP & PCAP (veth) | test_eth: verify graceful error reporting on missing TAP/PCAP interfaces and dynamic dlopen(libpcap) absence fallback. | Manual Linux test: attach to pre-existing user-owned tap0 (ip tuntap add ... user $USER) and to a veth pair via both --eth-veth and --eth-pcap; verify zero TX echo storms. |
| Phase 3: Windows Npcap / TAP-Windows | nix develop .#mingw --command make -C emu TARGET_OS=windows -j all dist-win test-win: verify ivory-xl1200.exe has zero static import of wpcap.dll (objdump -p). | Windows test with Npcap installed: --eth-list-ifs enumerates adapters and bridges frames without crashing when Npcap is absent. |
6. File Impact Summary
| File | Action | Purpose |
|---|---|---|
emu/src/eth_chaos_udp.c | New | Portable CHUDP (cbridge) client for EtherType 0x0804 Chaosnet (POSIX + Win32) |
emu/src/eth_mux.c | New | Lightweight EtherType multiplexer (0x0804 Chaosnet + 0x0800/0x0806 libslirp) |
emu/src/eth_pcap.c | New | Dynamically-loaded libpcap / Windows Npcap (wpcap.dll) backend + interface list |
emu/src/eth_tap_linux.c | Edit | Improve pre-existing persistent TAP diagnostics & veth guidance |
emu/src/main.c, emu_script.c, ui_workbench.c | Edit | --eth-chaos, --eth-pcap, --eth-list-ifs, :net config & Network & Serial UI |
emu/tests/test_eth.c, emu/Makefile | Edit | CHUDP/mux/PCAP unit tests & SHELL_SRCS wiring |
- Intel 82586 —
intel_82586_lan_coprocessor.pdf(mirror) - Intel 82586 —
intel_82586_reference_manual_1983.pdf(mirror)