postmarketos-base-ui: enable USB tethering v2
Compare changes
@@ -19,71 +19,17 @@ To achieve this, add a new NetworkManager Dispatcher event
@@ -95,40 +41,16 @@ index 93399cafb2..6cfa673500 100644
Enable USB tethering on postmarketOS' setup with unudhpcd and NetworkManager. Users can share their WWAN or WiFi iface of their phones with desktops/laptops over USB while still accessing the phone over USB with SSH.
Several Android/iOS phones allow you to share your WiFi or WWAN interface to a connected laptop/desktop over USB. This is similar to a WiFi hotspot, but over USB. As an user, you benefit from lower power consumption, no need to secure your hotspot, and you can share your WiFi connection as well. Bonus: US carriers cannot see that we're tethering and charge for this feature like on Android/iOS as we don't report this to the carrier like Android/iOS OS does :)
NetworkManager supports tethering out-of-the-box under the IPv4/IPv6 method shared
which spawns dnsmasq for DHCP requests from the connected client and DNS forwarding from the client to the DNS server configured on the phone. However, this heavily conflicts with postmarketOS setup in its initfs as unudhcpd also acts as DHCP server. Moreover, by default, NetworkManager does not manage USB Ethernet gadgets like we create in initfs.
This MR solves these problems as followed:
reapply
dispatcher action so we can add on the iface changes that are applied when a NetworkManager connection profile is changed. After a change to the connection profile, a reapply job needs to be executed which triggers the dispatcher action.manual
mode which is like in initfs, IP is static set to 172.16.42.1 for the phone, 172.16.42.2 for the connected client, iface becomes managed by NetworkManager and unudhcpd handles DHCP requests. If unudhcpd is not running, it gets spawned.shared
mode which is USB tethering, NetworkManager spawns dnsmasq and uses IP is 172.16.42.1 for the phone and a DHCP server for the connected client. The whole available range is used. If unudhcpd is running, it gets killed to avoid conflicts with dnsmasq. NetworkManager will also arrange the necessary configs so IP forwarding is enabled in the kernel and firewall. These configs are removed when tethering is disabled again.When the mode is changed, UDC of the gadget is reactivated to trigger a disconnect/connect event on the connected client. This way, we ensure that the client performs a DHCP request to request an IP from either unudhcpd or dnsmasq, depending on the mode. The script logs with logger
to syslog under the tag nm-tethering
.
No matter which mode is active, SSH login over USB still works as the phone still uses the same IP 172.16.42.1.
Checkout the branch and build it with pmbootstrap. mrtest
does not work as the CI times out, CI builds skipped.
To use this feature:
NM should now launch its own dnsmasq instance, configure the firewall to allow internet sharing over usb0. It will trigger a script to re-establish the USB ethernet connection with the desktop. This way, the desktop will get an IP in the 10.X.X.X range and also a DNS server to which it can send DNS queries for this connection. Normally, you should be able to access the Web over usb0 now if you have WiFi or WWAN turned ON on the phone.
autoconnect
property to true
.usb0
.Draft until these TODOs are addressed or a solution if on the way for them.
Fixes #1904 (moved)
Fixes unudhcpd#1 (moved)
Contributes to #1518
Superseeds !3301 (closed)
Tested on Plasma Mobile, but Settings cannot set the connection to shared mode and back. So only the CLI way is available there.
CC: @craftyguy