Allow QuicConnectionCloser to close loopback QUIC connection

The test for closing QUIC connection feature runs QuicTestServer
on the device to ensure the server tears down the connection after the
registered payload is sent to the server.
It is difficult to verify this with public servers because there is no
way to verify server internal state.

Before this CL, QuicConnectionCloser only closed connection when the
network's linkproperties contained the source address of the QUIC
connection.
This was to avoid sending packets from unused addresses.
However, this made it difficult to verify the feature in tests because
QuicTestServer listens on loopback address.

This could be solved by using test networks.
However, this requires a good amount of work, including updating
QuicTestServer to read packets from a tun file descriptor instead of a
UDP socket, and updating Cronet to allow overriding hostname resolution
when the HttpEngine is bound to a network.

So, this CL allows QuicConnectionCloser to close loopback QUIC
connections.
The impact of this change should be negligible because running a QUIC
server on the device is uncommon. Also, even if the connection is
closed, Cronet reconnects to the server quickly.

Flag: EXEMPT guarded by chromium flag
Test: TH
Bug: 311792075
Change-Id: I579b3cd912c47f15498527d7dc49e4169b9fe75f
This commit is contained in:
Motomu Utsumi 2025-04-25 15:15:45 +09:00
commit f56926095e

View file

@ -254,8 +254,14 @@ public class QuicConnectionCloser {
Log.d(TAG, "Close QUIC socket for " + info + ", destroySocket=" + destroySocket);
final NetworkAgentInfo nai = getNetworkAgentInfoForNetId(info.netId);
if (nai == null || !nai.linkProperties.getAddresses().contains(info.src.getAddress())) {
if (nai == null) return; // The network has gone away already
final boolean isLoopbackConnection = info.dst.getAddress().isLoopbackAddress();
final boolean lpContainsSourceAddress =
nai.linkProperties.getAddresses().contains(info.src.getAddress());
if (!isLoopbackConnection && !lpContainsSourceAddress) {
// The device should not send a packet with an unused source address.
// Loopback connections are closed exceptionally to simplify device local testing.
return;
}