Add Linux KVM slirp networking - #3
Merged
Merged
Conversation
There was a problem hiding this comment.
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()returnstrueunconditionally when slirp is enabled. The watchdog thread checksnet->tap_readable()every 20ms and callsinterrupt_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 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 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 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 || '')\")"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--net slirp/network: "slirp", including TCP host forwarding.--net autoby advertising the KVM virtio-net device and letting the guest init configureeth0.Validation
npm run test:unitNODE_VMM_KERNEL=/home/misael/.cache/node-vmm/kernels/gocracker-guest-standard-vmlinux npm run test:e2enpm run test:coveragenode --test dist/test/native.test.jsnpm run test:consumersnpm run test:js-appssudo -n env PATH="$PATH" NODE_VMM_KERNEL=/home/misael/.cache/node-vmm/kernels/gocracker-guest-standard-vmlinux npm run test:real-appsnpm run pack:check--net slirp -p <host>:3000returnedmanual-linux-slirp-ok--net auto -p <host>:3000returnedmanual-linux-tap-ok