The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008, The Android Open Source Project |
| 3 | * |
Elliott Hughes | dd66bcb | 2011-04-12 11:28:59 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7 | * |
Elliott Hughes | dd66bcb | 2011-04-12 11:28:59 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9 | * |
Elliott Hughes | dd66bcb | 2011-04-12 11:28:59 -0700 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "NetUtils" |
| 18 | |
Luke Huang | 92ae35e | 2019-01-04 19:46:47 +0800 | [diff] [blame] | 19 | #include <vector> |
| 20 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include "jni.h" |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 22 | #include <nativehelper/JNIHelp.h> |
Luke Huang | 92ae35e | 2019-01-04 19:46:47 +0800 | [diff] [blame] | 23 | #include <nativehelper/ScopedLocalRef.h> |
Paul Jensen | 3876495 | 2014-05-20 11:25:35 -0400 | [diff] [blame] | 24 | #include "NetdClient.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <utils/misc.h> |
| 26 | #include <android_runtime/AndroidRuntime.h> |
| 27 | #include <utils/Log.h> |
| 28 | #include <arpa/inet.h> |
Lorenzo Colitti | cbe4f7c | 2015-03-06 19:57:39 +0900 | [diff] [blame] | 29 | #include <net/if.h> |
| 30 | #include <linux/filter.h> |
Paul Jensen | 578a76e | 2016-01-14 14:54:39 -0500 | [diff] [blame] | 31 | #include <linux/if_arp.h> |
markchien | 150e191 | 2018-12-27 22:49:51 +0800 | [diff] [blame] | 32 | #include <linux/tcp.h> |
Elliott Hughes | 7691b78 | 2016-05-11 15:18:13 -0700 | [diff] [blame] | 33 | #include <netinet/ether.h> |
Paul Jensen | 578a76e | 2016-01-14 14:54:39 -0500 | [diff] [blame] | 34 | #include <netinet/icmp6.h> |
Lorenzo Colitti | cbe4f7c | 2015-03-06 19:57:39 +0900 | [diff] [blame] | 35 | #include <netinet/ip.h> |
Paul Jensen | 578a76e | 2016-01-14 14:54:39 -0500 | [diff] [blame] | 36 | #include <netinet/ip6.h> |
Lorenzo Colitti | cbe4f7c | 2015-03-06 19:57:39 +0900 | [diff] [blame] | 37 | #include <netinet/udp.h> |
Robert Greenwalt | 0216e61 | 2011-01-14 16:29:58 -0800 | [diff] [blame] | 38 | #include <cutils/properties.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 40 | #include "core_jni_helpers.h" |
| 41 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | extern "C" { |
Mike Lockwood | 0900f36 | 2009-07-10 17:24:07 -0400 | [diff] [blame] | 43 | int ifc_enable(const char *ifname); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | int ifc_disable(const char *ifname); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | #define NETUTILS_PKG_NAME "android/net/NetworkUtils" |
| 48 | |
| 49 | namespace android { |
| 50 | |
Luke Huang | 92ae35e | 2019-01-04 19:46:47 +0800 | [diff] [blame] | 51 | constexpr int MAXPACKETSIZE = 8 * 1024; |
Luke Huang | 0f790b9 | 2019-05-02 01:54:50 -0700 | [diff] [blame] | 52 | // FrameworkListener limits the size of commands to 4096 bytes. |
| 53 | constexpr int MAXCMDSIZE = 4096; |
Luke Huang | 92ae35e | 2019-01-04 19:46:47 +0800 | [diff] [blame] | 54 | |
| 55 | static void throwErrnoException(JNIEnv* env, const char* functionName, int error) { |
| 56 | ScopedLocalRef<jstring> detailMessage(env, env->NewStringUTF(functionName)); |
| 57 | if (detailMessage.get() == NULL) { |
| 58 | // Not really much we can do here. We're probably dead in the water, |
| 59 | // but let's try to stumble on... |
| 60 | env->ExceptionClear(); |
| 61 | } |
| 62 | static jclass errnoExceptionClass = |
| 63 | MakeGlobalRefOrDie(env, FindClassOrDie(env, "android/system/ErrnoException")); |
| 64 | |
| 65 | static jmethodID errnoExceptionCtor = |
| 66 | GetMethodIDOrDie(env, errnoExceptionClass, |
| 67 | "<init>", "(Ljava/lang/String;I)V"); |
| 68 | |
| 69 | jobject exception = env->NewObject(errnoExceptionClass, |
| 70 | errnoExceptionCtor, |
| 71 | detailMessage.get(), |
| 72 | error); |
| 73 | env->Throw(reinterpret_cast<jthrowable>(exception)); |
| 74 | } |
| 75 | |
markchien | 150e191 | 2018-12-27 22:49:51 +0800 | [diff] [blame] | 76 | static void android_net_utils_attachDropAllBPFFilter(JNIEnv *env, jobject clazz, jobject javaFd) |
| 77 | { |
| 78 | struct sock_filter filter_code[] = { |
| 79 | // Reject all. |
| 80 | BPF_STMT(BPF_RET | BPF_K, 0) |
| 81 | }; |
| 82 | struct sock_fprog filter = { |
| 83 | sizeof(filter_code) / sizeof(filter_code[0]), |
| 84 | filter_code, |
| 85 | }; |
| 86 | |
| 87 | int fd = jniGetFDFromFileDescriptor(env, javaFd); |
| 88 | if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter, sizeof(filter)) != 0) { |
| 89 | jniThrowExceptionFmt(env, "java/net/SocketException", |
| 90 | "setsockopt(SO_ATTACH_FILTER): %s", strerror(errno)); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | static void android_net_utils_detachBPFFilter(JNIEnv *env, jobject clazz, jobject javaFd) |
| 95 | { |
| 96 | int dummy = 0; |
| 97 | int fd = jniGetFDFromFileDescriptor(env, javaFd); |
| 98 | if (setsockopt(fd, SOL_SOCKET, SO_DETACH_FILTER, &dummy, sizeof(dummy)) != 0) { |
| 99 | jniThrowExceptionFmt(env, "java/net/SocketException", |
| 100 | "setsockopt(SO_DETACH_FILTER): %s", strerror(errno)); |
| 101 | } |
| 102 | |
| 103 | } |
Erik Kline | a3ca6bd | 2016-05-24 20:12:08 +0900 | [diff] [blame] | 104 | static void android_net_utils_setupRaSocket(JNIEnv *env, jobject clazz, jobject javaFd, |
| 105 | jint ifIndex) |
| 106 | { |
| 107 | static const int kLinkLocalHopLimit = 255; |
| 108 | |
| 109 | int fd = jniGetFDFromFileDescriptor(env, javaFd); |
| 110 | |
| 111 | // Set an ICMPv6 filter that only passes Router Solicitations. |
| 112 | struct icmp6_filter rs_only; |
| 113 | ICMP6_FILTER_SETBLOCKALL(&rs_only); |
| 114 | ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &rs_only); |
| 115 | socklen_t len = sizeof(rs_only); |
| 116 | if (setsockopt(fd, IPPROTO_ICMPV6, ICMP6_FILTER, &rs_only, len) != 0) { |
| 117 | jniThrowExceptionFmt(env, "java/net/SocketException", |
| 118 | "setsockopt(ICMP6_FILTER): %s", strerror(errno)); |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | // Most/all of the rest of these options can be set via Java code, but |
| 123 | // because we're here on account of setting an icmp6_filter go ahead |
| 124 | // and do it all natively for now. |
| 125 | // |
| 126 | // TODO: Consider moving these out to Java. |
| 127 | |
| 128 | // Set the multicast hoplimit to 255 (link-local only). |
| 129 | int hops = kLinkLocalHopLimit; |
| 130 | len = sizeof(hops); |
| 131 | if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &hops, len) != 0) { |
| 132 | jniThrowExceptionFmt(env, "java/net/SocketException", |
| 133 | "setsockopt(IPV6_MULTICAST_HOPS): %s", strerror(errno)); |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | // Set the unicast hoplimit to 255 (link-local only). |
| 138 | hops = kLinkLocalHopLimit; |
| 139 | len = sizeof(hops); |
| 140 | if (setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &hops, len) != 0) { |
| 141 | jniThrowExceptionFmt(env, "java/net/SocketException", |
| 142 | "setsockopt(IPV6_UNICAST_HOPS): %s", strerror(errno)); |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | // Explicitly disable multicast loopback. |
| 147 | int off = 0; |
| 148 | len = sizeof(off); |
| 149 | if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &off, len) != 0) { |
| 150 | jniThrowExceptionFmt(env, "java/net/SocketException", |
| 151 | "setsockopt(IPV6_MULTICAST_LOOP): %s", strerror(errno)); |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | // Specify the IPv6 interface to use for outbound multicast. |
| 156 | len = sizeof(ifIndex); |
| 157 | if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, &ifIndex, len) != 0) { |
| 158 | jniThrowExceptionFmt(env, "java/net/SocketException", |
| 159 | "setsockopt(IPV6_MULTICAST_IF): %s", strerror(errno)); |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | // Additional options to be considered: |
| 164 | // - IPV6_TCLASS |
| 165 | // - IPV6_RECVPKTINFO |
| 166 | // - IPV6_RECVHOPLIMIT |
| 167 | |
| 168 | // Bind to [::]. |
| 169 | const struct sockaddr_in6 sin6 = { |
| 170 | .sin6_family = AF_INET6, |
| 171 | .sin6_port = 0, |
| 172 | .sin6_flowinfo = 0, |
| 173 | .sin6_addr = IN6ADDR_ANY_INIT, |
| 174 | .sin6_scope_id = 0, |
| 175 | }; |
| 176 | auto sa = reinterpret_cast<const struct sockaddr *>(&sin6); |
| 177 | len = sizeof(sin6); |
| 178 | if (bind(fd, sa, len) != 0) { |
| 179 | jniThrowExceptionFmt(env, "java/net/SocketException", |
| 180 | "bind(IN6ADDR_ANY): %s", strerror(errno)); |
| 181 | return; |
| 182 | } |
| 183 | |
| 184 | // Join the all-routers multicast group, ff02::2%index. |
| 185 | struct ipv6_mreq all_rtrs = { |
| 186 | .ipv6mr_multiaddr = {{{0xff,2,0,0,0,0,0,0,0,0,0,0,0,0,0,2}}}, |
| 187 | .ipv6mr_interface = ifIndex, |
| 188 | }; |
| 189 | len = sizeof(all_rtrs); |
| 190 | if (setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &all_rtrs, len) != 0) { |
| 191 | jniThrowExceptionFmt(env, "java/net/SocketException", |
| 192 | "setsockopt(IPV6_JOIN_GROUP): %s", strerror(errno)); |
| 193 | return; |
| 194 | } |
| 195 | } |
| 196 | |
Paul Jensen | 32a58f0 | 2014-06-20 13:58:14 -0400 | [diff] [blame] | 197 | static jboolean android_net_utils_bindProcessToNetwork(JNIEnv *env, jobject thiz, jint netId) |
Paul Jensen | 3876495 | 2014-05-20 11:25:35 -0400 | [diff] [blame] | 198 | { |
Paul Jensen | 32a58f0 | 2014-06-20 13:58:14 -0400 | [diff] [blame] | 199 | return (jboolean) !setNetworkForProcess(netId); |
Paul Jensen | 3876495 | 2014-05-20 11:25:35 -0400 | [diff] [blame] | 200 | } |
| 201 | |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 202 | static jint android_net_utils_getBoundNetworkForProcess(JNIEnv *env, jobject thiz) |
Paul Jensen | 3876495 | 2014-05-20 11:25:35 -0400 | [diff] [blame] | 203 | { |
| 204 | return getNetworkForProcess(); |
| 205 | } |
| 206 | |
Paul Jensen | 32a58f0 | 2014-06-20 13:58:14 -0400 | [diff] [blame] | 207 | static jboolean android_net_utils_bindProcessToNetworkForHostResolution(JNIEnv *env, jobject thiz, |
| 208 | jint netId) |
Paul Jensen | 3876495 | 2014-05-20 11:25:35 -0400 | [diff] [blame] | 209 | { |
Paul Jensen | 32a58f0 | 2014-06-20 13:58:14 -0400 | [diff] [blame] | 210 | return (jboolean) !setNetworkForResolv(netId); |
Paul Jensen | 3876495 | 2014-05-20 11:25:35 -0400 | [diff] [blame] | 211 | } |
| 212 | |
Lorenzo Colitti | 9f1274b | 2014-08-21 11:45:54 -0700 | [diff] [blame] | 213 | static jint android_net_utils_bindSocketToNetwork(JNIEnv *env, jobject thiz, jint socket, |
Paul Jensen | 32a58f0 | 2014-06-20 13:58:14 -0400 | [diff] [blame] | 214 | jint netId) |
Paul Jensen | 3876495 | 2014-05-20 11:25:35 -0400 | [diff] [blame] | 215 | { |
Lorenzo Colitti | 9f1274b | 2014-08-21 11:45:54 -0700 | [diff] [blame] | 216 | return setNetworkForSocket(netId, socket); |
Paul Jensen | 3876495 | 2014-05-20 11:25:35 -0400 | [diff] [blame] | 217 | } |
| 218 | |
Paul Jensen | 6bc2c2c | 2014-05-07 15:27:40 -0400 | [diff] [blame] | 219 | static jboolean android_net_utils_protectFromVpn(JNIEnv *env, jobject thiz, jint socket) |
| 220 | { |
| 221 | return (jboolean) !protectFromVpn(socket); |
| 222 | } |
| 223 | |
Paul Jensen | cee9b51 | 2015-05-06 07:32:40 -0400 | [diff] [blame] | 224 | static jboolean android_net_utils_queryUserAccess(JNIEnv *env, jobject thiz, jint uid, jint netId) |
| 225 | { |
| 226 | return (jboolean) !queryUserAccess(uid, netId); |
| 227 | } |
| 228 | |
Remi NGUYEN VAN | 12da4a5 | 2018-07-04 11:15:56 +0900 | [diff] [blame] | 229 | static bool checkLenAndCopy(JNIEnv* env, const jbyteArray& addr, int len, void* dst) |
| 230 | { |
| 231 | if (env->GetArrayLength(addr) != len) { |
| 232 | return false; |
| 233 | } |
| 234 | env->GetByteArrayRegion(addr, 0, len, reinterpret_cast<jbyte*>(dst)); |
| 235 | return true; |
| 236 | } |
| 237 | |
Luke Huang | 92ae35e | 2019-01-04 19:46:47 +0800 | [diff] [blame] | 238 | static jobject android_net_utils_resNetworkQuery(JNIEnv *env, jobject thiz, jint netId, |
| 239 | jstring dname, jint ns_class, jint ns_type, jint flags) { |
| 240 | const jsize javaCharsCount = env->GetStringLength(dname); |
| 241 | const jsize byteCountUTF8 = env->GetStringUTFLength(dname); |
| 242 | |
| 243 | // Only allow dname which could be simply formatted to UTF8. |
| 244 | // In native layer, res_mkquery would re-format the input char array to packet. |
| 245 | std::vector<char> queryname(byteCountUTF8 + 1, 0); |
| 246 | |
| 247 | env->GetStringUTFRegion(dname, 0, javaCharsCount, queryname.data()); |
| 248 | int fd = resNetworkQuery(netId, queryname.data(), ns_class, ns_type, flags); |
| 249 | |
| 250 | if (fd < 0) { |
| 251 | throwErrnoException(env, "resNetworkQuery", -fd); |
| 252 | return nullptr; |
| 253 | } |
| 254 | |
| 255 | return jniCreateFileDescriptor(env, fd); |
| 256 | } |
| 257 | |
| 258 | static jobject android_net_utils_resNetworkSend(JNIEnv *env, jobject thiz, jint netId, |
| 259 | jbyteArray msg, jint msgLen, jint flags) { |
| 260 | uint8_t data[MAXCMDSIZE]; |
| 261 | |
| 262 | checkLenAndCopy(env, msg, msgLen, data); |
| 263 | int fd = resNetworkSend(netId, data, msgLen, flags); |
| 264 | |
| 265 | if (fd < 0) { |
| 266 | throwErrnoException(env, "resNetworkSend", -fd); |
| 267 | return nullptr; |
| 268 | } |
| 269 | |
| 270 | return jniCreateFileDescriptor(env, fd); |
| 271 | } |
| 272 | |
Luke Huang | ec21447 | 2019-04-11 17:54:41 -0700 | [diff] [blame] | 273 | static jobject android_net_utils_resNetworkResult(JNIEnv *env, jobject thiz, jobject javaFd) { |
Luke Huang | 92ae35e | 2019-01-04 19:46:47 +0800 | [diff] [blame] | 274 | int fd = jniGetFDFromFileDescriptor(env, javaFd); |
| 275 | int rcode; |
| 276 | std::vector<uint8_t> buf(MAXPACKETSIZE, 0); |
| 277 | |
| 278 | int res = resNetworkResult(fd, &rcode, buf.data(), MAXPACKETSIZE); |
Luke Huang | 5386f49 | 2019-03-26 15:50:10 +0800 | [diff] [blame] | 279 | jniSetFileDescriptorOfFD(env, javaFd, -1); |
Luke Huang | 92ae35e | 2019-01-04 19:46:47 +0800 | [diff] [blame] | 280 | if (res < 0) { |
| 281 | throwErrnoException(env, "resNetworkResult", -res); |
| 282 | return nullptr; |
| 283 | } |
| 284 | |
| 285 | jbyteArray answer = env->NewByteArray(res); |
| 286 | if (answer == nullptr) { |
| 287 | throwErrnoException(env, "resNetworkResult", ENOMEM); |
| 288 | return nullptr; |
| 289 | } else { |
| 290 | env->SetByteArrayRegion(answer, 0, res, |
| 291 | reinterpret_cast<jbyte*>(buf.data())); |
| 292 | } |
| 293 | |
Luke Huang | ec21447 | 2019-04-11 17:54:41 -0700 | [diff] [blame] | 294 | jclass class_DnsResponse = env->FindClass("android/net/DnsResolver$DnsResponse"); |
| 295 | jmethodID ctor = env->GetMethodID(class_DnsResponse, "<init>", "([BI)V"); |
| 296 | |
| 297 | return env->NewObject(class_DnsResponse, ctor, answer, rcode); |
Luke Huang | 92ae35e | 2019-01-04 19:46:47 +0800 | [diff] [blame] | 298 | } |
Lorenzo Colitti | cbe4f7c | 2015-03-06 19:57:39 +0900 | [diff] [blame] | 299 | |
Luke Huang | c09f2d6 | 2019-03-08 14:48:59 +0800 | [diff] [blame] | 300 | static void android_net_utils_resNetworkCancel(JNIEnv *env, jobject thiz, jobject javaFd) { |
| 301 | int fd = jniGetFDFromFileDescriptor(env, javaFd); |
| 302 | resNetworkCancel(fd); |
Luke Huang | 5386f49 | 2019-03-26 15:50:10 +0800 | [diff] [blame] | 303 | jniSetFileDescriptorOfFD(env, javaFd, -1); |
Luke Huang | c09f2d6 | 2019-03-08 14:48:59 +0800 | [diff] [blame] | 304 | } |
| 305 | |
markchien | 150e191 | 2018-12-27 22:49:51 +0800 | [diff] [blame] | 306 | static jobject android_net_utils_getTcpRepairWindow(JNIEnv *env, jobject thiz, jobject javaFd) { |
| 307 | if (javaFd == NULL) { |
| 308 | jniThrowNullPointerException(env, NULL); |
| 309 | return NULL; |
| 310 | } |
| 311 | |
| 312 | int fd = jniGetFDFromFileDescriptor(env, javaFd); |
| 313 | struct tcp_repair_window trw = {}; |
| 314 | socklen_t size = sizeof(trw); |
| 315 | |
| 316 | // Obtain the parameters of the TCP repair window. |
| 317 | int rc = getsockopt(fd, IPPROTO_TCP, TCP_REPAIR_WINDOW, &trw, &size); |
| 318 | if (rc == -1) { |
| 319 | throwErrnoException(env, "getsockopt : TCP_REPAIR_WINDOW", errno); |
| 320 | return NULL; |
| 321 | } |
| 322 | |
| 323 | struct tcp_info tcpinfo = {}; |
| 324 | socklen_t tcpinfo_size = sizeof(tcp_info); |
| 325 | |
| 326 | // Obtain the window scale from the tcp info structure. This contains a scale factor that |
| 327 | // should be applied to the window size. |
| 328 | rc = getsockopt(fd, IPPROTO_TCP, TCP_INFO, &tcpinfo, &tcpinfo_size); |
| 329 | if (rc == -1) { |
| 330 | throwErrnoException(env, "getsockopt : TCP_INFO", errno); |
| 331 | return NULL; |
| 332 | } |
| 333 | |
| 334 | jclass class_TcpRepairWindow = env->FindClass("android/net/TcpRepairWindow"); |
| 335 | jmethodID ctor = env->GetMethodID(class_TcpRepairWindow, "<init>", "(IIIIII)V"); |
| 336 | |
| 337 | return env->NewObject(class_TcpRepairWindow, ctor, trw.snd_wl1, trw.snd_wnd, trw.max_window, |
| 338 | trw.rcv_wnd, trw.rcv_wup, tcpinfo.tcpi_rcv_wscale); |
| 339 | } |
| 340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | // ---------------------------------------------------------------------------- |
| 342 | |
| 343 | /* |
| 344 | * JNI registration. |
| 345 | */ |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 346 | static const JNINativeMethod gNetworkUtilMethods[] = { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | /* name, signature, funcPtr */ |
Paul Jensen | 32a58f0 | 2014-06-20 13:58:14 -0400 | [diff] [blame] | 348 | { "bindProcessToNetwork", "(I)Z", (void*) android_net_utils_bindProcessToNetwork }, |
Paul Jensen | 72db88e | 2015-03-10 10:54:12 -0400 | [diff] [blame] | 349 | { "getBoundNetworkForProcess", "()I", (void*) android_net_utils_getBoundNetworkForProcess }, |
Paul Jensen | 32a58f0 | 2014-06-20 13:58:14 -0400 | [diff] [blame] | 350 | { "bindProcessToNetworkForHostResolution", "(I)Z", (void*) android_net_utils_bindProcessToNetworkForHostResolution }, |
Lorenzo Colitti | 9f1274b | 2014-08-21 11:45:54 -0700 | [diff] [blame] | 351 | { "bindSocketToNetwork", "(II)I", (void*) android_net_utils_bindSocketToNetwork }, |
Paul Jensen | 6bc2c2c | 2014-05-07 15:27:40 -0400 | [diff] [blame] | 352 | { "protectFromVpn", "(I)Z", (void*)android_net_utils_protectFromVpn }, |
Paul Jensen | cee9b51 | 2015-05-06 07:32:40 -0400 | [diff] [blame] | 353 | { "queryUserAccess", "(II)Z", (void*)android_net_utils_queryUserAccess }, |
markchien | 150e191 | 2018-12-27 22:49:51 +0800 | [diff] [blame] | 354 | { "attachDropAllBPFFilter", "(Ljava/io/FileDescriptor;)V", (void*) android_net_utils_attachDropAllBPFFilter }, |
| 355 | { "detachBPFFilter", "(Ljava/io/FileDescriptor;)V", (void*) android_net_utils_detachBPFFilter }, |
| 356 | { "getTcpRepairWindow", "(Ljava/io/FileDescriptor;)Landroid/net/TcpRepairWindow;", (void*) android_net_utils_getTcpRepairWindow }, |
Erik Kline | a3ca6bd | 2016-05-24 20:12:08 +0900 | [diff] [blame] | 357 | { "setupRaSocket", "(Ljava/io/FileDescriptor;I)V", (void*) android_net_utils_setupRaSocket }, |
Luke Huang | 92ae35e | 2019-01-04 19:46:47 +0800 | [diff] [blame] | 358 | { "resNetworkSend", "(I[BII)Ljava/io/FileDescriptor;", (void*) android_net_utils_resNetworkSend }, |
| 359 | { "resNetworkQuery", "(ILjava/lang/String;III)Ljava/io/FileDescriptor;", (void*) android_net_utils_resNetworkQuery }, |
Luke Huang | ec21447 | 2019-04-11 17:54:41 -0700 | [diff] [blame] | 360 | { "resNetworkResult", "(Ljava/io/FileDescriptor;)Landroid/net/DnsResolver$DnsResponse;", (void*) android_net_utils_resNetworkResult }, |
Luke Huang | c09f2d6 | 2019-03-08 14:48:59 +0800 | [diff] [blame] | 361 | { "resNetworkCancel", "(Ljava/io/FileDescriptor;)V", (void*) android_net_utils_resNetworkCancel }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | }; |
| 363 | |
| 364 | int register_android_net_NetworkUtils(JNIEnv* env) |
| 365 | { |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 366 | return RegisterMethodsOrDie(env, NETUTILS_PKG_NAME, gNetworkUtilMethods, |
| 367 | NELEM(gNetworkUtilMethods)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | }; // namespace android |