diff options
author | Chad Brubaker <cbrubaker@google.com> | 2014-03-14 16:36:04 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-03-14 16:36:04 +0000 |
commit | ff9da494622a7f9358979509849ab94364d17706 (patch) | |
tree | 1ff890a171f92aeb74f7db6bea75ad76b27024a6 | |
parent | 78a06696b714dd97076b98a415aadcc174fe3af0 (diff) | |
parent | 4b59883afd498dd993263c95aa6db84cbe7c49b4 (diff) | |
download | frameworks_base-ff9da494622a7f9358979509849ab94364d17706.zip frameworks_base-ff9da494622a7f9358979509849ab94364d17706.tar.gz frameworks_base-ff9da494622a7f9358979509849ab94364d17706.tar.bz2 |
am 4b59883a: am 7c2b1625: am 78f204ae: am 8e240af5: Merge "Remove SO_BINDTODEVICE from VPN protect" into klp-dev
* commit '4b59883afd498dd993263c95aa6db84cbe7c49b4':
Remove SO_BINDTODEVICE from VPN protect
4 files changed, 8 insertions, 35 deletions
diff --git a/core/java/android/net/VpnService.java b/core/java/android/net/VpnService.java index d7dc7f5..7385dff 100644 --- a/core/java/android/net/VpnService.java +++ b/core/java/android/net/VpnService.java @@ -151,9 +151,10 @@ public class VpnService extends Service { } /** - * Protect a socket from VPN connections. The socket will be bound to the - * current default network interface, so its traffic will not be forwarded - * through VPN. This method is useful if some connections need to be kept + * Protect a socket from VPN connections. After protecting, data sent + * through this socket will go directly to the underlying network, + * 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 * destination is covered by VPN routes. Otherwise its outgoing packets * will be sent back to the VPN interface and cause an infinite loop. This diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 88882f3..bf5e72f 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -3665,8 +3665,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { int user = UserHandle.getUserId(Binder.getCallingUid()); if (ConnectivityManager.isNetworkTypeValid(type) && mNetTrackers[type] != null) { synchronized(mVpns) { - mVpns.get(user).protect(socket, - mNetTrackers[type].getLinkProperties().getInterfaceName()); + mVpns.get(user).protect(socket); } return true; } diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java index b8bcda7..0a58552 100644 --- a/services/core/java/com/android/server/connectivity/Vpn.java +++ b/services/core/java/com/android/server/connectivity/Vpn.java @@ -284,13 +284,12 @@ public class Vpn extends BaseNetworkStateTracker { } /** - * Protect a socket from routing changes by binding it to the given - * interface. The socket is NOT closed by this method. + * Protect a socket from VPN rules by binding it to the main routing table. + * The socket is NOT closed by this method. * * @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(); int appUid = pm.getPackageUid(mPackage, mUserId); @@ -304,8 +303,6 @@ public class Vpn extends BaseNetworkStateTracker { } finally { 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 void jniReset(String interfaze); private native int jniCheck(String interfaze); - private native void jniProtect(int socket, String interfaze); private static RouteInfo findIPv4DefaultRoute(LinkProperties prop) { for (RouteInfo route : prop.getAllRoutes()) { diff --git a/services/core/jni/com_android_server_connectivity_Vpn.cpp b/services/core/jni/com_android_server_connectivity_Vpn.cpp index ab8c959..bf34a74 100644 --- a/services/core/jni/com_android_server_connectivity_Vpn.cpp +++ b/services/core/jni/com_android_server_connectivity_Vpn.cpp @@ -302,15 +302,6 @@ static int check_interface(const char *name) 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) @@ -433,19 +424,6 @@ static jint check(JNIEnv *env, jobject thiz, jstring jName) 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[] = { @@ -455,7 +433,6 @@ static JNINativeMethod gMethods[] = { {"jniSetRoutes", "(Ljava/lang/String;Ljava/lang/String;)I", (void *)setRoutes}, {"jniReset", "(Ljava/lang/String;)V", (void *)reset}, {"jniCheck", "(Ljava/lang/String;)I", (void *)check}, - {"jniProtect", "(ILjava/lang/String;)V", (void *)protect}, }; int register_android_server_connectivity_Vpn(JNIEnv *env) |