UDE is a small, portable alternative to VDE
(Virtual Distributed Ethernet). Its virtual switch speaks Ethernet frames over
localhost UDP instead of Unix-domain sockets, so it runs unchanged on Linux,
the BSDs, macOS and Windows (Winsock). Emulators such as 86Box or QEMU, TAP
bridges, and small network services plug into it the way they plug into
vde_switch.
UDE has four parts:
| Part | What it is |
|---|---|
libude (include/ude.h) |
Client library (static libude.a, plus shared libude.so.0 or libude-0.dll): connect to a switch, send and receive frames. It holds the portable socket layer and a transport abstraction that covers UDE/UDP and classic VDE (libvdeplug). |
| protocol libraries (optional) | libude-ipv4 (ARP, IPv4, ICMP), libude-udp, libude-tcp and libude-dhcp (DHCP client and server), layered on libude. A small, portable, event-driven IPv4 host stack that uses no OS IP stack. See Protocol libraries. |
| udeswitch | The switch daemon: MAC learning with aging, flooding, idle-port expiry, hub mode, stats, pcapng capture and monitor (mirror) ports. |
| tools | udelink (a cable between two switches, UDE or VDE, or over a byte stream such as ssh) and udetap (Linux TAP bridge, Linux only), built only on libude; udedhcpd (DHCP server, with network boot information), udetftpd (read-only TFTP server, for network booting), udeping (ICMP ping, or layer-2 ping with -L) and udenc (a clone of OpenBSD netcat, TCP and UDP) and udeslirp (a NAT gateway to the host's network, like QEMU's user-mode networking), built on the protocol libraries; uderouter (an IPv4 router between switches), built on libude-ipv4; udectl (capture control, the port list and MAC table, kicking ports and flushing MACs) and udedump (a monitor port that writes pcapng or prints a summary, like tcpdump). |
Plain C99 with no dependencies beyond the platform socket API (libvdeplug is
optional). The build uses autosetup,
which is vendored in autosetup/, so building needs only a C compiler and GNU make.
Documentation. The manual pages are in docs/ (mdoc; make install
installs them with the check-in's date and version), starting with
ude(7). The guides are in www/, Fossil Markdown with
pikchr diagrams: fossil ui serves them at /doc/ckout/www/index.md,
and the optional make html and make pdf build static HTML and a PDF
(see www/build.md).
Build
./configure # autosetup; uses tclsh if present, else builds its bundled jimsh
make
make test # unit tests + end-to-end tests with real processes (~30 s)
make install # PREFIX via --prefix=..., DESTDIR supported
make html # optional: www/ and the manual pages as HTML (needs fossil)
make pdf # optional: the same as one PDF (needs Chrome or WeasyPrint)
Source tarballs come from Fossil's tarball generator (the /tarball page or
fossil tarball); there is no make dist.
Out-of-tree builds work too: mkdir build && cd build && ../configure && make.
./configure --help lists every option. These are the ones specific to UDE:
| Option | Effect |
|---|---|
--lib-only |
build only libude (same as --disable-daemon --disable-tools) |
--disable-daemon |
don't build udeswitch |
--disable-tools |
don't build any of the programs in tools/ |
--disable-ipv4 |
don't build libude-ipv4; this also disables libude-udp, libude-tcp, libude-dhcp the IPv4 tools and uderouter |
--disable-udp |
don't build libude-udp; this also disables libude-dhcp and the IPv4 tools |
--disable-tcp |
don't build libude-tcp; this also disables udenc and udeslirp |
--disable-dhcp |
don't build libude-dhcp; this also disables the IPv4 tools (udeping, udenc, udedhcpd, udetftpd, udeslirp) |
--disable-shared |
build only the static libraries (libude.a, libude-ipv4.a, ...); the programs are then linked statically |
--static |
link the programs with the static libraries instead of the shared ones; the shared libraries are still built (add --disable-shared to skip them) |
--disable-tap |
don't build udetap (default: build it if linux/if_tun.h is found) |
--disable-vdeplug |
don't build the vde:// transport (default: build it if libvdeplug is found) |
--disable-werror |
don't build with -Werror (the default is -Wall -Wextra -Werror and more) |
CC=clang |
any C99 compiler; gcc and clang are tested |
udetap and the VDE transport are detected: without linux/if_tun.h or
libvdeplug, configure leaves them out and says so, and the --disable-
options leave them out even where they could be built. --enable-tap and
--enable-vdeplug are still accepted and turn a missing header or library
into an error.
Shared libraries and the programs
By default the programs are linked with the shared libraries, and each one only with the libraries it uses itself (the rest come in through the libraries' own dependencies):
| Program | Shared libraries it links |
|---|---|
udeswitch, udelink, udetap, udectl, udedump |
libude |
udeping, udedhcpd |
libude-dhcp, libude-ipv4, libude |
udetftpd |
libude-dhcp, libude-udp, libude-ipv4, libude |
udenc, udeslirp |
libude-tcp, libude-dhcp, libude-udp, libude-ipv4, libude |
uderouter |
libude-ipv4, libude |
The shared libraries link each other the same way: libude-udp and
libude-tcp need libude-ipv4, which needs libude; libude-dhcp needs
libude-udp, libude-ipv4 and libude. Only libude links libvdeplug.
On ELF systems configure adds -Wl,--as-needed where the linker has it, so
no library is named that is not used, and readelf -d shows exactly these
NEEDED entries. No rpath is written into the libraries or the programs
(except on macOS, where an installed program gets an rpath to $libdir,
as the libraries' install names are @rpath/...).
udeswitch also uses the socket layer and wire protocol of libude, which
the shared library does not export; it links those two objects
(lib/net_compat.c and lib/proto.c) itself.
./configure --static links the programs with libude.a,
libude-ipv4.a, ... as before (the C library stays dynamic). It changes
only the programs: the shared libraries are still built and installed for
other users, unless --disable-shared is given too. --disable-shared
alone implies --static, as there is nothing to link against.
Until make install, a dynamically linked program cannot find its
libraries. So in the build tree the real programs go into .libs/, the
directory libtool uses for the same purpose, and make writes an sh
wrapper with the program's name into the build directory:
#!/bin/sh
# udenc - build-tree wrapper written by make (scripts/mkwrapper.sh).
# It runs .libs/udenc with the shared libraries of this build
# directory. "make install" installs the real program, not this script.
ude_builddir='/home/me/ude/build'
LD_LIBRARY_PATH="$ude_builddir${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH
exec "$ude_builddir/.libs/udenc" "$@"
The wrapper holds the build directory as an absolute path, so ./udenc,
build/udenc or the full path work from any directory, in-tree and
out-of-tree; it adds to an existing LD_LIBRARY_PATH rather than replacing
it, and exec keeps the process id, so signals and kill reach the
program. On macOS the wrapper sets DYLD_LIBRARY_PATH too. The tests
(make test, tests/run_tests.sh, tests/manual_tap.sh) run the
wrappers; under sudo the wrapper sets the path itself after sudo has
cleaned the environment. To run a program in a debugger, run
.libs/PROGRAM with LD_LIBRARY_PATH set to the build directory.
make install installs the real programs from .libs/ and the libraries,
never the wrappers. With --static there are no wrappers and the programs
are written straight into the build directory.
Windows looks for DLLs next to the .exe first, and the build writes both
into the build directory, so MinGW builds have no wrappers: run the .exe
files directly, on Windows or under Wine. make install copies the DLLs
next to the programs in $bindir.
The build installs ude.pc, so emulators can use pkg-config --cflags --libs ude.
Each protocol library has its own pkg-config file whose Requires names the
library below it: ude-ipv4 (requires ude), ude-udp and ude-tcp
(require ude-ipv4) and ude-dhcp (requires ude-udp). For example,
pkg-config --libs ude-dhcp gives -lude-dhcp -lude-udp -lude-ipv4 -lude.
Version information
The version number lives in the VERSION file at the top of the tree
(MAJOR.MINOR.PATCH, currently 0.1.0). The Fossil repository has the
manifest setting turned on (a repository setting, which fossil clone
copies from the server), so every Fossil checkout and every tarball made by Fossil contains manifest and
manifest.uuid. As in SQLite and Fossil itself, make runs
scripts/mkversion.tcl (with the same tclsh or bundled jimsh that runs
configure) to turn those three files into ude_version.h in the build
directory, and it regenerates the header whenever any of them changes:
#define UDE_VERSION "0.1.0"
#define UDE_VERSION_NUMBER 1000 /* major*1000000 + minor*1000 + patch */
#define UDE_SOURCE_ID "2026-11-29 03:49:08 b4009bb258e463220a7620980cb7a2cc8cd0d50623754872a2e686fbcb845f98"
#define UDE_SCM_DATETIME "2026-11-29T03:49:08.000Z"
UDE_SOURCE_ID is the check-in time (UTC) followed by the full check-in
hash. UDE_VERSION_NUMBER drops leading zeros so that C doesn't read it
as octal: 1.2.4 is 1002004. In a plain copy of the tree without the
manifest files, the source id and date are "unknown" and the build still
works.
ude.h includes ude_version.h, which make install installs next to it.
At run time ude_version(), ude_sourceid() and ude_libversion_number()
return the values libude was built with, like their sqlite3_*
counterparts; they always give the full source id. Every program prints its
version with -V or --version, showing the check-in hash cut to 10 digits
the way Fossil shows check-in names:
$ udeswitch --version
udeswitch 0.1.0 (2026-11-29 17:27:25 bba2b95814)
Windows (MinGW-w64)
Cross-compiling from Debian or Ubuntu:
sudo apt install gcc-mingw-w64-x86-64 # or gcc-mingw-w64-i686 for 32-bit
./configure --host=x86_64-w64-mingw32 # or --host=i686-w64-mingw32
make # -> udeswitch.exe udectl.exe udedump.exe udelink.exe udeping.exe
# udenc.exe udedhcpd.exe udetftpd.exe udeslirp.exe uderouter.exe,
# linked with libude-0.dll libude-ipv4-0.dll libude-udp-0.dll
# libude-tcp-0.dll libude-dhcp-0.dll in the same directory,
# their import libraries (libude.dll.a, libude-ipv4.dll.a, ...) and .a files
make test # builds test_core.exe test_pcapng.exe test_impair.exe test_lib.exe test_net.exe test_stack.exe
# (and the udecat.exe and udetftp.exe test clients)
# (run them on Windows or under Wine), and checks every
# .exe and .dll for imports old Windows lacks (see below)
You can also build natively under MSYS2 with ./configure && make (the configure
script detects *-mingw*). Windows builds link -lws2_32. They skip udetap
(no TAP) and the VDE transport (libvdeplug is POSIX-only). To link against the
DLLs, define UDE_USE_DLL (one macro covers every UDE library); the static
libraries need nothing extra.
Windows versions
The aim is that a 32-bit build (--host=i686-w64-mingw32) runs on Windows
NT 4.0 and Windows 2000 and everything after them, and on Windows 95, 98 and
ME as far as possible. A 64-bit build runs on every 64-bit Windows (XP x64
onwards). The code uses only Winsock 2 and Win32 calls that NT 4.0 already
has:
- The clocks (
ude_now_ms,ude_now_us) useQueryPerformanceCounter, notGetTickCount64(Vista). On a machine without a performance counter, which only Windows before XP can report, they fall back toGetTickCount, widened to 64 bits, with millisecond resolution. - IPv4 addresses are parsed and printed by libude itself, not with
inet_ptonandinet_ntop(Vista). The parser accepts exactly whatinet_pton(AF_INET)does: four decimal parts of 0 to 255, without leading zeros. - configure builds with
_WIN32_WINNT=0x0400andWINVER=0x0400, so the Windows headers do not declare anything newer than NT 4.0. - The DLLs are linked with
-static-libgcc, so a 32-bit build needs nolibgcc_s_dw2-1.dll. SIO_UDP_CONNRESET, which keeps a Windows UDP socket from reporting an earlier ICMP port unreachable asWSAECONNRESET, is XP and later (Windows 2000 got it in a service pack). Where it fails, that error is ignored anyway.
make test in a Windows build runs tests/check_imports.sh. It lists every
function each program and DLL imports, with the target's objdump (found
by configure, or set OBJDUMP=), and fails on any that is not in
tests/win_imports.txt, which lists only what NT 4.0 and Windows 95 have. It
also checks that the PE headers ask for Windows 4.0 at most (5.2 for 64-bit
builds), as MinGW-w64 sets them. Before adding a name to the list, check
when Windows got it. A toolchain that targets the UCRT (api-ms-win-crt-*,
Windows 10, or 7 with an update) instead of msvcrt.dll fails this check; for
old Windows, use one that targets msvcrt.dll, such as Debian's and
Ubuntu's gcc-mingw-w64 or MSYS2's MINGW32 environment.
On the older systems:
- Windows NT 4.0 has Winsock 2 and runs UDE without a service pack.
- Windows 95 needs Microsoft's Winsock 2 update for Windows 95
(
ws2_32.dll), and anmsvcrt.dll, which Internet Explorer 4 and later install, as do many programs. Windows 98 and ME have both. - Windows 95, 98 and ME cannot replace a file in one step (
MoveFileExAis only a stub there), soudedhcpd -fdeletes the lease file and then renamesFILE.tmpto it. This is not atomic: after a crash between the two steps there is no FILE, and the complete new leases are inFILE.tmp. Rename it back before startingudedhcpdagain. If the rename fails, udedhcpd reports an error and leavesFILE.tmp.
The 32-bit build has been run on Windows NT 4.0 without a service pack
(all programs), and on Windows 95 and 98 (udedhcpd and udeping).
Windows 9x needs CreateThread to get a pointer for the thread id, which
NT does not; udenc's standard input thread passes one.
Quick start
./udeswitch -v & # 127.0.0.1:7500
./udeping -L -r -m 02:00:00:00:00:02 & # a layer-2 responder
./udeping -L -m 02:00:00:00:00:01 -c 3 02:00:00:00:00:02 # ping it through the switch
An IPv4 network: switch, DHCP server and two netcats
A UDE switch is an isolated Ethernet: nothing hands out addresses unless a DHCP server runs on it, and there is no router to anywhere else.
./udeswitch & # the "cable"
./udedhcpd -a 10.0.0.1/24 & # leases 10.0.0.100-199
./udenc -v -l 9000 # terminal 1: gets 10.0.0.100, listens (TCP)
./udenc -v 10.0.0.100 9000 # terminal 2: type, and it appears in 1
./udeping 10.0.0.100 # terminal 3: ICMP ping, Ctrl+C to stop
Each client prints the address it got (udenc: 10.0.0.100/24 on
c6:1f:...:9e (DHCP from 10.0.0.1, lease 3600 s)) to standard error; udenc
does so only with -v, as nc prints nothing by default. Give a client a
fixed address with --addr 10.0.0.9/24 (-a for udeping and udedhcpd; no
DHCP), or a fixed MAC with --mac and a reservation (udedhcpd -r
MAC=ADDR) for a predictable lease.
udeswitch
udeswitch [-p PORT] [-b ADDR] [-P MAXPORTS] [-M MACCAP] [-a MACAGE] [-T PORTIDLE]
[-m MAXFRAME] [-H] [-R] [-s SECS] [-n NAME] [-w FILE] [-A POLICY] [-C FILE] [-v[v]]
| Flag | Default | Meaning |
|---|---|---|
-p |
7500 | UDP port |
-b |
127.0.0.1 | bind address. A warning is printed if the address is not in 127.0.0.0/8 (including 0.0.0.0; there is no auth yet) |
-P |
64 | maximum number of ports (clients) |
-M |
4096 | MAC table capacity |
-a |
300 s | MAC aging time (0 = never) |
-T |
300 s | idle timeout before a client is dropped (0 = never). Announced in HELLO_ACK; see Idle timeout and keepalives |
-m |
1522 | largest frame accepted (1514 + 802.1Q tag + 4 bytes slack for senders that include the FCS); at most 65200, so that every frame the switch forwards is captured and mirrored whole (see MIRROR) |
-H |
hub mode: flood every frame (it still never sends back to the ingress port) | |
-R |
require HELLO: drop DATA from endpoints that haven't registered | |
-s |
dump stats every N seconds. kill -USR1 dumps them on demand (POSIX) |
|
-w |
capture every frame received, from startup, to FILE in pcapng format (- = standard output). udectl stops, restarts and rotates it. See Capture and monitor ports |
|
-A, --policy |
none | who may send management (udectl) and monitor (udedump) requests: none (nobody), local (loopback peers only) or any (prints a warning). Was -C. |
-C, --configuration |
optional TOML configuration file (or UDE_CONFIG). Command-line options override the file. See ude.conf(5). |
|
-v |
log events (ports, learning, MAC moves). -vv also logs every frame |
|
-V |
print the version, check-in date and short hash, then exit (also --version) |
SIGINT/SIGTERM (Ctrl+C / Ctrl+Break on Windows) shut the switch down cleanly.
With -v it prints final stats on exit.
All the programs accept -V/--version and -h/--help.
udelink: linking switches
udelink [-n NAME] [-l ADDR] [-L ADDR] [-k MS] [-r MS] [-I SPEC] [-A SPEC]
[-B SPEC] [-S SEED] [-s] [-q] [-v] A B
udelink is a cable between two switches, like dpipe vde_plug =
vde_plug for VDE: every frame one side receives is sent to the other,
unchanged. A and B are anything ude_open() accepts: a udeswitch
(host:port, udp://host:port), a classic vde_switch (vde:///path,
when libude is built with libvdeplug), or another libvdeplug URL. Either
side may instead be -, standard input and output in vde_plug's stream
format: each frame preceded by its length, 2 bytes big-endian. That is
what vde_plug URL speaks on its standard input and output, so dpipe
and ssh link switches across hosts as with VDE.
udelink 127.0.0.1:7500 127.0.0.1:7600 # two udeswitches
udelink 127.0.0.1:7500 vde:///tmp/vde.ctl # a udeswitch and a vde_switch
udelink 127.0.0.1:7500 192.0.2.10:7500 # a switch on another host (plain UDP)
dpipe udelink 127.0.0.1:7500 - = ssh host udelink - 127.0.0.1:7500 # over ssh
dpipe udelink 127.0.0.1:7500 - = ssh host vde_plug /tmp/vde.ctl # to remote VDE
| Option | Default | Meaning |
|---|---|---|
-n NAME |
udelink:OTHER-SIDE |
port name on both switches (HELLO NAME, or the VDE port description); at most 31 bytes are kept |
-l ADDR, -L ADDR |
127.0.0.1 for a loopback switch, else 0.0.0.0 | local address[:port] of A's and B's UDP sockets |
-k MS |
5000 | HELLO interval on UDE sides (-1 off, 0 the switch's idle timeout / 2) |
-r MS |
1000 | how often to reopen a side that failed |
-I SPEC |
impair the link both ways (see Link impairment) | |
-A SPEC, -B SPEC |
impair only the frames from A to B, or from B to A | |
-S SEED |
from the clock | seed of the impairment's random numbers (decimal), for runs that repeat exactly |
-s |
print the frame counters per direction on exit | |
-q, -v |
only errors; or one line per forwarded frame (implies -s) |
- Registration and restarts. On a UDE side
udelinkregisters with HELLO and repeats HELLO every-kmilliseconds as its keepalive, even while frames flow (ude_keepalive_hello()in libude). A switch that restarts, or dropped the port, so learns it again with its name, also with-R.udelinklogs when a switch stops answering (no HELLO_ACK for three intervals) and when it answers again; frames sent meanwhile are lost, as on a cable that was pulled. A VDE side is reopened when it fails, at once and then every-rmilliseconds: libude now notices avde_switchthat exits by the end of its control stream. If a side can't be opened at startup,udelinkexits with status 1 (a mistyped address should not retry forever). - What is forwarded. Every frame, including broadcasts and multicasts,
except one whose destination starts with
55:44:45(UDE's control range, which libude refuses to send). Frames above 65507 bytes can't travel over UDP and are dropped. The far switch applies its own-m. Each switch learns the other side's MACs on the link port. - Standard input and output. At the end of standard input
udelinkexits (status 0), asvde_plugdoes, once the frames an impairment still holds are delivered; a failed write to standard output ends it with status 1. Only one side can be-. - Loops. UDE has no spanning tree protocol. Two paths between the
same switches (two links, or a link plus a VDE cable) make a loop in
which every broadcast circulates forever. Don't build one.
udelinkrefuses to link a switch to itself, and when the same broadcast or multicast frame comes back 100 times within a second it prints a warning and drops further copies of that frame for the rest of the second, which ends that storm (the loop stays, and the next broadcast starts another). - Exit.
SIGINT/SIGTERMclose both sides (BYE on UDE sides) and exit with status 0. Usage errors exit with status 2.
Link impairment
Like VDE's wirefilter, udelink can make the cable a bad one: lossy,
slow, late, jittery, duplicating or corrupting, for testing how protocols
and emulated machines cope. -I SPEC applies to both directions, -A SPEC
to frames from A to B, -B SPEC to frames from B to A (wirefilter's LR and
RL). SPEC is KEY=VALUE[,KEY=VALUE...]; several options apply in order and
each changes only the keys it names, so -I delay=50ms -B delay=0 delays
only A to B. Each direction has its own queue and random sequence.
| Key | Value | Meaning |
|---|---|---|
loss |
percent, 0-100, up to 4 decimals, % optional |
drop frames at random |
burst |
average burst length, ≥ 1 (decimals allowed) | with loss, losses come in bursts (Gilbert-Elliott: the long-run loss rate stays loss) |
dup |
percent | send a second copy (both copies then go through rate and delay) |
corrupt |
percent | flip one random bit of the frame |
delay |
time: ms by default, or us, ms, s (up to 1 hour) |
added latency |
jitter |
time | uniform random latency of ± this much on top of delay (never below zero) |
reorder |
reorder, reorder=1 or reorder=0 |
let jitter reorder frames; by default order is kept |
rate |
bit/s; k, M, G = 1000s |
bandwidth: each frame takes length × 8 / rate on the wire |
queue |
bytes; k, M = 1024s |
the drop-tail queue in front of rate (default 100 ms worth, at least 3044 bytes: two full frames) |
mtu |
bytes, header included | drop longer frames |
none |
clear all keys given so far |
A frame goes through the steps in this order: mtu, loss, dup, then for
each copy corrupt, rate (wait for the wire; drop if the queue is full)
and delay/jitter.
- Reordering policy. Without
reorder, a frame is never released before the one in front of it: jitter only delays, and a frame drawn early waits for its predecessor (so on busy links the delay tends towards the top of the window). Withreorder, each frame leaves at its own time and frames overtake each other.dupcopies go out back to back. - Rate. Counts the frame bytes only (no preamble, inter-frame gap or
FCS). An empty queue accepts any frame; otherwise a frame that would
push the backlog over
queuebytes is dropped (counted as "queue full"). - Corruption.
corruptis the share of frames that get one bit flipped, not wirefilter's-n(bit errors per megabyte). A corrupted frame that lands in55:44:45is dropped like any control-range frame. - Limits. At most 65536 frames or 64 MiB wait per direction; beyond that frames are dropped and counted as "overflow".
- Timing. Frames are released from the main loop, which sleeps until
the next one is due; there are no threads. The clock is libude's
(
ude_now_us(), QueryPerformanceCounter or GetTickCount on Windows), and how close a delay gets to its target depends on the system's timer (about 1 ms on Linux; 10-16 ms on older Windows). - Random numbers. splitmix64, seeded with
-Sor from the clock; the seed is logged at start, so-Srepeats a run exactly (given the same frames in the same order). - Counters.
-sprints, per impaired direction, frames in and out, dropped over the MTU, lost, dropped at a full queue or by the overflow limit, duplicated, corrupted, and still held at exit. - The impairment is fixed at startup; changing it at run time (through a
control socket, like
udectlfor the switch) is possible future work.
# A 56k modem: 56 kbit/s, 100 ms of latency, a 4 KiB modem buffer.
udelink -I rate=56k,queue=4k,delay=100ms 127.0.0.1:7500 127.0.0.1:7600
# A lossy WAN: 80 ms ± 10 ms, 1% loss in bursts of 3, 0.1% duplicates.
udelink -I delay=80ms,jitter=10ms,loss=1%,burst=3,dup=0.1 -S 42 127.0.0.1:7500 vde:///tmp/sw
# ADSL: 8 Mbit/s down (A to B), 1 Mbit/s up, 20 ms each way.
udelink -I delay=20ms -A rate=8M -B rate=1M 127.0.0.1:7500 127.0.0.1:7600
Capture and monitor ports
There are two ways to see the traffic on a switch, and both write pcapng that Wireshark, tshark and capinfos read:
./udeswitch -A local -w all.pcapng & # capture from startup; allow udectl
# and udedump from this host
./udectl status # capturing to /.../all.pcapng: 120 frames, ...
./udectl capture stop
./udectl capture start # appends a new section to all.pcapng
mv all.pcapng all.1.pcapng && ./udectl capture rotate # logrotate style
./udectl capture rotate /tmp/next.pcapng # or switch to another file
./udedump # one line per frame, like tcpdump
./udedump -w - | wireshark -k -i - # live in Wireshark
./udedump -w x.pcapng -c 100 # 100 frames, then exit
udectl [-s HOST:PORT] [-t MS] [-q] capture start [FILE] | capture stop
| capture rotate [FILE] | capture status | status
udedump [-s URL] [-w FILE|-] [-c COUNT] [-p] [-q] [-n NAME] [-l LOCAL]
udeswitch -wandudectlrecord in the switch. Each frame is written once, as it comes in, before any forwarding decision, so the file also holds frames the switch then drops (runts, oversized frames, group source MACs, filtered frames, frames from unregistered endpoints with-R, frames refused because the port table is full) and floods. Control messages are not captured. Every packet carries the inbound direction flag and a comment naming its ingress port (port 3 127.0.0.1:40001 qemu, orno port 127.0.0.1:40001), and timestamps have nanosecond resolution.capture start FILEtruncates FILE;capture startalone appends a new section to the last file.capture rotate FILEopens FILE first and keeps the old file if that fails;capture rotatealone closes and reopens the same name, so it is the command to run after renaming the file. A relative FILE is made absolute byudectl(the switch opens it, so it has to be on the same host). Neither the switch norudectloverwrites or appends to a file that is not empty and not pcapng.udedumpis a client of the switch: it subscribes as a monitor port with a MONITOR message, and the switch then sends it a MIRROR message for every datagram it receives from the other ports. A MIRROR carries the same record the switch's own capture writes: the switch's timestamp, the ingress port, the sender's address and port name, and the bytes. Soudedump -wwrites the same interface description and the same packets (timestamps, lengths, bytes, direction flag and comment) asudeswitch -wfor the same traffic; only the section header namesudedumpas the writer. A monitor is never learned from and never flooded to, so it doesn't change what the other ports see, and frames it sends are dropped. It keeps its subscription with keepalives like any client (a monitor's keepalive is a MONITOR message, so it also resubscribes after the switch restarts), and sends BYE on exit. Without-wit prints a summary: time, ingress port and its name, MACs, VLAN tag, ethertype, and for IPv4 the addresses and protocol (with ports for TCP and UDP), ARP and IPv6. Monitors work in switch and hub mode, on the UDE/UDP transport.- Limits. There is no rate limit or backlog: the switch sends each
MIRROR with a non-blocking
sendto(), so a monitor that can't keep up loses frames in its socket buffer, and the switch never blocks or queues for it. Each monitor costs one more send per frame and counts against-P. Both captures keep at most 65200 bytes of a datagram (the IDB snap length), which is also the largest-m, so only datagrams the switch drops as too big can be cut, and then both record the original length. - Flushing. The switch flushes the capture file after each burst of
received datagrams (at most 256 per wakeup), and on stop, rotate and exit;
udedumpflushes whenever it has nothing more to read. A live reader therefore sees frames within one burst, and a killed switch loses at most that burst.
Both are management functions, so the switch refuses them unless it is
started with -A local (or -A any); see
Security. udeswitch -w
needs no -A, but then the capture runs until the switch exits.
Introspection and port management
udectl also shows what the switch knows, and changes it: the ports with
their counters, the MAC table, removing ("kicking") a port, and flushing
MACs. Like capture control, this needs udeswitch -A local (or -A any).
udectl [-s HOST:PORT] [-t MS] [-q] [-p] ports | macs [PORT] | kick PORT
| flush [PORT|MAC]
$ ./udectl ports
switch udeswitch: 4 ports (at most 64)
ID PEER NAME TYPE MACS IDLE UPTIME RX FRAMES RX BYTES TX FRAMES TX BYTES DROPPED
1 127.0.0.1:40001 vm1 hello 1 1.5s 1.8s 2 120 8 480 0
2 127.0.0.1:40002 vm2 hello 1 1.4s 1.7s 3 180 2 120 0
3 127.0.0.1:40003 vm3 hello 1 1.3s 1.6s 4 240 1 60 0
4 127.0.0.1:40004 - auto 1 1.5s 1.5s 1 60 0 0 0
$ ./udectl macs
switch udeswitch: 4 MACs in the table (at most 4096)
MAC PORT NAME AGE
02:00:00:00:00:aa 4 - 1.5s
52:54:00:00:00:01 1 vm1 1.5s
52:54:00:00:00:02 2 vm2 1.4s
52:54:00:00:00:03 3 vm3 1.3s
$ ./udectl -p ports | head -1 # for scripts: tab-separated, times in ms
1 127.0.0.1:40001 vm1 hello 1 1509 1809 2 120 8 480 0
$ ./udectl kick vm3 # or: kick 3, kick 127.0.0.1:40003
kicked port 3 (127.0.0.1:40003 vm3), 1 MAC flushed
$ ./udectl flush 2 # the MACs of port 2; the port stays
flushed 1 MAC of port 2 (127.0.0.1:40002 vm2)
$ ./udectl flush 52:54:00:00:00:01 # one MAC
flushed 52:54:00:00:00:01 of port 1 (127.0.0.1:40001 vm1)
$ ./udectl flush # the whole table
flushed 1 MAC
- PORT is a port id (
3, orid=3), the client's UDP endpoint (127.0.0.1:40003orpeer=...) or the name it gave in HELLO (vm3orname=vm3; a name that two ports share is refused as ambiguous, use the id). A MAC can be writtenmac=...too. - ports lists, per port: id, peer, name (
-if none), type (auto: registered by its first datagram,hello, ormonitor), MACs learned on it, time since it was last heard from (IDLE), time since it registered (UPTIME), frames and bytes received from it and sent to it, and frames from it the switch dropped. macs lists MAC, port, port name and the time since the MAC was last seen as a source. With-p,portsprints the same fields in that order andmacsprints MAC, port, name and age; kick and flush print port id, peer, name and MACs flushed (-for an empty field). - kick removes the port at once, as BYE does: its MACs are flushed and
the client gets ERROR 9. A kick is not a ban: a client that keeps
sending (or a keepalive) registers again as a new port, unless the
switch runs with
-Rand the client doesn't send HELLO. Ports of well-behaved clients, such as libude ones, come back by themselves; to keep one out, stop the client. - flush forgets MACs. Frames to them are flooded until they are learned again; nothing else changes.
- The lists come in pages (see the wire protocol), so they work for any
number of ports and MACs, but they are not a snapshot: a port or MAC that
appears or goes while
udectlreads may be missing or listed in its new state. - The same calls are in libude:
ude_mgmt_open(),ude_mgmt_ports(),ude_mgmt_macs(),ude_mgmt_kick(),ude_mgmt_flush()andude_mgmt_capture()(seeinclude/ude.h).udectlis built on them.
Network options of udeping, udenc, udedhcpd and udetftpd
The IPv4 programs share these options (common/ude_netcli.c). Without
--addr, they get their address by DHCP. udeping and udedhcpd accept
the short letters too; udenc takes only the long options, because nc
uses those letters for its own options (-s source address, -N
shutdown, -v verbose...).
| Long option | Short (udeping, udedhcpd, udetftpd) | Default | Meaning |
|---|---|---|---|
--switch URL |
-s URL |
127.0.0.1:7500 | switch (vde:///path with libvdeplug) |
--mac MAC |
-m MAC |
random | MAC address. The default is random, unicast and locally administered (x2:...), so it never collides with UDE's reserved 55:44:45 range |
--name NAME |
-n NAME |
program name | client name for the switch; also the DHCP host name |
--addr ADDR[/LEN] |
-a ADDR[/LEN] |
DHCP | static address (/24 if no length) |
--gateway GATEWAY |
-g GATEWAY |
none | static default gateway (with --addr) |
--dns DNS |
-N DNS |
none | static DNS server, up to 3 times (with --addr) |
--dhcp-timeout SECS |
-T SECS |
10 | how long to wait for a DHCP lease |
--log |
-v |
log ARP and DHCP events |
Long options take their value as --addr 10.0.0.9 or --addr=10.0.0.9,
and may be shortened to any unambiguous prefix (--dhcp).
On exit (end of the run, Ctrl+C) a DHCP client sends DHCPRELEASE.
udeping
udeping [net options] [-c N] [-i SECS] [-W SECS] [-S BYTES] [-t TTL] [-q] HOST
udeping [net options] -r
udeping -L -m MAC [-s URL] [-c N] [-i SECS] [-W SECS] (-r | DSTMAC)
ICMP echo over IPv4, with ping-like output and statistics. -c count
(default: until Ctrl+C), -i interval and -W reply timeout in seconds
(fractions allowed, default 1), -S payload size (default 56), -t the
TTL (default 64; a router where it runs out answers "time to live
exceeded"), -q only the summary. The exit status is 0 if any reply came back. -r just keeps
an address and answers pings; every libude-ipv4 program answers pings
anyway, including udedhcpd and udenc.
udeping 10.0.0.1 # DHCP, then ping the DHCP server
udeping -a 10.0.0.9/24 -c 3 10.0.0.100 # static address
-L is the older layer-2 ping, kept as a mode: raw Ethernet frames of
EtherType 0x88B5 between two libude clients, with no IP at all. It is useful
to check a switch path before any addressing exists:
udeping -L -r -m 02:00:00:00:00:02 & # responder
udeping -L -m 02:00:00:00:00:01 -c 5 02:00:00:00:00:02 # RTT through the switch
(Before the IPv4 mode existed this was the only mode; its old -d DSTMAC
and millisecond -i/-w options became -L ... DSTMAC and seconds.)
udenc
udenc [-46DdhklNnuvz] [-I length] [-O length] [-p source_port]
[-q seconds] [-s sourceaddr] [-W recvlimit] [-w timeout]
[network options] [destination] [port]
udenc -l [options] [address] port
udenc [-l] [options] -p port # listen on port: traditional nc -l -p, and older udenc
A clone of OpenBSD's nc (netcat.c 1.241) on the UDE network, with
Debian's -q: TCP by default (libude-tcp), UDP with -u. The options, the
messages of -v, the exit status and, above all, when it stops, follow
OpenBSD's readwrite() and listen loop, so scripts written for nc behave
the same. Addresses are numeric IPv4 only: there is no resolver.
udenc -l 9000 > file # receive a file
udenc -N 10.0.0.100 9000 < file # send it: -N sends FIN after the end of input
udenc -k -l 7000 # serve one connection after another
udenc -z -v 10.0.0.100 20-25 # which ports are open?
udenc -u -l 9000 # UDP: talk to the first sender
| Option | Meaning, as in OpenBSD nc |
|---|---|
-4 |
IPv4 (always; accepted for compatibility) |
-D |
socket debugging: accepted, no effect |
-d |
do not read standard input |
-h, --help |
help (exit status 0; OpenBSD exits 1) |
-I length |
TCP receive buffer, at most 65535 (no window scaling) |
-k |
listen for another connection after the current one; needs -l |
-l |
listen; udenc -l [address] port, where address must be ours or 0.0.0.0 |
-N |
shut down the sending side (TCP FIN) after the end of standard input |
-n |
numeric only: accepted, no effect (names are never resolved) |
-O length |
TCP send buffer |
-p port |
source port of a connection; with -l, or without a destination, the port to listen on (see below) |
-q seconds |
Debian: after the end of input, quit seconds later; implies -N; negative = never (default) |
-s sourceaddr |
source address: must be the interface's own address (it has one) |
-u |
UDP |
-v |
verbose: Listening on, Bound on, Connection received on, Connection to ... succeeded!, connect to ... failed: ..., and the address the interface got |
-W recvlimit |
stop after receiving that many packets (reads) |
-w timeout |
connect timeout, and quit after timeout idle seconds; no effect on waiting for a connection in listen mode |
-z |
scan: connect and close, send nothing (TCP only) |
-V, --version |
print the version (-V without a value; -V rtable, nc's routing table, is refused) |
Listening on a port: udenc -l 9000, udenc -l -p 9000 and udenc
-p 9000 all listen on port 9000, for TCP and with -u. The first is
OpenBSD's form. The second is the traditional and Debian nc -l -p form,
which OpenBSD nc rejects ("cannot use -p and -l"); udenc before the nc
options also used it (udenc -u -l -p 9000). The third, -p with no
destination, is a udenc extension: OpenBSD nc prints its usage and
traditional nc says "no destination". With -l -p PORT port both ports
must agree.
Older udenc options: besides -u HOST PORT, -u -l -p PORT, -q
and -v (now nc's verbose; --log logs ARP and DHCP), these short
network options still work where they do not clash with nc: -s URL
(a value that is not an IPv4 address is the switch; an IPv4 address is
nc's source address), -m MAC (a MAC address; nc's minimum TTL is not
supported), -a ADDR[/LEN], -g GATEWAY, -T SECS (a number of seconds;
nc's TOS is not supported) and -V. -n NAME and -N DNS are now
nc's -n and -N flags: use --name and --dns. -t never worked
(TCP was "not implemented"); TCP is now the default and -t is nc's
telnet option, which is not supported.
Ports can be ranges (lo-hi) when connecting; each port is tried in turn.
The network options above (--switch, --addr, --log...) are long
options only. These nc options are refused with a clear message, since
the stack has nothing they could map to: -6 (no IPv6), -C -c -e -H -K
-o -R -Z and -T keyword (TLS, CRLF, TOS), -F (descriptor passing),
-i (line delay), -M and -m minttl (TTL), -P -X -x (proxies), -r
(random ports), -S (TCP MD5), -t (telnet), -U (Unix sockets),
-V rtable (routing tables).
When it stops (end-of-file behaviour, as in OpenBSD readwrite()).
There are four directions: standard input, network out, network in,
standard output.
- End of standard input closes network out. With
-Nthat sends a FIN after everything queued; without it nothing is sent, so the peer does not see the end untiludencexits, exactly as withnc. - The peer's FIN (end of network in) closes standard output; if standard output fails (a closed pipe), network in is closed too.
- If network out is gone (a reset, or
-N), standard input is no longer read. - It is done when both inputs are gone, or both outputs are gone, or, in listen mode, when network in is gone (even if standard input is still open: a listener stops when its client half-closes).
-w: done after that many seconds without activity in either direction.-q(Debian): done → close the connection, waitseconds, exit 0 (-q 0exits at once). In listen or UDP mode, end of standard input with-qalso closes network in and cancels-k.- A reset (TCP) or an ICMP destination unreachable for our datagrams (UDP,
as a connected socket reports
ECONNREFUSED) closes both network directions. -u -lwithout-kwaits for the first datagram, then talks only to its sender; standard input is read from then on. With-kthe socket is not connected: it prints datagrams from anyone and cannot send, so standard input stops after the first read, as innc.-l(TCP) serves one connection, then exits; with-kit listens again. As innc, the listener is closed and reopened between connections, so connections waiting meanwhile are reset.
Exit status: 1 for bad arguments, a failed bind, or when connecting
failed for every port; otherwise 0, including after a reset or an idle
-w. Ctrl+C ends it like a signal ends nc (status 130): queued data is
still handed to TCP, and it gets about two seconds to go out.
Differences from OpenBSD nc, besides the refused options:
- Extensions:
-l -p portand-p portlisten (above);-s,-m,-Tand-Valso take udenc's older meanings when the value fits them, and-aand-gare udenc options. - Hosts and ports are numeric: no DNS and no service names (
-vprints[tcp/*]wherencprints the service name). - After it is done,
udenckeeps the stack running for up to 30 s so that queued data and the FIN are delivered, which the kernel does forncafter it exits. - Connecting to an address that does not answer ARP waits for the SYN
retries (about 2 minutes) or
-w; Linux gives up after about 3 s with "No route to host". - UDP datagrams carry at most 1472 bytes of input each (no
fragmentation);
ncreads up to 16 KB and lets the kernel fragment. With-u -v,ncprobes the port before printing "succeeded";udencprints it at once and finds out from the ICMP error.-z -uis not supported. -Wcounts reads from the TCP layer, which do not matchnc'sread()calls exactly.
As example code, udenc.c shows a long-running libude program with its
own event loop: wait on the switch and standard input at once
(common/ude_stdin.c), never longer than ude_ipv4_timeout_ms(), then
ude_ipv4_poll(ip, 0); TCP events and datagrams arrive in callbacks.
udedhcpd
udedhcpd -a ADDR/LEN [-p START-END] [-L SECS] [-g ROUTER] [-N DNS]...
[-r MAC=ADDR]... [-f FILE] [-B ADDR] [-b [CLASS=]FILE]... [-q] [net options]
| Flag | Default | Meaning |
|---|---|---|
-a |
(required) | the server's own address, and the subnet it serves |
-p |
.100-.199 | address pool: full addresses or host numbers (-p 50-99). Subnets smaller than a /24 default to every host address |
-L |
3600 | lease time in seconds |
-g |
none | router to hand out (option 3). There is none by default: the network is isolated until a router exists |
-N |
none | DNS server to hand out (option 6), up to 3 times |
-r |
reservation: always give ADDR to MAC (repeatable; may be outside the pool) | |
-f |
none | lease file: keep bound leases in FILE across restarts |
-B, --next-server |
none | network boot: the TFTP server (siaddr, and option 66 when asked for), e.g. a udetftpd |
-b, --boot-file |
none | network boot: the file to boot (the file field, and option 67 when asked for). CLASS= limits it to iPXE (ipxe=) or to a client architecture (option 93): bios=, efi32=, efi64= (7 and 9), arm32=, arm64= or a number (exact). Repeatable; iPXE entries win, then an exact architecture, then efi64 for 7 or 9, then a plain FILE |
-q |
don't log DHCP messages (they are logged by default) |
It implements DISCOVER/OFFER/REQUEST/ACK, NAK, RELEASE, DECLINE (the address is set aside for 10 minutes) and INFORM, renewals and INIT-REBOOT. Offers are held for 60 s. It prefers a client's reservation, then its current lease, then the address it asks for, then the first free one. Leases live in memory; the lease table is printed on exit.
With -f FILE, the bound leases are also kept in FILE, so they survive a
restart of the server: clients keep their addresses, and new clients don't
get an address someone still holds. It is a text file with one lease per
line and the expiry as an absolute Unix time:
# udedhcpd lease file v1
# MAC IP EXPIRES HOSTNAME (EXPIRES in Unix time, UTC)
02:00:00:00:00:0a 10.0.0.100 1796000000 alice
The server rewrites it whenever a lease is granted, renewed, released or
declined, by writing FILE.tmp, flushing it to disk and renaming it over
FILE (MoveFileEx on Windows), so FILE always holds a complete version
(except on Windows 95, 98 and ME; see "Windows versions"). At
startup it reads the file, skips leases that have expired and lines it can't
use (logging them), and writes it back. A missing file is created; a file
that doesn't start with the first line above is refused and left alone, so a
wrong -f can't destroy anything. Offers are not saved (they last 60 s).
The format and the load/save functions are part of libude-dhcp
(ude_dhcpd_save_leases, ude_dhcpd_load_leases, ude_dhcpd_restore). The server is an ordinary host on the
network: it answers ARP and ping for its own address. It doesn't depend on
a router; udeslirp is one, and the two can share a subnet.
udeslirp
udeslirp [-v] [-a ADDR/LEN] [-b ADDR] [-D ADDR[:PORT]] [-R FORWARD]... [-s URL] [-m MAC] [-n NAME]
[--route NET/LEN:GATEWAY]... [--dns-address ADDR|none] [--host-loopback] [--restrict] [--deny ADDR/LEN]...
[--no-icmp] [--max-connections N] [--max-udp N]
[--tcp-timeout SECS] [--udp-timeout SECS] [--connect-timeout SECS] [-C FILE]
A NAT gateway from the UDE network to the host's network, in the manner of QEMU's user-mode networking (SLIRP): no root, no TAP device, no routing or firewall rules. It joins the switch as the gateway, 10.0.2.2/24 by default, and carries the guests' traffic out through ordinary sockets of the host:
- TCP: the guest's connection is terminated in
udeslirp(libude-tcp answers for any address, seeUDE_TCP_LISTEN_ANY) and spliced to a host socket connected to the real destination, with half-close passed both ways. The guest's SYN is answered only once the host'sconnect()succeeded (UDE_TCP_LISTEN_DEFER), so a refused port is a reset in the guest, an unreachable host an ICMP unreachable from the gateway, and a silent one silence. Idle connections are reset after--tcp-timeout(2 hours). - UDP: one host socket per guest address and port, which accepts replies
from the last 8 addresses the guest sent to (endpoint-independent mapping,
address-dependent filtering); it is closed after
--udp-timeout(60 s) idle. - ICMP: echo requests go out through unprivileged ICMP sockets (Linux,
when the group is in
net.ipv4.ping_group_range; macOS). Where there are none (Windows, a Linux that disallows them,--no-icmp) the guest gets "communication administratively prohibited" (type 3 code 13). Pings to the gateway and the DNS address are always answered; a TTL that expires at the gateway gets time exceeded, so traceroute shows the first hop. - DNS: address 3 of the subnet (10.0.2.3) relays UDP and TCP port 53 to
the host's resolver (the first
nameserverin/etc/resolv.conf, or-D). - Port forwards:
-R tcp:2222:10.0.2.15:22(orudp:, andtcp:HOSTADDR:...) bring host connections into a guest, from the gateway's address. HOSTADDR defaults to-b, or to 0.0.0.0 (as in QEMU's SLIRP); a non-loopback listen address is warned about once. -b/--bind ADDR: outgoing host sockets (TCP, UDP, DNS, and ping sockets where they exist) are bound to ADDR before connecting or sending, so the traffic leaves through that interface. Implicit forwards listen on ADDR too. A bind that the host cannot make is reported at startup (cannot bind to ADDR: ...) and the process exits.--host-loopbackstill maps the gateway to 127.0.0.1; the socket is bound to ADDR first, which on Linux still reaches loopback services.- The host's loopback is off limits by default.
--host-loopbackmaps the gateway's address to the host's 127.0.0.1, as SLIRP does; it lets every guest, and anyone who can join the switch, use services that listen on 127.0.0.1 because they trust only local users.--denyand--restrictnarrow what guests can reach. - Subnets behind a router:
--route 10.0.1.0/24:10.0.2.254(repeatable, up to 16) serves the hosts of 10.0.1.0/24, behind a router such asuderouterat 10.0.2.254 onudeslirp's subnet, like its own guests: replies, ICMP errors and port forwards to them go to the router's MAC address. A guest's packet for a routed subnet is passed on to the router with its TTL decremented. The gateway must be on the subnet; a default route, or a network inside the subnet, is refused.
DHCP stays a separate program, so a guest may use udedhcpd, a static
address, or another DHCP server running in a VM. With udedhcpd on the
same subnet (-g the gateway, -N the DNS address, a pool that avoids
both), guests are configured by DHCP:
udeswitch &
udedhcpd -a 10.0.2.4/24 -g 10.0.2.2 -N 10.0.2.3 -p 15-99 &
udeslirp -v -R tcp:2222:10.0.2.15:22 &
-C/--configuration FILE (or UDE_CONFIG) reads a TOML file: each long
option is also a key of the [udeslirp] table, with _ for - (--switch
is connection, --addr is address), booleans have a --no-X form, and
forward, route and deny are arrays. --check-config reports unknown keys and
--print-config shows the effective options. See ude.conf(5),
udeslirp(8) and
www/howto/internet.md.
uderouter
uderouter -i SWITCH,ADDR/LEN[,MAC] -i ... [-r NET/LEN:GATEWAY]... [-n NAME]
[-v] [-q] [--no-icmp-errors] [-C FILE]
An IPv4 router between two or more switches, each a broadcast domain and
subnet of its own, with no privileges and no help from the host's network.
On each switch named with -i (any URL: 127.0.0.1:7500, vde:///tmp/sw)
it is a host with that address, answering ARP and ping, and it forwards
unicast IPv4 between them:
- Table: a connected route per interface plus the static routes of
-r(default:GATEWAYfor 0.0.0.0/0; the gateway must be on a connected subnet), longest prefix first. Up to 16 interfaces and 48 routes. - Forwarding: the TTL is decremented with an incremental checksum update
(RFC 1624); TTL exceeded, no route (network unreachable) and a next hop
that does not answer ARP (host unreachable, after 3 requests a second
apart; 16 packets per interface wait meanwhile) are answered with ICMP,
unless
--no-icmp-errors. ICMP errors follow RFC 1812 (none about ICMP errors, later fragments or broadcasts) and are limited to 100 a second. - MTU: packets over 1500 bytes are fragmented (RFC 791, options copied where required), or dropped with ICMP fragmentation needed and the MTU if DF is set (RFC 1191).
- Not forwarded: broadcasts, multicast, and packets from impossible or the router's own addresses. Each switch needs its own DHCP server.
- Its own addresses: pings are answered from the address pinged; UDP and TCP get port unreachable, other protocols protocol unreachable.
- MAC:
02:55:and the interface address in hexadecimal unless given, so it is the same across restarts.
udeswitch -p 7500 &
udeswitch -p 7600 &
uderouter -i 127.0.0.1:7500,10.0.1.1/24 -i 127.0.0.1:7600,10.0.2.1/24 &
udedhcpd -s 127.0.0.1:7500 -a 10.0.1.2/24 -g 10.0.1.1 &
udedhcpd -s 127.0.0.1:7600 -a 10.0.2.2/24 -g 10.0.2.1 &
With a leg on udeslirp's subnet and -r default:10.0.2.2, plus udeslirp
--route for the subnets behind it, every subnet reaches the outside. Each
long option is a key of [uderouter] (interface and route are arrays;
connection is ignored). See uderouter(8) and
www/howto/multiple-networks.md, which
also covers routing with the Linux host through udetap.
udetftpd
udetftpd -a ADDR/LEN -r DIR [-B N] [-W N] [-t SECS] [-R N] [-c N] [-q] [-C FILE] [net options]
| Flag | Default | Meaning |
|---|---|---|
-a |
(required) | the server's own address |
-r, --root |
(required) | the directory served |
-B, --max-blksize |
1468 | largest block size a client may negotiate (1468 fills one Ethernet frame) |
-W, --max-window |
16 | largest window (RFC 7440 windowsize) a client may negotiate, up to 64 |
-t, --timeout |
1 | seconds before a retransmission, unless the client negotiates its own |
-R, --retries |
5 | retransmissions before a transfer is given up |
-c, --max-transfers |
64 | transfers at once |
-q, --quiet |
don't log requests and transfers (--no-quiet undoes it) |
|
-C, --configuration |
optional TOML configuration file (or UDE_CONFIG); each long option is a key of [udetftpd], and address and connection stand for --addr and --switch. See ude.conf(5) |
A read-only TFTP server (RFC 1350) with option negotiation (RFC 2347:
blksize, timeout, tsize and windowsize), octet and netascii modes, and any
number of blocks (the block number wraps from 65535 to 0, so a 40 MB initrd
works at 512-byte blocks). Each transfer has its own port and keeps its
window in memory, so a retransmission never reads the file again. Write
requests get an access violation. Names are relative to the root: leading
slashes are dropped, \ counts as / (for Windows boot files), and ..,
: and control characters are refused; on POSIX systems a name must also
resolve, symbolic links included, to a regular file inside the root.
Together with udedhcpd -B ADDR -b FILE it network boots emulated
machines; www/howto/netboot.md boots the Debian
installer in QEMU that way.
udetap (Linux only)
sudo ip tuntap add dev ude0 mode tap user $USER # once
udetap -i ude0 -s 127.0.0.1:7500 &
sudo ip addr add 10.0.0.1/24 dev ude0 && sudo ip link set ude0 up
This was checked by hand: the host kernel answered an ARP request that a test client
sent through the switch and udetap. tests/manual_tap.sh (root; not part of
make test) goes further: in a throw-away network namespace, Linux gets a
lease from udedhcpd with busybox udhcpc, pings udedhcpd and a
udeping -r, is pinged by udeping, exchanges UDP with udenc, gets
ICMP port unreachable from a closed port, and exchanges 1 MB each way over
TCP with udenc in both roles against OpenBSD nc (or socat, with
LNC=socat), plus resets for closed ports in both directions. See www/howto/recipes.md for QEMU, VDE and
more recipes.
libude in 15 lines
#include <ude.h>
ude_lib_init();
ude_conn_opts o; ude_conn_opts_init(&o); o.name = "86box"; o.hello = 1;
char err[256];
ude_conn *c = ude_open("127.0.0.1:7500", &o, err, sizeof err); /* or "vde:///tmp/vde.ctl" */
ude_send_frame(c, frame, len);
long n = ude_recv_frame(c, buf, sizeof buf, 10); /* ms; 0 = poll, -1 = block */
/* or wait on ude_get_fd(c) in your own loop and call ude_service(c) periodically */
ude_close(c); /* sends BYE */
ude_lib_cleanup();
A monitor (what udedump does) opens with o.hello = 0, calls
ude_monitor(c, 2000), and then reads every datagram the switch receives,
with its ingress port, sender and the switch's timestamp, through
ude_recv_mirror(c, buf, sizeof buf, &info, timeout_ms).
libude-udp in 20 lines
#include <ude_dhcp.h> /* includes ude_udp.h, ude_ipv4.h and ude.h */
static void on_dgram(void *ctx, ude_udp *s, uint32_t ip, uint16_t port,
const uint8_t *data, size_t len)
{
ude_udp_sendto(s, ip, port, data, len); /* an echo server */
}
...
ude_conn *c = ude_open("127.0.0.1:7500", &o, err, sizeof err);
uint8_t mac[6]; ude_net_random_mac(mac);
ude_ipv4 *ip = ude_ipv4_new(c, mac); /* an IPv4 host on the switch */
ude_dhcp_client *dc = ude_dhcp_client_new(ip, "echo");
ude_udp *s = ude_udp_open(ip, 7, on_dgram, NULL);
for (;;)
ude_ipv4_poll(ip, -1); /* frames, ARP, ICMP, DHCP timers, UDP callbacks */
Or, with your own event loop: wait on ude_get_fd(c) for at most
ude_ipv4_timeout_ms(ip) and then call ude_ipv4_poll(ip, 0); udenc.c
does exactly that. A static address is ude_ipv4_configure(ip, &cfg)
instead of a DHCP client.
Protocol libraries
libude stays minimal: a switch connection and Ethernet frames. Anything above Ethernet lives in separate, optional libraries layered on top, each with its own public header, static and shared build, pkg-config file and configure switch:
libude-dhcp ude_dhcp.h DHCP client + server ude-dhcp.pc
|
libude-tcp libude-udp ude_udp.h UDP sockets ude-udp.pc
ude_tcp.h |
TCP connections |
ude-tcp.pc |
\ |
+---- libude-ipv4 ude_ipv4.h ARP, IPv4, ICMP ude-ipv4.pc
|
libude ude.h switch connection ude.pc
+ Ethernet frames
| Library | Linux | Windows | Prefix |
|---|---|---|---|
| libude-ipv4 | libude-ipv4.so.0, libude-ipv4.a |
libude-ipv4-0.dll, libude-ipv4.dll.a |
ude_ipv4_*, ude_inet_*, ude_net_*, UDE_NET_* errors |
| libude-udp | libude-udp.so.0, libude-udp.a |
libude-udp-0.dll, ... |
ude_udp_* |
| libude-tcp | libude-tcp.so.0, libude-tcp.a |
libude-tcp-0.dll, ... |
ude_tcp_* |
| libude-dhcp | libude-dhcp.so.0, libude-dhcp.a |
libude-dhcp-0.dll, ... |
ude_dhcp_* (client), ude_dhcpd_* (server) |
| libude-ipv6 | reserved name, not implemented |
Each shared library links against the shared libraries below it that it
uses. Programs link only what they use, dynamically unless configured with
--static (see Shared libraries and the programs):
udeswitch and udetap use libude alone; udeping, udenc and
udedhcpd use DHCP, and udenc and udeslirp also use TCP and UDP.
Why DHCP is its own library and not part of libude-udp: it is an
application protocol, not transport. Most UDP users (a TFTP server, a game, a
test tool) don't need it, and the client and the server share one message
codec that belongs to neither. A future router can link libude-dhcp to
serve its subnets, and a DHCP-only embedder doesn't drag in anything else.
How the stack works.
- No OS IP stack and no threads.
ude_ipv4is an IPv4 host on oneude_conn: it builds and parses every frame itself, so it behaves the same on Linux, Windows and over VDE. Everything is driven byude_ipv4_poll(), or byude_ipv4_input()/ude_ipv4_tick()/ude_ipv4_timeout_ms()from an existing event loop such as an emulator's. The clock and the frame output can be replaced (ude_ipv4_new_io()), which is howtest_stackruns a whole network in simulated time. - ARP: a 32-entry cache (entries live 5 minutes), RFC 826 merge rules,
requests retried every second and given up after 3 (queued packets are then
dropped; at most 16 packets wait at a time, beyond that sends return
UDE_NET_ENOBUFS), replies for our address, a gratuitous ARP when an address is configured, and address-conflict detection (logged). - IPv4: header checksums are verified and padding is trimmed. Fragments are counted and dropped cleanly (UDE's MTU is 1500 and nothing here sends fragments). Unknown protocols get ICMP protocol unreachable. Packets are routed on-link or via the configured router; there is no loopback.
- ICMP: echo requests are answered automatically (never for
broadcasts). Echo replies and errors go to an optional callback
(
ude_ipv4_set_icmp_cb), which is howudepingworks; errors about a packet we sent also go to the handler of its protocol (ude_ipv4_set_proto_err), which is how TCP hears them. - Layers plug in from above, so lower libraries never depend on upper
ones. A protocol registers a handler for its IP protocol number
(
ude_ipv4_set_proto); a layer with timers registers a module (tick,timeout_ms,detach).ude_ipv4_free()detaches everything on the interface, newest first. While the interface has no address, packets are passed up markedfor_us = 0, which is what lets the DHCP client hear offers, andude_udp_sendto_ex()can send from 0.0.0.0 to a given MAC. - Routing hooks (for
udeslirp):ude_ipv4_set_route_hook()sees every unicast packet sent to our MAC address, for any destination, and either takes it or has it delivered locally as if addressed to us (the packet keeps its real destination, which replies and ICMP errors use as their source);ude_ipv4_set_arp_proxy()answers ARP for other addresses (proxy ARP). - UDP: ports with callbacks, ephemeral ports from 49152, checksums always sent (and checked when the sender used one), and ICMP port unreachable for closed ports.
- DHCP client: DISCOVER, OFFER, REQUEST, ACK with exponential backoff
(1 s to 16 s); renewing (unicast to the server) at T1 and rebinding
(broadcast) at T2, retrying at half the remaining time; on expiry or NAK the
address is removed and it starts again. RELEASE on exit. It asks for the
mask, router, DNS, lease time and T1/T2, sends the host name (option 12) and
client id (option 61, the MAC), and reports BOUND, RENEWED and LOST events.
If an ACK has no subnet mask option (or an unreasonable one), the client
uses the mask of the address class (/8, /16 or /24), as RFC 1122 section
3.2.2.9 says a host should assume until it knows better, and as
systemd-networkd and dhcpcd do; it ignores offers of addresses that can't
be a host address (class D or E, loopback, or the network or broadcast
address).
udedhcpdalways sends the mask. - TCP (
libude-tcp): see below. - IPv6 (
libude-ipv6) is a reserved name only.
libude-tcp
A small TCP after RFC 9293, registered like UDP as a protocol handler and a
module of the interface. One callback per connection gets events
(CONNECTED, READABLE, WRITABLE, CLOSED, and ACCEPT on a listener),
always from ude_ipv4_poll()/ude_ipv4_tick() or frame input and never from
inside a ude_tcp_* call, so a callback may call anything. Calls return
UDE_NET_* codes in the same style as UDP; failures are
UDE_NET_ECONNREFUSED, _ECONNRESET and _ETIMEDOUT.
| Function | What it does |
|---|---|
ude_tcp_connect(ip, dst, port, lport, opts, fn, ctx, &err) |
active open (local port 0 = ephemeral, from 49152) |
ude_tcp_listen(ip, port, backlog, opts, fn, ctx), ude_tcp_accept() |
passive open; ACCEPT says a connection is ready |
ude_tcp_listen_ex(..., flags, ...), ude_tcp_confirm() |
for routers: UDE_TCP_LISTEN_ANY takes connections to any address and port that reach the stack; UDE_TCP_LISTEN_DEFER hands them over at the SYN and answers only on ude_tcp_confirm() (or a reset on ude_tcp_abort(), nothing on ude_tcp_close()) |
ude_tcp_send(), ude_tcp_recv() |
queue data (returns what fit); read (0 = the peer's FIN) |
ude_tcp_shutdown() |
half-close: FIN after the queued data, keep receiving |
ude_tcp_close(), ude_tcp_abort() |
release the handle (graceful, in the background) or reset |
ude_tcp_pending(ip) |
connections still delivering data, to poll before exit |
ude_tcp_build(), ude_tcp_parse() |
the segment codec, with the pseudo-header checksum |
What it does:
- The three-way handshake (also simultaneous open), the full state machine including TIME-WAIT (60 s) and half-close, and an orphaned FIN-WAIT-2 that gives up after 60 s.
- A reset for a segment to a port with nothing listening (that is how a closed port refuses), and RFC 5961 challenge ACKs for a RST or SYN inside the window that is not exactly at the expected sequence number.
- Initial sequence numbers after RFC 6528: a 4 microsecond clock plus a SipHash-2-4 of the connection's addresses and ports with a random key.
- Retransmission with the RFC 6298 timer (1 s initial, 200 ms minimum, 60 s
maximum, exponential backoff); 6 SYN retries (about 2 minutes) and 10 data
retries before the connection fails with
ETIMEDOUT. - Flow control with zero-window probes, and silly window avoidance on both sides.
- Congestion control after RFC 5681: slow start, congestion avoidance, fast retransmit after three duplicate ACKs and NewReno recovery (RFC 6582).
- MSS option (1460, and what the peer announces); 64 KB buffers by default,
set with
ude_tcp_opts. ude_tcp_close()with unread data, or with data arriving later, resets the connection, as Linux and BSD do.
Limitations, by design for a small emulator-network stack: no window
scaling (so at most 64 KB in flight), timestamps, SACK, ECN, urgent data,
Nagle algorithm, delayed ACKs, keepalives or path MTU discovery. Out-of-order
data is kept as one block beyond the next expected byte; other out-of-order
segments are dropped and the peer retransmits them. ICMP destination
unreachable ends a connection attempt (as in Linux) but is ignored on an
open connection (a soft error, RFC 1122 4.2.3.9). An address that does not
answer ARP is noticed only when the SYN retries run out. There is no SO_REUSEADDR: a port in TIME-WAIT can't be
reused for the same peer until it ends, but listeners can be reopened at once.
Wire protocol (version 1)
One UDP datagram carries exactly one message. There are two kinds:
DATA: a raw Ethernet frame, with no header
+-----------+-----------+-----------+---------------------+
| dst MAC 6 | src MAC 6 | type/len 2| payload ... | 14 .. max_frame bytes, no FCS
+-----------+-----------+-----------+---------------------+
- The switch identifies a client (a port) by its UDP source address:port. The
first datagram from a new endpoint registers it automatically, unless
-Ris set. - The switch sends frames back to that same endpoint, so the client must send and receive on one socket.
- Frames shorter than 14 bytes are dropped. Short frames are not padded or
rejected (an emulator may send unpadded 42-byte ARP frames), and frames larger
than
-mare dropped. Frames with a group (multicast or broadcast) source MAC are dropped.
CONTROL: an 8-byte header followed by TLVs
0 1 2 3 4 5 6 7
+------+------+------+------+------+------+------+------+
| 'U' | 'D' | 'E' | ver=1| type |flags |payload len BE|
+------+------+------+------+------+------+------+------+
| TLV: type(1) len(1) value(len) ... |
Read as a frame, the magic is destination MAC 55:44:45:xx:xx:xx. That's a
group address (the I/G bit of 0x55 is set) in a block that no protocol we know
of uses. UDE reserves the whole 55:44:45:00:00:00/24 destination range:
datagrams starting with it are always parsed as control and never forwarded, and
libude refuses to send such frames. An unknown ver means the datagram is
dropped and counted.
| type | name | direction | contents / behaviour |
|---|---|---|---|
| 0x01 | HELLO | client → switch | optional NAME. Registers (or re-registers) the endpoint. Optional unless the switch runs with -R |
| 0x02 | HELLO_ACK | switch → client | PORT_ID (u32), IDLE_TIMEOUT (u16 s, 0 = ports never expire), MAX_FRAME (u16), NAME |
| 0x03 | KEEPALIVE | client → switch | refreshes the port (and registers it, unless -R). Always accepted and acked, even when the idle timeout is 0 |
| 0x04 | KEEPALIVE_ACK | switch → client | PORT_ID |
| 0x05 | BYE | client → switch | removes the port and flushes its MACs at once |
| 0x10-0x12 | AUTH_CHALLENGE / RESPONSE / RESULT | reserved for authentication (see below). v0 answers with ERROR | |
| 0x20 | DATA_SEALED | reserved: an authenticated or sequenced data frame | |
| 0x30 | CAPTURE_START | manager → switch | optional FILE, optional REQUEST_ID. Starts capturing to FILE (truncated), or without FILE appends a new section to the last file. ERROR 6 if already capturing |
| 0x31 | CAPTURE_STOP | manager → switch | optional REQUEST_ID. Stops capturing; stopping when stopped is not an error |
| 0x32 | CAPTURE_ROTATE | manager → switch | optional FILE, optional REQUEST_ID. Moves to FILE, or reopens the same name. ERROR 6 if not capturing |
| 0x33 | CAPTURE_STATUS | manager → switch | optional REQUEST_ID |
| 0x34 | CAPTURE_REPLY | switch → manager | answer to 0x30-0x33: REQUEST_ID (if given), CAPTURE_STATE (u8: 0 stopped, 1 capturing), FILE (the current or last file, if any), FRAMES and BYTES (u64, written to the current file), MONITORS (u16) |
| 0x40 | MONITOR | client → switch | optional NAME. Registers the endpoint as a monitor port, or turns its existing port into one (its MACs are flushed). A later HELLO makes it a normal port again |
| 0x41 | MONITOR_ACK | switch → client | as HELLO_ACK, plus IF_NAME: the interface name the switch uses in its own capture files. From then on the client receives a MIRROR for every datagram the switch receives from other ports |
| 0x42 | MIRROR | switch → monitor | one received datagram with its ingress metadata; see below |
| 0x50 | PORT_LIST | manager → switch | optional REQUEST_ID, optional CURSOR. Asks for a page of the port list |
| 0x51 | PORT_LIST_REPLY | switch → manager | REQUEST_ID, the switch's NAME, PORT_COUNT and MAX_PORTS (u16), then one record per port, each starting with PORT_ID: PEER, NAME (if any), PORT_FLAGS (u8: 1 registered with HELLO, 2 monitor), MAC_COUNT, RX_FRAMES, RX_BYTES, TX_FRAMES, TX_BYTES, RX_DROPPED, AGE_MS (since last heard from), UPTIME_MS. Paged, see below |
| 0x52 | MAC_LIST | manager → switch | optional REQUEST_ID, CURSOR, and a port (PORT_ID, PEER or NAME) to list only its MACs |
| 0x53 | MAC_LIST_REPLY | switch → manager | REQUEST_ID, NAME, MAC_COUNT (the whole table) and MAC_CAPACITY, then per MAC, in MAC order: MAC, PORT_ID, AGE_MS (since last seen as a source). Paged |
| 0x54 | PORT_KICK | manager → switch | optional REQUEST_ID, one of PORT_ID, PEER or NAME. Removes the port and flushes its MACs; its endpoint gets ERROR 9 |
| 0x55 | MAC_FLUSH | manager → switch | optional REQUEST_ID; with MAC, that MAC; with PORT_ID, PEER or NAME, that port's MACs; with neither, the whole table |
| 0x56 | MGMT_REPLY | switch → manager | answer to 0x54 and 0x55: REQUEST_ID, the port concerned (PORT_ID, PEER, NAME; none for a whole-table flush), MAC (if one MAC was flushed) and MAC_COUNT (MACs flushed) |
| 0x7F | ERROR | switch → client | ERROR_CODE (u16: 1 port table full, 2 unsupported, 3 HELLO required, 4 denied by -A, 5 bad request, 6 capture file error, 7 no such port or MAC, 8 the name matches more than one port, 9 sent to a client whose port a manager removed), TEXT, and REQUEST_ID if the request had one |
TLV types: 1 NAME, 2 PORT_ID, 3 IDLE_TIMEOUT, 4 MAX_FRAME, 5 AUTH_METHODS, 6 NONCE, 7 AUTH_PROOF, 8 ERROR_CODE, 9 TEXT, 10 FILE (a path, 1-255 bytes, no NUL), 11 REQUEST_ID (u32, chosen by the client and echoed), 12 CAPTURE_STATE (u8), 13 FRAMES (u64), 14 BYTES (u64), 15 MONITORS (u16), 16 TIMESTAMP (u64 ns since 1970-01-01 UTC), 17 PEER (IPv4 address and UDP port, 6 bytes; 18 bytes reserved for IPv6), 18 ORIG_LEN (u32), 19 IF_NAME, 20 CURSOR (opaque, at most 16 bytes), 21 PORT_FLAGS (u8), 22 MAC_COUNT (u32), 23 RX_FRAMES, 24 RX_BYTES, 25 TX_FRAMES, 26 TX_BYTES, 27 RX_DROPPED (u64), 28 AGE_MS (u32), 29 UPTIME_MS (u64), 30 PORT_COUNT (u16), 31 MAX_PORTS (u16), 32 MAC (6 bytes), 33 MAC_CAPACITY (u32). All integers are big-endian. Receivers ignore unknown TLVs and unknown control types, which keeps the protocol forward-compatible.
Management requests (0x30-0x33, 0x50, 0x52, 0x54, 0x55) and MONITOR are checked against -A before
anything else: with none (the default) every request gets ERROR 4,
with local only peers in 127.0.0.0/8 are served, and with any
everyone is. Management requests don't register a port.
They are answered once and not retransmitted, so a manager that gets no
answer may simply ask again (CAPTURE_STATUS is safe to repeat; a repeated
CAPTURE_START is refused with ERROR 6). A FILE value is a path on the
switch's host. FILE is limited to 255 bytes by the one-byte TLV
length; udectl refuses a longer path (after making it absolute), and
the switch never sees one. Short names such as /tmp/switch.pcapng are
the expected use.
Paged replies. A list reply is at most 1400 bytes (UDE_MGMT_PAGE_MAX),
so it fits an Ethernet-sized path without fragmentation; a record is never
split. When more follows, the reply carries a CURSOR; the manager sends the
same request again with that CURSOR (and a new REQUEST_ID) for the next
page. The last page has flag 0x01 (END) in the header and no CURSOR; an
empty list is a single END page. The switch keeps no state between pages:
the cursor (opaque to managers; today the last port id or MAC sent) says
where to go on, and lists are in port-id or MAC order, so a port or MAC
added or removed between pages doesn't make the others repeat or vanish.
Because the requests change nothing, a manager may resend one that got no
answer; PORT_KICK and MAC_FLUSH are sent once (a lost answer to a kick
turns into "no such port" when repeated).
MIRROR: what a monitor port receives
+------+------+------+------+------+------+------+------+
| 'U' | 'D' | 'E' | ver=1| 0x42 |flags | TLV len BE |
+------+------+------+------+------+------+------+------+
| TIMESTAMP (2+8) PORT_ID (2+4) PEER (2+6) [NAME] |
| [ORIG_LEN (2+4)] |
+---------------------------------------------------------+
| the received datagram, as captured (0..65200 bytes) |
+---------------------------------------------------------+
Unlike every other control message, the length field covers only the TLVs: the captured bytes follow them, up to the end of the datagram, because a frame is longer than a TLV can be. The fields are exactly what the switch hands to its own capture file, from the same place in the switch (one capture hook feeds both), so they match it:
TIMESTAMP: the switch's wall clock when the datagram arrived.PORT_ID: the ingress port, or 0 if the sender has no port (the table was full, or-Rand no HELLO yet).PEER: the sender's address and port.NAME: the port's name, if it has one.- The bytes: the whole datagram, including runts (even an empty one) and
frames the switch then drops, at most
UDE_CAPTURE_SNAPLEN= 65200 bytes. If the datagram was longer,ORIG_LENgives its length.
Size limits. A UDP datagram over IPv4 carries at most 65507 bytes. The
largest MIRROR overhead is 307 bytes: the 8-byte header, TIMESTAMP (10),
PORT_ID (6), PEER as IPv6 (20), ORIG_LEN (6) and a 255-byte NAME
(257); switch port names are actually at most 31 bytes. 65507 − 307 =
65200, so the switch accepts -m up to 65200 and every frame it forwards
is mirrored whole. On loopback (MTU 65536) such a datagram is not even
fragmented; over a network it is fragmented by IP like any large UDP
datagram, and a monitor needs a receive buffer of 64 KiB (libude's is).
Over IPv4 a datagram larger than 65507 bytes can't reach the switch, so
only datagrams between 65201 and 65507 bytes, which the switch drops as
too big, are ever cut.
In libude, ude_recv_mirror() returns the bytes and a ude_mirror_info
(timestamp, port, peer, name, lengths), ude_monitor_if_name() the
IF_NAME, and ude_recv_frame() on a monitor connection just the bytes.
Idle timeout and keepalives
UDP is connectionless, so a client can vanish (crash, kill -9, a closed
emulator) without anything reaching the switch. The switch therefore removes a
port, and flushes its MACs, after -T seconds (default 300) without any
datagram from it. Every datagram refreshes the port: frames, HELLO and
KEEPALIVE alike.
- HELLO_ACK always carries the switch's
IDLE_TIMEOUTin seconds (capped at 65535). A client that sent HELLO should send a KEEPALIVE whenever it has sent nothing forIDLE_TIMEOUT/2seconds. The switch answers each one with KEEPALIVE_ACK. IDLE_TIMEOUT0 (udeswitch -T 0) means ports never expire, and clients need not send KEEPALIVEs. The switch still accepts and acks them; it never refuses a KEEPALIVE because of the timeout setting.- libude does this automatically: with
keepalive_msleft at 0 (auto), a connection that got a HELLO_ACK sends KEEPALIVE everyIDLE_TIMEOUT/2, or none if the timeout is 0. The timing runs fromude_recv_frame()andude_service(), and any datagram sent restarts it. A connection without HELLO doesn't know the timeout and sends one every 30 s.keepalive_ms> 0 forces an interval, and -1 turns keepalives off. ude_keepalive_hello()makes a connection send HELLO, not KEEPALIVE, every interval, whether or not it sent frames. HELLO refreshes the port just as well, and a switch that restarted (or dropped the port) learns the port and its name again from it, also with-R, which drops frames and KEEPALIVEs from endpoints that haven't said HELLO.udelinkuses it. The switch logs a repeated HELLO with an unchanged name only at-vv.- Clients that use no control messages at all (raw-UDP emulator backends) stay registered as long as they send frames at least once per idle timeout.
Why raw frames with an optional control channel?
- Easy for emulators. "
sendto()the frame andrecvfrom()frames" is the whole client. QEMU's-netdev dgramand-netdev socket,udp=already do exactly this, so they should talk toudeswitchwith no changes (expected but not yet tested). An 86Box backend is about 100 lines, or none at all if it links libude. - No per-frame overhead or parsing on the hot path. It is the same model as VDE's data path, where each port's data socket carries raw frames.
- Ports are UDP endpoints. UDP is connectionless, so the endpoint is the session. On loopback it can't be NATed, and once one process has bound an address:port, no other user can bind it. That makes the endpoint a reasonable identity to attach authentication to later.
- Control is optional but available. Clients that want a port id, liveness, clean unregistering or (later) auth use HELLO, KEEPALIVE and BYE. Clients that don't simply send frames and are expired after the idle timeout.
- The alternative was a mandatory per-datagram header (magic, version and type on every frame). It is cleaner on paper, but it breaks compatibility with existing raw-UDP emulator backends and costs bytes and branches on every frame. The control-magic collision risk is contained by reserving a destination range that no protocol uses.
Design notes
include/ude.h public API: ude_open/send/recv/close, utils
include/ude_transport.h transport vtable (udp, vde, ...)
lib/net_compat.[ch] ALL platform #ifdefs: Winsock init, closesocket, socklen_t,
errno vs WSAGetLastError, non-blocking, select(),
monotonic clock, signals, SIO_UDP_CONNRESET
lib/proto.[ch] wire protocol: classify, TLV builder/iterator (pure)
lib/conn.c transport-independent ude_conn layer
lib/transport_udp.c UDE/UDP transport (HELLO, keepalives, BYE)
lib/transport_vde.c libvdeplug transport (built if libvdeplug is found; POSIX)
lib/util.c MAC parse/format, hexdump, frame builder
lib/mgmt.c management client (ude_mgmt_*: capture, lists, kick, flush)
daemon/mactable.[ch] MAC -> port hash table (chained, fixed node pool, aging)
daemon/porttable.[ch] endpoint -> port slots (open-addressed index)
daemon/switch_core.[ch] forwarding engine; no socket I/O (io.send callback)
daemon/udeswitch.c socket loop, options, signals, the -w capture file
common/ude_getopt.[ch] tiny portable getopt for the programs (MSVC has none)
common/ude_cli.[ch] -V/--version output for the programs
common/ude_netcli.[ch] shared network options + DHCP/static bring-up (IPv4 tools)
common/ude_stdin.[ch] wait on stdin and a connection at once (udenc; see below)
common/ude_pcapng.[ch] pcapng writer (udeswitch -w, udedump; see below)
common/ude_impair.[ch] link impairment engine (udelink -I/-A/-B)
include/ude_ipv4.h libude-ipv4 public API
ipv4/ipv4.c the IPv4 host: ARP cache and queue, IPv4 in/out, ICMP
ipv4/pkt.c ipv4_pkt.h pure codecs (ARP, IPv4, ICMP), checksums, addresses
ipv4/ude_bytes.h big-endian load/store, pseudo-header sum (internal)
include/ude_udp.h libude-udp public API
udp/udp.c UDP sockets
include/ude_tcp.h libude-tcp public API
tcp/tcp.c TCP connections
include/ude_dhcp.h libude-dhcp public API (client and server)
dhcp/dhcp_msg.[ch] DHCP message codec (shared by client and server)
dhcp/client.c DHCP client state machine
dhcp/server.c DHCP server
tools/ udectl, udedump, udelink, udeping, udenc, udedhcpd,
udeslirp, uderouter, udetap (Linux-only file)
common/ude_route.[ch] routes, interfaces, TTL and fragmentation for
udeslirp and uderouter
common/ude_tftpd.[ch] the TFTP server engine of udetftpd
tests/udecat.c internal test and debug client for the end-to-end tests:
built by `make test`, never installed
tests/udetftp.c internal TFTP client for the end-to-end tests, likewise
tests/test_tftp.c udetftpd's server engine on a simulated network
tests/test_core.c engine unit tests driven by a fake io (no sockets)
tests/test_pcapng.c pcapng writer, byte by byte; also a pcapng checker
tests/test_impair.c udelink's impairment engine on simulated time
tests/test_lib.c public-API tests (also linked against the .so)
tests/test_net.c protocol codec tests (ARP, IPv4, ICMP, UDP, DHCP)
tests/test_tcp.c libude-tcp on a simulated lossy network
tests/test_stack.c the protocol libraries on a simulated network
tests/test_route.c routes, interfaces, TTL and fragmentation (ude_route.c)
tests/run_tests.sh end-to-end: real switch + clients
tests/check_imports.sh Windows builds: imports and PE versions, against
tests/win_imports.txt the list of Windows functions old Windows has
tests/manual_tap.sh manual test against the Linux IP stack (root; not in make test)
scripts/mkversion.tcl writes ude_version.h from VERSION and Fossil's manifest
scripts/mkwrapper.sh writes the build-tree wrapper of a dynamically linked program
scripts/mkhtml.sh "make html": www/ with fossil, the manual pages with mandoc
scripts/mkpdf.sh "make pdf": the HTML joined into one PDF
docs/ manual pages (mdoc); docs/mkversion writes their date and version
www/ guides in Fossil Markdown with pikchr (templates for now)
extsrc/ unmodified third-party sources (tomlc17, MIT); see extsrc/README
- The switch core has no socket I/O.
ude_switch_input(sw, from, buf, len, now)takes a datagram and callsio.send()for each output. Time is passed in, sotests/test_core.ctests flooding, learning, filtering, MAC moves, aging, expiry, control messages and hub mode deterministically. The same engine could run inside an emulator or behind another front-end. - Forwarding. The switch learns every non-group source MAC. Group destinations and unknown unicast are flooded to all ports except the ingress port. Known unicast goes to exactly one port, and a frame whose destination lives on its own ingress port is filtered. Nothing is ever sent back to the ingress port. A MAC seen on a new port moves there (and is logged). When a port is removed by BYE or idle timeout, its MACs are flushed right away, so later frames for them are flooded instead of black-holed.
- No allocation on the forwarding path. Both tables are preallocated. A full MAC table stops learning (and keeps flooding) rather than evicting entries.
- Portability. In the libraries, only
lib/net_compat.[ch]contains#ifdef _WIN32. It handlesselect(), which works on every platform, and Windows quirks such asSIO_UDP_CONNRESETandWSAECONNRESETafter ICMP port-unreachable, which a switch must ignore. The protocol libraries have no platform code at all. The one exception among the programs iscommon/ude_stdin.c:udencwaits on standard input and the switch at once, and Windows'select()accepts only sockets, so there a helper thread copies standard input into a loopback socket.udetap.candtransport_vde.care platform-specific by nature and are compiled only where they apply. - The pcapng writer is a program module, not a library.
common/ude_pcapng.cwrites one section with one Ethernet interface (linktype 1,if_tsresol9 for nanoseconds) and Enhanced Packet Blocks with optional flags and comment, through stdio, with no platform code other than the clock. It lives incommon/with the other code that several programs share, so it has no ABI to keep stable: libude stays a switch connection and Ethernet frames, and the switch core stays free of I/O (it calls anio.capturehook, andudeswitch.cowns the file). If a pcap file transport or an embedding application needs it, it can move into a library then. - Single-threaded event loop.
select()with a 250 ms tick for expiry and aging, draining up to 256 datagrams per wakeup. On Linux,recvmmsg/sendmmsgbatching and an epoll front-end are easy future optimisations.
Security: localhost UDP has no filesystem ACLs
udeswitch is open by default: any local process can plug in, and there is no authentication yet. Authentication will be opt-in (a shared-secret challenge-response, enabled by giving the switch a secret), so the default stays open and existing clients keep working.
A VDE switch is a Unix socket directory, so file permissions decide who can plug
in. A UDP port on 127.0.0.0/8 can be reached by every local user. v0 limits the
exposure: it binds 127.0.0.1 by default, warns if you bind a non-loopback
address (anything outside 127.0.0.0/8, including 0.0.0.0), and -R requires
HELLO. Unicast replies only reach the socket that owns the endpoint, so
nobody can eavesdrop on a port they don't own. But anyone local can join.
Capture and monitor ports are the exception to "no eavesdropping": a
monitor sees every frame, and capture requests make the switch write files
with its own permissions. So they have their own policy, udeswitch -A:
none(default): no capture requests and no monitors (-wstill works, but it can't be stopped or rotated). Nothing changes for a switch that doesn't ask for these features.local: only peers on 127.0.0.0/8 may send capture requests or subscribe as monitors, so a switch bound to a LAN address doesn't let the LAN sniff it or write files. On a shared host every local user can still do both, just as every local user can join; until authentication exists, use it where you trust the local users.any: anyone who can reach the switch (with a warning).
The same policy covers the port list, the MAC table, kicking and flushing: a manager may see every client's address and name and disconnect any of them, so these are not open by default either. Any peer the policy lets in may use all of them, whether or not it is a port itself, and the requests never make it one. A kicked port is only removed, not banned (see Introspection).
The switch only overwrites or appends to files that are empty or already
pcapng, so a request can't destroy an arbitrary file the switch can write,
but it can create new files anywhere the switch user can. When
authentication arrives, the plan is that an -A auth policy allows these
requests only from authenticated endpoints, and that MONITOR and the
capture requests may come only after a successful AUTH exchange.
The protocol leaves room for authentication without breaking v1 clients:
- Shared-secret challenge-response (CHAP-style), planned first and opt-in.
HELLO carries
AUTH_METHODS. Only if the switch is given a secret (-k keyfile) does it answerAUTH_CHALLENGE{NONCE_s}. The client repliesAUTH_RESPONSE{NONCE_c, AUTH_PROOF = HMAC-SHA256(secret, "UDE1" | NONCE_s | NONCE_c | client endpoint | port id)}, and the switch sendsAUTH_RESULT. Only then does the endpoint become a port. DATA from unauthenticated endpoints is dropped (the-Rcode path already exists). Because loopback endpoints can't be hijacked once bound, authenticating the endpoint once is enough on localhost. HMAC-SHA256 is about 300 lines of portable C, so this stays dependency-free. - Sealed data (
DATA_SEALED, 0x20) for use beyond localhost: control header, sequence number, frame, truncated HMAC. This protects integrity and blocks replay. Confidentiality would need an AEAD (e.g. ChaCha20-Poly1305), which is still small enough to vendor. - Linux-only option: peer UID checks. Look up the owner of a source endpoint
via
sock_diagor/proc/net/udpand apply a UID/GID allow-list. That gives back VDE-like permissions without secrets. It would live behind net_compat or a separatepeercredmodule.
Transport abstraction: tools that work with UDE and VDE
include/ude_transport.h defines a small vtable (match, open, send, recv,
fd, service, close). ude_open(url) chooses the first transport whose
match() accepts the URL:
udp://host:port,host:port,:port→ UDE over UDP (always built)vde:///path/to/switch,vde:path,/path/to/switch,vxvde://...and other plugin URLs,vdeplug:<string passed verbatim>→ libvdeplug (built when found;make testchecks it against a realvde_switch)
Two incompatible libraries are both called libvdeplug, with the same API:
vdeplug4 (libvdeplug.so.2, Debian/Ubuntu libvdeplug-dev), whose
vde_open() takes URLs, and the classic vde2 library (libvdeplug.so.3,
from vde-2 2.3.x source builds), whose vde_open() takes only a plain switch
path. configure tells them apart with a link probe (only vdeplug4 exports
__vde_version_tag) and reports VDE transport (libvdeplug): yes (vdeplug4) or
yes (vde2). On vde2, libude strips the vde:// scheme before calling
vde_open(). Plugin URLs such as vxvde:// need vdeplug4 and give a clear error
on vde2.
The protocol libraries and the tools built on them (udedhcpd, udeping,
udenc, udetftpd and udeslirp) talk to the switch only
through ude.h, so each of them runs on either kind of switch with no extra
code. Possible
future transports: in-process loopback (tests and embedding), a pcap file writer,
and sealed UDP.
VDE compatibility
| Classic VDE | UDE |
|---|---|
vde_switch -s /tmp/sw (socket dir) |
udeswitch -p 7500 (UDP endpoint) |
port registration on the ctl stream socket (request port, description) |
first datagram, or HELLO with NAME → HELLO_ACK with PORT_ID |
| per-port data socket (Unix datagram, raw frames) | the client's UDP endpoint (raw frames) |
| ctl socket EOF = port gone | BYE, or idle timeout (UDP has no EOF), kept alive by KEEPALIVE |
vde_plug, libvdeplug URLs |
libude / ude_open() URLs |
wirefilter -l LOSS -L BURST -d DELAY -D DUP -b BANDWIDTH -s SPEED -n NOISE -m MTU -c CHANQUEUE, LR/RL prefixes (dpipe vde_plug = wirefilter = vde_plug) |
udelink -I loss=…,burst=…,delay=…,jitter=…,dup=…,rate=…,queue=…,corrupt=…,mtu=…, -A/-B per direction (see "Link impairment"). rate with a drop-tail queue stands for both -b and -s; corrupt is a per-frame chance of one flipped bit, not bits per MB; fixed at startup (no wirefilter console); -S for repeatable runs |
dpipe vde_plug = vde_plug (cable between switches), vde_plug URL over ssh |
udelink A B, between any two of udeswitch, vde_switch and a byte stream (-, vde_plug's 2-byte length format, so udelink and vde_plug talk to each other). No STP in either: avoid loops |
management console (unixterm, -M): port/print, port/remove, hash/print, hash/delete |
stats via -s and SIGUSR1; udectl ports, kick, macs, flush (and capture control) over the control channel, refused unless -A allows them. No VDE console syntax: udectl is a client, not a terminal |
hub mode (-x), ports, VLANs |
-H hub mode. VLAN-aware switching isn't implemented yet (tagged frames are forwarded as-is) |
Bridging the two worlds:
- Already working: every libude tool can join a classic
vde_switch(udeping -L -s vde:///tmp/sw ...), andudelink 127.0.0.1:7500 vde:///tmp/swcables audeswitchto avde_switch. - Next: a libvdeplug plugin (
libvdeplug_ude.so, schemeude://). libvdeplug4 loadslibvdeplug_<scheme>.soplugins, so every existing VDE application (vde_plug, QEMU-nic vde, 86Box's VDE backend on Linux and macOS) could then connect to audeswitchwithude://127.0.0.1:7500. It also turnsvde_plug vde:///tmp/sw ude://127.0.0.1:7500into a ready-made VDE↔UDE bridge.
Testing
make test runs:
test_core: 508 checks on the engine, tables and protocol, with no sockets, plus libude's own IPv4 address parser and printer (against whatinet_ptonaccepts and rejects), endpoint strings and the clocks, including the capture and monitor messages (access policy and its default, errors, request ids, the capture hook seeing dropped and flooded frames once, monitors excluded from learning and flooding, MIRROR carrying the capture hook's exact record, the MIRROR encoding at the size limits, and-mcapped at the snap length), a HELLO repeated as a keepalive keeping the port, its id and MACs, refreshing it, and being logged at-vonly when the name changes, and the programs' long option tables copied with their end entry (ude_longopt_copy()), and introspection: 50 ports and 500 MACs listed over several pages each no larger than 1400 bytes, every item once and in order, a port's MACs, bad cursors, kicks by id, peer and name (the client told with ERROR 9, a name two ports share refused, the client coming back as a new port), flushing one MAC, one port's and all, empty lists, and everything refused under-A nonetest_pcapng: 53 checks on the pcapng writer, byte by byte: block layout, option padding, original lengths, a second section appended, write errors, the shared port comment and the file check.test_pcapng -d FILEprints every interface and packet field, for comparing capturestest_impair: 55 checks onudelink's impairment engine on simulated time with fixed seeds: the SPEC parser and its errors, loss within tolerance of the rate (also in bursts, with the expected mean burst length), the same seed giving the same losses, duplication, exactly one flipped bit per corrupted frame, the MTU, exact constant delay, jitter within its window with and without reordering, rate shaping spacing frames by their serialization time, and the drop-tail queuetest_libandtest_shared: the public API over a back-to-back UDP "crossover cable", once linked statically and once againstlibude.so(which checks the exported symbols), includingude_keepalive_hello()sending HELLO every interval while frames flow, and the management calls' checks of addresses and port selectors, and their timeouttest_net: 329 checks on the protocol codecs: the Internet checksum (RFC 1071 example and a real IPv4 header), address parsing, random MACs, and build/parse round trips for ARP, IPv4, ICMP (echo and errors), UDP (pseudo-header checksums) and DHCP (every option used), plus truncated, corrupted and fragmented packets; the DHCP client against a scripted server with and without a subnet mask option; the lease file format and loading rules; and network boot: sname, file and options 66, 67, 93 and 77 (both forms) and 175, and the boot file the server picks for BIOS, EFI and iPXE clients (efi64covers both 7 and 9; a numeric 9 entry beatsefi64)test_stackandtest_stack_shared: 111 checks with a DHCP server, three DHCP clients and a static host on a simulated hub, in simulated time (static and shared libraries). It covers leases from the pool and from a reservation, the options handed out, pings between all of them, UDP echo, ICMP port unreachable, fragment drop, ARP giving up after 3 requests, renewal at T1, release, losing the lease when the server is gone, a server restart from its lease file, and a router's use of libude-ipv4: static routes and their next hops, whole packets sent through ARP, and the callback for a next hop that never answerstest_route: 157 checks oncommon/ude_route.c, shared byudeslirpanduderouter: parsing routes and interfaces (switch URLs with commas, bad prefixes, network, broadcast and martian addresses, MACs), the default MAC, the table (duplicates, longest prefix match), the TTL update against a full checksum, and fragmentation (offsets, MF, copied and dropped options, DF, a too-small MTU)test_tftp: 91 checks onudetftpd's server engine on a simulated hub (POSIX only): file name cleaning, plain and negotiated transfers (OACK values, caps, ignored and out-of-range options), windows (a partial ACK, a duplicate ACK ignored, retransmission after the negotiated timeout), netascii with CR LF split across blocks, missing files,.., symbolic links in and out of the root, a directory, WRQ and bad modes refused, a lost ACK, giving up after the retries, a client's error, a stray packet (error 5), a repeated request, the transfer limit, and block number rollover (70001 blocks, lock-step and windowed)test_tcpandtest_tcp_shared: 223 checks on libude-tcp in simulated time. The segment codec; then one TCP against a scripted peer, segment by segment: the handshake and its retries, a reset for a closed port, RFC 5961 challenge ACKs, zero-window probes, retransmission backoff, half-close, TIME-WAIT, reset on close with unread data, ICMP destination unreachable during a connection attempt; then two TCPs over a hub that loses, duplicates and reorders frames: 1.5 MB plus 300 KB on a clean link, 1.2 MB and 1 MB at once with 3% loss, 2% duplicates and 5% reordering, 15% loss, and five connections on one listener. Every byte is checked../test_tcp SEEDruns the lossy parts with another random sequence. Last, the router features: proxy ARP and replies from the address a packet was sent to, a listener for any address that defers the handshake (the SYN retransmitted while undecided, a reset on abort, silence on close, data both ways after a late confirm)tests/run_tests.sh: 305 end-to-end checks (318 with valgrind) with a realudeswitchandudecat(the internal test client,tests/udecat.c),udectl,udedump,udelink,udeping,udenc,udedhcpd,udetftpd,udeslirpanduderouterprocesses, andudetftp(the internal TFTP client,tests/udetftp.c). It needs no scripting language (no Python):udecatsends the bursts, runts and raw datagrams. It covers the-V/--versionoutput and exit status of every program (udetap where it is built; it answers before touching a TAP device, so no root is needed),--helpand an unknown long option exiting without a crash, the same three under valgrind when it is installed (it reports reads of uninitialized memory that happen not to crash), the build-tree wrapper run from another directory, flooding of broadcast and unknown unicast, learning then unicast-only delivery, no hairpin, MAC moves, idle-client timeout with MAC flush while keepalives keep other ports alive, automatic keepalives everyIDLE_TIMEOUT/2and none with-T 0(which still acks them), BYE, hub mode, oversized frame drop, require-HELLO, clean SIGINT shutdown, L2 ping, the same tools over a realvde_switch(skipped if VDE isn't installed), and an IPv4 network: two DHCP clients get leases (one reserved), ping each other and the server, a static host pings too, leases renew and are released on exit, a client without a server times out, andudedhcpd -fkeeps leases across a restart.udeslirp(sharing the subnet withudedhcpd): pings to the gateway and the DNS address, 1.5 MB and 400 KB through outbound NAT to the host's loopback and back in through a TCP port forward, byte for byte, refused ports as resets, idle TCP reset, UDP both ways through NAT and a UDP forward, the DNS relay, UDP mapping expiry,--deny, outside pings refused without ICMP sockets and relayed in a user namespace where they can be allowed, a default forward reachable on a non-loopback host address,--bindto 127.0.0.1 and to a host address (the source seen by a host listener),--host-loopbackwith a non-loopback bind, and bad forwards and--bindvalues. One configuration file startsudedhcpd(next_server,boot_file),udetftpdandudeslirp(forward,deny) with-Cand withUDE_CONFIG, an instance and the command line overriding it, and--print-config,--check-configand bad values are checked.uderouterbetween two switches: pings across (TTL 63) and to its far address,udeping -t 1getting time exceeded, network and host unreachable (a silent host and a silent gateway),--no-icmp-errors,-q, the statistics, refused interfaces and routes, and a configuration file (arrays, no--switchfrom[global]); then chained withudeslirp --routeon a third switch: a ping and 200 KB and 50 KB of TCP from one subnet out through NAT to the host and back in through a port forward to the other subnet, byte for byte.udencis checked againstnc's behaviour: TCP with 200 KB and 100 KB both ways intact,-vmessages, no FIN without-Nuntil-wexpires,-kserving two clients in turn, a reset ("Connection refused") from a closed port, a-zscan, death by SIGINT, a-wconnect timeout, UDP both ways with the listener locking onto its first sender, Debian's-q, andnc's argument errors. Capture:udeswitch -wrecords the expected frames,udectlstops, restarts (a second section) and rotates it and refuses to overwrite a text file,udedumpreceives each frame once in switch mode while unicast between two other clients is still not flooded to a third and shows each frame's ingress port,udedump -w -cwrites pcapng, the default-A nonerefuses both tools, and for the same trafficudedump -wandudeswitch -wwrite identical interface and packet records (compared field by field withtest_pcapng -d, and withtsharkif it is installed), also at the size limits: a 65200-byte frame whole, 65400- and 65507-byte datagrams cut to 65200, and runts of 5 and 0 bytes (sent withudecat raw). Introspection:udectl portsandmacs(plain and-p) against two named clients,macs PORT,flush MAC,kick ADDR:PORT(the client receives ERROR 9 and the switch logs and counts it), a second kick failing, flushing the whole table while the ports stay, usage errors,udectl -hlisting the commands, and 40 ports with 300 MACs read over several pages with every item once (40udecatclients).udelinkbetween two switches: flooding and MAC learning across the link (unicast reaches only its port on the far side), the port names, a restart of the far switch (with-R) after which the link says HELLO again and frames flow, BYE and counters on exit, a loop of two links warned about and its storm cut, the standard input/output stream both ways with a55:44:45frame dropped (the stream built withprintf), usage errors and-h; and if VDE is installed, a link to avde_switchboth ways, through a restart of thevde_switch, and overdpipewithvde_plug(given a plain socket path, which the classic vde-2vde_plugand vdeplug4's both take). Link impairment through two switches: a delay in one direction only, 100% and (seeded, repeatable) 50% loss, duplication, the MTU, corruption in one direction, rate limiting with queue drops, the counters of each, and bad SPECs. TFTP:udedhcpd -B -bnaming the boot file, transfers compared byte for byte at 512 and 1468 bytes with a window of 8 and tsize, caps on blksize and windowsize, netascii, 70001 blocks (rollover), a lost ACK, three transfers at once, a missing file,..and a symbolic link out of the root refused, one inside served, WRQ refused, a transfer through audelinklosing 10% of the frames, usage errors and the counters on exit. Logs go totest-logs/.
The IPv4 parts are skipped when the protocol libraries are disabled.
udecat (tests/udecat.c) is an internal test and debug client, not a
tool for users. make test builds it (with a wrapper in a dynamically linked
build, like the programs) and make install does not install it. It sends
Ethernet frames through libude: send src=MAC dst=MAC [type=0x88b5]
[data=TEXT|hex=HEX] [len=N] [count=N] [inc] [nopad] (len pads or cuts the
frame to N bytes, up to 65535; count repeats it; inc counts the last two
bytes of src up, one per frame), prints the frames it receives (wait MS,
listen), and sends HELLO (-H, -n NAME, hello) or leaves without BYE
(-B). raw [hex=HEX] [len=N] [count=N] sends a UDP datagram straight to a
udeswitch with none of libude's checks, so that runts, a 0-byte datagram or
one longer than any frame can be sent. udecat -h lists everything.
A Windows build can't run these on the build machine. Its make test instead
runs tests/check_imports.sh on every program, DLL and test program, which
fails on an import that Windows NT 4.0 or 95 lacks or on PE headers that ask
for a newer Windows (see "Windows versions"). The test programs run under
Wine or on Windows.
Roadmap
- libvdeplug plugin
ude://, which makes UDE usable from QEMU, vde_plug and 86Box (VDE backend) right away. - 86Box integration: a native
net_ude.cbackend built on libude, which also works on Windows where 86Box has no VDE. Settings: switch address and an optional name. - Authentication (opt-in; the switch stays open by default): HMAC challenge-response, then sealed data (see Security).
- Network services on the protocol libraries (each runs on UDE or VDE):
- More protocol libraries, names reserved:
libude-ipv6: IPv6 with neighbour discovery and SLAAC
- Switch features: VLANs (802.1Q-aware ports), per-port
mirroring (monitors that see only some ports), IPv6 endpoints, rate limits, a Windows
service wrapper, and
recvmmsgbatching.
Author
Mike Swanson
License
Licensed under the ISC license (see COPYING). The vendored autosetup/ is BSD-2-Clause. The vendored extsrc/tomlc17 is MIT (see extsrc/LICENSE.tomlc17).