[RFC] Rethinkering USB tethering
What?
USB tethering allows to share your phone mobile data or WiFi connection over USB to any connected device. The connected device sees an USB ethernet adapter and can reach the Internet through it. This is different from the classic USB networking postmarketOS offered already for years where only a simple DHCP server (unudhpcd
) provided a fixed IP and allowed SSH traffic to login into the device remotely over USB.
In !3819 (merged), support for USB tethering was introduced by handing over the USB ethernet interface to NetworkManager once the device booted.
Problems
While this works fine in terms of functionality, it caused several issues after it was merged:
- !4400 no separate toggle for USB networking and USB ethernet
- #2290 Netboot hook is broken due to handover because the rootfs cannot be reached anymore. The handover simulates a disconnect to allow handing over the interface to NetworkManager
- #2483 A Samsung device broke because of the handover, probably a bug in some kernel driver, but still.
Thus, we need to rethinker USB tethering to avoid the handover and have more control over the interfaces.
Proposal
- Provide both NetworkManager and
unudhpcd
their own TAP interface they fully manage on their own. This way, NetworkManager can turn ON/OFF the USB tethering interface without doing a handover fromunudhcpd
and SSH login over USB still works if NetworkManager's setup breaks. - Route SSH and DHCP traffic to
unudhpcd
while other traffic is routed to NetworkManager usingnftables
. - On boot, we only have the
unudhcpd
TAP interface, later when the device is fully booted, NetworkManager will also have a TAP interface. Link them both to the original USB ethernet interface using a network bridge which is created at boot by the initramfs.
By doing this, both can co-exist without conflicting and doing handovers.
If USB tethering is disabled, the connected device will only be able to use SSH and DHCP as the USB tethering iface will be turned OFF by NetworkManager. The unudhcpd
iface remains active all the time.
Request For Comments
What do you think about this idea? This would hopefully solve a lot side-effects as listed above.
CC: @craftyguy