Skip to content

Android build: libslirp (-netdev user) and DNS from the app - #146

Merged
dylanneve1 merged 1 commit into
mainfrom
net/libslirp-android
Nov 3, 2026
Merged

dylanneve1 merged 1 commit into
mainfrom
net/libslirp-android

Conversation

@dylanneve1

@dylanneve1 dylanneve1 commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Adds libslirp to the Android build so -netdev user exists, and gives it a way to find the resolver on Android.

  • native/build-android.sh: new build_libslirp step (libslirp 4.9.7, pinned tarball and sha256, built with meson_dep against our glib). QEMU is configured with -Dslirp=enabled for the executable and the in-process library. CI's configure log shows "slirp support: YES 4.9.7" for both.
  • native/patches/libslirp-android.patch: libslirp reads its resolvers from the file named in SLIRP_RESOLV_CONF instead of /etc/resolv.conf (unset means /etc/resolv.conf, as upstream). It also turns a g_error() (abort) on a refused socket into a warning.
  • CI and release dep caches are keyed on native/patches/** as well as the build script.
  • docs/NETWORKING.md: new section "libslirp on Android" that defines the interface for the app side (issue 83, PR 148): the app writes nameserver <addr> lines from LinkProperties.getDnsServers() to a private file, sets SLIRP_RESOLV_CONF before QEMU starts, and replaces the file with a rename on network changes. libslirp re-reads it when it changes, at most once a second. If there are no resolvers the app deletes the file.

APK size (debug APK from CI, against main at 0492bd5): 11,074,765 to 11,215,929 bytes, +141 KB (+1.3%). Each QEMU .so grows by about 128 KB uncompressed (libqemu-system-aarch64.so 12,459,888 to 12,588,272).

Tested:

  • Android emulator (sdk_gphone64_arm64, the CI APK's libqemu-system-aarch64.so run from adb shell): -netdev help lists user, and -netdev user,id=n0 is accepted. The binary has no virt machine (Inferno builds only the Apple machines), so no Linux guest could run on it.
  • Linux x86_64 host, end to end: Ubuntu's stock qemu-system-aarch64 (8.2.2) with the patched libslirp 4.9.7 loaded through LD_LIBRARY_PATH, -M virt with Debian trixie's arm64 netboot kernel and an initramfs that runs udhcpc, ping and wget, on -netdev user.
    • SLIRP_RESOLV_CONF file with nameserver 1.1.1.1: lease 10.0.2.15, router 10.0.2.2, DNS 10.0.2.3; example.com resolves and wget http://example.com/ returns the page.
    • File with nameserver 192.0.2.1 (unreachable): lease ok, example.com doesn't resolve. So the file is what slirp uses, not the host's /etc/resolv.conf.
    • File missing: lease ok, name resolution fails, QEMU keeps running and the guest shuts down normally.
  • A small harness on the static libslirp: IPv6 link-local with %scope is parsed, a rename over the file is picked up after the 1 s cache, and with the variable unset it reads /etc/resolv.conf.

Not tested:

  • DHCP and DNS from the Android build itself: there is no guest machine in it that can run without Apple files. The first real check is the t8030 guest with the Network setting (PR 148), on the emulator or the Pixel 10.
  • Behaviour without the INTERNET permission on Android. The code paths are ordinary socket() errors (EACCES): TCP gets a reset, UDP is dropped, and the one abort on that path is now a warning. Not run.

Closes #82

…LIRP_RESOLV_CONF

build-android.sh builds libslirp 4.9.7 (pinned tarball and sha256) and
configures QEMU with -Dslirp=enabled for the executable and the in-process
library. Android has no /etc/resolv.conf, so a small libslirp patch reads the
resolvers from the file named in SLIRP_RESOLV_CONF; the app writes it from
LinkProperties. The patch also turns an abort on a refused socket into a
warning. The dep caches are now keyed on native/patches too.

docs/NETWORKING.md describes the interface for the app side (#83).
@dylanneve1
dylanneve1 merged commit 7e7ab40 into main Nov 3, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android build: enable libslirp (-netdev user) and fix DNS on Android

2 participants