mirror of
git://f0xx.org/android_cast
synced 2026-07-29 07:20:00 +03:00
sync
This commit is contained in:
@@ -85,10 +85,13 @@ public final class RemoteAccessVpnService extends VpnService {
|
||||
String[] parts = address.split("/");
|
||||
b.addAddress(InetAddress.getByName(parts[0]),
|
||||
parts.length > 1 ? Integer.parseInt(parts[1]) : 32);
|
||||
} else {
|
||||
b.addAddress("10.66.66.2", 32);
|
||||
}
|
||||
b.addRoute("10.66.66.0", 24);
|
||||
for (String route : parseAllowedRoutes(wgConfig)) {
|
||||
String[] rp = route.split("/");
|
||||
if (rp.length >= 2) {
|
||||
b.addRoute(rp[0], Integer.parseInt(rp[1]));
|
||||
}
|
||||
}
|
||||
b.setMtu(1280);
|
||||
tun = b.establish();
|
||||
Log.i(TAG, "VPN interface established");
|
||||
@@ -105,6 +108,25 @@ public final class RemoteAccessVpnService extends VpnService {
|
||||
return m.find() ? m.group(1).trim() : null;
|
||||
}
|
||||
|
||||
/** Routes from AllowedIPs= lines (split tunnel — typically server wg /32). */
|
||||
private static String[] parseAllowedRoutes(String wgConfig) {
|
||||
if (wgConfig == null) {
|
||||
return new String[0];
|
||||
}
|
||||
Matcher m = Pattern.compile("(?m)^AllowedIPs\\s*=\\s*(.+)$").matcher(wgConfig);
|
||||
if (!m.find()) {
|
||||
return new String[0];
|
||||
}
|
||||
String[] parts = m.group(1).trim().split("\\s*,\\s*");
|
||||
java.util.ArrayList<String> out = new java.util.ArrayList<>();
|
||||
for (String p : parts) {
|
||||
if (!p.isEmpty()) {
|
||||
out.add(p.trim());
|
||||
}
|
||||
}
|
||||
return out.toArray(new String[0]);
|
||||
}
|
||||
|
||||
private void tearDown() {
|
||||
if (tun != null) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user