Merge 4a11c6adc783099386a3c8ac82da34cf82915224 into 9bdfd76819bd97aa790a679c47025ca8c535ee59

This commit is contained in:
WGH 2025-09-06 05:45:15 +03:00 committed by GitHub
commit 0a43353f99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -62,13 +62,11 @@ pub async fn udp_recv_pktinfo(
buf: &mut [u8],
) -> std::io::Result<(usize, SocketAddr, IpAddr)> {
sock.async_io(Interest::READABLE, || {
// according to documented struct definition in RFC 3542,
// sizeof(in6_pktinfo) should always be larger than sizeof(in_pktinfo),
// this assert just double checks that. The goal is to avoid
// a heap allocation with Vec at runtime.
assert!(cmsg_space::<nix::libc::in6_pktinfo>() >= cmsg_space::<nix::libc::in_pktinfo>());
let mut control_message_buffer = [0u8; cmsg_space::<nix::libc::in6_pktinfo>()];
const CONTROL_MESSAGE_BUFFER_SIZE: usize = max_usize(
cmsg_space::<nix::libc::in_pktinfo>(),
cmsg_space::<nix::libc::in6_pktinfo>(),
);
let mut control_message_buffer = [0u8; CONTROL_MESSAGE_BUFFER_SIZE];
let iov = &mut [std::io::IoSliceMut::new(buf)];
let res = nix::sys::socket::recvmsg::<SockaddrStorage>(
sock.as_raw_fd(),
@ -151,3 +149,7 @@ pub fn assign_ipv6_address(device_name: &str, local: Ipv6Addr, peer: Ipv6Addr) {
.unwrap();
rtnl.send(&nl_header).unwrap();
}
const fn max_usize(a: usize, b: usize) -> usize {
if a > b { a } else { b }
}