lkl: add libslirp network backend for user-mode networking#631
Open
xdqi wants to merge 5 commits intolkl:masterfrom
Open
lkl: add libslirp network backend for user-mode networking#631xdqi wants to merge 5 commits intolkl:masterfrom
xdqi wants to merge 5 commits intolkl:masterfrom
Conversation
Add a virtio-net backend using libslirp that provides full TCP/IP networking without root privileges or pre-configured TAP interfaces. Features: - User-mode NAT (guest 10.0.2.0/24, gateway 10.0.2.2, DNS 10.0.2.3) - Port forwarding via lkl_netdev_slirp_add_hostfwd/remove_hostfwd - Auto-detected when slirp/libslirp.h is present (POSIX) or pkg-config finds slirp (NT64/MinGW) - Portable: supports both POSIX (pthread/poll) and Win32 (Winsock) - Packet ring buffer between slirp send_packet callback and LKL rx - Dedicated poll thread drives slirp internal socket I/O Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
tavip
reviewed
May 4, 2026
Add SPDX-License-Identifier, update copyright name, and fix missing blank lines after declarations throughout the file for checkpatch compliance. Signed-off-by: Sheldon Qi <3365420+xdqi@users.noreply.github.com>
The stub at tools/lkl/include/mingw32/sys/uio.h intercepts the system <sys/uio.h> on MSYS2 builds, preventing struct iovec from being defined. lkl_host.h already provides struct iovec for MinGW in its #else branch, and MSYS2 uses the system header natively. Signed-off-by: Sheldon Qi <3365420+xdqi@users.noreply.github.com>
Add a test suite for the libslirp-based network backend, similar to the existing pipe/tap/raw tests. Uses the NAT network (10.0.2.0/24) with gateway 10.0.2.2. Tests netdev creation, kernel boot, interface configuration, and ICMP connectivity through the slirp gateway. Signed-off-by: Sheldon Qi <3365420+xdqi@users.noreply.github.com>
Add libslirp-dev for Ubuntu and mingw-w64-x86_64-libslirp for MSYS2 so the slirp network backend is auto-detected and tested in CI. Signed-off-by: Sheldon Qi <3365420+xdqi@users.noreply.github.com>
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
Add a libslirp-based virtio-net backend to LKL, enabling user-mode TCP/IP networking without root privileges or pre-configured TAP interfaces.
Motivation
The existing LKL network backends (TAP, macvtap, DPDK, VDE, wintap) all require either root privileges, pre-configured host interfaces, or specific hardware. libslirp provides user-mode NAT networking — the same stack used by QEMU's
-netdev user— allowing LKL guests to access the network without any host configuration.Changes
tools/lkl/lib/virtio_net_slirp.ctools/lkl/include/lkl.hlkl_netdev_slirp_create,add_hostfwd,remove_hostfwdtools/lkl/Makefile.autoconftools/lkl/lib/Buildvirtio_net_slirp.otools/lkl/include/mingw32/sys/uio.hstruct iovecArchitecture
10.0.2.0/24, gateway10.0.2.2, DNS10.0.2.3send_packetcallback and LKL RX pathAPI
Build
Requires
libslirp-dev(pkg-config:slirp). The backend is auto-detected at build time — no extra flags needed. If slirp is not installed, the backend is silently disabled.Example usage
Disclaimer
🤖 Generated with Claude Code but I've audited the code.