Skip to content

Commit 24d5b75

Browse files
committed
Bug 1938063 - update Rust quinn-udp crate to v0.5.9 r=kershaw,supply-chain-reviewers
`quinn-udp` `v0.5.9` contains another fix for Bug 1916558, disabling URO on Windows all together. See quinn-rs/quinn#2092. In addition `quinn-udp` `v0.5.9` unblocks Bug 1933904 through quinn-rs/quinn#2079. Differential Revision: https://phabricator.services.mozilla.com/D232475
1 parent 69e02c7 commit 24d5b75

File tree

8 files changed

+73
-78
lines changed

8 files changed

+73
-78
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

supply-chain/audits.toml

+5
Original file line numberDiff line numberDiff line change
@@ -3956,6 +3956,11 @@ who = "Max Inden <[email protected]>"
39563956
criteria = "safe-to-deploy"
39573957
delta = "0.5.6 -> 0.5.8"
39583958

3959+
[[audits.quinn-udp]]
3960+
who = "Max Inden <[email protected]>"
3961+
criteria = "safe-to-deploy"
3962+
delta = "0.5.8 -> 0.5.9"
3963+
39593964
[[audits.quote]]
39603965
who = "Nika Layzell <[email protected]>"
39613966
criteria = "safe-to-deploy"
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"files":{"Cargo.toml":"5f3321d35730fb66ae6d4637b39852087fa5950c3a2d1b078ffa75ee0ff172d2","LICENSE-APACHE":"c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4","LICENSE-MIT":"4b2d0aca6789fa39e03d6738e869ea0988cceba210ca34ebb59c15c463e93a04","benches/throughput.rs":"095137508f85b68174978ff968cade74587751484402ca09269ffc2631d97f34","build.rs":"f15147312964f6a6dfc1a3b3d9645022c14a7be8bdb9bd321afc9a218235b431","src/cmsg/mod.rs":"63d6ea7126341fededdaef14260a7eed715ad3f507d4da586dbab814f581a54d","src/cmsg/unix.rs":"7917bce2f3c8e844eca2e4cfea82669b2a31cf311321dc42532626db4ee42de8","src/cmsg/windows.rs":"6fb936ec4a283efc5796872e777441e3039c40589073865644a8ef7936af4f4b","src/fallback.rs":"6378c177db7ba0eb88115b63f1ec9e17b05f53b1daae2c1e215520f103145585","src/lib.rs":"9672bd2003d779c95d11a85d05a5dac5d421a9d5dcd9f1475de94aca93f23f73","src/unix.rs":"214e078d745afd1cfe8be0880c492c2792a0cbfe6c21e74d4b9a4f47c92f0ae8","src/windows.rs":"c37b86003f815219f547420b14bd9f4b9172315122f8ea398c20e1cb3b35673a","tests/tests.rs":"6563e5d1d2c695616c590b3b92b58a7672351d85de47f2a2f6da008b909bccb3"},"package":"52cd4b1eff68bf27940dd39811292c49e007f4d0b4c357358dc9b0197be6b527"}
1+
{"files":{"Cargo.toml":"739bf78e6b796c0d89224ba2bbed4350a16536fc1ebac928c018dbdee46a3686","LICENSE-APACHE":"c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4","LICENSE-MIT":"4b2d0aca6789fa39e03d6738e869ea0988cceba210ca34ebb59c15c463e93a04","benches/throughput.rs":"095137508f85b68174978ff968cade74587751484402ca09269ffc2631d97f34","build.rs":"f15147312964f6a6dfc1a3b3d9645022c14a7be8bdb9bd321afc9a218235b431","src/cmsg/mod.rs":"63d6ea7126341fededdaef14260a7eed715ad3f507d4da586dbab814f581a54d","src/cmsg/unix.rs":"7917bce2f3c8e844eca2e4cfea82669b2a31cf311321dc42532626db4ee42de8","src/cmsg/windows.rs":"6fb936ec4a283efc5796872e777441e3039c40589073865644a8ef7936af4f4b","src/fallback.rs":"6378c177db7ba0eb88115b63f1ec9e17b05f53b1daae2c1e215520f103145585","src/lib.rs":"3c20f8012db32df03acb8b76094ce3f86f112159adf5e51ac9e2e9dec86516f1","src/unix.rs":"6583182c85cdaf7e1232332d161e4e537a3ea66b33604634daeba87df337dd9d","src/windows.rs":"09554e6b40fae544c1985b04dbe402454e0591877df243b10e86ff780a92aa1b","tests/tests.rs":"babb0fc08884958203b2a0546647e44a67f6b457fe2784935e32d73becb20f4c"},"package":"1c40286217b4ba3a71d644d752e6a0b71f13f1b6a2c5311acfcbe0c2418ed904"}

third_party/rust/quinn-udp/Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
edition = "2021"
1414
rust-version = "1.71"
1515
name = "quinn-udp"
16-
version = "0.5.8"
16+
version = "0.5.9"
1717
build = "build.rs"
1818
autolib = false
1919
autobins = false
@@ -98,6 +98,4 @@ features = [
9898
"Win32_Foundation",
9999
"Win32_System_IO",
100100
"Win32_Networking_WinSock",
101-
"Win32_System_SystemInformation",
102-
"Win32_System_Threading",
103101
]

third_party/rust/quinn-udp/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ pub struct RecvMeta {
106106
pub ecn: Option<EcnCodepoint>,
107107
/// The destination IP address which was encoded in this datagram
108108
///
109-
/// Populated on platforms: Windows, Linux, Android, FreeBSD, OpenBSD, NetBSD, macOS,
110-
/// and iOS.
109+
/// Populated on platforms: Windows, Linux, Android (API level > 25),
110+
/// FreeBSD, OpenBSD, NetBSD, macOS, and iOS.
111111
pub dst_ip: Option<IpAddr>,
112112
}
113113

third_party/rust/quinn-udp/src/unix.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -330,19 +330,27 @@ fn send(
330330
}
331331
}
332332

333-
if e.raw_os_error() == Some(libc::EINVAL) {
334-
// Some arguments to `sendmsg` are not supported.
335-
// Switch to fallback mode.
333+
// Some arguments to `sendmsg` are not supported. Switch to
334+
// fallback mode and retry if we haven't already.
335+
if e.raw_os_error() == Some(libc::EINVAL) && !state.sendmsg_einval() {
336336
state.set_sendmsg_einval();
337+
prepare_msg(
338+
transmit,
339+
&dst_addr,
340+
&mut msg_hdr,
341+
&mut iovec,
342+
&mut cmsgs,
343+
encode_src_ip,
344+
state.sendmsg_einval(),
345+
);
346+
continue;
337347
}
338348

339349
// - EMSGSIZE is expected for MTU probes. Future work might be able to avoid
340350
// these by automatically clamping the MTUD upper bound to the interface MTU.
341351
if e.raw_os_error() != Some(libc::EMSGSIZE) {
342352
return Err(e);
343353
}
344-
345-
return Ok(());
346354
}
347355
}
348356
}

third_party/rust/quinn-udp/src/windows.rs

+23-61
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ use std::{
1010

1111
use libc::{c_int, c_uint};
1212
use once_cell::sync::Lazy;
13-
use windows_sys::Win32::{
14-
Networking::WinSock,
15-
System::{
16-
SystemInformation::IMAGE_FILE_MACHINE_ARM64,
17-
Threading::{GetCurrentProcess, IsWow64Process2},
18-
},
19-
};
13+
use windows_sys::Win32::Networking::WinSock;
2014

2115
use crate::{
2216
cmsg::{self, CMsgHdr},
@@ -113,40 +107,34 @@ impl UdpSocketState {
113107
)?;
114108
}
115109

116-
match &*IS_WINDOWS_ON_ARM {
117-
Ok(true) => {
118-
// Bug on Windows on ARM, not receiving `UDP_COALESCED_INFO` `CMSG`
119-
// when _Virtual Machine Platform_ feature enabled. See
120-
// <https://github.com/quinn-rs/quinn/issues/2041> for details.
121-
debug!("detected Windows on ARM host thus not enabling URO")
122-
}
123-
Ok(false) => {
124-
// Opportunistically try to enable URO
125-
let result = set_socket_option(
126-
&*socket.0,
127-
WinSock::IPPROTO_UDP,
128-
WinSock::UDP_RECV_MAX_COALESCED_SIZE,
129-
// u32 per
130-
// https://learn.microsoft.com/en-us/windows/win32/winsock/ipproto-udp-socket-options.
131-
// Choice of 2^16 - 1 inspired by msquic.
132-
u16::MAX as u32,
133-
);
134-
135-
if let Err(_e) = result {
136-
debug!("failed to enable URO: {_e}");
137-
}
138-
}
139-
Err(_e) => {
140-
debug!("failed to detect host system thus not enabling URO: {_e}");
141-
}
142-
}
143-
144110
let now = Instant::now();
145111
Ok(Self {
146112
last_send_error: Mutex::new(now.checked_sub(2 * IO_ERROR_LOG_INTERVAL).unwrap_or(now)),
147113
})
148114
}
149115

116+
/// Enable or disable receive offloading.
117+
///
118+
/// Also referred to as UDP Receive Segment Coalescing Offload (URO) on Windows.
119+
///
120+
/// <https://learn.microsoft.com/en-us/windows-hardware/drivers/network/udp-rsc-offload>
121+
///
122+
/// Disabled by default on Windows due to <https://github.com/quinn-rs/quinn/issues/2041>.
123+
pub fn set_gro(&self, socket: UdpSockRef<'_>, enable: bool) -> io::Result<()> {
124+
set_socket_option(
125+
&*socket.0,
126+
WinSock::IPPROTO_UDP,
127+
WinSock::UDP_RECV_MAX_COALESCED_SIZE,
128+
match enable {
129+
// u32 per
130+
// https://learn.microsoft.com/en-us/windows/win32/winsock/ipproto-udp-socket-options.
131+
// Choice of 2^16 - 1 inspired by msquic.
132+
true => u16::MAX as u32,
133+
false => 0,
134+
},
135+
)
136+
}
137+
150138
/// Sends a [`Transmit`] on the given socket.
151139
///
152140
/// This function will only ever return errors of kind [`io::ErrorKind::WouldBlock`].
@@ -493,29 +481,3 @@ static MAX_GSO_SEGMENTS: Lazy<usize> = Lazy::new(|| {
493481
Err(_) => 1,
494482
}
495483
});
496-
497-
/// Evaluates to [`Ok(true)`] if executed either directly on Windows on ARM, or
498-
/// on an emulator which itself executes on Windows on ARM.
499-
///
500-
/// See
501-
/// <https://learn.microsoft.com/en-us/windows/arm/apps-on-arm-x86-emulation#detecting-emulation>
502-
/// for details.
503-
static IS_WINDOWS_ON_ARM: Lazy<io::Result<bool>> = Lazy::new(|| {
504-
let mut process_machine: u16 = 0;
505-
let mut native_machine: u16 = 0;
506-
507-
let result = unsafe {
508-
IsWow64Process2(
509-
GetCurrentProcess(),
510-
&mut process_machine as *mut u16,
511-
&mut native_machine as *mut u16,
512-
)
513-
};
514-
515-
match result {
516-
// See
517-
// <https://learn.microsoft.com/en-us/windows/win32/api/wow64apiset/nf-wow64apiset-iswow64process2#return-value>.
518-
0 => Err(io::Error::last_os_error()),
519-
_ => Ok(native_machine == IMAGE_FILE_MACHINE_ARM64),
520-
}
521-
});

third_party/rust/quinn-udp/tests/tests.rs

+26-4
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,12 @@ fn test_send_recv(send: &Socket, recv: &Socket, transmit: Transmit) {
225225
);
226226
let send_v6 = send.local_addr().unwrap().as_socket().unwrap().is_ipv6();
227227
let recv_v6 = recv.local_addr().unwrap().as_socket().unwrap().is_ipv6();
228-
let src = meta.addr.ip();
229-
let dst = meta.dst_ip.unwrap();
230-
for addr in [src, dst] {
228+
let mut addresses = vec![meta.addr.ip()];
229+
// Not populated on every OS. See `RecvMeta::dst_ip` for details.
230+
if let Some(addr) = meta.dst_ip {
231+
addresses.push(addr);
232+
}
233+
for addr in addresses {
231234
match (send_v6, recv_v6) {
232235
(_, false) => assert_eq!(addr, Ipv4Addr::LOCALHOST),
233236
// Windows gives us real IPv4 addrs, whereas *nix use IPv6-mapped IPv4
@@ -240,7 +243,26 @@ fn test_send_recv(send: &Socket, recv: &Socket, transmit: Transmit) {
240243
),
241244
}
242245
}
243-
assert_eq!(meta.ecn, transmit.ecn);
246+
247+
let ipv4_or_ipv4_mapped_ipv6 = match transmit.destination.ip() {
248+
IpAddr::V4(_) => true,
249+
IpAddr::V6(a) => a.to_ipv4_mapped().is_some(),
250+
};
251+
252+
// On Android API level <= 25 the IPv4 `IP_TOS` control message is
253+
// not supported and thus ECN bits can not be received.
254+
if ipv4_or_ipv4_mapped_ipv6
255+
&& cfg!(target_os = "android")
256+
&& std::env::var("API_LEVEL")
257+
.ok()
258+
.and_then(|v| v.parse::<u32>().ok())
259+
.expect("API_LEVEL environment variable to be set on Android")
260+
<= 25
261+
{
262+
assert_eq!(meta.ecn, None);
263+
} else {
264+
assert_eq!(meta.ecn, transmit.ecn);
265+
}
244266
}
245267
assert_eq!(datagrams, expected_datagrams);
246268
}

0 commit comments

Comments
 (0)