From 3ad6630c23a8c677a5f590918bb4b79b6f800d52 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Fri, 22 Nov 2024 12:34:34 +0200 Subject: [PATCH 01/20] feat: Solaris support WIP --- .github/workflows/check.yml | 21 ++++-- build.rs | 10 ++- src/bsd.rs | 141 ++++++++++++++++++++++++++---------- src/lib.rs | 22 ++++-- 4 files changed, 135 insertions(+), 59 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 3b997179..25d38462 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -111,7 +111,7 @@ jobs: cargo +${{ matrix.rust-toolchain }} test "${OPTIONS[@]}" fi cargo +${{ matrix.rust-toolchain }} bench --no-run - + - uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2 with: files: lcov.info @@ -253,7 +253,7 @@ jobs: strategy: fail-fast: false matrix: - os: [freebsd, openbsd, netbsd] # rust on solaris is too old + os: [freebsd, openbsd, netbsd, solaris] runs-on: ubuntu-latest steps: @@ -317,21 +317,26 @@ jobs: - if: matrix.os == 'solaris' uses: vmactions/solaris-vm@a89b9438868c70db27e41625f0a5de6ff5e90809 with: + release: "11.4-gcc" usesh: true envs: "CARGO_TERM_COLOR RUST_BACKTRACE GITHUB_ACTIONS" + prepare: | + pkg install clang-libs run: | - sh rustup.sh --default-toolchain stable --component llvm-tools -y - . "$HOME/.cargo/env" + source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install) + export LIBCLANG_PATH="/usr/lib/amd64" export RUST_LOG=trace - cargo install cargo-llvm-cov --locked + # cargo install cargo-llvm-cov --locked cargo check --all-targets cargo clippy - cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info + # FIXME: error[E0463]: can't find crate for `profiler_builtins`, + # cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info + cargo test --no-fail-fast cargo test --no-fail-fast --release - - uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0 + - uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2 with: - file: lcov.info + files: lcov.info fail_ci_if_error: false token: ${{ secrets.CODECOV_TOKEN }} verbose: true diff --git a/build.rs b/build.rs index a4843034..8ae8af9a 100644 --- a/build.rs +++ b/build.rs @@ -17,10 +17,11 @@ fn bindgen() { let bindings = bindgen::Builder::default() .header_contents( "route.h", - "#include \n#include \n#include ", + "#include \n#include \n#include \n#include ", ) - // Only generate bindings for the following types - .allowlist_type("rt_msghdr|rt_metrics"); + // Only generate bindings for the following types and items + .allowlist_type("rt_msghdr|rt_metrics|if_data") + .allowlist_item("RTAX_MAX|RTM_GET|RTM_VERSION|RTA_DST|RTA_IFP"); let bindings = bindings // Tell cargo to invalidate the built crate whenever any of the // included header files changed. @@ -87,7 +88,8 @@ fn main() { any( target_os = "freebsd", target_os = "openbsd", - target_os = "netbsd" + target_os = "netbsd", + target_os = "solaris" ) } } diff --git a/src/bsd.rs b/src/bsd.rs index ebe48997..bc4d51be 100644 --- a/src/bsd.rs +++ b/src/bsd.rs @@ -10,48 +10,64 @@ use std::{ marker::PhantomData, mem::size_of, net::IpAddr, + num::TryFromIntError, ops::Deref, ptr, slice, }; use libc::{ - freeifaddrs, getifaddrs, getpid, if_data, if_indextoname, ifaddrs, in6_addr, in_addr, - sockaddr_in, sockaddr_in6, sockaddr_storage, AF_UNSPEC, PF_ROUTE, RTAX_MAX, + freeifaddrs, getifaddrs, getpid, if_indextoname, ifaddrs, in6_addr, in_addr, sockaddr, + sockaddr_dl, sockaddr_in, sockaddr_in6, sockaddr_storage, AF_UNSPEC, PF_ROUTE, }; use static_assertions::{const_assert, const_assert_eq}; #[allow( non_camel_case_types, clippy::struct_field_names, - clippy::too_many_lines + clippy::too_many_lines, + clippy::cognitive_complexity, + dead_code // RTA_IFP is only used on NetBSD and Solaris )] mod bindings { include!(env!("BINDINGS")); } -use crate::{bsd::bindings::rt_msghdr, routesocket::RouteSocket}; - -#[cfg(any(apple, target_os = "freebsd", target_os = "openbsd"))] -const RTM_ADDRS: i32 = libc::RTA_DST; - -#[cfg(target_os = "netbsd")] -const RTM_ADDRS: i32 = libc::RTA_DST | libc::RTA_IFP; +#[cfg(any(target_os = "netbsd", target_os = "solaris"))] +use crate::bsd::bindings::RTA_IFP; +use crate::{ + aligned_by, + bsd::bindings::{if_data, rt_msghdr, RTAX_MAX, RTA_DST}, + default_err, + routesocket::RouteSocket, + unlikely_err, +}; #[cfg(apple)] const ALIGN: usize = size_of::(); -#[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] +#[cfg(bsd)] // See https://github.com/freebsd/freebsd-src/blob/524a425d30fce3d5e47614db796046830b1f6a83/sys/net/route.h#L362-L371 // See https://github.com/NetBSD/src/blob/4b50954e98313db58d189dd87b4541929efccb09/sys/net/route.h#L329-L331 +// See https://github.com/Arquivotheca/Solaris-8/blob/2ad1d32f9eeed787c5adb07eb32544276e2e2444/osnet_volume/usr/src/cmd/cmd-inet/usr.sbin/route.c#L238-L239 const ALIGN: usize = size_of::(); -use crate::{aligned_by, default_err}; +#[cfg(any(apple, target_os = "freebsd", target_os = "openbsd"))] +asserted_const_with_type!(RTM_ADDRS, i32, RTA_DST, u32); -asserted_const_with_type!(AF_INET, u8, libc::AF_INET, i32); -asserted_const_with_type!(AF_INET6, u8, libc::AF_INET6, i32); -asserted_const_with_type!(AF_LINK, u8, libc::AF_LINK, i32); -asserted_const_with_type!(RTM_VERSION, u8, libc::RTM_VERSION, i32); -asserted_const_with_type!(RTM_GET, u8, libc::RTM_GET, i32); +#[cfg(any(target_os = "netbsd", target_os = "solaris"))] +asserted_const_with_type!(RTM_ADDRS, i32, RTA_DST | RTA_IFP, u32); + +#[cfg(not(target_os = "solaris"))] +type AddressFamily = u8; + +#[cfg(target_os = "solaris")] +type AddressFamily = u16; + +asserted_const_with_type!(AF_INET, AddressFamily, libc::AF_INET, i32); +asserted_const_with_type!(AF_INET6, AddressFamily, libc::AF_INET6, i32); +asserted_const_with_type!(AF_LINK, AddressFamily, libc::AF_LINK, i32); +asserted_const_with_type!(RTM_VERSION, u8, crate::bsd::bindings::RTM_VERSION, u32); +asserted_const_with_type!(RTM_GET, u8, crate::bsd::bindings::RTM_GET, u32); const_assert!(size_of::() + ALIGN <= u8::MAX as usize); const_assert!(size_of::() + ALIGN <= u8::MAX as usize); @@ -138,7 +154,7 @@ impl Iterator for IfAddrPtr<'_> { } } -fn if_name_mtu(idx: u32) -> Result<(String, usize)> { +fn if_name_mtu(idx: u32) -> Result<(String, Option)> { let mut name = [0; libc::IF_NAMESIZE]; // if_indextoname writes into the provided buffer. if unsafe { if_indextoname(idx, name.as_mut_ptr()).is_null() } { @@ -150,18 +166,17 @@ fn if_name_mtu(idx: u32) -> Result<(String, usize)> { .to_str() .map_err(|err| Error::new(ErrorKind::Other, err))? }; - for ifa in IfAddrs::new()?.iter() { if ifa.addr().sa_family == AF_LINK && ifa.name() == name { if let Some(ifa_data) = ifa.data() { if let Ok(mtu) = usize::try_from(ifa_data.ifi_mtu) { - return Ok((name.to_string(), mtu)); + return Ok((name.to_string(), Some(mtu))); } } - return Err(default_err()); + return Ok((name.to_string(), None)); } } - Err(default_err()) + Ok((name.to_string(), None)) } #[repr(C)] @@ -170,10 +185,18 @@ union SockaddrStorage { sin6: sockaddr_in6, } -impl SockaddrStorage { - const fn len(&self) -> u8 { - unsafe { self.sin.sin_len } - } +fn sockaddr_len(af: AddressFamily) -> Result { + let sa_len = match af { + AF_INET => size_of::(), + AF_INET6 => size_of::(), + _ => { + return Err(Error::new( + ErrorKind::InvalidInput, + "Unsupported address family {:af}", + )) + } + }; + Ok(aligned_by(sa_len, ALIGN)) } impl From for SockaddrStorage { @@ -181,6 +204,7 @@ impl From for SockaddrStorage { match ip { IpAddr::V4(ip) => SockaddrStorage { sin: sockaddr_in { + #[cfg(not(target_os = "solaris"))] #[allow(clippy::cast_possible_truncation)] // `sockaddr_in` len is <= u8::MAX per `const_assert!` above. sin_len: size_of::() as u8, @@ -194,6 +218,7 @@ impl From for SockaddrStorage { }, IpAddr::V6(ip) => SockaddrStorage { sin6: sockaddr_in6 { + #[cfg(not(target_os = "solaris"))] #[allow(clippy::cast_possible_truncation)] // `sockaddr_in6` len is <= u8::MAX per `const_assert!` above. sin6_len: size_of::() as u8, @@ -204,7 +229,9 @@ impl From for SockaddrStorage { sin6_port: 0, sin6_flowinfo: 0, sin6_scope_id: 0, - }, + #[cfg(target_os = "solaris")] + __sin6_src_id: 0, + }, }, } } @@ -217,13 +244,17 @@ struct RouteMessage { } impl RouteMessage { - fn new(remote: IpAddr, seq: i32) -> Self { + fn new(remote: IpAddr, seq: i32) -> Result { let sa = SockaddrStorage::from(remote); - Self { + let sa_len = sockaddr_len(match remote { + IpAddr::V4(_) => AF_INET, + IpAddr::V6(_) => AF_INET6, + })?; + Ok(Self { rtm: rt_msghdr { #[allow(clippy::cast_possible_truncation)] // `rt_msghdr` len + `ALIGN` is <= u8::MAX per `const_assert!` above. - rtm_msglen: (size_of::() + aligned_by(sa.len().into(), ALIGN)) as u16, + rtm_msglen: (size_of::() + sa_len) as u16, rtm_version: RTM_VERSION, rtm_type: RTM_GET, rtm_seq: seq, @@ -231,7 +262,7 @@ impl RouteMessage { ..Default::default() }, sa, - } + }) } const fn version(&self) -> u8 { @@ -254,20 +285,20 @@ impl From<&RouteMessage> for &[u8] { } } -impl From> for rt_msghdr { - fn from(value: Vec) -> Self { +impl From<&[u8]> for rt_msghdr { + fn from(value: &[u8]) -> Self { debug_assert!(value.len() >= size_of::()); unsafe { ptr::read_unaligned(value.as_ptr().cast()) } } } -fn if_index(remote: IpAddr) -> Result { +fn if_index_mtu(remote: IpAddr) -> Result<(u16, Option)> { // Open route socket. let mut fd = RouteSocket::new(PF_ROUTE, AF_UNSPEC)?; // Send route message. let query_seq = RouteSocket::new_seq(); - let query = RouteMessage::new(remote, query_seq); + let query = RouteMessage::new(remote, query_seq)?; let query_version = query.version(); let query_type = query.kind(); fd.write_all((&query).into())?; @@ -285,13 +316,44 @@ fn if_index(remote: IpAddr) -> Result { if len < size_of::() { return Err(default_err()); } - let reply: rt_msghdr = buf.into(); + let (reply, mut sa) = buf.split_at(size_of::()); + let reply: rt_msghdr = reply.into(); if reply.rtm_version == query_version && reply.rtm_pid == pid && reply.rtm_seq == query_seq { // This is a reply to our query. return if reply.rtm_type == query_type { // This is the reply we are looking for. - Ok(reply.rtm_index) + // Some BSDs let us get the interface index and MTU directly from the reply. + let mtu: Option = if reply.rtm_rmx.rmx_mtu != 0 { + Some( + reply + .rtm_rmx + .rmx_mtu + .try_into() + .map_err(|e: TryFromIntError| unlikely_err(e.to_string()))?, + ) + } else { + None + }; + if reply.rtm_index != 0 { + // Some BSDs return the interface index directly. + Ok((reply.rtm_index, mtu)) + } else { + // For others, we need to extract it from the sockaddrs. + for i in 0..RTAX_MAX { + if (reply.rtm_addrs & (1 << i)) != 0 { + let saddr = unsafe { &*ptr::from_ref(sa).cast::() }; + if saddr.sa_family == AF_LINK { + let sdl = unsafe { + ptr::read_unaligned(sa.as_ptr().cast::()) + }; + return Ok((sdl.sdl_index, mtu)); + } + (_, sa) = sa.split_at(sockaddr_len(saddr.sa_family)?); + } + } + Err(default_err()) + } } else { Err(default_err()) }; @@ -300,6 +362,7 @@ fn if_index(remote: IpAddr) -> Result { } pub fn interface_and_mtu_impl(remote: IpAddr) -> Result<(String, usize)> { - let if_index = if_index(remote)?; - if_name_mtu(if_index.into()) + let (if_index, mtu1) = if_index_mtu(remote)?; + let (if_name, mtu2) = if_name_mtu(if_index.into())?; + Ok((if_name, mtu1.or(mtu2).ok_or_else(default_err)?)) } diff --git a/src/lib.rs b/src/lib.rs index 5f856955..4101a4c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,7 +50,7 @@ use std::{ #[cfg(not(target_os = "windows"))] macro_rules! asserted_const_with_type { ($name:ident, $t1:ty, $e:expr, $t2:ty) => { - #[allow(clippy::cast_possible_truncation)] // Guarded by the following `const_assert_eq!`. + #[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap)] // Guarded by the following `const_assert_eq!`. const $name: $t1 = $e as $t1; const_assert_eq!($name as $t2, $e); }; @@ -131,15 +131,21 @@ mod test { } #[cfg(any(apple, target_os = "freebsd",))] - const LOOPBACK: NameMtu = NameMtu(Some("lo0"), 16_384); + const LOOPBACK: &[NameMtu] = &[NameMtu(Some("lo0"), 16_384), NameMtu(Some("lo0"), 16_384)]; #[cfg(target_os = "linux")] - const LOOPBACK: NameMtu = NameMtu(Some("lo"), 65_536); + const LOOPBACK: &[NameMtu] = &[NameMtu(Some("lo0"), 65_536), NameMtu(Some("lo0"), 65_536)]; #[cfg(target_os = "windows")] - const LOOPBACK: NameMtu = NameMtu(Some("loopback_0"), 4_294_967_295); + const LOOPBACK: &[NameMtu] = &[ + NameMtu(Some("lo0"), 4_294_967_295), + NameMtu(Some("lo0"), 4_294_967_295), + ]; #[cfg(target_os = "openbsd")] - const LOOPBACK: NameMtu = NameMtu(Some("lo0"), 32_768); + const LOOPBACK: &[NameMtu] = &[NameMtu(Some("lo0"), 32_768), NameMtu(Some("lo0"), 32_768)]; #[cfg(target_os = "netbsd")] - const LOOPBACK: NameMtu = NameMtu(Some("lo0"), 33_624); + const LOOPBACK: &[NameMtu] = &[NameMtu(Some("lo0"), 33_624), NameMtu(Some("lo0"), 33_624)]; + #[cfg(target_os = "solaris")] + // Note: Different loopback MTUs for IPv4 and IPv6?! + const LOOPBACK: &[NameMtu] = &[NameMtu(Some("lo0"), 8_232), NameMtu(Some("lo0"), 8_252)]; // Non-loopback interface names are unpredictable, so we only check the MTU. const INET: NameMtu = NameMtu(None, 1_500); @@ -148,7 +154,7 @@ mod test { fn loopback_v4() { assert_eq!( interface_and_mtu(IpAddr::V4(Ipv4Addr::LOCALHOST)).unwrap(), - LOOPBACK + LOOPBACK[0] ); } @@ -156,7 +162,7 @@ mod test { fn loopback_v6() { assert_eq!( interface_and_mtu(IpAddr::V6(Ipv6Addr::LOCALHOST)).unwrap(), - LOOPBACK + LOOPBACK[1] ); } From f119e9230dc84cc2c5cd56f6308f8fc76a942f79 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Fri, 22 Nov 2024 12:43:30 +0200 Subject: [PATCH 02/20] Fixes --- README.md | 1 + src/bsd.rs | 10 ++++++---- src/lib.rs | 7 ++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 760efb5f..c116263d 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ println!("MTU towards {destination} is {mtu} on {name}"); * FreeBSD * NetBSD * OpenBSD +* Solaris ## Notes diff --git a/src/bsd.rs b/src/bsd.rs index bc4d51be..26cd930e 100644 --- a/src/bsd.rs +++ b/src/bsd.rs @@ -166,17 +166,19 @@ fn if_name_mtu(idx: u32) -> Result<(String, Option)> { .to_str() .map_err(|err| Error::new(ErrorKind::Other, err))? }; + let mut mtu = None; for ifa in IfAddrs::new()?.iter() { if ifa.addr().sa_family == AF_LINK && ifa.name() == name { if let Some(ifa_data) = ifa.data() { - if let Ok(mtu) = usize::try_from(ifa_data.ifi_mtu) { - return Ok((name.to_string(), Some(mtu))); + if let Ok(ifi_mtu) = usize::try_from(ifa_data.ifi_mtu) { + mtu = Some(ifi_mtu); + break; } } - return Ok((name.to_string(), None)); + break; } } - Ok((name.to_string(), None)) + Ok((name.to_string(), mtu)) } #[repr(C)] diff --git a/src/lib.rs b/src/lib.rs index 4101a4c7..c90b85dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,7 @@ //! * FreeBSD //! * NetBSD //! * OpenBSD +//! * Solaris //! //! # Notes //! @@ -133,11 +134,11 @@ mod test { #[cfg(any(apple, target_os = "freebsd",))] const LOOPBACK: &[NameMtu] = &[NameMtu(Some("lo0"), 16_384), NameMtu(Some("lo0"), 16_384)]; #[cfg(target_os = "linux")] - const LOOPBACK: &[NameMtu] = &[NameMtu(Some("lo0"), 65_536), NameMtu(Some("lo0"), 65_536)]; + const LOOPBACK: &[NameMtu] = &[NameMtu(Some("lo"), 65_536), NameMtu(Some("lo"), 65_536)]; #[cfg(target_os = "windows")] const LOOPBACK: &[NameMtu] = &[ - NameMtu(Some("lo0"), 4_294_967_295), - NameMtu(Some("lo0"), 4_294_967_295), + NameMtu(Some("loopback_0"), 4_294_967_295), + NameMtu(Some("loopback_0"), 4_294_967_295), ]; #[cfg(target_os = "openbsd")] const LOOPBACK: &[NameMtu] = &[NameMtu(Some("lo0"), 32_768), NameMtu(Some("lo0"), 32_768)]; From bb9a768f98cdffedf3437ff12168b13fbc3e8ca3 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Dec 2024 10:56:01 +0200 Subject: [PATCH 03/20] More llvm --- .github/workflows/check.yml | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index abf9f88f..84c7d951 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -255,6 +255,8 @@ jobs: matrix: os: [freebsd, openbsd, netbsd, solaris] runs-on: ubuntu-latest + env: + RUST_LOG: trace steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 @@ -264,13 +266,12 @@ jobs: uses: vmactions/freebsd-vm@debf37ca7b7fa40e19c542ef7ba30d6054a706a4 with: usesh: true - envs: "CARGO_TERM_COLOR RUST_BACKTRACE GITHUB_ACTIONS" + envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" prepare: | pkg install -y curl llvm run: | sh rustup.sh --default-toolchain stable --component llvm-tools -y . "$HOME/.cargo/env" - export RUST_LOG=trace cargo install cargo-llvm-cov --locked cargo check --all-targets cargo clippy @@ -281,22 +282,22 @@ jobs: uses: vmactions/openbsd-vm@0cfe06e734a0ea3a546fca7ebf200b984b94d58a with: usesh: true - envs: "CARGO_TERM_COLOR RUST_BACKTRACE GITHUB_ACTIONS" + envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" prepare: | pkg_add rust llvm-16.0.6p30 # rustup doesn't support OpenBSD at all run: | export LIBCLANG_PATH=/usr/local/llvm16/lib - export RUST_LOG=trace + cargo install cargo-llvm-cov --locked cargo check --all-targets cargo clippy - cargo test --no-fail-fast + cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast --release - if: matrix.os == 'netbsd' uses: vmactions/netbsd-vm@7c9086fdb4cc1aa814cda6e305390c2b966551a9 with: usesh: true - envs: "CARGO_TERM_COLOR RUST_BACKTRACE GITHUB_ACTIONS" + envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" prepare: | /usr/sbin/pkg_add pkgin pkgin -y install curl clang @@ -304,14 +305,10 @@ jobs: sh rustup.sh --default-toolchain stable --component llvm-tools -y . "$HOME/.cargo/env" export LIBCLANG_PATH=/usr/pkg/lib - export RUST_LOG=trace cargo install cargo-llvm-cov --locked cargo check --all-targets cargo clippy - cargo test --no-fail-fast - # FIXME: error[E0463]: can't find crate for `profiler_builtins`, - # so don't fail the workflow when that happens. - cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info || true + cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast --release - if: matrix.os == 'solaris' @@ -319,19 +316,16 @@ jobs: with: release: "11.4-gcc" usesh: true - envs: "CARGO_TERM_COLOR RUST_BACKTRACE GITHUB_ACTIONS" + envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" prepare: | pkg install clang-libs run: | source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install) export LIBCLANG_PATH="/usr/lib/amd64" - export RUST_LOG=trace - # cargo install cargo-llvm-cov --locked + cargo install cargo-llvm-cov --locked cargo check --all-targets cargo clippy - # FIXME: error[E0463]: can't find crate for `profiler_builtins`, - # cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info - cargo test --no-fail-fast + cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast --release - uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a # v5.0.7 From a81f76b9d76ab1ba1182773c27186afbf234707a Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Dec 2024 11:15:22 +0200 Subject: [PATCH 04/20] `set -e -x` --- .github/workflows/check.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 84c7d951..7070c478 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -59,7 +59,7 @@ jobs: - os: ubuntu-20.04 rust-toolchain: stable type: debug - - os: macos-12 + - os: macos-13 rust-toolchain: stable type: debug - os: windows-2019 @@ -268,8 +268,10 @@ jobs: usesh: true envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" prepare: | + set -e -x pkg install -y curl llvm run: | + set -e -x sh rustup.sh --default-toolchain stable --component llvm-tools -y . "$HOME/.cargo/env" cargo install cargo-llvm-cov --locked @@ -284,8 +286,10 @@ jobs: usesh: true envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" prepare: | + set -e -x pkg_add rust llvm-16.0.6p30 # rustup doesn't support OpenBSD at all run: | + set -e -x export LIBCLANG_PATH=/usr/local/llvm16/lib cargo install cargo-llvm-cov --locked cargo check --all-targets @@ -299,9 +303,11 @@ jobs: usesh: true envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" prepare: | + set -e -x /usr/sbin/pkg_add pkgin pkgin -y install curl clang run: | + set -e -x sh rustup.sh --default-toolchain stable --component llvm-tools -y . "$HOME/.cargo/env" export LIBCLANG_PATH=/usr/pkg/lib @@ -318,8 +324,10 @@ jobs: usesh: true envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" prepare: | + set -e -x pkg install clang-libs run: | + set -e -x source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install) export LIBCLANG_PATH="/usr/lib/amd64" cargo install cargo-llvm-cov --locked From a49c2e55f6044d5ecf71f08d2b738f417b1d4f20 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Dec 2024 11:30:37 +0200 Subject: [PATCH 05/20] Again --- .github/workflows/check.yml | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 7070c478..53190544 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -268,12 +268,11 @@ jobs: usesh: true envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" prepare: | - set -e -x + set -e pkg install -y curl llvm - run: | - set -e -x sh rustup.sh --default-toolchain stable --component llvm-tools -y - . "$HOME/.cargo/env" + run: | + set -e cargo install cargo-llvm-cov --locked cargo check --all-targets cargo clippy @@ -286,14 +285,17 @@ jobs: usesh: true envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" prepare: | - set -e -x + set -e pkg_add rust llvm-16.0.6p30 # rustup doesn't support OpenBSD at all run: | - set -e -x + ls -l $HOME + cat $HOME/.profile + set -e export LIBCLANG_PATH=/usr/local/llvm16/lib cargo install cargo-llvm-cov --locked cargo check --all-targets - cargo clippy + # FIXME: clippy not available on openbsd + # cargo clippy cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast --release @@ -303,13 +305,12 @@ jobs: usesh: true envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" prepare: | - set -e -x + set -e /usr/sbin/pkg_add pkgin pkgin -y install curl clang - run: | - set -e -x sh rustup.sh --default-toolchain stable --component llvm-tools -y - . "$HOME/.cargo/env" + run: | + set -e export LIBCLANG_PATH=/usr/pkg/lib cargo install cargo-llvm-cov --locked cargo check --all-targets @@ -324,11 +325,13 @@ jobs: usesh: true envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" prepare: | - set -e -x + set -e pkg install clang-libs - run: | - set -e -x source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install) + run: | + ls -l $HOME + cat $HOME/.profile + set -e export LIBCLANG_PATH="/usr/lib/amd64" cargo install cargo-llvm-cov --locked cargo check --all-targets From 32b155a3ac0b3f73911927dd22b347aea9ede683 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Dec 2024 11:45:31 +0200 Subject: [PATCH 06/20] More --- .github/workflows/check.yml | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 53190544..a8d5f70a 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -81,7 +81,7 @@ jobs: - uses: ./neqo/.github/actions/rust with: version: ${{ matrix.rust-toolchain }} - components: ${{ matrix.rust-toolchain == 'stable' && 'llvm-tools' || '' }} ${{ matrix.rust-toolchain == 'nightly' && 'rust-src' || '' }} + components: ${{ matrix.rust-toolchain == 'stable' && 'clippy llvm-tools' || '' }} ${{ matrix.rust-toolchain == 'nightly' && 'rust-src' || '' }} tools: ${{ matrix.rust-toolchain == 'stable' && 'cargo-llvm-cov, ' || '' }} token: ${{ secrets.GITHUB_TOKEN }} @@ -260,7 +260,6 @@ jobs: steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - run: curl -o rustup.sh --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs - if: matrix.os == 'freebsd' uses: vmactions/freebsd-vm@debf37ca7b7fa40e19c542ef7ba30d6054a706a4 @@ -270,12 +269,13 @@ jobs: prepare: | set -e pkg install -y curl llvm - sh rustup.sh --default-toolchain stable --component llvm-tools -y + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \ + sh -s -- --default-toolchain stable --profile minimal --component clippy llvm-tools -y run: | set -e cargo install cargo-llvm-cov --locked cargo check --all-targets - cargo clippy + cargo clippy -- -D warnings cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast --release @@ -288,14 +288,12 @@ jobs: set -e pkg_add rust llvm-16.0.6p30 # rustup doesn't support OpenBSD at all run: | - ls -l $HOME - cat $HOME/.profile set -e export LIBCLANG_PATH=/usr/local/llvm16/lib cargo install cargo-llvm-cov --locked cargo check --all-targets - # FIXME: clippy not available on openbsd - # cargo clippy + # FIXME: clippy not currently available on openbsd + # cargo clippy -- -D warnings cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast --release @@ -308,13 +306,14 @@ jobs: set -e /usr/sbin/pkg_add pkgin pkgin -y install curl clang - sh rustup.sh --default-toolchain stable --component llvm-tools -y + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \ + sh -s -- --default-toolchain stable --profile minimal --component clippy llvm-tools -y run: | set -e export LIBCLANG_PATH=/usr/pkg/lib cargo install cargo-llvm-cov --locked cargo check --all-targets - cargo clippy + cargo clippy -- -D warnings cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast --release @@ -327,15 +326,14 @@ jobs: prepare: | set -e pkg install clang-libs - source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install) + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \ + sh -s -- --default-toolchain stable --profile minimal --component clippy llvm-tools -y run: | - ls -l $HOME - cat $HOME/.profile set -e export LIBCLANG_PATH="/usr/lib/amd64" cargo install cargo-llvm-cov --locked cargo check --all-targets - cargo clippy + cargo clippy -- -D warnings cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast --release From 302d5a1b63e6b0a05b13dcecb65758b847343c35 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Dec 2024 11:52:47 +0200 Subject: [PATCH 07/20] Again --- .github/workflows/check.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a8d5f70a..65461709 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -271,6 +271,10 @@ jobs: pkg install -y curl llvm curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \ sh -s -- --default-toolchain stable --profile minimal --component clippy llvm-tools -y + ls -la || true + ls -la $HOME || true + cat $HOME/.profile || true + run: | set -e cargo install cargo-llvm-cov --locked @@ -326,8 +330,7 @@ jobs: prepare: | set -e pkg install clang-libs - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \ - sh -s -- --default-toolchain stable --profile minimal --component clippy llvm-tools -y + source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install) run: | set -e export LIBCLANG_PATH="/usr/lib/amd64" From d7d7c6654ab0256d9528cdb4ed6b8e469bd3831c Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Dec 2024 11:58:24 +0200 Subject: [PATCH 08/20] Again --- .github/workflows/check.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 65461709..bfabcd5f 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -274,8 +274,12 @@ jobs: ls -la || true ls -la $HOME || true cat $HOME/.profile || true - + pwd run: | + pwd + ls -la || true + ls -la $HOME || true + cat $HOME/.profile || true set -e cargo install cargo-llvm-cov --locked cargo check --all-targets @@ -328,7 +332,7 @@ jobs: usesh: true envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" prepare: | - set -e + # set -e pkg install clang-libs source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install) run: | From 8cfc8dced91b22fb9a35806814bbb8c9df87521d Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Dec 2024 12:06:10 +0200 Subject: [PATCH 09/20] Again --- .github/workflows/check.yml | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index bfabcd5f..251f6324 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -266,21 +266,13 @@ jobs: with: usesh: true envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" - prepare: | + prepare: | # This executes as root set -e pkg install -y curl llvm + run: | # This executes as user + set -e curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \ sh -s -- --default-toolchain stable --profile minimal --component clippy llvm-tools -y - ls -la || true - ls -la $HOME || true - cat $HOME/.profile || true - pwd - run: | - pwd - ls -la || true - ls -la $HOME || true - cat $HOME/.profile || true - set -e cargo install cargo-llvm-cov --locked cargo check --all-targets cargo clippy -- -D warnings @@ -292,10 +284,10 @@ jobs: with: usesh: true envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" - prepare: | + prepare: | # This executes as root set -e pkg_add rust llvm-16.0.6p30 # rustup doesn't support OpenBSD at all - run: | + run: | # This executes as user set -e export LIBCLANG_PATH=/usr/local/llvm16/lib cargo install cargo-llvm-cov --locked @@ -310,15 +302,14 @@ jobs: with: usesh: true envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" - prepare: | + prepare: | # This executes as root set -e /usr/sbin/pkg_add pkgin pkgin -y install curl clang + run: | # This executes as user + set -e curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \ sh -s -- --default-toolchain stable --profile minimal --component clippy llvm-tools -y - run: | - set -e - export LIBCLANG_PATH=/usr/pkg/lib cargo install cargo-llvm-cov --locked cargo check --all-targets cargo clippy -- -D warnings @@ -331,11 +322,11 @@ jobs: release: "11.4-gcc" usesh: true envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" - prepare: | + prepare: | # This executes as root # set -e pkg install clang-libs source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install) - run: | + run: | # This executes as user set -e export LIBCLANG_PATH="/usr/lib/amd64" cargo install cargo-llvm-cov --locked From 1b6bd1d55837a56a72e79ed60fc536c6b57eacea Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Dec 2024 12:20:56 +0200 Subject: [PATCH 10/20] More --- .github/workflows/check.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 251f6324..8a5f5186 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -273,6 +273,7 @@ jobs: set -e curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \ sh -s -- --default-toolchain stable --profile minimal --component clippy llvm-tools -y + . "$HOME/.cargo/env" cargo install cargo-llvm-cov --locked cargo check --all-targets cargo clippy -- -D warnings @@ -286,14 +287,16 @@ jobs: envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" prepare: | # This executes as root set -e - pkg_add rust llvm-16.0.6p30 # rustup doesn't support OpenBSD at all + pkg_add rust rust-clippy llvm-16.0.6p30 # rustup doesn't support OpenBSD at all run: | # This executes as user set -e + find /usr/local/llvm16 -ls export LIBCLANG_PATH=/usr/local/llvm16/lib + export LLVM_COV=/usr/local/llvm16/bin/llvm-cov + export LLVM_PROFDATA=/usr/local/llvm16/bin/llvm-profdata cargo install cargo-llvm-cov --locked cargo check --all-targets - # FIXME: clippy not currently available on openbsd - # cargo clippy -- -D warnings + cargo clippy -- -D warnings cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast --release @@ -310,6 +313,7 @@ jobs: set -e curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \ sh -s -- --default-toolchain stable --profile minimal --component clippy llvm-tools -y + . "$HOME/.cargo/env" cargo install cargo-llvm-cov --locked cargo check --all-targets cargo clippy -- -D warnings @@ -323,11 +327,11 @@ jobs: usesh: true envs: "CARGO_TERM_COLOR RUST_BACKTRACE RUST_LOG GITHUB_ACTIONS" prepare: | # This executes as root - # set -e + set -e pkg install clang-libs - source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install) run: | # This executes as user set -e + source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install) export LIBCLANG_PATH="/usr/lib/amd64" cargo install cargo-llvm-cov --locked cargo check --all-targets From 826e5474ed53fd2e39ec3a07ab4a276760db05c8 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Dec 2024 12:30:10 +0200 Subject: [PATCH 11/20] Again --- .github/workflows/check.yml | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 8a5f5186..61eeb046 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -291,13 +291,17 @@ jobs: run: | # This executes as user set -e find /usr/local/llvm16 -ls - export LIBCLANG_PATH=/usr/local/llvm16/lib - export LLVM_COV=/usr/local/llvm16/bin/llvm-cov - export LLVM_PROFDATA=/usr/local/llvm16/bin/llvm-profdata - cargo install cargo-llvm-cov --locked cargo check --all-targets cargo clippy -- -D warnings - cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info + # FIXME: No profiler support in openbsd currently + # error[E0463]: can't find crate for `profiler_builtins` + # = note: the compiler may have been built without the profiler runtime + # export LIBCLANG_PATH=/usr/local/llvm16/lib + # export LLVM_COV=/usr/local/llvm16/bin/llvm-cov + # export LLVM_PROFDATA=/usr/local/llvm16/bin/llvm-profdata + # cargo install cargo-llvm-cov --locked + # cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info + cargo test --no-fail-fast # Remove this once profiler is supported cargo test --no-fail-fast --release - if: matrix.os == 'netbsd' @@ -314,10 +318,14 @@ jobs: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \ sh -s -- --default-toolchain stable --profile minimal --component clippy llvm-tools -y . "$HOME/.cargo/env" - cargo install cargo-llvm-cov --locked cargo check --all-targets cargo clippy -- -D warnings - cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info + # FIXME: No profiler support in openbsd currently + # error[E0463]: can't find crate for `profiler_builtins` + # = note: the compiler may have been built without the profiler runtime + # cargo install cargo-llvm-cov --locked + # cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info + cargo test --no-fail-fast # Remove this once profiler is supported cargo test --no-fail-fast --release - if: matrix.os == 'solaris' @@ -329,13 +337,13 @@ jobs: prepare: | # This executes as root set -e pkg install clang-libs - run: | # This executes as user + run: | # This executes as also as root on Solaris set -e - source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install) + source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install) || true # This doesn't exit with zero on success export LIBCLANG_PATH="/usr/lib/amd64" - cargo install cargo-llvm-cov --locked cargo check --all-targets cargo clippy -- -D warnings + cargo install cargo-llvm-cov --locked cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast --release From 63c3b52d1a9b3cd3efbde9da38579f4c2ab671ef Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Dec 2024 12:40:27 +0200 Subject: [PATCH 12/20] Again --- .github/workflows/check.yml | 15 +++++++-------- src/bsd.rs | 3 ++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 61eeb046..e3d8f27c 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -290,13 +290,12 @@ jobs: pkg_add rust rust-clippy llvm-16.0.6p30 # rustup doesn't support OpenBSD at all run: | # This executes as user set -e - find /usr/local/llvm16 -ls + export LIBCLANG_PATH=/usr/local/llvm16/lib cargo check --all-targets cargo clippy -- -D warnings - # FIXME: No profiler support in openbsd currently - # error[E0463]: can't find crate for `profiler_builtins` - # = note: the compiler may have been built without the profiler runtime - # export LIBCLANG_PATH=/usr/local/llvm16/lib + # FIXME: No profiler support in openbsd currently, error is: + # > error[E0463]: can't find crate for `profiler_builtins` + # > = note: the compiler may have been built without the profiler runtime # export LLVM_COV=/usr/local/llvm16/bin/llvm-cov # export LLVM_PROFDATA=/usr/local/llvm16/bin/llvm-profdata # cargo install cargo-llvm-cov --locked @@ -320,9 +319,9 @@ jobs: . "$HOME/.cargo/env" cargo check --all-targets cargo clippy -- -D warnings - # FIXME: No profiler support in openbsd currently - # error[E0463]: can't find crate for `profiler_builtins` - # = note: the compiler may have been built without the profiler runtime + # FIXME: No profiler support in netbsd currently, error is: + # > error[E0463]: can't find crate for `profiler_builtins` + # > = note: the compiler may have been built without the profiler runtime # cargo install cargo-llvm-cov --locked # cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast # Remove this once profiler is supported diff --git a/src/bsd.rs b/src/bsd.rs index 26cd930e..e4d57d3f 100644 --- a/src/bsd.rs +++ b/src/bsd.rs @@ -344,7 +344,8 @@ fn if_index_mtu(remote: IpAddr) -> Result<(u16, Option)> { // For others, we need to extract it from the sockaddrs. for i in 0..RTAX_MAX { if (reply.rtm_addrs & (1 << i)) != 0 { - let saddr = unsafe { &*ptr::from_ref(sa).cast::() }; + let saddr = + unsafe { ptr::read_unaligned(sa.as_ptr().cast::()) }; if saddr.sa_family == AF_LINK { let sdl = unsafe { ptr::read_unaligned(sa.as_ptr().cast::()) From e27640b69efddf6f3fd36b9bbbc8ef66f8f1125c Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Dec 2024 13:17:21 +0200 Subject: [PATCH 13/20] Again --- .github/workflows/check.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index e3d8f27c..689e2169 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -342,8 +342,12 @@ jobs: export LIBCLANG_PATH="/usr/lib/amd64" cargo check --all-targets cargo clippy -- -D warnings - cargo install cargo-llvm-cov --locked - cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info + # FIXME: No profiler support in openbsd currently, error is: + # > error[E0463]: can't find crate for `profiler_builtins` + # > = note: the compiler may have been built without the profiler runtime + # cargo install cargo-llvm-cov --locked + # cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info + cargo test --no-fail-fast # Remove this once profiler is supported cargo test --no-fail-fast --release - uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a # v5.0.7 From 9b8cd70fb7655e9cbbe2b55f56a83f2cb67b45fd Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Dec 2024 13:27:53 +0200 Subject: [PATCH 14/20] Minimize diff --- .github/workflows/check.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 689e2169..1f4b4805 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -81,7 +81,7 @@ jobs: - uses: ./neqo/.github/actions/rust with: version: ${{ matrix.rust-toolchain }} - components: ${{ matrix.rust-toolchain == 'stable' && 'clippy llvm-tools' || '' }} ${{ matrix.rust-toolchain == 'nightly' && 'rust-src' || '' }} + components: ${{ matrix.rust-toolchain == 'stable' && 'llvm-tools' || '' }} ${{ matrix.rust-toolchain == 'nightly' && 'rust-src' || '' }} tools: ${{ matrix.rust-toolchain == 'stable' && 'cargo-llvm-cov, ' || '' }} token: ${{ secrets.GITHUB_TOKEN }} @@ -260,6 +260,7 @@ jobs: steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - run: curl -o rustup.sh --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs - if: matrix.os == 'freebsd' uses: vmactions/freebsd-vm@debf37ca7b7fa40e19c542ef7ba30d6054a706a4 @@ -271,8 +272,7 @@ jobs: pkg install -y curl llvm run: | # This executes as user set -e - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \ - sh -s -- --default-toolchain stable --profile minimal --component clippy llvm-tools -y + sh rustup.sh --default-toolchain stable --profile minimal --component clippy llvm-tools -y . "$HOME/.cargo/env" cargo install cargo-llvm-cov --locked cargo check --all-targets @@ -314,8 +314,7 @@ jobs: pkgin -y install curl clang run: | # This executes as user set -e - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \ - sh -s -- --default-toolchain stable --profile minimal --component clippy llvm-tools -y + sh rustup.sh --default-toolchain stable --profile minimal --component clippy llvm-tools -y . "$HOME/.cargo/env" cargo check --all-targets cargo clippy -- -D warnings From e3e493e74d312b53985db3a2cd74db95c0f95347 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Dec 2024 13:31:30 +0200 Subject: [PATCH 15/20] Cleanup --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1f4b4805..d474c46e 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -274,9 +274,9 @@ jobs: set -e sh rustup.sh --default-toolchain stable --profile minimal --component clippy llvm-tools -y . "$HOME/.cargo/env" - cargo install cargo-llvm-cov --locked cargo check --all-targets cargo clippy -- -D warnings + cargo install cargo-llvm-cov --locked cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast --release From 1516dca6566bf16ddf2d508c013dcf46479bca68 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Dec 2024 17:18:51 +0200 Subject: [PATCH 16/20] Don't sync `target` back to host --- .github/workflows/check.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index d474c46e..2431621a 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -279,6 +279,7 @@ jobs: cargo install cargo-llvm-cov --locked cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast --release + rm -rf target # Don't sync this back to host - if: matrix.os == 'openbsd' uses: vmactions/openbsd-vm@0cfe06e734a0ea3a546fca7ebf200b984b94d58a @@ -302,6 +303,7 @@ jobs: # cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast # Remove this once profiler is supported cargo test --no-fail-fast --release + rm -rf target # Don't sync this back to host - if: matrix.os == 'netbsd' uses: vmactions/netbsd-vm@7c9086fdb4cc1aa814cda6e305390c2b966551a9 @@ -325,6 +327,7 @@ jobs: # cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast # Remove this once profiler is supported cargo test --no-fail-fast --release + rm -rf target # Don't sync this back to host - if: matrix.os == 'solaris' uses: vmactions/solaris-vm@a89b9438868c70db27e41625f0a5de6ff5e90809 @@ -348,6 +351,7 @@ jobs: # cargo llvm-cov test --no-fail-fast --lcov --output-path lcov.info cargo test --no-fail-fast # Remove this once profiler is supported cargo test --no-fail-fast --release + rm -rf target # Don't sync this back to host - uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a # v5.0.7 with: From 327d2f90640700170d8c22fa0e3db7e3fea42f9e Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Tue, 3 Dec 2024 12:19:44 +0200 Subject: [PATCH 17/20] Update src/bsd.rs Co-authored-by: Max Inden --- src/bsd.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bsd.rs b/src/bsd.rs index e4d57d3f..6dbdea8d 100644 --- a/src/bsd.rs +++ b/src/bsd.rs @@ -194,7 +194,7 @@ fn sockaddr_len(af: AddressFamily) -> Result { _ => { return Err(Error::new( ErrorKind::InvalidInput, - "Unsupported address family {:af}", + "Unsupported address family {af:?}", )) } }; From 43f2534c149c567c939e060bb27982fa5bf00031 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Tue, 3 Dec 2024 12:32:27 +0200 Subject: [PATCH 18/20] Suggestions from @mxinden --- src/bsd.rs | 95 +++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 51 deletions(-) diff --git a/src/bsd.rs b/src/bsd.rs index e4d57d3f..f9119a87 100644 --- a/src/bsd.rs +++ b/src/bsd.rs @@ -166,18 +166,11 @@ fn if_name_mtu(idx: u32) -> Result<(String, Option)> { .to_str() .map_err(|err| Error::new(ErrorKind::Other, err))? }; - let mut mtu = None; - for ifa in IfAddrs::new()?.iter() { - if ifa.addr().sa_family == AF_LINK && ifa.name() == name { - if let Some(ifa_data) = ifa.data() { - if let Ok(ifi_mtu) = usize::try_from(ifa_data.ifi_mtu) { - mtu = Some(ifi_mtu); - break; - } - } - break; - } - } + let mtu = IfAddrs::new()? + .iter() + .find(|ifa| ifa.addr().sa_family == AF_LINK && ifa.name() == name) + .and_then(|ifa| ifa.data()) + .and_then(|ifa_data| usize::try_from(ifa_data.ifi_mtu).ok()); Ok((name.to_string(), mtu)) } @@ -320,46 +313,46 @@ fn if_index_mtu(remote: IpAddr) -> Result<(u16, Option)> { } let (reply, mut sa) = buf.split_at(size_of::()); let reply: rt_msghdr = reply.into(); - if reply.rtm_version == query_version && reply.rtm_pid == pid && reply.rtm_seq == query_seq + if !(reply.rtm_version == query_version + && reply.rtm_pid == pid + && reply.rtm_seq == query_seq) { - // This is a reply to our query. - return if reply.rtm_type == query_type { - // This is the reply we are looking for. - // Some BSDs let us get the interface index and MTU directly from the reply. - let mtu: Option = if reply.rtm_rmx.rmx_mtu != 0 { - Some( - reply - .rtm_rmx - .rmx_mtu - .try_into() - .map_err(|e: TryFromIntError| unlikely_err(e.to_string()))?, - ) - } else { - None - }; - if reply.rtm_index != 0 { - // Some BSDs return the interface index directly. - Ok((reply.rtm_index, mtu)) - } else { - // For others, we need to extract it from the sockaddrs. - for i in 0..RTAX_MAX { - if (reply.rtm_addrs & (1 << i)) != 0 { - let saddr = - unsafe { ptr::read_unaligned(sa.as_ptr().cast::()) }; - if saddr.sa_family == AF_LINK { - let sdl = unsafe { - ptr::read_unaligned(sa.as_ptr().cast::()) - }; - return Ok((sdl.sdl_index, mtu)); - } - (_, sa) = sa.split_at(sockaddr_len(saddr.sa_family)?); - } - } - Err(default_err()) - } - } else { - Err(default_err()) - }; + continue; + } + if reply.rtm_type != query_type { + return Err(default_err()); + } + + // This is a reply to our query. + // This is the reply we are looking for. + // Some BSDs let us get the interface index and MTU directly from the reply. + let mtu: Option = if reply.rtm_rmx.rmx_mtu != 0 { + Some( + reply + .rtm_rmx + .rmx_mtu + .try_into() + .map_err(|e: TryFromIntError| unlikely_err(e.to_string()))?, + ) + } else { + None + }; + if reply.rtm_index != 0 { + // Some BSDs return the interface index directly. + return Ok((reply.rtm_index, mtu)); + } + // For others, we need to extract it from the sockaddrs. + for i in 0..RTAX_MAX { + if (reply.rtm_addrs & (1 << i)) == 0 { + continue; + } + let saddr = unsafe { ptr::read_unaligned(sa.as_ptr().cast::()) }; + if saddr.sa_family != AF_LINK { + (_, sa) = sa.split_at(sockaddr_len(saddr.sa_family)?); + continue; + } + let sdl = unsafe { ptr::read_unaligned(sa.as_ptr().cast::()) }; + return Ok((sdl.sdl_index, mtu)); } } } From 95f3fde7f667dc81198a6b7536a98134f6827f80 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Tue, 3 Dec 2024 13:55:41 +0200 Subject: [PATCH 19/20] libc@0.2.158 --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f2df25da..03b808d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -146,9 +146,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.160" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b21006cd1874ae9e650973c565615676dc4a274c965bb0a73796dac838ce4f" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "libloading" From dabd4ccac0ed0673f59f87d5008e567a95041ecb Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Thu, 12 Dec 2024 18:18:52 +0200 Subject: [PATCH 20/20] Fix mozbuild --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index e055aa97..5a14cfd1 100644 --- a/build.rs +++ b/build.rs @@ -16,7 +16,7 @@ fn clang_args() -> Vec { let mut flags: Vec = std::fs::read_to_string(flags_path) .expect("Failed to read extra-bindgen-flags file") .split_whitespace() - .to_owned() + .map(std::borrow::ToOwned::to_owned) .collect(); flags.push(String::from("-include"));