Skip to content

Add Linux KVM slirp networking - #3

Merged
misaelzapata merged 1 commit into
port-macos-supportfrom
linux-slirp-network
May 3, 2026
Merged

Add Linux KVM slirp networking#3
misaelzapata merged 1 commit into
port-macos-supportfrom
linux-slirp-network

Conversation

@misaelzapata

Copy link
Copy Markdown
Owner

Summary

  • Add Linux/KVM libslirp user-mode networking for --net slirp / network: "slirp", including TCP host forwarding.
  • Preserve Linux TAP/NAT --net auto by advertising the KVM virtio-net device and letting the guest init configure eth0.
  • Update native build detection, CI/prebuild dependencies, docs, capabilities, and e2e/unit coverage.

Validation

  • npm run test:unit
  • NODE_VMM_KERNEL=/home/misael/.cache/node-vmm/kernels/gocracker-guest-standard-vmlinux npm run test:e2e
  • npm run test:coverage
  • node --test dist/test/native.test.js
  • npm run test:consumers
  • npm run test:js-apps
  • sudo -n env PATH="$PATH" NODE_VMM_KERNEL=/home/misael/.cache/node-vmm/kernels/gocracker-guest-standard-vmlinux npm run test:real-apps
  • npm run pack:check
  • Manual CLI smoke: --net slirp -p <host>:3000 returned manual-linux-slirp-ok
  • Manual CLI smoke: --net auto -p <host>:3000 returned manual-linux-tap-ok

Copilot AI review requested due to automatic review settings May 3, 2026 20:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Linux/KVM libslirp user-mode networking support to complement existing TAP/NAT (--net auto) behavior, aligning KVM networking features more closely with WHP/HVF while extending port publishing coverage and documentation.

Changes:

  • Extend host capabilities / CLI / docs to advertise and describe Linux --net slirp (with TCP host forwarding).
  • Update native build + GYP wiring to optionally link libslirp on Linux (pkg-config-driven) and update CI deps accordingly.
  • Add/adjust unit + e2e coverage for slirp networking and interactive console behavior.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/unit.test.ts Expands kernel candidate/capabilities assertions and adds a probeHvf assertion for unsupported hosts.
test/e2e.test.ts Adds HTTP port-publish e2e for KVM slirp and adjusts interactive run args / PTY input line endings.
src/rootfs.ts Reorders interactive console selection blocks (PTY vs getty ordering).
src/net.ts Adjusts Linux TAP/NAT network config (removes kernel ip= arg for Linux tap path).
src/kvm.ts Adds coverage ignores around console notification control logic.
src/index.ts Advertises slirp as a network mode and ensures virtio-net kernel args are added for non-none networking (non-HVF).
src/cli.ts Updates help text to reflect WHP/HVF auto→slirp behavior.
scripts/build-native.mjs Adds Linux pkg-config detection and env wiring for libslirp flags.
native/kvm/backend.cc Implements KVM virtio-net slirp integration + host forwarding + new N-API config parsing.
docs/testing.md Documents rootless considerations and adds Linux slirp port-publish smoke example.
docs/sdk.md Documents net: "slirp" as a rootless-friendly option when available.
docs/features.md Updates feature matrix and networking descriptions for Linux slirp support.
binding.gyp Adds Linux conditional compile/link configuration for libslirp.
README.md Updates Linux deps and networking notes to include slirp.
.github/workflows/release-prebuilds.yml Adds libglib2.0-dev dependency for Linux prebuild job.
.github/workflows/ci.yml Adds libslirp-dev + libglib2.0-dev to Linux CI jobs.
Comments suppressed due to low confidence (1)

native/kvm/backend.cc:2203

  • tap_readable() returns true unconditionally when slirp is enabled. The watchdog thread checks net->tap_readable() every 20ms and calls interrupt_all() when it’s true, so this will force continuous interrupts even when there is no network traffic, leading to unnecessary KVM_RUN exits and high host CPU usage. Make the slirp path only report readable when there is pending slirp I/O (e.g., queued RX frames, or poll slirp fds for readiness) instead of always true.
	  bool tap_readable() const {
    if (slirp_enabled()) {
      return true;
    }
	    struct pollfd pfd {};
	    pfd.fd = tap_.get();
	    pfd.events = POLLIN;
	    int rc = poll(&pfd, 1, 0);
	    return rc > 0 && (pfd.revents & POLLIN);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread native/kvm/backend.cc
Comment on lines +2602 to +2616
void enqueue_slirp_rx(const uint8_t* data, size_t len) {
if (data == nullptr || len == 0) {
return;
}
slirp_rx_frames_.emplace_back(data, data + len);
}

void flush_slirp_rx() {
while (!slirp_rx_frames_.empty()) {
const std::vector<uint8_t>& frame = slirp_rx_frames_.front();
if (!inject_rx_frame(frame.data(), frame.size())) {
return;
}
slirp_rx_frames_.pop_front();
}
Comment thread native/kvm/backend.cc
Comment on lines +2995 to +2998
fwd.host_port = static_cast<uint16_t>(GetUint32(env, entry, "hostPort", 0));
fwd.guest_port = static_cast<uint16_t>(GetUint32(env, entry, "guestPort", 0));
Check(fwd.host_port > 0, "netSlirpHostFwds entries require hostPort");
Check(fwd.guest_port > 0, "netSlirpHostFwds entries require guestPort");
Comment thread binding.gyp
Comment on lines +23 to +26
["\"<!(node -e \"process.stdout.write(process.env.NODE_VMM_HAVE_LIBSLIRP || '')\")\"=='1'", {
"defines+": ["NODE_VMM_HAVE_LIBSLIRP"],
"cflags_cc+": ["<!@(node -e \"process.stdout.write(process.env.NODE_VMM_LIBSLIRP_CFLAGS || '')\")"],
"libraries+": ["<!@(node -e \"process.stdout.write(process.env.NODE_VMM_LIBSLIRP_LIBS || '')\")"]
@misaelzapata
misaelzapata merged commit 53de92f into port-macos-support May 3, 2026
8 checks 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