Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
python-pip
dosfstools
mingw-w64-x86_64-ccache
mingw-w64-x86_64-libslirp

- name: Checkout
if: runner.os == 'Linux'
Expand Down Expand Up @@ -108,7 +109,7 @@ jobs:
if: runner.os == 'Linux'
run: |
sudo apt update -y
sudo apt install -y ccache libjsmn-dev libfuse3-dev
sudo apt install -y ccache libjsmn-dev libfuse3-dev libslirp-dev
- name: Install clang toolchain
if: runner.os == 'Linux'
run: |
Expand Down
7 changes: 7 additions & 0 deletions tools/lkl/Makefile.autoconf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ define virtio_net_vde
LDLIBS += $(shell pkg-config --libs vdeplug)
endef

define virtio_net_slirp
$(call set_autoconf_var,VIRTIO_NET_SLIRP,y)
LDLIBS += $(shell pkg-config --libs slirp)
endef

define zpoline_conf
$(eval zpoline_dir=$(abspath $(srctree)/$(1)))
$(if $(strip $(foreach f, $(zpoline_dir), $(wildcard $(f)/libzpoline.so))),$(call set_autoconf_var,ZPOLINE_DIR,$(zpoline_dir)))
Expand All @@ -83,6 +88,7 @@ define posix_host
$(if $(filter $(1),elf64-littleriscv),$(call riscv64_host))
$(if $(filter yes,$(dpdk)),$(call virtio_net_dpdk))
$(if $(filter yes,$(vde)),$(call virtio_net_vde))
$(if $(strip $(call find_include,slirp/libslirp.h)),$(call virtio_net_slirp))
$(if $(strip $(call find_include,fuse3/fuse.h)),$(call set_autoconf_var,FUSE,y))
$(if $(strip $(call find_include,archive.h)),$(call set_autoconf_var,ARCHIVE,y))
$(if $(strip $(call find_include,linux/if_tun.h)),$(call set_autoconf_var,VIRTIO_NET_MACVTAP,y))
Expand All @@ -96,6 +102,7 @@ define nt64_host
$(call set_autoconf_var,NEEDS_LARGP,y)
$(call set_autoconf_var,VIRTIO_NET,y)
$(call set_autoconf_var,NT64,y)
$(if $(strip $(shell pkg-config --cflags slirp 2>/dev/null)),$(call virtio_net_slirp))
CFLAGS += -Wl,--enable-auto-image-base -Wl,--image-base -Wl,0x10000000 \
-Wl,--out-implib=$(OUTPUT)liblkl.dll.a -Wl,--export-all-symbols \
-Wl,--enable-auto-import
Expand Down
56 changes: 56 additions & 0 deletions tools/lkl/include/lkl.h
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,62 @@ lkl_netdev_wintap_create(const char *ifparams)
}
#endif

/**
* lkl_netdev_slirp_create - create slirp net_device for the virtio net backend
*
* Provides user-mode TCP/IP networking without requiring root privileges.
* Guest network is 10.0.2.0/24 with gateway at 10.0.2.2 and DNS at 10.0.2.3.
* Use lkl_netdev_slirp_add_hostfwd() for port forwarding from host to guest.
*/
#ifdef LKL_HOST_CONFIG_VIRTIO_NET_SLIRP
struct lkl_netdev *lkl_netdev_slirp_create(void);

/**
* lkl_netdev_slirp_add_hostfwd - add port forwarding from host to guest
*
* @nd - netdev returned by lkl_netdev_slirp_create()
* @is_udp - 1 for UDP, 0 for TCP
* @host_addr - host address to listen on (e.g. "0.0.0.0")
* @host_port - host port number
* @guest_addr - guest address (e.g. "10.0.2.15")
* @guest_port - guest port number
* @returns 0 on success, -1 on failure
*/
int lkl_netdev_slirp_add_hostfwd(struct lkl_netdev *nd, int is_udp,
const char *host_addr, int host_port,
const char *guest_addr, int guest_port);

/**
* lkl_netdev_slirp_remove_hostfwd - remove a port forwarding rule
*
* @nd - netdev returned by lkl_netdev_slirp_create()
* @is_udp - 1 for UDP, 0 for TCP
* @host_addr - host address
* @host_port - host port number
* @returns 0 on success, -1 on failure
*/
int lkl_netdev_slirp_remove_hostfwd(struct lkl_netdev *nd, int is_udp,
const char *host_addr, int host_port);
#else
static inline struct lkl_netdev *lkl_netdev_slirp_create(void)
{
return NULL;
}
static inline int
lkl_netdev_slirp_add_hostfwd(struct lkl_netdev *nd, int is_udp,
const char *host_addr, int host_port,
const char *guest_addr, int guest_port)
{
return -1;
}
static inline int
lkl_netdev_slirp_remove_hostfwd(struct lkl_netdev *nd, int is_udp,
const char *host_addr, int host_port)
{
return -1;
}
#endif

/**
* lkl_add_neighbor - add a permanent arp entry
* @ifindex - the ifindex of the interface
Expand Down
2 changes: 2 additions & 0 deletions tools/lkl/lib/Build
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CFLAGS_posix-host.o += -D_FILE_OFFSET_BITS=64
CFLAGS_virtio_net_vde.o += $(pkg-config --cflags vdeplug 2>/dev/null)
CFLAGS_virtio_net_slirp.o += $(shell pkg-config --cflags slirp 2>/dev/null)
CFLAGS_nt-host.o += -D_WIN32_WINNT=0x0600

liblkl-y += fs.o
Expand All @@ -18,6 +19,7 @@ liblkl-$(LKL_HOST_CONFIG_VIRTIO_NET_FD) += virtio_net_raw.o
liblkl-$(LKL_HOST_CONFIG_VIRTIO_NET_MACVTAP) += virtio_net_macvtap.o
liblkl-$(LKL_HOST_CONFIG_VIRTIO_NET_DPDK) += virtio_net_dpdk.o
liblkl-$(LKL_HOST_CONFIG_VIRTIO_NET_VDE) += virtio_net_vde.o
liblkl-$(LKL_HOST_CONFIG_VIRTIO_NET_SLIRP) += virtio_net_slirp.o
liblkl-$(LKL_HOST_CONFIG_VIRTIO_NET_FD) += virtio_net_pipe.o
liblkl-$(LKL_HOST_CONFIG_NT64) += virtio_net_wintap.o
liblkl-$(LKL_HOST_CONFIG_VFIO_PCI) += vfio_pci.o
Expand Down
Loading
Loading