XL1200-EMU Symbolics XL1200 Emulator
Plans & Roadmap SpecsPARTIAL docs/networking-chaosnet-plan.md

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.md for overall sequencing and docs/emulator/peripherals-and-backends.md for 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 EtherType 0x0804 Chaosnet frames.
  • eth_tap_linux.c: Linux-only /dev/net/tun (IFF_TAP | IFF_NO_PI) and AF_PACKET (SOCK_RAW) for veth / NIC attachment — not yet exposed cleanly for pre-existing persistent TAP or veth/PCAP in the Network & Serial UI, 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:

  1. Chaosnet Bridge Integration (cbridge / CHUDP) + libslirp Hybrid Multiplexer: Zero-privilege simultaneous Internet (IPv4 via libslirp) + native Chaosnet (EtherType 0x0804 via external cbridge / CHUDP UDP 42042) on both Linux and Windows.
  2. 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-loaded libpcap (eth_pcap.c) alongside zero-dep AF_PACKET (--eth-veth), enabling reliable attachment to Linux veth pairs and host bridges.
  3. Native Windows L2 Options: Dynamically-loaded Npcap (wpcap.dll) sharing eth_pcap.c (zero mandatory runtime DLL dependency) plus optional TAP-Windows / WinTUN attachment.
  4. 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/>&amp; 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"| PCAP

2. Core & Portability Invariants

  • Zero Core Changes: emu/src/eth_82586.c and libivory_core.so/.dll remain untouched (IVORY_CORE_ABI_VERSION == 4U).
  • No Mandatory New Runtime DLLs on Windows: eth_pcap.c loads wpcap.dll (Windows Npcap) or libpcap.so.1 / libpcap.so (Linux) dynamically via emu_dlopen / emu_dlsym (LoadLibraryA / GetProcAddress), so ivory-xl1200.exe runs 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_frame and poll_rx_frame (draining without stalling emu_thread), compatible with emu_os.h / Winsock2 (WSAStartup already initialized in emu_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 cbridge instance (the standard open-source Chaosnet bridge used across Symbolics, ITS, and CADR communities) using the CHUDP encapsulation protocol (UDP port 42042 by default, configurable as host: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 UDP sendto().
  • 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 MAC or broadcast ff:ff:ff:ff:ff:ff, src = bridge synthetic MAC 08:00:05:cb:00:01, ethertype = 0x0804), and delivers it into Eth82586.
  • Works identically on Linux (POSIX sockets) 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: inspects uint16_t ethertype = (frame[12] << 8) | frame[13]:
      • 0x0804 → forwards to chaos_backend.
      • 0x0800 (IPv4) / 0x0806 (ARP) / 0x86DD (IPv6) → forwards to ip_backend.
    • poll_rx_frame: round-robin polls chaos_backend and ip_backend, waking emu_thread cleanly.
  • Result: One XL1200 instance gets both Internet TCP/IP (libslirp) and native Genera Chaosnet (File Server, Namespace, ZMail, Telnet, Host-to-Host via cbridge) 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 calls ioctl(fd, TUNSETIFF, &ifr) with IFF_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 requiring CAP_NET_ADMIN at runtime.
  • Concrete polish needed:
    1. Detect & report clear actionable diagnostics on EPERM/EBUSY (e.g., "interface 'xl0' busy or not owned by user; pre-create with ip tuntap add dev xl0 mode tap user $USER").
    2. Expose persistent TAP cleanly in Network & Serial workbench UI and document a copy-paste systemd-networkd / ip tuntap + bridge setup snippet in docs/emulator/peripherals-and-backends.md.

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-dependency AF_PACKET, adding a dynamically-loaded libpcap backend (--eth-pcap <ifname>) provides:
    • Cross-OS parity (libpcap.so on Linux, wpcap.dll on Windows, libpcap.dylib on macOS).
    • Reliable Linux veth pair 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 without PACKET_IGNORE_OUTGOING.
    • pcap_findalldevs() enumeration helper to populate an interface picker dropdown in the Network & Serial workbench UI!

Phase 3: Windows Native L2 Options

  1. Npcap (wpcap.dll, Primary Windows L2 Path — via eth_pcap.c):
    • Dynamically load wpcap.dll (searching %SystemRoot%\System32\Npcap\wpcap.dll first via SetDllDirectoryA / 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's ia_addr since Npcap on Windows ignores PCAP_D_IN).
    • Supports tapping physical Ethernet NICs, Hyper-V virtual switches, and Npcap Loopback Adapter for host↔guest Chaosnet/IPv4!
  2. TAP-Windows / WinTUN (Secondary Windows Option — emu/src/eth_tap_win.c, optional):
    • Opens an existing TAP-Windows6 (OpenVPN TAP-Windows NDIS6 L2 adapter, \\.\Global\{GUID}.tap) using overlapped ReadFile/WriteFile + TAP_WIN_IOCTL_SET_MEDIA_STATUS, giving Windows users a pure L2 virtual NIC (carrying both IPv4 and Chaosnet 0x0804) without needing a physical Ethernet link. (Note: WinTUN is L3-only IP and cannot carry EtherType 0x0804 Chaosnet frames, so TAP-Windows6 or Npcap is preferred for true L2.)

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_udp cbridge mux) works unmodified on macOS via POSIX sockets.
  • L2 Interface Tapping Options on macOS:
    1. libpcap (/dev/bpf*) via eth_pcap.c: Ships built-in on macOS (/usr/lib/libpcap.A.dylib), supports en0 or feth fake-Ethernet pairs (ifconfig feth0 create), requires chmod / ChmodBPF group permissions on /dev/bpf*.
    2. vmnet.framework (VMNET_SHARED_MODE / VMNET_BRIDGED_MODE): Apple's native userspace L2 virtual NIC API (requires com.apple.vm.networking entitlement or root sudo).
    3. macOS TAP kexts (tuntaposx) are deprecated on modern macOS (>= 11); prefer cbridge + libslirp or libpcap/feth / vmnet.framework.

4. CLI, Config (define-machine) & Network & Serial UI

SurfaceNew / 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

PhaseAutomated TestsEnd-to-End Verification
Phase 1: cbridge + libslirp MuxExpand 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-Windowsnix 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

FileActionPurpose
emu/src/eth_chaos_udp.cNewPortable CHUDP (cbridge) client for EtherType 0x0804 Chaosnet (POSIX + Win32)
emu/src/eth_mux.cNewLightweight EtherType multiplexer (0x0804 Chaosnet + 0x0800/0x0806 libslirp)
emu/src/eth_pcap.cNewDynamically-loaded libpcap / Windows Npcap (wpcap.dll) backend + interface list
emu/src/eth_tap_linux.cEditImprove pre-existing persistent TAP diagnostics & veth guidance
emu/src/main.c, emu_script.c, ui_workbench.cEdit--eth-chaos, --eth-pcap, --eth-list-ifs, :net config & Network & Serial UI
emu/tests/test_eth.c, emu/MakefileEditCHUDP/mux/PCAP unit tests & SHELL_SRCS wiring
Related Chip Datasheets (2)All Component Datasheets →