feat(network): add IPvlan and Macvlan modes with DHCP and host access - #271
feat(network): add IPvlan and Macvlan modes with DHCP and host access#271ericma15 wants to merge 10 commits into
Conversation
yoshi3jp
left a comment
There was a problem hiding this comment.
This PR appears to be in conflict with the project policy.
Android, both in the Kernel and in the userland, is not suited for this kind of network topology, in my opinion.
I'm not sure about whether default android kernel support macvlan or ipvlan. it is just a true virtual device in linux kernel like veth. it has better performance and cost low cpu than a nat (no repacket packet and no ct entry). they are basic network solution in many container network solution.,like docker. does this project only for standard google gki kernel without any other kernerl conifg (except some must have)? |
Summary
This PR adds native IPvlan and Macvlan networking support to Droidspaces
across the backend, CLI, socket API, Android UI, configuration storage,
capability checks, and documentation.
The new modes give containers direct Layer 2 access to the Android host's
upstream network without using Droidspaces NAT or sharing the host network
namespace.
Motivation
The existing networking modes cover:
host: shares the Android network namespacenat: provides isolated networking behind Droidspaces NATnone: disables networkinggateway: delegates networking through another containerHowever, there was no way for a container to appear directly on the physical
LAN and obtain an address from the external router.
IPvlan and Macvlan fill this gap:
with Wi-Fi hardware.
reservations and Layer 2 identity where the underlying network supports it.
What changed
New networking modes
Added:
Both modes create a child link from an Android host interface and move it into
the container network namespace as
eth0.The parent interface can be explicitly configured:
When omitted, Droidspaces automatically detects the active Android uplink.
DHCP and static addressing
Direct L2 modes support two addressing methods:
For DHCP mode, Droidspaces does not run its embedded NAT DHCP server. Instead,
the container's own NetworkManager, systemd-networkd, dhcpcd, or equivalent
client requests an address directly from the external router.
Static configuration supports:
The existing IPv6-disable option is also honored.
Stable DHCP identity for IPvlan
IPvlan interfaces share the parent MAC address. Using the MAC as the DHCP
client identifier would make Android and multiple containers appear as the
same DHCP client.
For systemd-networkd guests, this PR therefore generates:
The identity is derived from the container UUID and remains stable across
restarts. Legacy containers without a UUID use a deterministic container-name
fallback.
Some routers ignore DHCP option 61 and identify clients only by MAC address.
The Android UI displays a warning for this limitation.
Optional Macvlan MAC address
Macvlan supports an optional user-provided unicast MAC:
When omitted, the kernel-selected address is left unchanged. This can be used
with router-side DHCP reservations.
Guest network-manager policy
The per-boot network-service policy now distinguishes networking modes:
host,none, and direct-L2 static mode keep guest network managersblocked.
nat,gateway, and direct-L2 DHCP mode allow guest network managers tostart.
/run, so existing container imagesreceive the corrected policy without requiring re-extraction.
For PTP host access,
dshost0is marked unmanaged for both systemd-networkdand NetworkManager.
Host-to-container access
Linux normally isolates a Macvlan/IPvlan parent from its child interfaces.
Three host-access modes are provided:
noneKeeps the normal kernel parent/child isolation.
ptp— recommendedCreates a private point-to-point veth between Android and the container:
/30from a private169.254.0.0/16pooldshost0inside the container/32routes for the container's primary LAN addressThis does not add another address to the physical LAN.
shimCreates a shared host-side IPvlan or Macvlan sibling on the selected parent:
/32/32route for each container addressAndroid UI
The Android application now includes:
When Macvlan is selected, the UI always displays the Wi-Fi limitation:
Wi-Fi Macvlan and 4addr handling
A normal Wi-Fi STA generally cannot transmit frames using a second source MAC
address.
When Macvlan uses a
wlan*parent, Droidspaces makes a best-effort attempt torun:
Failure is logged but does not prevent the container from starting.
Both sides must support and enable 4-address/WDS mode:
Droidspaces can attempt to enable the phone side but cannot configure the
router. IPvlan does not require this because it shares the parent MAC address.
Kernel capability detection
The machine-readable requirements check now reports:
Support is determined using live Netlink capability probes rather than relying
only on
/proc/config.gz.The Android UI independently disables IPvlan or Macvlan when the corresponding
backend capability is unavailable. These are optional feature requirements and
do not prevent Droidspaces from using the existing network modes.
Required kernel options are documented as:
CLI and socket API
The new fields are supported by:
Windows build reliability
The repository now forces Unix line endings for shell scripts:
This prevents Android assets built from a Windows checkout from receiving a
CRLF shebang such as
#!/system/bin/sh\r, which otherwise fails at runtimewith
No such file or directory.Compatibility
Existing networking modes and existing container configurations retain their
previous defaults and behavior.
Direct L2 defaults are:
No host-access interfaces or routes are created unless explicitly requested.
The embedded Droidspaces DHCP server remains limited to NAT mode; IPvlan and
Macvlan DHCP requests go directly to the external network.
Testing
The following were tested on a rooted Android aarch64 device:
CONFIG_IPVLANcapability probeCONFIG_MACVLANcapability probeiw dev wlan0 set 4addr onrequestEnd-to-end Macvlan over Wi-Fi remains dependent on phone driver/firmware and
router-side 4addr/WDS support. This limitation is explicitly surfaced in the
UI and runtime logs.
Known limitations
allocate separate leases even when a unique DUID is provided.(Need router support rfc4361,find some old tplink and firehome not supported,can set a static ip instead)
access point.
container.
direct-L2 IPv6 traffic remains independent of the host-access helper.
Test on my Oneplus 9R with ColorOs 15 (modify) with self-compiled kernel 4.19.325-perf+
Router: xiaomi be7000
IPvlan Mode all pass
Macvlan Mode lack a 4addr support router,so arp cannot pass.