Skip to content

[client] Add IPv6 dual-stack support#148

Open
lixmal wants to merge 8 commits intomainfrom
feature/ipv6-support
Open

[client] Add IPv6 dual-stack support#148
lixmal wants to merge 8 commits intomainfrom
feature/ipv6-support

Conversation

@lixmal
Copy link
Copy Markdown
Contributor

@lixmal lixmal commented Mar 30, 2026

Add IPv6 dual-stack support to the Android client.

  • Expand TunAdapter.ConfigureInterface to accept an IPv6 address and add it to the VPN builder
  • Display peer IPv6 addresses in the peer list with a copy-to-clipboard option
  • Add a "Disable IPv6" toggle in Advanced settings
  • Point netbird submodule to the IPv6 branch

Summary by CodeRabbit

  • New Features

    • Peer IPv6 addresses shown in peer lists and a new "Copy IPv6" clipboard action.
    • Advanced Settings: toggle to disable IPv6 overlay addressing on the tunnel (persists).
    • TV-remote: remote control can toggle the IPv6 disable option.
    • Tunnel reconfiguration now supports assigning an IPv6 address when available.
  • Bug Fixes / Enhancements

    • Exit-node detection now recognizes IPv6 default routes.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 30, 2026

Warning

Rate limit exceeded

@lixmal has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 41 minutes and 4 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 41 minutes and 4 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 27314c95-e115-4667-8b2a-6355fe799d16

📥 Commits

Reviewing files that changed from the base of the PR and between 70eb8be and 8f3adec.

📒 Files selected for processing (2)
  • tool/src/main/java/io/netbird/client/tool/AndroidPlatformFiles.java
  • tool/src/main/java/io/netbird/client/tool/EngineRunner.java
📝 Walkthrough

Walkthrough

Adds IPv6 support across UI and tooling: new disable‑IPv6 preference and UI row, peer model and adapter show/copy IPv6, TUN/VPN tooling accepts and persists IPv6 address, NetworkChangeNotifier gains an IPv6 setter, and the netbird submodule pointer is bumped.

Changes

Cohort / File(s) Summary
Advanced Settings UI
app/src/main/java/io/netbird/client/ui/advanced/AdvancedFragment.java, app/src/main/res/layout/fragment_advanced.xml, app/src/main/res/values/strings.xml
Add layout_disable_ipv6 and switch_disable_ipv6; initialize from goPreferences.getDisableIPv6(), persist via goPreferences.setDisableIPv6(...) + commit, add TV-remote toggle handling and strings.
Peer Model & List UI
app/src/main/java/io/netbird/client/ui/home/Peer.java, app/src/main/java/io/netbird/client/ui/home/PeersAdapter.java, app/src/main/java/io/netbird/client/ui/home/PeersFragmentViewModel.java, app/src/main/res/menu/peer_clipboard_menu.xml
Add ipv6 field and getIpv6() to Peer; viewmodel constructs Peer with IPv6; adapter displays IPv6 under IPv4 when present and enables copy_ipv6 menu item/handler.
Resource Detection
app/src/main/java/io/netbird/client/ui/home/Resource.java
isExitNode() now guards null address and treats presence of "0.0.0.0/0" or "::/0" in address as an exit node.
VPN/TUN Interface Logic
tool/src/main/java/io/netbird/client/tool/IFace.java, tool/src/main/java/io/netbird/client/tool/TUNParameters.java, tool/src/main/java/io/netbird/client/tool/NetworkChangeNotifier.java, tool/src/main/java/io/netbird/client/tool/VPNService.java
Add addressV6 parameter/field; configureInterface/createTun accept/parse optional IPv6 and add IPv6 to VPN builder when present; append IPv6 blackhole ::/0 when IPv4 default route present and no IPv6; TUNParameters stores addressV6; NetworkChangeNotifier adds setInterfaceIPv6.
Menu & Strings
app/src/main/res/menu/peer_clipboard_menu.xml, app/src/main/res/values/strings.xml
Add copy_ipv6 menu item and peers_clipboard_copy_ipv6, plus advanced setting strings for disable IPv6.
Dependencies
netbird (git submodule)
Bump netbird submodule pointer to a newer commit.

Sequence Diagram(s)

sequenceDiagram
    participant User as "User (UI)"
    participant Advanced as "AdvancedFragment"
    participant Prefs as "goPreferences"
    participant VM as "PeersFragmentViewModel"
    participant Adapter as "PeersAdapter"
    participant Clipboard as "Clipboard"
    participant VPN as "VPNService"
    participant IFace as "IFace / TUN builder"

    User->>Advanced: Toggle Disable IPv6
    Advanced->>Prefs: setDisableIPv6(isChecked) + commit
    Prefs-->>Advanced: ack

    VM->>Adapter: bind Peer(status, ip, ipv6, fqdn)
    Adapter->>User: display IPv4\nIPv6 (if present)
    User->>Adapter: long-press -> copy IPv6
    Adapter->>Clipboard: copy "IPv6 Address"

    VPN->>IFace: configureInterface(address, addressV6, mtu, dns, routes)
    IFace->>IFace: parse addrV6, add IPv6 addr to builder or append ::/0 route
    IFace-->>VPN: tunFd / success
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • mlsmaycon

Poem

🐇 I hopped through lines to add a second lane,
Gave peers a tiny IPv6 name.
A switch to hush the extra route,
TUN learnt to speak both stacks no doubt.
Clipboard copies now pair with a twitch.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and directly summarizes the main objective of the changeset: adding IPv6 dual-stack support across the Android client.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/ipv6-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@lixmal lixmal force-pushed the feature/ipv6-support branch from fa435ce to 3f573e8 Compare March 30, 2026 17:38
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/src/main/java/io/netbird/client/ui/home/Resource.java`:
- Around line 38-40: The isExitNode method in class Resource can NPE and misses
IPv6 when multiple addresses are present; update Resource.isExitNode to be
null-safe and use the same containment logic for both IPv4 and IPv6 (e.g., check
address != null and then address.contains("0.0.0.0/0") ||
address.contains("::/0")) so both "0.0.0.0/0,::/0" and "::/0,10.0.0.0/8" are
detected consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 07976be7-06ad-4c85-aeb7-69281ce165ee

📥 Commits

Reviewing files that changed from the base of the PR and between f7e1c65 and 3f573e8.

📒 Files selected for processing (13)
  • app/src/main/java/io/netbird/client/ui/advanced/AdvancedFragment.java
  • app/src/main/java/io/netbird/client/ui/home/Peer.java
  • app/src/main/java/io/netbird/client/ui/home/PeersAdapter.java
  • app/src/main/java/io/netbird/client/ui/home/PeersFragmentViewModel.java
  • app/src/main/java/io/netbird/client/ui/home/Resource.java
  • app/src/main/res/layout/fragment_advanced.xml
  • app/src/main/res/menu/peer_clipboard_menu.xml
  • app/src/main/res/values/strings.xml
  • netbird
  • tool/src/main/java/io/netbird/client/tool/IFace.java
  • tool/src/main/java/io/netbird/client/tool/NetworkChangeNotifier.java
  • tool/src/main/java/io/netbird/client/tool/TUNParameters.java
  • tool/src/main/java/io/netbird/client/tool/VPNService.java

Comment thread app/src/main/java/io/netbird/client/ui/home/Resource.java
lixmal and others added 4 commits March 30, 2026 19:53
Use contains() for IPv6 check to match IPv4 logic, so multi-address
strings like "0.0.0.0/0,::/0" are handled correctly. Add null guard
for address field.
# Conflicts:
#	app/src/main/java/io/netbird/client/ui/home/PeersFragmentViewModel.java
#	netbird
pappz
pappz previously approved these changes Apr 15, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tool/src/main/java/io/netbird/client/tool/IFace.java`:
- Around line 80-82: The current logic only adds a blackhole ::/0 when addrV6 ==
null and hasIPv4DefaultRoute(routes) is true, but the presence of an IPv6
address is not the right signal — we must add the ::/0 blackhole whenever there
is an IPv4 default route and there is no IPv6 default route. Change the
condition in IFace where routes are built: replace the addrV6 == null check with
a check for absence of an IPv6 default route (e.g., !hasIPv6DefaultRoute(routes)
or !routes.stream().anyMatch(r -> r.prefix.equals("::/0"))), so that if
hasIPv4DefaultRoute(routes) && no IPv6 /0 route then routes.add(new
Route("::/0")). Use or add a helper like hasIPv6DefaultRoute(routes) to mirror
hasIPv4DefaultRoute for clarity; keep Route and routes usage unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 08479a13-3a8b-4b3b-b88c-f6846203f348

📥 Commits

Reviewing files that changed from the base of the PR and between bce03cb and 70eb8be.

📒 Files selected for processing (2)
  • netbird
  • tool/src/main/java/io/netbird/client/tool/IFace.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • netbird

Comment on lines +80 to +82
if (addrV6 == null && hasIPv4DefaultRoute(routes)) {
routes.add(new Route("::/0"));
}
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot Apr 21, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n tool/src/main/java/io/netbird/client/tool/IFace.java | head -90

Repository: netbirdio/android-client

Length of output: 4092


🏁 Script executed:

cat -n tool/src/main/java/io/netbird/client/tool/IFace.java | sed -n '60,180p'

Repository: netbirdio/android-client

Length of output: 5157


🏁 Script executed:

fd -t f "Route\.java" --exec cat {} \;

Repository: netbirdio/android-client

Length of output: 396


Blackhole IPv6 based on missing ::/0 route, not missing IPv6 address.

The presence of an IPv6 interface address does not guarantee a ::/0 default route exists. With allowFamily(AF_INET6) enabled and an IPv4 default route (0.0.0.0/0), non-matching IPv6 traffic can fall through to the underlying network if no ::/0 route is present. Add the blackhole whenever 0.0.0.0/0 exists and no IPv6 /0 route exists, regardless of whether an IPv6 address is configured on the interface.

Proposed fix
-        if (addrV6 == null && hasIPv4DefaultRoute(routes)) {
+        if (hasIPv4DefaultRoute(routes) && !hasIPv6DefaultRoute(routes)) {
             routes.add(new Route("::/0"));
         }
-    // Blackhole IPv6 when the tunnel has an IPv4 default route but no IPv6
-    // address on the interface, to prevent IPv6 leaks around the tunnel.
+    // Blackhole IPv6 when the tunnel has an IPv4 default route but no IPv6
+    // default route, to prevent IPv6 leaks around the tunnel.
     private boolean hasIPv4DefaultRoute(LinkedList<Route> routes) {
         for (Route r : routes) {
             if ("0.0.0.0".equals(r.addr) && r.prefixLength == 0) {
                 return true;
             }
         }
         return false;
     }
+
+    private boolean hasIPv6DefaultRoute(LinkedList<Route> routes) {
+        for (Route r : routes) {
+            if (r.addr != null && r.addr.contains(":") && r.prefixLength == 0) {
+                return true;
+            }
+        }
+        return false;
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tool/src/main/java/io/netbird/client/tool/IFace.java` around lines 80 - 82,
The current logic only adds a blackhole ::/0 when addrV6 == null and
hasIPv4DefaultRoute(routes) is true, but the presence of an IPv6 address is not
the right signal — we must add the ::/0 blackhole whenever there is an IPv4
default route and there is no IPv6 default route. Change the condition in IFace
where routes are built: replace the addrV6 == null check with a check for
absence of an IPv6 default route (e.g., !hasIPv6DefaultRoute(routes) or
!routes.stream().anyMatch(r -> r.prefix.equals("::/0"))), so that if
hasIPv4DefaultRoute(routes) && no IPv6 /0 route then routes.add(new
Route("::/0")). Use or add a helper like hasIPv6DefaultRoute(routes) to mirror
hasIPv4DefaultRoute for clarity; keep Route and routes usage unchanged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In the hasIpv6 case mgmt will send a proper non black hole route as well

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@lixmal, thanks for the clarification! That makes sense — since the management server will always supply a proper IPv6 route when an IPv6 address is assigned to the interface, the addrV6 == null guard is the correct signal for when the blackhole is needed. The existing logic is intentional and correct. My apologies for the noise.


✏️ Learnings added
Learnt from: lixmal
Repo: netbirdio/android-client PR: 148
File: tool/src/main/java/io/netbird/client/tool/IFace.java:80-82
Timestamp: 2026-04-21T11:08:22.712Z
Learning: In `tool/src/main/java/io/netbird/client/tool/IFace.java` (netbirdio/android-client), the blackhole `::/0` route is intentionally added only when `addrV6 == null && hasIPv4DefaultRoute(routes)`. When an IPv6 address IS configured (`addrV6 != null`), the NetBird management server always sends a proper (non-blackhole) IPv6 route, so no blackhole is needed in that case. The `addrV6 == null` check is the correct condition to detect when mgmt won't send an IPv6 route.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

New PlatformFiles.CacheDir() method in the netbird submodule.
Pass context.getCacheDir() through from EngineRunner.
@lixmal lixmal deployed to android-release April 21, 2026 08:55 — with GitHub Actions Active
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