Skip to content

Commit

Permalink
Feature/exit node android (#14)
Browse files Browse the repository at this point in the history
* Support exit node feature

* Add protect socket
  • Loading branch information
pappz authored May 7, 2024
1 parent d57df27 commit 19fb27f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions android/tool/src/main/java/io/netbird/client/tool/IFace.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
class IFace implements TunAdapter {

private static final String LOGTAG = "IFace";
private final VPNService tunService;
private final VPNService vpnService;

public IFace(VPNService tunService) {
this.tunService = tunService;
public IFace(VPNService vpnService) {
this.vpnService = vpnService;
}

@Override
Expand All @@ -38,9 +38,13 @@ public long configureInterface(String address, long mtu, String dns, String sear
}
}

@Override
public boolean protectSocket(int fd) {
return vpnService.protect(fd);
}

private int createTun(String ip, int prefixLength, int mtu, String dns, String[] searchDomains, LinkedList<Route> routes) throws Exception {
VpnService.Builder builder = tunService.getBuilder();
VpnService.Builder builder = vpnService.getBuilder();
builder.addAddress(ip, prefixLength);
builder.allowFamily(OsConstants.AF_INET);
builder.allowFamily(OsConstants.AF_INET6);
Expand All @@ -56,7 +60,7 @@ private int createTun(String ip, int prefixLength, int mtu, String dns, String[]
Log.d(LOGTAG, "add route: "+r.addr+"/"+r.prefixLength);
}

disallowApp(builder, "com.google.android.projection.gearhead");
disallowApp(builder, "com.google.android.projection.gearhead");
disallowApp(builder, "com.google.android.apps.chromecast.app");
disallowApp(builder, "com.google.android.apps.messaging");
disallowApp(builder, "com.google.stadia.android");
Expand All @@ -65,7 +69,7 @@ private int createTun(String ip, int prefixLength, int mtu, String dns, String[]
builder.setMetered(false);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
tunService.setUnderlyingNetworks(null);
vpnService.setUnderlyingNetworks(null);
}

builder.setBlocking(true);
Expand All @@ -86,7 +90,7 @@ private void prepareDnsSetting(VpnService.Builder builder, String dns) {
return;
}

if(new DNSWatch(tunService).isPrivateDnsActive()) {
if(new DNSWatch(vpnService).isPrivateDnsActive()) {
Log.d(LOGTAG, "ignore DNS because private dns is active");
return;
}
Expand Down

0 comments on commit 19fb27f

Please sign in to comment.