Merge "Remove SO_BINDTODEVICE from VPN protect" into klp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
8e240af51d
@@ -151,9 +151,10 @@ public class VpnService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Protect a socket from VPN connections. The socket will be bound to the
|
* Protect a socket from VPN connections. After protecting, data sent
|
||||||
* current default network interface, so its traffic will not be forwarded
|
* through this socket will go directly to the underlying network,
|
||||||
* through VPN. This method is useful if some connections need to be kept
|
* so its traffic will not be forwarded through the VPN.
|
||||||
|
* This method is useful if some connections need to be kept
|
||||||
* outside of VPN. For example, a VPN tunnel should protect itself if its
|
* outside of VPN. For example, a VPN tunnel should protect itself if its
|
||||||
* destination is covered by VPN routes. Otherwise its outgoing packets
|
* destination is covered by VPN routes. Otherwise its outgoing packets
|
||||||
* will be sent back to the VPN interface and cause an infinite loop. This
|
* will be sent back to the VPN interface and cause an infinite loop. This
|
||||||
|
|||||||
@@ -3658,8 +3658,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||||||
int user = UserHandle.getUserId(Binder.getCallingUid());
|
int user = UserHandle.getUserId(Binder.getCallingUid());
|
||||||
if (ConnectivityManager.isNetworkTypeValid(type) && mNetTrackers[type] != null) {
|
if (ConnectivityManager.isNetworkTypeValid(type) && mNetTrackers[type] != null) {
|
||||||
synchronized(mVpns) {
|
synchronized(mVpns) {
|
||||||
mVpns.get(user).protect(socket,
|
mVpns.get(user).protect(socket);
|
||||||
mNetTrackers[type].getLinkProperties().getInterfaceName());
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -284,13 +284,12 @@ public class Vpn extends BaseNetworkStateTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Protect a socket from routing changes by binding it to the given
|
* Protect a socket from VPN rules by binding it to the main routing table.
|
||||||
* interface. The socket is NOT closed by this method.
|
* The socket is NOT closed by this method.
|
||||||
*
|
*
|
||||||
* @param socket The socket to be bound.
|
* @param socket The socket to be bound.
|
||||||
* @param interfaze The name of the interface.
|
|
||||||
*/
|
*/
|
||||||
public void protect(ParcelFileDescriptor socket, String interfaze) throws Exception {
|
public void protect(ParcelFileDescriptor socket) throws Exception {
|
||||||
|
|
||||||
PackageManager pm = mContext.getPackageManager();
|
PackageManager pm = mContext.getPackageManager();
|
||||||
int appUid = pm.getPackageUid(mPackage, mUserId);
|
int appUid = pm.getPackageUid(mPackage, mUserId);
|
||||||
@@ -304,8 +303,6 @@ public class Vpn extends BaseNetworkStateTracker {
|
|||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(token);
|
Binder.restoreCallingIdentity(token);
|
||||||
}
|
}
|
||||||
// bind the socket to the interface
|
|
||||||
jniProtect(socket.getFd(), interfaze);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -684,7 +681,6 @@ public class Vpn extends BaseNetworkStateTracker {
|
|||||||
private native int jniSetRoutes(String interfaze, String routes);
|
private native int jniSetRoutes(String interfaze, String routes);
|
||||||
private native void jniReset(String interfaze);
|
private native void jniReset(String interfaze);
|
||||||
private native int jniCheck(String interfaze);
|
private native int jniCheck(String interfaze);
|
||||||
private native void jniProtect(int socket, String interfaze);
|
|
||||||
|
|
||||||
private static RouteInfo findIPv4DefaultRoute(LinkProperties prop) {
|
private static RouteInfo findIPv4DefaultRoute(LinkProperties prop) {
|
||||||
for (RouteInfo route : prop.getAllRoutes()) {
|
for (RouteInfo route : prop.getAllRoutes()) {
|
||||||
|
|||||||
@@ -302,15 +302,6 @@ static int check_interface(const char *name)
|
|||||||
return ifr4.ifr_flags;
|
return ifr4.ifr_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bind_to_interface(int socket, const char *name)
|
|
||||||
{
|
|
||||||
if (setsockopt(socket, SOL_SOCKET, SO_BINDTODEVICE, name, strlen(name))) {
|
|
||||||
ALOGE("Cannot bind socket to %s: %s", name, strerror(errno));
|
|
||||||
return SYSTEM_ERROR;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
static void throwException(JNIEnv *env, int error, const char *message)
|
static void throwException(JNIEnv *env, int error, const char *message)
|
||||||
@@ -433,19 +424,6 @@ static jint check(JNIEnv *env, jobject thiz, jstring jName)
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void protect(JNIEnv *env, jobject thiz, jint socket, jstring jName)
|
|
||||||
{
|
|
||||||
const char *name = jName ? env->GetStringUTFChars(jName, NULL) : NULL;
|
|
||||||
if (!name) {
|
|
||||||
jniThrowNullPointerException(env, "name");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (bind_to_interface(socket, name) < 0) {
|
|
||||||
throwException(env, SYSTEM_ERROR, "Cannot protect socket");
|
|
||||||
}
|
|
||||||
env->ReleaseStringUTFChars(jName, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
static JNINativeMethod gMethods[] = {
|
static JNINativeMethod gMethods[] = {
|
||||||
@@ -455,7 +433,6 @@ static JNINativeMethod gMethods[] = {
|
|||||||
{"jniSetRoutes", "(Ljava/lang/String;Ljava/lang/String;)I", (void *)setRoutes},
|
{"jniSetRoutes", "(Ljava/lang/String;Ljava/lang/String;)I", (void *)setRoutes},
|
||||||
{"jniReset", "(Ljava/lang/String;)V", (void *)reset},
|
{"jniReset", "(Ljava/lang/String;)V", (void *)reset},
|
||||||
{"jniCheck", "(Ljava/lang/String;)I", (void *)check},
|
{"jniCheck", "(Ljava/lang/String;)I", (void *)check},
|
||||||
{"jniProtect", "(ILjava/lang/String;)V", (void *)protect},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int register_android_server_connectivity_Vpn(JNIEnv *env)
|
int register_android_server_connectivity_Vpn(JNIEnv *env)
|
||||||
|
|||||||
Reference in New Issue
Block a user