[PR #5807] [client] Fix NetworkAddresses discovery on Android and re-sync on network change #23970

Open
opened 2026-08-05 06:08:05 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/5807
Author: @MichaelUray
Created: 4/6/2026
Status: 🔄 Open

Base: mainHead: fix/android-network-addresses


📝 Commits (10+)

  • 90b70e5 fix(client): fix NetworkAddresses discovery on Android and re-sync on network change
  • 3ae6931 fix(client): address coderabbitai review on NetworkAddresses resync
  • 9fb609e fix(client): use ExternalIFaceDiscover for Android network addresses
  • 3dc24af fix(client): inject IFaceDiscover into root context for login-path network addresses
  • b4a69c2 fix(client): extract networkAddressWatchInterval constant
  • dabf64c fix(client): address CodeRabbit review on NetworkAddresses resync
  • ca0b06d fix(client): pass ctx to networkAddresses on FreeBSD and fix codespell
  • 9583bd2 Merge remote-tracking branch 'upstream/main' into fix/android-network-addresses
  • 60e1a9f fix(client): pass ctx to networkAddresses on iOS after merging main
  • 446a428 Merge remote-tracking branch 'upstream/main' into fix/android-network-addresses

📊 Changes

15 files changed (+586 additions, -17 deletions)

View changed files

📝 .gitignore (+2 -0)
📝 client/android/client.go (+34 -0)
📝 client/internal/engine.go (+169 -8)
client/internal/network_address_sync_test.go (+102 -0)
📝 client/system/info.go (+14 -0)
📝 client/system/info_android.go (+6 -0)
📝 client/system/info_darwin.go (+1 -1)
📝 client/system/info_freebsd.go (+1 -1)
📝 client/system/info_ios.go (+7 -0)
📝 client/system/info_linux.go (+1 -1)
📝 client/system/info_test.go (+25 -1)
📝 client/system/info_windows.go (+1 -1)
📝 client/system/network_addr.go (+21 -4)
client/system/network_addresses.go (+26 -0)
client/system/network_addresses_android.go (+176 -0)

📄 Description

Summary

Two issues prevented posture checks from working on Android:

  1. net.Interfaces() broken on Android 11+: SELinux blocks NETLINK_ROUTE sockets (golang/go#40569). Use wlynxg/anet (already an indirect dependency via pion/ice) as drop-in replacement on Android.
  2. MAC address filter skipped all interfaces: Android 10+ returns empty HardwareAddr for all interfaces, causing the MAC-based filter to skip everything. Removed the filter since loopback is already filtered by IP and MAC is only metadata not used for posture check matching.
  3. No re-sync on network change: When a mobile device switches between WiFi and cellular, NetworkAddresses changed but were never re-synced with the management server. Added a 10s network address watcher goroutine with 30s debounce that detects changes and triggers SyncMeta.

Includes unit tests for networkAddressesEqual() and networkAddresses().

Fixes #3614 #2962

Checklist

  • Bug fix
  • Create tests that fail without the change: added unit tests for address comparison and discovery
  • Documentation is not needed for this change (internal client behavior, no user-facing API or configuration change)

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

Related #3968 — Posture checks peer network range failed on iPhone (Android side)
Related #4657 — iOS Client loses all routes when Posture Checks enabled (Android side)
Related #5810 — Feature Request: Expose peer LAN network addresses via API

Summary by CodeRabbit

  • New Features

    • Android can trigger immediate metadata re-syncs when the underlying network changes.
    • Periodic background detection of local network changes prompts resyncs.
  • Bug Fixes

    • More reliable, debounced detection of network-address changes to reduce missed or duplicate updates.
    • Network discovery now respects caller context, captures interface MACs, and avoids loopback addresses or duplicates.
  • Tests

    • Added tests for address comparison and uniqueness.
  • Chores

    • Updated .gitignore to exclude build and generated docs directories.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/5807 **Author:** [@MichaelUray](https://github.com/MichaelUray) **Created:** 4/6/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/android-network-addresses` --- ### 📝 Commits (10+) - [`90b70e5`](https://github.com/netbirdio/netbird/commit/90b70e534a60bb5868cab7f165c4a9fd60ffc078) fix(client): fix NetworkAddresses discovery on Android and re-sync on network change - [`3ae6931`](https://github.com/netbirdio/netbird/commit/3ae6931e44f1ab6dcd1e3b618807fd306aef339b) fix(client): address coderabbitai review on NetworkAddresses resync - [`9fb609e`](https://github.com/netbirdio/netbird/commit/9fb609ef46c64ed9e06488639461978d60551a20) fix(client): use ExternalIFaceDiscover for Android network addresses - [`3dc24af`](https://github.com/netbirdio/netbird/commit/3dc24af0a269c688ed3fb84d30adbaffb93520da) fix(client): inject IFaceDiscover into root context for login-path network addresses - [`b4a69c2`](https://github.com/netbirdio/netbird/commit/b4a69c2c4f1e800e17392b554c05f1146274356b) fix(client): extract networkAddressWatchInterval constant - [`dabf64c`](https://github.com/netbirdio/netbird/commit/dabf64ccfef9460cfe0fb1371dbd6cb59505a429) fix(client): address CodeRabbit review on NetworkAddresses resync - [`ca0b06d`](https://github.com/netbirdio/netbird/commit/ca0b06de265f7ffdb931c731a50b2976b7f161d4) fix(client): pass ctx to networkAddresses on FreeBSD and fix codespell - [`9583bd2`](https://github.com/netbirdio/netbird/commit/9583bd29f816d3061e5a3adfdf7ff707108a703b) Merge remote-tracking branch 'upstream/main' into fix/android-network-addresses - [`60e1a9f`](https://github.com/netbirdio/netbird/commit/60e1a9fae7803f95fd4f641b981e5d5582aae240) fix(client): pass ctx to networkAddresses on iOS after merging main - [`446a428`](https://github.com/netbirdio/netbird/commit/446a42891401c2f4cf53515d32b3c58fc0c23244) Merge remote-tracking branch 'upstream/main' into fix/android-network-addresses ### 📊 Changes **15 files changed** (+586 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+2 -0) 📝 `client/android/client.go` (+34 -0) 📝 `client/internal/engine.go` (+169 -8) ➕ `client/internal/network_address_sync_test.go` (+102 -0) 📝 `client/system/info.go` (+14 -0) 📝 `client/system/info_android.go` (+6 -0) 📝 `client/system/info_darwin.go` (+1 -1) 📝 `client/system/info_freebsd.go` (+1 -1) 📝 `client/system/info_ios.go` (+7 -0) 📝 `client/system/info_linux.go` (+1 -1) 📝 `client/system/info_test.go` (+25 -1) 📝 `client/system/info_windows.go` (+1 -1) 📝 `client/system/network_addr.go` (+21 -4) ➕ `client/system/network_addresses.go` (+26 -0) ➕ `client/system/network_addresses_android.go` (+176 -0) </details> ### 📄 Description ## Summary Two issues prevented posture checks from working on Android: 1. **`net.Interfaces()` broken on Android 11+**: SELinux blocks `NETLINK_ROUTE` sockets ([golang/go#40569](https://github.com/golang/go/issues/40569)). Use `wlynxg/anet` (already an indirect dependency via pion/ice) as drop-in replacement on Android. 2. **MAC address filter skipped all interfaces**: Android 10+ returns empty `HardwareAddr` for all interfaces, causing the MAC-based filter to skip everything. Removed the filter since loopback is already filtered by IP and MAC is only metadata not used for posture check matching. 3. **No re-sync on network change**: When a mobile device switches between WiFi and cellular, NetworkAddresses changed but were never re-synced with the management server. Added a 10s network address watcher goroutine with 30s debounce that detects changes and triggers `SyncMeta`. Includes unit tests for `networkAddressesEqual()` and `networkAddresses()`. Fixes #3614 #2962 ## Checklist - [x] Bug fix - [x] Create tests that fail without the change: added unit tests for address comparison and discovery - [x] Documentation is **not needed** for this change (internal client behavior, no user-facing API or configuration change) By submitting this pull request, I confirm that I have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Related Issues Related #3968 — Posture checks peer network range failed on iPhone (Android side) Related #4657 — iOS Client loses all routes when Posture Checks enabled (Android side) Related #5810 — Feature Request: Expose peer LAN network addresses via API <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Android can trigger immediate metadata re-syncs when the underlying network changes. * Periodic background detection of local network changes prompts resyncs. * **Bug Fixes** * More reliable, debounced detection of network-address changes to reduce missed or duplicate updates. * Network discovery now respects caller context, captures interface MACs, and avoids loopback addresses or duplicates. * **Tests** * Added tests for address comparison and uniqueness. * **Chores** * Updated .gitignore to exclude build and generated docs directories. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 06:08:05 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#23970