Networking with curl#

There are several options for providing network functionality on L4Re.

Basically two variants exists with respect to where a driver for a network device can be placed.

One way is using an existing system, such as Linux, running it in a VM and using Virtio-net to expose networking to outside of the VM. Using an existing system, for example, Linux, gives further plenty of networking features, such as firewalls and routing capabilities, and also plenty of drivers for many, if not all, devices. A downside is that a whole operating system and VM is required for this option, even if it can be specifically customized for purpose of handling networking only.

A driver running in an L4Re application. This driver can either be ported from some other environment or operating system, or written from scratch. Eventually such a driver needs to interact with with the software components that use it. Use could be in-process, i.e. an application has a specific network driver built-in and thus directly talks to the network device. Or the driver offers its services to other components in the system through a shared memory interface. For network, Virtio-net is a common and established interface.

In L4Re, there’s a virtual network switch that also has support to integrate device drivers. Thus the virtual network switch can be seen as a network device driver with multiple Virtio-net interfaces, or a virtual network switch where one port is not Virtio but a physical network device.

Running the network switch with the ixl drivers#

The virtual network switch has support for the ixl network drivers. Please refer to the ixl drivers for details, such as supported network devices.

The application using the network is the famous curl. To work with the driver via virtio-net, it needs a networking stack. We use lwIP, which has also been brought to L4Re with appropriate connectors for virtio-net.

Building ixl and virtio-net-switch#

The switch has a compile-time configuration that needs to be enabled such that the functionality for network device drivers is included. Please have the ixl package cloned to l4/pkg/ixl and the CONFIG_VNS_IXL enabled option in the L4Re configuration.

Building curl#

Please have curl, zstd, and LwIP cloned to l4/pkg/curl, l4/pkg/zstd and l4/pkg/lwip respectively, next to the standard L4Re packages.

Compile everything.

Setting up the scenario#

The following ned script starts the network switch together with curl, downloading a web page.

virtio-net-switch-drv-example.cfg#
 1-- vim:ft=lua
 2local L4 = require("L4");
 3local ld = L4.default_loader;
 4
 5local vbus_eth  = ld:new_channel();
 6ld:start({ caps = {
 7                    sigma0   = L4.Env.sigma0;
 8                    icu      = L4.Env.icu;
 9                    iommu    = L4.Env.iommu;
10                    ethdevs  = vbus_eth:svr();
11                  },
12         },
13         "rom/io rom/ixl.vbus");
14
15local vswitch = ld:new_channel();
16ld:start({ caps = { vbus = vbus_eth, svr = vswitch:svr(); }, },
17         "rom/l4vio_switch");
18
19ld:start({}, "rom/curl --version");
20
21ld:start({ caps = { virtnet = vswitch:create(0), etc = L4.Env.rom  }, },
22         "rom/curl -s http://ftp.de.debian.org/debian/",
23         { IFCONFIG_IP4_vn0="dhcp" });

Please find a possible ixl.vbus here.

A resolv.conf file also needs to be supplied with the following content:

resolv.conf#
nameserver 10.0.2.3

A module.list entry looks like this:

modules.list#
entry virtio-net-switch-drv-example
roottask moe rom/virtio-net-switch-drv-example.cfg
module l4re
module ned
module io
module l4vio_switch
module curl
module virtio-net-switch-drv-example.cfg
module resolv.conf
module io/ixl.vbus

Put all the files in a directory picked up by L4Re’s image generation.

Run it with QEMU#

The use-case can be run like this in one commend. Of course, variables can also be put into your Makeconf.boot file, shortening the below command to just make qemu E=virtio-net-switch-drv-example.

make qemu E=virtio-net-switch-drv-example \
     MODULES_LIST=$PWD/modules.list \
     MODULE_SEARCH_PATH=$PWD/fiasco/build \
     QEMU_OPTIONS="-serial stdio -vnc none -m 1g -netdev user,id=net1 -device e1000,netdev=net1"

Build’n’Run Script#

The following shell script summarizes the above steps. Of course you can build this setup from your existing source tree, given all the needed repositories, as described above, are available. The files downloaded are exactly the ones from this pages (given you are looking at a version generated out of the referenced files).

 1#! /bin/bash
 2
 3set -xe
 4
 5BASERAWURL=https://raw.githubusercontent.com/L4Re/l4re.org/refs/heads/main/src/use-cases/net-swt-curl/
 6
 7mkdir demo
 8cd demo
 9
10wget -q $BASERAWURL/manifest-l4re-net-curl.xml
11
12# Get sources
13git clone https://github.com/kernkonzept/ham.git
14ham/ham init -f manifest-l4re-net-curl.xml
15ham/ham sync
16
17# Get individual files out of the page on l4re.org
18wget -q $BASERAWURL/modules.list
19wget -q $BASERAWURL/net-vswt-curl-example.cfg
20wget -q $BASERAWURL/resolv.conf
21wget -q $BASERAWURL/virtio-net-switch-drv-example.cfg
22
23# Build the microkernel
24make -C fiasco -j8
25
26# Build the user-level
27make -C l4 B=build
28# Enable usage of ixl network drivers in virtual network switch
29l4/tool/kconfig/scripts/config --file l4/build/.kconfig --enable CONFIG_VNS_IXL
30make -C l4/build -j8 oldconfig
31# Build
32make -C l4/build -j8 
33
34# Run QEMU
35make -C l4/build qemu E=virtio-net-switch-drv-example \
36     MODULES_LIST=$PWD/modules.list \
37     MODULE_SEARCH_PATH=$PWD/fiasco/build:$PWD \
38     QEMU_OPTIONS="-serial stdio -vnc none -m 1g -netdev user,id=net1 -device e1000,netdev=net1"