From 4fe6b7e545e50129344577c747e3db6dd9ec14d0 Mon Sep 17 00:00:00 2001 From: Steve Lau Date: Fri, 1 Dec 2023 09:03:26 +0800 Subject: [PATCH 1/4] feat: Enable ControlMessageOwned::{Ipv4RecvIf,Ipv4RecvDstAddr} for DragonFlyBSD --- changelog/2240.added.md | 1 + src/sys/socket/mod.rs | 8 ++++---- src/sys/socket/sockopt.rs | 4 ++-- test/sys/test_socket.rs | 7 +------ 4 files changed, 8 insertions(+), 12 deletions(-) create mode 100644 changelog/2240.added.md diff --git a/changelog/2240.added.md b/changelog/2240.added.md new file mode 100644 index 0000000000..315c67554c --- /dev/null +++ b/changelog/2240.added.md @@ -0,0 +1 @@ +Enable `ControlMessageOwned::Ipv4RecvIf` and `ControlMessageOwned::Ipv4RecvDstAddr` for DragonFlyBSD diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 1e081dd2ea..bb48f8ed99 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -748,11 +748,11 @@ pub enum ControlMessageOwned { #[cfg(feature = "net")] #[cfg_attr(docsrs, doc(cfg(feature = "net")))] Ipv6PacketInfo(libc::in6_pktinfo), - #[cfg(any(target_os = "freebsd", apple_targets, netbsdlike))] + #[cfg(bsd)] #[cfg(feature = "net")] #[cfg_attr(docsrs, doc(cfg(feature = "net")))] Ipv4RecvIf(libc::sockaddr_dl), - #[cfg(any(target_os = "freebsd", apple_targets, netbsdlike))] + #[cfg(bsd)] #[cfg(feature = "net")] #[cfg_attr(docsrs, doc(cfg(feature = "net")))] Ipv4RecvDstAddr(libc::in_addr), @@ -931,13 +931,13 @@ impl ControlMessageOwned { let info = unsafe { ptr::read_unaligned(p as *const libc::in_pktinfo) }; ControlMessageOwned::Ipv4PacketInfo(info) } - #[cfg(any(target_os = "freebsd", apple_targets, netbsdlike))] + #[cfg(bsd)] #[cfg(feature = "net")] (libc::IPPROTO_IP, libc::IP_RECVIF) => { let dl = unsafe { ptr::read_unaligned(p as *const libc::sockaddr_dl) }; ControlMessageOwned::Ipv4RecvIf(dl) }, - #[cfg(any(target_os = "freebsd", apple_targets, netbsdlike))] + #[cfg(bsd)] #[cfg(feature = "net")] (libc::IPPROTO_IP, libc::IP_RECVDSTADDR) => { let dl = unsafe { ptr::read_unaligned(p as *const libc::in_addr) }; diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index cad2cce180..5ebb885293 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -842,7 +842,7 @@ sockopt_impl!( libc::IPV6_RECVPKTINFO, bool ); -#[cfg(any(target_os = "freebsd", apple_targets, netbsdlike))] +#[cfg(bsd)] #[cfg(feature = "net")] sockopt_impl!( #[cfg_attr(docsrs, doc(cfg(feature = "net")))] @@ -854,7 +854,7 @@ sockopt_impl!( libc::IP_RECVIF, bool ); -#[cfg(any(target_os = "freebsd", apple_targets, netbsdlike))] +#[cfg(bsd)] #[cfg(feature = "net")] sockopt_impl!( #[cfg_attr(docsrs, doc(cfg(feature = "net")))] diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 1a9cdb465f..40160433ef 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -1880,12 +1880,7 @@ pub fn test_recv_ipv4pktinfo() { } } -#[cfg(any( - target_os = "freebsd", - apple_targets, - target_os = "netbsd", - target_os = "openbsd", -))] +#[cfg(bsd)] // qemu doesn't seem to be emulating this correctly in these architectures #[cfg_attr( all( From b62ada5f5d354484497b095c4f3a460282b57e53 Mon Sep 17 00:00:00 2001 From: Steve Lau Date: Fri, 1 Dec 2023 09:10:21 +0800 Subject: [PATCH 2/4] fix DrafonFlyBSD --- test/sys/test_socket.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 40160433ef..70ed1299e7 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -1750,14 +1750,7 @@ pub fn test_syscontrol() { // connect(fd.as_raw_fd(), &sockaddr).expect("connect failed"); } -#[cfg(any( - target_os = "android", - target_os = "freebsd", - apple_targets, - target_os = "linux", - target_os = "netbsd", - target_os = "openbsd", -))] +#[cfg(bsd)] fn loopback_address( family: AddressFamily, ) -> Option { From 9c334d51618800e0c0f82689173fed015e7ebc4d Mon Sep 17 00:00:00 2001 From: Steve Lau Date: Fri, 1 Dec 2023 09:13:44 +0800 Subject: [PATCH 3/4] fix Linux --- test/sys/test_socket.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 70ed1299e7..9ce127e2d9 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -1750,7 +1750,7 @@ pub fn test_syscontrol() { // connect(fd.as_raw_fd(), &sockaddr).expect("connect failed"); } -#[cfg(bsd)] +#[cfg(bsd, linux_android)] fn loopback_address( family: AddressFamily, ) -> Option { From d3731e0220fab56f1637b9fb5a75bcb3f8b76532 Mon Sep 17 00:00:00 2001 From: Steve Lau Date: Fri, 1 Dec 2023 09:17:02 +0800 Subject: [PATCH 4/4] fix cfg --- test/sys/test_socket.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 9ce127e2d9..8dd213e145 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -1750,7 +1750,7 @@ pub fn test_syscontrol() { // connect(fd.as_raw_fd(), &sockaddr).expect("connect failed"); } -#[cfg(bsd, linux_android)] +#[cfg(any(bsd, linux_android))] fn loopback_address( family: AddressFamily, ) -> Option {