Remove host IP from related VPN classes.
...since the daemon (racoon) gets the information by itself.
This commit is contained in:
@@ -30,12 +30,11 @@ class L2tpIpsecPskService extends VpnService<L2tpIpsecPskProfile> {
|
|||||||
@Override
|
@Override
|
||||||
protected void connect(String serverIp, String username, String password)
|
protected void connect(String serverIp, String username, String password)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
String hostIp = getHostIp();
|
|
||||||
L2tpIpsecPskProfile p = getProfile();
|
L2tpIpsecPskProfile p = getProfile();
|
||||||
|
|
||||||
// IPSEC
|
// IPSEC
|
||||||
AndroidServiceProxy ipsecService = startService(IPSEC_DAEMON);
|
AndroidServiceProxy ipsecService = startService(IPSEC_DAEMON);
|
||||||
ipsecService.sendCommand(hostIp, serverIp, L2tpService.L2TP_PORT,
|
ipsecService.sendCommand(serverIp, L2tpService.L2TP_PORT,
|
||||||
p.getPresharedKey());
|
p.getPresharedKey());
|
||||||
|
|
||||||
sleep(2000); // 2 seconds
|
sleep(2000); // 2 seconds
|
||||||
|
|||||||
@@ -30,11 +30,9 @@ class L2tpIpsecService extends VpnService<L2tpIpsecProfile> {
|
|||||||
@Override
|
@Override
|
||||||
protected void connect(String serverIp, String username, String password)
|
protected void connect(String serverIp, String username, String password)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
String hostIp = getHostIp();
|
|
||||||
|
|
||||||
// IPSEC
|
// IPSEC
|
||||||
AndroidServiceProxy ipsecService = startService(IPSEC_DAEMON);
|
AndroidServiceProxy ipsecService = startService(IPSEC_DAEMON);
|
||||||
ipsecService.sendCommand(hostIp, serverIp, L2tpService.L2TP_PORT,
|
ipsecService.sendCommand(serverIp, L2tpService.L2TP_PORT,
|
||||||
getUserkeyPath(), getUserCertPath(), getCaCertPath());
|
getUserkeyPath(), getUserCertPath(), getCaCertPath());
|
||||||
|
|
||||||
sleep(2000); // 2 seconds
|
sleep(2000); // 2 seconds
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ class MtpdHelper {
|
|||||||
"linkname", VPN_LINKNAME,
|
"linkname", VPN_LINKNAME,
|
||||||
"name", username,
|
"name", username,
|
||||||
"password", password,
|
"password", password,
|
||||||
"ipparam", serverIp + "@" + vpnService.getGatewayIp(),
|
|
||||||
"refuse-eap", "nodefaultroute", "usepeerdns",
|
"refuse-eap", "nodefaultroute", "usepeerdns",
|
||||||
"idle", "1800",
|
"idle", "1800",
|
||||||
"mtu", "1400",
|
"mtu", "1400",
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import android.app.Notification;
|
|||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.NetworkUtils;
|
|
||||||
import android.net.vpn.VpnManager;
|
import android.net.vpn.VpnManager;
|
||||||
import android.net.vpn.VpnProfile;
|
import android.net.vpn.VpnProfile;
|
||||||
import android.net.vpn.VpnState;
|
import android.net.vpn.VpnState;
|
||||||
@@ -30,11 +29,8 @@ import android.util.Log;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.NetworkInterface;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,7 +65,6 @@ abstract class VpnService<E extends VpnProfile> {
|
|||||||
private String mVpnDns1 = "";
|
private String mVpnDns1 = "";
|
||||||
private String mVpnDns2 = "";
|
private String mVpnDns2 = "";
|
||||||
private String mOriginalDomainSuffices;
|
private String mOriginalDomainSuffices;
|
||||||
private String mHostIp;
|
|
||||||
|
|
||||||
private long mStartTime; // VPN connection start time
|
private long mStartTime; // VPN connection start time
|
||||||
|
|
||||||
@@ -107,14 +102,6 @@ abstract class VpnService<E extends VpnProfile> {
|
|||||||
return mProfile;
|
return mProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the host IP for establishing the VPN connection.
|
|
||||||
*/
|
|
||||||
protected String getHostIp() throws IOException {
|
|
||||||
if (mHostIp == null) mHostIp = reallyGetHostIp();
|
|
||||||
return mHostIp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the IP address of the specified host name.
|
* Returns the IP address of the specified host name.
|
||||||
*/
|
*/
|
||||||
@@ -122,21 +109,6 @@ abstract class VpnService<E extends VpnProfile> {
|
|||||||
return InetAddress.getByName(hostName).getHostAddress();
|
return InetAddress.getByName(hostName).getHostAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the IP address of the default gateway.
|
|
||||||
*/
|
|
||||||
protected String getGatewayIp() throws IOException {
|
|
||||||
Enumeration<NetworkInterface> ifces =
|
|
||||||
NetworkInterface.getNetworkInterfaces();
|
|
||||||
for (; ifces.hasMoreElements(); ) {
|
|
||||||
NetworkInterface ni = ifces.nextElement();
|
|
||||||
int gateway = NetworkUtils.getDefaultRoute(ni.getName());
|
|
||||||
if (gateway == 0) continue;
|
|
||||||
return toInetAddress(gateway).getHostAddress();
|
|
||||||
}
|
|
||||||
throw new IOException("Default gateway is not available");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the system property. The method is blocked until the value is
|
* Sets the system property. The method is blocked until the value is
|
||||||
* settled in.
|
* settled in.
|
||||||
@@ -407,21 +379,6 @@ abstract class VpnService<E extends VpnProfile> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String reallyGetHostIp() throws IOException {
|
|
||||||
Enumeration<NetworkInterface> ifces =
|
|
||||||
NetworkInterface.getNetworkInterfaces();
|
|
||||||
for (; ifces.hasMoreElements(); ) {
|
|
||||||
NetworkInterface ni = ifces.nextElement();
|
|
||||||
int gateway = NetworkUtils.getDefaultRoute(ni.getName());
|
|
||||||
if (gateway == 0) continue;
|
|
||||||
Enumeration<InetAddress> addrs = ni.getInetAddresses();
|
|
||||||
for (; addrs.hasMoreElements(); ) {
|
|
||||||
return addrs.nextElement().getHostAddress();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new IOException("Host IP is not available");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void sleep(int ms) {
|
protected void sleep(int ms) {
|
||||||
try {
|
try {
|
||||||
Thread.currentThread().sleep(ms);
|
Thread.currentThread().sleep(ms);
|
||||||
|
|||||||
Reference in New Issue
Block a user