Closed link2xt closed 1 year ago
One problem I see is that some parts of quinn-udp/src/unix.rs
are behind #[cfg(target_os = "linux")]
without corresponding target_os = "android"
branch.
Another difference is that in my case Linux is x86_64, while Android is aarch64.
Could there be an alignment problem with cmsg?
Commenting out the whole body of Encoder::push
in quinn-udp/src/cmsg.rs
worked:
https://github.com/quinn-rs/quinn/blob/02037e72fa6b7f994a2db411977bcffacbb8b02c/quinn-udp/src/cmsg.rs#L35
I guess it is a problem with cmsg alignment or something.
The patch which makes it work for me:
commit 67419bac18a4900354964733b786236086824983 (HEAD -> no-cmsg)
Author: link2xt <link2xt@testrun.org>
Date: Tue Mar 14 23:29:24 2023 +0000
Comment out cmsg encoding
diff --git a/quinn-udp/src/cmsg.rs b/quinn-udp/src/cmsg.rs
index 2cd111e9..c6c9f2e8 100644
--- a/quinn-udp/src/cmsg.rs
+++ b/quinn-udp/src/cmsg.rs
@@ -33,6 +33,7 @@ impl<'a> Encoder<'a> {
/// - If insufficient buffer space remains.
/// - If `T` has stricter alignment requirements than `cmsghdr`
pub fn push<T: Copy + ?Sized>(&mut self, level: libc::c_int, ty: libc::c_int, value: T) {
+ /*
assert!(mem::align_of::<T>() <= mem::align_of::<libc::cmsghdr>());
let space = unsafe { libc::CMSG_SPACE(mem::size_of_val(&value) as _) as usize };
#[allow(clippy::unnecessary_cast)] // hdr.msg_controllen defined as size_t
@@ -53,6 +54,7 @@ impl<'a> Encoder<'a> {
}
self.len += space;
self.cmsg = unsafe { libc::CMSG_NXTHDR(self.hdr, cmsg).as_mut() };
+ */
}
/// Finishes appending control messages to the buffer
I am running kernel 3.10.108 on Android. Looks like it does not support any cmsg_type
except for IP_RETOPTS
and IP_PKTINFO
: https://elixir.bootlin.com/linux/v3.10.108/source/net/ipv4/ip_sockglue.c#L219
IP_TOS
is supported on later kernels: https://elixir.bootlin.com/linux/v6.2.6/source/net/ipv4/ip_sockglue.c#L308
It was introduced in this commit: https://github.com/torvalds/linux/commit/f02db315b8d888570cb0d4496cfbb7e4acb047cb
For unknown cmsg types Linux returns EINVAL and does not send anything at all.
I suggest disabling adding IP_TOS
cmsg for Linux < 3.13 or all Androids.
I made a fix: ~#1512~ #1516
This can be closed, given #1516 was merged
While trying to get quinn-based file transfer (https://github.com/deltachat/deltachat-core-rust/pull/4007) working on Android, we discovered that no UDP packets are sent.
I compiled a CLI application
deltachat-repl
with NDK and ran it in Termux understrace
to find out what is happening. Apparently allsendmmsg
calls failed with EINVAL error.Example of the first
sendmmsg
call:Normally, on Linux,
sendmmsg
call looks like this:The difference I see is
msg_len=1200
when running on Linux, but not on Android, but this is a return value, it is written by the syscall on success.Sending UDP packets with
ncat
from Termux works, so it is not a problem with a general network permission.