Skip to content

Conversation

@doromaraujo
Copy link
Collaborator

@doromaraujo doromaraujo commented Oct 8, 2025

Describe your changes

Allows user to toggle network resources on android client via exported functions.

Since we can't update the routes table on android's tun interface after creating a VPN when a network route change is detected, this also exports a function to renew the tun.Device's file descriptor used in android devices with a new implementation of WireGuard's tun.Device interface.

RenewableTUN is used in place of the created unmonitored tun on client/iface/device/device_android's Create function when passing a tun.Device to WGTunDevice's filteredDevice field. The unmonitored tun is added as a device to RenewableTUN, which manages a queue of tun.Devices internally.

Every call to a tun.Device method implemented by RenewableTUN uses the latest queued tun.Device's implementation.

When renewing a file descriptor in device_android, a new unmonitored tun is created with it, then it is added to RenewableTUN, deferring closure of the oldest tun.Device managed by it.

This also fixes a bug that didn't allow android clients to properly save its current profile's state with the same approach
used in iOS.

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

pappz and others added 20 commits September 23, 2025 19:29
To return information regarding if the network route is selected for a
given peer or not
Android has the same limitation as iOS in regard to file creation, so
it can't create the state file at the default location returned by
ServiceManager's GetStatePath (/var/lib/netbird/state.json)
Added to iface_create.go and iface_create_darwin.go
Since this is only used in android's context, it throws an error
when those implementations are called
…paths

This was done to lower the amount of parameters passed to
android/client's NewClient function
@doromaraujo doromaraujo requested a review from pappz October 9, 2025 03:14
closeAwareDevice adds a bool indicating whether its
wrapped tun.Device's Close method was called.

This was done so that when the engine reads or writes
from a device, it won't receive an error if the device
has already been closed in order to not call RenewableTUN
Close method (which will close all devices)
@sonarqubecloud
Copy link

@doromaraujo doromaraujo requested a review from pappz October 18, 2025 00:20
log.Debugf("error reading from device: %v", err)

if device.IsClosed() {
err = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, we will lose packages. Right? We should solve this somehow.
I see multiple options.

  • Syncrhonize the AddDevice and Read, Write functions. So the r.peekLast will provide an up-to-date device.
  • In case of error, retry to read, write the package into, from a "newer" device if it is available. So rerun the r.peekLast() in a for loop while there are new devices.

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.

2 participants