From 91dd91fa99aeee6bc439f4c70c4424e4b824ad03 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Tue, 28 Dec 2021 21:25:56 -0800 Subject: [PATCH] Tolerate wide IP_TOS cmsgs --- quinn-udp/src/unix.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/quinn-udp/src/unix.rs b/quinn-udp/src/unix.rs index fd057497e..cf5c06a96 100644 --- a/quinn-udp/src/unix.rs +++ b/quinn-udp/src/unix.rs @@ -488,7 +488,16 @@ fn decode_recv( match (cmsg.cmsg_level, cmsg.cmsg_type) { // FreeBSD uses IP_RECVTOS here, and we can be liberal because cmsgs are opt-in. (libc::IPPROTO_IP, libc::IP_TOS) | (libc::IPPROTO_IP, libc::IP_RECVTOS) => unsafe { - ecn_bits = cmsg::decode::(cmsg); + // Linux reportedly returns 4-byte values here instead of the expected, documented + // 1-byte, e.g. in kernel 4.4.0-19041-Microsoft or on Github Actions. Future work: + // find out why, report upstream? + if cmsg.cmsg_len as usize + == libc::CMSG_LEN(mem::size_of::() as _) as usize + { + ecn_bits = cmsg::decode::(cmsg) as u8; + } else { + ecn_bits = cmsg::decode::(cmsg); + } }, (libc::IPPROTO_IPV6, libc::IPV6_TCLASS) => unsafe { // Temporary hack around broken macos ABI. Remove once upstream fixes it.