Loading Android.bp +23 −0 Original line number Diff line number Diff line Loading @@ -150,6 +150,22 @@ cc_defaults { }, } cc_defaults { // Similar to resolv_test_mts_coverage_defaults, but it's for the tests that don't need // root access. name: "resolv_test_mts_coverage_without_root_defaults", test_config_template: ":resolv_test_config_without_root_template", compile_multilib: "both", multilib: { lib32: { suffix: "32", }, lib64: { suffix: "64", }, }, } cc_library { name: "libnetd_resolv", version_script: "libnetd_resolv.map.txt", Loading Loading @@ -307,6 +323,13 @@ filegroup { ], } filegroup { name: "resolv_test_config_without_root_template", srcs: [ "resolv_test_config_without_root_template.xml", ], } filegroup { name: "resolv_unit_test_files", srcs: [ Loading DnsTlsSocket.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -94,6 +94,12 @@ Status DnsTlsSocket::tcpConnect() { return Status(err); } // Set TCP MSS to a suitably low value to be more reliable. const int v = 1220; if (setsockopt(mSslFd.get(), SOL_TCP, TCP_MAXSEG, &v, sizeof(v)) == -1) { LOG(WARNING) << "Failed to set TCP_MAXSEG: " << errno; } const Status tfo = enableSockopt(mSslFd.get(), SOL_TCP, TCP_FASTOPEN_CONNECT); if (!isOk(tfo) && tfo.code() != ENOPROTOOPT) { LOG(WARNING) << "Failed to enable TFO: " << tfo.msg(); Loading doh/connection/driver.rs +27 −15 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ use std::collections::HashMap; use std::default::Default; use std::future; use std::io; use std::pin::Pin; use thiserror::Error; use tokio::net::UdpSocket; use tokio::select; Loading Loading @@ -80,7 +79,7 @@ const MAX_UDP_PACKET_SIZE: usize = 65536; struct Driver { request_rx: mpsc::Receiver<Request>, status_tx: watch::Sender<Status>, quiche_conn: Pin<Box<quiche::Connection>>, quiche_conn: quiche::Connection, socket: UdpSocket, // This buffer is large, boxing it will keep it // off the stack and prevent it being copied during Loading Loading @@ -119,7 +118,7 @@ async fn optional_timeout(timeout: Option<boot_time::Duration>, net_id: u32) { pub async fn drive( request_rx: mpsc::Receiver<Request>, status_tx: watch::Sender<Status>, quiche_conn: Pin<Box<quiche::Connection>>, quiche_conn: quiche::Connection, socket: UdpSocket, net_id: u32, ) -> Result<()> { Loading @@ -130,7 +129,7 @@ impl Driver { fn new( request_rx: mpsc::Receiver<Request>, status_tx: watch::Sender<Status>, quiche_conn: Pin<Box<quiche::Connection>>, quiche_conn: quiche::Connection, socket: UdpSocket, net_id: u32, ) -> Self { Loading Loading @@ -163,7 +162,8 @@ impl Driver { self.quiche_conn.peer_error() ); // We don't care if the receiver has hung up let _ = self.status_tx.send(Status::Dead { session: self.quiche_conn.session() }); let session = self.quiche_conn.session().map(<[_]>::to_vec); let _ = self.status_tx.send(Status::Dead { session }); Err(Error::Closed) } else { Ok(()) Loading @@ -180,7 +180,8 @@ impl Driver { self.quiche_conn.peer_error() ); // We don't care if the receiver has hung up let _ = self.status_tx.send(Status::Dead { session: self.quiche_conn.session() }); let session = self.quiche_conn.session().map(<[_]>::to_vec); let _ = self.status_tx.send(Status::Dead { session }); self.request_rx.close(); // Drain the pending DNS requests from the queue to make their corresponding future Loading Loading @@ -265,10 +266,8 @@ impl H3Driver { let _ = self.driver.status_tx.send(Status::H3); loop { if let Err(e) = self.drive_once().await { let _ = self .driver .status_tx .send(Status::Dead { session: self.driver.quiche_conn.session() }); let session = self.driver.quiche_conn.session().map(<[_]>::to_vec); let _ = self.driver.status_tx.send(Status::Dead { session }); return Err(e); } } Loading Loading @@ -445,17 +444,30 @@ impl H3Driver { ); self.respond(stream_id) } // This clause is for quiche 0.10.x, we're still on 0.9.x //h3::Event::Reset(e) => { // self.streams.get_mut(&stream_id).map(|stream| stream.error = Some(e)); // self.respond(stream_id); //} h3::Event::Reset(e) => { debug!( "process_h3_event: h3::Event::Reset with error code {} on stream ID {}, network {}", e, stream_id, self.driver.net_id ); if let Some(stream) = self.streams.get_mut(&stream_id) { stream.error = Some(e) } self.respond(stream_id); } h3::Event::Datagram => { warn!("Unexpected Datagram received"); // We don't care if something went wrong with the datagram, we didn't // want it anyways. let _ = self.discard_datagram(stream_id); } h3::Event::PriorityUpdate => { debug!( "process_h3_event: h3::Event::PriorityUpdate on stream ID {}, network {}", stream_id, self.driver.net_id ); // It tells us that PRIORITY_UPDATE frame is received, but we are not // using it in our code currently. No-op should be fine. } h3::Event::GoAway => self.shutdown(false, b"SERVER GOAWAY").await?, } Ok(()) Loading doh/tests/doh_frontend/src/client.rs +2 −3 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ use log::{debug, error, info, warn}; use quiche::h3::NameValue; use std::collections::{hash_map, HashMap}; use std::net::SocketAddr; use std::pin::Pin; use std::time::Duration; pub const DNS_HEADER_SIZE: usize = 12; Loading @@ -35,7 +34,7 @@ const URL_PATH_PREFIX: &str = "/dns-query?dns="; /// Manages a QUIC and HTTP/3 connection. No socket I/O operations. pub struct Client { /// QUIC connection. conn: Pin<Box<quiche::Connection>>, conn: quiche::Connection, /// HTTP/3 connection. h3_conn: Option<quiche::h3::Connection>, Loading @@ -59,7 +58,7 @@ pub struct Client { } impl Client { fn new(conn: Pin<Box<quiche::Connection>>, addr: &SocketAddr, id: ConnectionID) -> Client { fn new(conn: quiche::Connection, addr: &SocketAddr, id: ConnectionID) -> Client { Client { conn, h3_conn: None, Loading resolv_test_config_without_root_template.xml 0 → 100644 +37 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2022 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- Workaround for MTS coverage because test infra is running the 64 bit test suite on cf_x86_phone (32-bit). See b/147785146 for details. We need to push the correct binary against the architecture of test device with "append-bitness" option. --> <configuration description="Configuration for {MODULE} tests"> <option name="test-suite-tag" value="mts" /> <option name="config-descriptor:metadata" key="mainline-param" value="CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex+com.google.android.tethering.apex" /> <target_preparer class="com.android.testutils.DisableConfigSyncTargetPreparer" /> <target_preparer class="com.android.compatibility.common.tradefed.targetprep.FilePusher"> <option name="cleanup" value="true" /> <option name="push" value="{MODULE}->/data/local/tmp/{MODULE}" /> <option name="append-bitness" value="true" /> </target_preparer> <test class="com.android.tradefed.testtype.GTest" > <option name="native-test-device-path" value="/data/local/tmp" /> <option name="module-name" value="{MODULE}" /> <option name="runtime-hint" value="10m" /> <!-- test-timeout unit is ms, value = 10 min --> <option name="native-test-timeout" value="600000" /> </test> </configuration> Loading
Android.bp +23 −0 Original line number Diff line number Diff line Loading @@ -150,6 +150,22 @@ cc_defaults { }, } cc_defaults { // Similar to resolv_test_mts_coverage_defaults, but it's for the tests that don't need // root access. name: "resolv_test_mts_coverage_without_root_defaults", test_config_template: ":resolv_test_config_without_root_template", compile_multilib: "both", multilib: { lib32: { suffix: "32", }, lib64: { suffix: "64", }, }, } cc_library { name: "libnetd_resolv", version_script: "libnetd_resolv.map.txt", Loading Loading @@ -307,6 +323,13 @@ filegroup { ], } filegroup { name: "resolv_test_config_without_root_template", srcs: [ "resolv_test_config_without_root_template.xml", ], } filegroup { name: "resolv_unit_test_files", srcs: [ Loading
DnsTlsSocket.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -94,6 +94,12 @@ Status DnsTlsSocket::tcpConnect() { return Status(err); } // Set TCP MSS to a suitably low value to be more reliable. const int v = 1220; if (setsockopt(mSslFd.get(), SOL_TCP, TCP_MAXSEG, &v, sizeof(v)) == -1) { LOG(WARNING) << "Failed to set TCP_MAXSEG: " << errno; } const Status tfo = enableSockopt(mSslFd.get(), SOL_TCP, TCP_FASTOPEN_CONNECT); if (!isOk(tfo) && tfo.code() != ENOPROTOOPT) { LOG(WARNING) << "Failed to enable TFO: " << tfo.msg(); Loading
doh/connection/driver.rs +27 −15 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ use std::collections::HashMap; use std::default::Default; use std::future; use std::io; use std::pin::Pin; use thiserror::Error; use tokio::net::UdpSocket; use tokio::select; Loading Loading @@ -80,7 +79,7 @@ const MAX_UDP_PACKET_SIZE: usize = 65536; struct Driver { request_rx: mpsc::Receiver<Request>, status_tx: watch::Sender<Status>, quiche_conn: Pin<Box<quiche::Connection>>, quiche_conn: quiche::Connection, socket: UdpSocket, // This buffer is large, boxing it will keep it // off the stack and prevent it being copied during Loading Loading @@ -119,7 +118,7 @@ async fn optional_timeout(timeout: Option<boot_time::Duration>, net_id: u32) { pub async fn drive( request_rx: mpsc::Receiver<Request>, status_tx: watch::Sender<Status>, quiche_conn: Pin<Box<quiche::Connection>>, quiche_conn: quiche::Connection, socket: UdpSocket, net_id: u32, ) -> Result<()> { Loading @@ -130,7 +129,7 @@ impl Driver { fn new( request_rx: mpsc::Receiver<Request>, status_tx: watch::Sender<Status>, quiche_conn: Pin<Box<quiche::Connection>>, quiche_conn: quiche::Connection, socket: UdpSocket, net_id: u32, ) -> Self { Loading Loading @@ -163,7 +162,8 @@ impl Driver { self.quiche_conn.peer_error() ); // We don't care if the receiver has hung up let _ = self.status_tx.send(Status::Dead { session: self.quiche_conn.session() }); let session = self.quiche_conn.session().map(<[_]>::to_vec); let _ = self.status_tx.send(Status::Dead { session }); Err(Error::Closed) } else { Ok(()) Loading @@ -180,7 +180,8 @@ impl Driver { self.quiche_conn.peer_error() ); // We don't care if the receiver has hung up let _ = self.status_tx.send(Status::Dead { session: self.quiche_conn.session() }); let session = self.quiche_conn.session().map(<[_]>::to_vec); let _ = self.status_tx.send(Status::Dead { session }); self.request_rx.close(); // Drain the pending DNS requests from the queue to make their corresponding future Loading Loading @@ -265,10 +266,8 @@ impl H3Driver { let _ = self.driver.status_tx.send(Status::H3); loop { if let Err(e) = self.drive_once().await { let _ = self .driver .status_tx .send(Status::Dead { session: self.driver.quiche_conn.session() }); let session = self.driver.quiche_conn.session().map(<[_]>::to_vec); let _ = self.driver.status_tx.send(Status::Dead { session }); return Err(e); } } Loading Loading @@ -445,17 +444,30 @@ impl H3Driver { ); self.respond(stream_id) } // This clause is for quiche 0.10.x, we're still on 0.9.x //h3::Event::Reset(e) => { // self.streams.get_mut(&stream_id).map(|stream| stream.error = Some(e)); // self.respond(stream_id); //} h3::Event::Reset(e) => { debug!( "process_h3_event: h3::Event::Reset with error code {} on stream ID {}, network {}", e, stream_id, self.driver.net_id ); if let Some(stream) = self.streams.get_mut(&stream_id) { stream.error = Some(e) } self.respond(stream_id); } h3::Event::Datagram => { warn!("Unexpected Datagram received"); // We don't care if something went wrong with the datagram, we didn't // want it anyways. let _ = self.discard_datagram(stream_id); } h3::Event::PriorityUpdate => { debug!( "process_h3_event: h3::Event::PriorityUpdate on stream ID {}, network {}", stream_id, self.driver.net_id ); // It tells us that PRIORITY_UPDATE frame is received, but we are not // using it in our code currently. No-op should be fine. } h3::Event::GoAway => self.shutdown(false, b"SERVER GOAWAY").await?, } Ok(()) Loading
doh/tests/doh_frontend/src/client.rs +2 −3 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ use log::{debug, error, info, warn}; use quiche::h3::NameValue; use std::collections::{hash_map, HashMap}; use std::net::SocketAddr; use std::pin::Pin; use std::time::Duration; pub const DNS_HEADER_SIZE: usize = 12; Loading @@ -35,7 +34,7 @@ const URL_PATH_PREFIX: &str = "/dns-query?dns="; /// Manages a QUIC and HTTP/3 connection. No socket I/O operations. pub struct Client { /// QUIC connection. conn: Pin<Box<quiche::Connection>>, conn: quiche::Connection, /// HTTP/3 connection. h3_conn: Option<quiche::h3::Connection>, Loading @@ -59,7 +58,7 @@ pub struct Client { } impl Client { fn new(conn: Pin<Box<quiche::Connection>>, addr: &SocketAddr, id: ConnectionID) -> Client { fn new(conn: quiche::Connection, addr: &SocketAddr, id: ConnectionID) -> Client { Client { conn, h3_conn: None, Loading
resolv_test_config_without_root_template.xml 0 → 100644 +37 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2022 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- Workaround for MTS coverage because test infra is running the 64 bit test suite on cf_x86_phone (32-bit). See b/147785146 for details. We need to push the correct binary against the architecture of test device with "append-bitness" option. --> <configuration description="Configuration for {MODULE} tests"> <option name="test-suite-tag" value="mts" /> <option name="config-descriptor:metadata" key="mainline-param" value="CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex+com.google.android.tethering.apex" /> <target_preparer class="com.android.testutils.DisableConfigSyncTargetPreparer" /> <target_preparer class="com.android.compatibility.common.tradefed.targetprep.FilePusher"> <option name="cleanup" value="true" /> <option name="push" value="{MODULE}->/data/local/tmp/{MODULE}" /> <option name="append-bitness" value="true" /> </target_preparer> <test class="com.android.tradefed.testtype.GTest" > <option name="native-test-device-path" value="/data/local/tmp" /> <option name="module-name" value="{MODULE}" /> <option name="runtime-hint" value="10m" /> <!-- test-timeout unit is ms, value = 10 min --> <option name="native-test-timeout" value="600000" /> </test> </configuration>