Merge "Remove dependency on libnetd_client"
This commit is contained in:
@@ -108,10 +108,8 @@ cc_defaults {
|
|||||||
"-Wthread-safety",
|
"-Wthread-safety",
|
||||||
],
|
],
|
||||||
shared_libs: [
|
shared_libs: [
|
||||||
"libbase",
|
|
||||||
"liblog",
|
"liblog",
|
||||||
"libnativehelper",
|
"libnativehelper",
|
||||||
"libnetd_client",
|
|
||||||
],
|
],
|
||||||
header_libs: [
|
header_libs: [
|
||||||
"dnsproxyd_protocol_headers",
|
"dnsproxyd_protocol_headers",
|
||||||
@@ -135,10 +133,10 @@ cc_library_shared {
|
|||||||
name: "libframework-connectivity-jni",
|
name: "libframework-connectivity-jni",
|
||||||
defaults: ["libframework-connectivity-defaults"],
|
defaults: ["libframework-connectivity-defaults"],
|
||||||
srcs: [
|
srcs: [
|
||||||
|
"jni/android_net_NetworkUtils.cpp",
|
||||||
"jni/onload.cpp",
|
"jni/onload.cpp",
|
||||||
],
|
],
|
||||||
shared_libs: ["libandroid"],
|
shared_libs: ["libandroid"],
|
||||||
static_libs: ["libconnectivityframeworkutils"],
|
|
||||||
apex_available: [
|
apex_available: [
|
||||||
"//apex_available:platform",
|
"//apex_available:platform",
|
||||||
"com.android.tethering",
|
"com.android.tethering",
|
||||||
|
|||||||
@@ -37,7 +37,6 @@
|
|||||||
#include <utils/Log.h>
|
#include <utils/Log.h>
|
||||||
#include <utils/misc.h>
|
#include <utils/misc.h>
|
||||||
|
|
||||||
#include "NetdClient.h"
|
|
||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -113,14 +112,14 @@ static jlong android_net_utils_getBoundNetworkHandleForProcess(JNIEnv *env, jobj
|
|||||||
}
|
}
|
||||||
|
|
||||||
static jboolean android_net_utils_bindProcessToNetworkForHostResolution(JNIEnv *env, jobject thiz,
|
static jboolean android_net_utils_bindProcessToNetworkForHostResolution(JNIEnv *env, jobject thiz,
|
||||||
jint netId)
|
jint netId, jlong netHandle)
|
||||||
{
|
{
|
||||||
return (jboolean) !setNetworkForResolv(netId);
|
return (jboolean) !android_setprocdns(netHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
static jint android_net_utils_bindSocketToNetwork(JNIEnv *env, jobject thiz, jobject javaFd,
|
static jint android_net_utils_bindSocketToNetworkHandle(JNIEnv *env, jobject thiz, jobject javaFd,
|
||||||
jint netId) {
|
jlong netHandle) {
|
||||||
return setNetworkForSocket(netId, AFileDescriptor_getFd(env, javaFd));
|
return android_setsocknetwork(netHandle, AFileDescriptor_getFd(env, javaFd));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool checkLenAndCopy(JNIEnv* env, const jbyteArray& addr, int len, void* dst)
|
static bool checkLenAndCopy(JNIEnv* env, const jbyteArray& addr, int len, void* dst)
|
||||||
@@ -132,7 +131,7 @@ static bool checkLenAndCopy(JNIEnv* env, const jbyteArray& addr, int len, void*
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static jobject android_net_utils_resNetworkQuery(JNIEnv *env, jobject thiz, jint netId,
|
static jobject android_net_utils_resNetworkQuery(JNIEnv *env, jobject thiz, jlong netHandle,
|
||||||
jstring dname, jint ns_class, jint ns_type, jint flags) {
|
jstring dname, jint ns_class, jint ns_type, jint flags) {
|
||||||
const jsize javaCharsCount = env->GetStringLength(dname);
|
const jsize javaCharsCount = env->GetStringLength(dname);
|
||||||
const jsize byteCountUTF8 = env->GetStringUTFLength(dname);
|
const jsize byteCountUTF8 = env->GetStringUTFLength(dname);
|
||||||
@@ -142,7 +141,8 @@ static jobject android_net_utils_resNetworkQuery(JNIEnv *env, jobject thiz, jint
|
|||||||
std::vector<char> queryname(byteCountUTF8 + 1, 0);
|
std::vector<char> queryname(byteCountUTF8 + 1, 0);
|
||||||
|
|
||||||
env->GetStringUTFRegion(dname, 0, javaCharsCount, queryname.data());
|
env->GetStringUTFRegion(dname, 0, javaCharsCount, queryname.data());
|
||||||
int fd = resNetworkQuery(netId, queryname.data(), ns_class, ns_type, flags);
|
|
||||||
|
int fd = android_res_nquery(netHandle, queryname.data(), ns_class, ns_type, flags);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
jniThrowErrnoException(env, "resNetworkQuery", -fd);
|
jniThrowErrnoException(env, "resNetworkQuery", -fd);
|
||||||
@@ -152,12 +152,12 @@ static jobject android_net_utils_resNetworkQuery(JNIEnv *env, jobject thiz, jint
|
|||||||
return jniCreateFileDescriptor(env, fd);
|
return jniCreateFileDescriptor(env, fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static jobject android_net_utils_resNetworkSend(JNIEnv *env, jobject thiz, jint netId,
|
static jobject android_net_utils_resNetworkSend(JNIEnv *env, jobject thiz, jlong netHandle,
|
||||||
jbyteArray msg, jint msgLen, jint flags) {
|
jbyteArray msg, jint msgLen, jint flags) {
|
||||||
uint8_t data[MAXCMDSIZE];
|
uint8_t data[MAXCMDSIZE];
|
||||||
|
|
||||||
checkLenAndCopy(env, msg, msgLen, data);
|
checkLenAndCopy(env, msg, msgLen, data);
|
||||||
int fd = resNetworkSend(netId, data, msgLen, flags);
|
int fd = android_res_nsend(netHandle, data, msgLen, flags);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
jniThrowErrnoException(env, "resNetworkSend", -fd);
|
jniThrowErrnoException(env, "resNetworkSend", -fd);
|
||||||
@@ -172,7 +172,7 @@ static jobject android_net_utils_resNetworkResult(JNIEnv *env, jobject thiz, job
|
|||||||
int rcode;
|
int rcode;
|
||||||
std::vector<uint8_t> buf(MAXPACKETSIZE, 0);
|
std::vector<uint8_t> buf(MAXPACKETSIZE, 0);
|
||||||
|
|
||||||
int res = resNetworkResult(fd, &rcode, buf.data(), MAXPACKETSIZE);
|
int res = android_res_nresult(fd, &rcode, buf.data(), MAXPACKETSIZE);
|
||||||
jniSetFileDescriptorOfFD(env, javaFd, -1);
|
jniSetFileDescriptorOfFD(env, javaFd, -1);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
jniThrowErrnoException(env, "resNetworkResult", -res);
|
jniThrowErrnoException(env, "resNetworkResult", -res);
|
||||||
@@ -196,23 +196,22 @@ static jobject android_net_utils_resNetworkResult(JNIEnv *env, jobject thiz, job
|
|||||||
|
|
||||||
static void android_net_utils_resNetworkCancel(JNIEnv *env, jobject thiz, jobject javaFd) {
|
static void android_net_utils_resNetworkCancel(JNIEnv *env, jobject thiz, jobject javaFd) {
|
||||||
int fd = AFileDescriptor_getFd(env, javaFd);
|
int fd = AFileDescriptor_getFd(env, javaFd);
|
||||||
resNetworkCancel(fd);
|
android_res_cancel(fd);
|
||||||
jniSetFileDescriptorOfFD(env, javaFd, -1);
|
jniSetFileDescriptorOfFD(env, javaFd, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static jobject android_net_utils_getDnsNetwork(JNIEnv *env, jobject thiz) {
|
static jobject android_net_utils_getDnsNetwork(JNIEnv *env, jobject thiz) {
|
||||||
unsigned dnsNetId = 0;
|
net_handle_t dnsNetHandle = NETWORK_UNSPECIFIED;
|
||||||
if (int res = getNetworkForDns(&dnsNetId) < 0) {
|
if (int res = android_getprocdns(&dnsNetHandle) < 0) {
|
||||||
jniThrowErrnoException(env, "getDnsNetId", -res);
|
jniThrowErrnoException(env, "getDnsNetwork", -res);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
bool privateDnsBypass = dnsNetId & NETID_USE_LOCAL_NAMESERVERS;
|
|
||||||
|
|
||||||
static jclass class_Network = MakeGlobalRefOrDie(
|
static jclass class_Network = MakeGlobalRefOrDie(
|
||||||
env, FindClassOrDie(env, "android/net/Network"));
|
env, FindClassOrDie(env, "android/net/Network"));
|
||||||
static jmethodID ctor = env->GetMethodID(class_Network, "<init>", "(IZ)V");
|
static jmethodID method = env->GetStaticMethodID(class_Network, "fromNetworkHandle",
|
||||||
return env->NewObject(
|
"(J)Landroid/net/Network;");
|
||||||
class_Network, ctor, dnsNetId & ~NETID_USE_LOCAL_NAMESERVERS, privateDnsBypass);
|
return env->CallStaticObjectMethod(class_Network, method, static_cast<jlong>(dnsNetHandle));
|
||||||
}
|
}
|
||||||
|
|
||||||
static jobject android_net_utils_getTcpRepairWindow(JNIEnv *env, jobject thiz, jobject javaFd) {
|
static jobject android_net_utils_getTcpRepairWindow(JNIEnv *env, jobject thiz, jobject javaFd) {
|
||||||
@@ -261,12 +260,12 @@ static const JNINativeMethod gNetworkUtilMethods[] = {
|
|||||||
{ "bindProcessToNetworkHandle", "(J)Z", (void*) android_net_utils_bindProcessToNetworkHandle },
|
{ "bindProcessToNetworkHandle", "(J)Z", (void*) android_net_utils_bindProcessToNetworkHandle },
|
||||||
{ "getBoundNetworkHandleForProcess", "()J", (void*) android_net_utils_getBoundNetworkHandleForProcess },
|
{ "getBoundNetworkHandleForProcess", "()J", (void*) android_net_utils_getBoundNetworkHandleForProcess },
|
||||||
{ "bindProcessToNetworkForHostResolution", "(I)Z", (void*) android_net_utils_bindProcessToNetworkForHostResolution },
|
{ "bindProcessToNetworkForHostResolution", "(I)Z", (void*) android_net_utils_bindProcessToNetworkForHostResolution },
|
||||||
{ "bindSocketToNetwork", "(Ljava/io/FileDescriptor;I)I", (void*) android_net_utils_bindSocketToNetwork },
|
{ "bindSocketToNetworkHandle", "(Ljava/io/FileDescriptor;J)I", (void*) android_net_utils_bindSocketToNetworkHandle },
|
||||||
{ "attachDropAllBPFFilter", "(Ljava/io/FileDescriptor;)V", (void*) android_net_utils_attachDropAllBPFFilter },
|
{ "attachDropAllBPFFilter", "(Ljava/io/FileDescriptor;)V", (void*) android_net_utils_attachDropAllBPFFilter },
|
||||||
{ "detachBPFFilter", "(Ljava/io/FileDescriptor;)V", (void*) android_net_utils_detachBPFFilter },
|
{ "detachBPFFilter", "(Ljava/io/FileDescriptor;)V", (void*) android_net_utils_detachBPFFilter },
|
||||||
{ "getTcpRepairWindow", "(Ljava/io/FileDescriptor;)Landroid/net/TcpRepairWindow;", (void*) android_net_utils_getTcpRepairWindow },
|
{ "getTcpRepairWindow", "(Ljava/io/FileDescriptor;)Landroid/net/TcpRepairWindow;", (void*) android_net_utils_getTcpRepairWindow },
|
||||||
{ "resNetworkSend", "(I[BII)Ljava/io/FileDescriptor;", (void*) android_net_utils_resNetworkSend },
|
{ "resNetworkSend", "(J[BII)Ljava/io/FileDescriptor;", (void*) android_net_utils_resNetworkSend },
|
||||||
{ "resNetworkQuery", "(ILjava/lang/String;III)Ljava/io/FileDescriptor;", (void*) android_net_utils_resNetworkQuery },
|
{ "resNetworkQuery", "(JLjava/lang/String;III)Ljava/io/FileDescriptor;", (void*) android_net_utils_resNetworkQuery },
|
||||||
{ "resNetworkResult", "(Ljava/io/FileDescriptor;)Landroid/net/DnsResolver$DnsResponse;", (void*) android_net_utils_resNetworkResult },
|
{ "resNetworkResult", "(Ljava/io/FileDescriptor;)Landroid/net/DnsResolver$DnsResponse;", (void*) android_net_utils_resNetworkResult },
|
||||||
{ "resNetworkCancel", "(Ljava/io/FileDescriptor;)V", (void*) android_net_utils_resNetworkCancel },
|
{ "resNetworkCancel", "(Ljava/io/FileDescriptor;)V", (void*) android_net_utils_resNetworkCancel },
|
||||||
{ "getDnsNetwork", "()Landroid/net/Network;", (void*) android_net_utils_getDnsNetwork },
|
{ "getDnsNetwork", "()Landroid/net/Network;", (void*) android_net_utils_getDnsNetwork },
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ public class Network implements Parcelable {
|
|||||||
// value in the native/android/net.c NDK implementation.
|
// value in the native/android/net.c NDK implementation.
|
||||||
private static final long HANDLE_MAGIC = 0xcafed00dL;
|
private static final long HANDLE_MAGIC = 0xcafed00dL;
|
||||||
private static final int HANDLE_MAGIC_SIZE = 32;
|
private static final int HANDLE_MAGIC_SIZE = 32;
|
||||||
|
private static final int USE_LOCAL_NAMESERVERS_FLAG = 0x80000000;
|
||||||
|
|
||||||
// A boolean to control how getAllByName()/getByName() behaves in the face
|
// A boolean to control how getAllByName()/getByName() behaves in the face
|
||||||
// of Private DNS.
|
// of Private DNS.
|
||||||
@@ -189,7 +190,7 @@ public class Network implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public int getNetIdForResolv() {
|
public int getNetIdForResolv() {
|
||||||
return mPrivateDnsBypass
|
return mPrivateDnsBypass
|
||||||
? (int) (0x80000000L | (long) netId) // Non-portable DNS resolution flag.
|
? (USE_LOCAL_NAMESERVERS_FLAG | netId) // Non-portable DNS resolution flag.
|
||||||
: netId;
|
: netId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,12 +453,13 @@ public class Network implements Parcelable {
|
|||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Network.fromNetworkHandle refusing to instantiate NETID_UNSET Network.");
|
"Network.fromNetworkHandle refusing to instantiate NETID_UNSET Network.");
|
||||||
}
|
}
|
||||||
if ((networkHandle & ((1L << HANDLE_MAGIC_SIZE) - 1)) != HANDLE_MAGIC
|
if ((networkHandle & ((1L << HANDLE_MAGIC_SIZE) - 1)) != HANDLE_MAGIC) {
|
||||||
|| networkHandle < 0) {
|
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Value passed to fromNetworkHandle() is not a network handle.");
|
"Value passed to fromNetworkHandle() is not a network handle.");
|
||||||
}
|
}
|
||||||
return new Network((int) (networkHandle >> HANDLE_MAGIC_SIZE));
|
final int netIdForResolv = (int) (networkHandle >>> HANDLE_MAGIC_SIZE);
|
||||||
|
return new Network((netIdForResolv & ~USE_LOCAL_NAMESERVERS_FLAG),
|
||||||
|
((netIdForResolv & USE_LOCAL_NAMESERVERS_FLAG) != 0) /* privateDnsBypass */);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -485,7 +487,7 @@ public class Network implements Parcelable {
|
|||||||
if (netId == 0) {
|
if (netId == 0) {
|
||||||
return 0L; // make this zero condition obvious for debugging
|
return 0L; // make this zero condition obvious for debugging
|
||||||
}
|
}
|
||||||
return (((long) netId) << HANDLE_MAGIC_SIZE) | HANDLE_MAGIC;
|
return (((long) getNetIdForResolv()) << HANDLE_MAGIC_SIZE) | HANDLE_MAGIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
// implement the Parcelable interface
|
// implement the Parcelable interface
|
||||||
|
|||||||
@@ -92,12 +92,16 @@ public class NetworkUtils {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public native static boolean bindProcessToNetworkForHostResolution(int netId);
|
public native static boolean bindProcessToNetworkForHostResolution(int netId);
|
||||||
|
|
||||||
|
private static native int bindSocketToNetworkHandle(FileDescriptor fd, long netHandle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Explicitly binds {@code fd} to the network designated by {@code netId}. This
|
* Explicitly binds {@code fd} to the network designated by {@code netId}. This
|
||||||
* overrides any binding via {@link #bindProcessToNetwork}.
|
* overrides any binding via {@link #bindProcessToNetwork}.
|
||||||
* @return 0 on success or negative errno on failure.
|
* @return 0 on success or negative errno on failure.
|
||||||
*/
|
*/
|
||||||
public static native int bindSocketToNetwork(FileDescriptor fd, int netId);
|
public static int bindSocketToNetwork(FileDescriptor fd, int netId) {
|
||||||
|
return bindSocketToNetworkHandle(fd, new Network(netId).getNetworkHandle());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if {@code uid} can access network designated by {@code netId}.
|
* Determine if {@code uid} can access network designated by {@code netId}.
|
||||||
@@ -108,14 +112,22 @@ public class NetworkUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static native FileDescriptor resNetworkSend(
|
||||||
|
long netHandle, byte[] msg, int msglen, int flags) throws ErrnoException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DNS resolver series jni method.
|
* DNS resolver series jni method.
|
||||||
* Issue the query {@code msg} on the network designated by {@code netId}.
|
* Issue the query {@code msg} on the network designated by {@code netId}.
|
||||||
* {@code flags} is an additional config to control actual querying behavior.
|
* {@code flags} is an additional config to control actual querying behavior.
|
||||||
* @return a file descriptor to watch for read events
|
* @return a file descriptor to watch for read events
|
||||||
*/
|
*/
|
||||||
public static native FileDescriptor resNetworkSend(
|
public static FileDescriptor resNetworkSend(
|
||||||
int netId, byte[] msg, int msglen, int flags) throws ErrnoException;
|
int netId, byte[] msg, int msglen, int flags) throws ErrnoException {
|
||||||
|
return resNetworkSend(new Network(netId).getNetworkHandle(), msg, msglen, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native FileDescriptor resNetworkQuery(
|
||||||
|
long netHandle, String dname, int nsClass, int nsType, int flags) throws ErrnoException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DNS resolver series jni method.
|
* DNS resolver series jni method.
|
||||||
@@ -124,8 +136,11 @@ public class NetworkUtils {
|
|||||||
* {@code flags} is an additional config to control actual querying behavior.
|
* {@code flags} is an additional config to control actual querying behavior.
|
||||||
* @return a file descriptor to watch for read events
|
* @return a file descriptor to watch for read events
|
||||||
*/
|
*/
|
||||||
public static native FileDescriptor resNetworkQuery(
|
public static FileDescriptor resNetworkQuery(
|
||||||
int netId, String dname, int nsClass, int nsType, int flags) throws ErrnoException;
|
int netId, String dname, int nsClass, int nsType, int flags) throws ErrnoException {
|
||||||
|
return resNetworkQuery(new Network(netId).getNetworkHandle(), dname, nsClass, nsType,
|
||||||
|
flags);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DNS resolver series jni method.
|
* DNS resolver series jni method.
|
||||||
|
|||||||
Reference in New Issue
Block a user