add more cfg for BSD os

This commit is contained in:
Zhang Jingqiang 2024-01-10 11:10:48 +08:00
parent cd1eff2ed9
commit 331ff1e13c
33 changed files with 208 additions and 78 deletions

17
doc/transparent_proxy.md Normal file
View file

@ -0,0 +1,17 @@
Transparent Proxy
=====
Linux
---
[netfilter TPROXY](https://docs.kernel.org/networking/tproxy.html)
FreeBSD
---
[ipfw forward](https://man.freebsd.org/cgi/man.cgi?query=ipfw)
OpenBSD
---
[pf divert-to](https://man.openbsd.org/pf.conf.5#divert-to)

View file

@ -137,7 +137,8 @@ pub fn parse_clap() -> anyhow::Result<Option<ProcArgs>> {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "dragonfly",
target_os = "netbsd",
))]
if let Some(s) = group_name.strip_prefix("core") {
let mut cpu = CpuAffinity::default();

View file

@ -45,7 +45,12 @@ pub(crate) mod http_rproxy;
pub(crate) mod sni_proxy;
pub(crate) mod socks_proxy;
pub(crate) mod tcp_stream;
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
))]
pub(crate) mod tcp_tproxy;
pub(crate) mod tls_stream;
@ -133,7 +138,12 @@ pub(crate) enum AnyServerConfig {
PlainQuicPort(plain_quic_port::PlainQuicPortConfig),
IntelliProxy(intelli_proxy::IntelliProxyConfig),
TcpStream(Box<tcp_stream::TcpStreamServerConfig>),
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd"
))]
TcpTProxy(tcp_tproxy::TcpTProxyServerConfig),
TlsStream(Box<tls_stream::TlsStreamServerConfig>),
SniProxy(Box<sni_proxy::SniProxyServerConfig>),
@ -154,7 +164,12 @@ macro_rules! impl_transparent0 {
AnyServerConfig::PlainQuicPort(s) => s.$f(),
AnyServerConfig::IntelliProxy(s) => s.$f(),
AnyServerConfig::TcpStream(s) => s.$f(),
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd"
))]
AnyServerConfig::TcpTProxy(s) => s.$f(),
AnyServerConfig::TlsStream(s) => s.$f(),
AnyServerConfig::SniProxy(s) => s.$f(),
@ -178,7 +193,12 @@ macro_rules! impl_transparent1 {
AnyServerConfig::PlainQuicPort(s) => s.$f(p),
AnyServerConfig::IntelliProxy(s) => s.$f(p),
AnyServerConfig::TcpStream(s) => s.$f(p),
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd"
))]
AnyServerConfig::TcpTProxy(s) => s.$f(p),
AnyServerConfig::TlsStream(s) => s.$f(p),
AnyServerConfig::SniProxy(s) => s.$f(p),
@ -267,7 +287,12 @@ fn load_server(
.context("failed to load this TcpStream server")?;
Ok(AnyServerConfig::TcpStream(Box::new(server)))
}
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd"
))]
"tcp_tproxy" | "tcptproxy" => {
let server = tcp_tproxy::TcpTProxyServerConfig::parse(map, position)
.context("failed to load this TcpTProxy server")?;

View file

@ -21,7 +21,8 @@ use g3_io_ext::{AsyncUdpRecv, UdpCopyRemoteError, UdpCopyRemoteRecv};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use g3_io_ext::{RecvMsgBuf, RecvMsgHdr, UdpCopyPacket};
@ -59,7 +60,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv_packets(
&mut self,

View file

@ -22,7 +22,8 @@ use g3_io_ext::{AsyncUdpSend, UdpCopyRemoteError, UdpCopyRemoteSend};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use g3_io_ext::{SendMsgHdr, UdpCopyPacket};
@ -63,7 +64,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send_packets(
&mut self,

View file

@ -22,7 +22,8 @@ use g3_io_ext::{AsyncUdpRecv, UdpRelayRemoteError, UdpRelayRemoteRecv};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use g3_io_ext::{RecvMsgBuf, RecvMsgHdr, UdpRelayPacket};
use g3_types::net::UpstreamAddr;
@ -98,7 +99,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv_packets(
inner: &mut T,
@ -150,7 +152,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv_packets(
&mut self,

View file

@ -24,7 +24,8 @@ use g3_io_ext::{AsyncUdpSend, UdpRelayRemoteError, UdpRelayRemoteSend};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use g3_io_ext::{SendMsgHdr, UdpRelayPacket};
use g3_resolver::{ResolveError, ResolveLocalError};
@ -269,7 +270,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send_packets(
inner: &mut T,
@ -319,7 +321,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send_packets(
&mut self,

View file

@ -25,7 +25,8 @@ use g3_io_ext::{AsyncUdpRecv, UdpCopyRemoteError, UdpCopyRemoteRecv};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use g3_io_ext::{RecvMsgBuf, RecvMsgHdr, UdpCopyPacket};
use g3_socks::v5::UdpInput;
@ -84,7 +85,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv_packets(
&mut self,

View file

@ -22,7 +22,8 @@ use g3_io_ext::{AsyncUdpSend, UdpCopyRemoteError, UdpCopyRemoteSend};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use g3_io_ext::{SendMsgHdr, UdpCopyPacket};
use g3_socks::v5::UdpOutput;
@ -77,7 +78,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send_packets(
&mut self,

View file

@ -26,7 +26,8 @@ use g3_io_ext::{AsyncUdpRecv, UdpRelayRemoteError, UdpRelayRemoteRecv};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use g3_io_ext::{RecvMsgBuf, RecvMsgHdr, UdpRelayPacket};
use g3_socks::v5::UdpInput;
@ -103,7 +104,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv_packets(
&mut self,

View file

@ -23,7 +23,8 @@ use g3_io_ext::{AsyncUdpSend, UdpRelayRemoteError, UdpRelayRemoteSend};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use g3_io_ext::{SendMsgHdr, UdpRelayPacket};
use g3_socks::v5::SocksUdpHeader;
@ -82,7 +83,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send_packets(
&mut self,

View file

@ -54,7 +54,12 @@ mod http_rproxy;
mod sni_proxy;
mod socks_proxy;
mod tcp_stream;
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd"
))]
mod tcp_tproxy;
mod tls_stream;

View file

@ -42,7 +42,12 @@ use super::http_rproxy::HttpRProxyServer;
use super::sni_proxy::SniProxyServer;
use super::socks_proxy::SocksProxyServer;
use super::tcp_stream::TcpStreamServer;
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd"
))]
use super::tcp_tproxy::TcpTProxyServer;
use super::tls_stream::TlsStreamServer;
@ -296,7 +301,12 @@ fn spawn_new_unlocked(config: AnyServerConfig) -> anyhow::Result<()> {
AnyServerConfig::PlainQuicPort(c) => PlainQuicPort::prepare_initial(c)?,
AnyServerConfig::IntelliProxy(c) => IntelliProxy::prepare_initial(c)?,
AnyServerConfig::TcpStream(c) => TcpStreamServer::prepare_initial(*c)?,
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd"
))]
AnyServerConfig::TcpTProxy(c) => TcpTProxyServer::prepare_initial(c)?,
AnyServerConfig::TlsStream(c) => TlsStreamServer::prepare_initial(*c)?,
AnyServerConfig::SniProxy(c) => SniProxyServer::prepare_initial(*c)?,

View file

@ -24,7 +24,8 @@ use g3_io_ext::{AsyncUdpRecv, UdpRelayClientError, UdpRelayClientRecv};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use g3_io_ext::{RecvMsgBuf, RecvMsgHdr, UdpRelayPacket};
use g3_socks::v5::UdpInput;
@ -237,7 +238,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv_packets(
&mut self,

View file

@ -23,7 +23,8 @@ use g3_io_ext::{AsyncUdpSend, UdpRelayClientError, UdpRelayClientSend};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use g3_io_ext::{SendMsgHdr, UdpRelayPacket};
use g3_socks::v5::SocksUdpHeader;
@ -79,7 +80,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send_packets(
&mut self,

View file

@ -24,7 +24,8 @@ use g3_io_ext::{AsyncUdpRecv, UdpCopyClientError, UdpCopyClientRecv};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use g3_io_ext::{RecvMsgBuf, RecvMsgHdr, UdpCopyPacket};
use g3_socks::v5::UdpInput;
@ -163,7 +164,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv_packets(
&mut self,

View file

@ -22,7 +22,8 @@ use g3_io_ext::{AsyncUdpSend, UdpCopyClientError, UdpCopyClientSend};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use g3_io_ext::{SendMsgHdr, UdpCopyPacket};
use g3_socks::v5::UdpOutput;
@ -77,7 +78,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send_packets(
&mut self,

View file

@ -23,7 +23,8 @@ use thiserror::Error;
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use super::UdpCopyPacket;
@ -58,7 +59,8 @@ pub trait UdpCopyClientRecv {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv_packets(
&mut self,
@ -79,7 +81,8 @@ pub trait UdpCopyClientSend {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send_packets(
&mut self,

View file

@ -130,7 +130,8 @@ impl<'a, T: UdpCopyClientRecv + ?Sized> UdpCopyRecv for ClientRecv<'a, T> {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv_packets(
&mut self,
@ -164,7 +165,8 @@ impl<'a, T: UdpCopyRemoteRecv + ?Sized> UdpCopyRecv for RemoteRecv<'a, T> {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv_packets(
&mut self,
@ -224,7 +226,8 @@ impl<'a, T: UdpCopyClientSend + ?Sized> UdpCopySend for ClientSend<'a, T> {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send_packets(
&mut self,
@ -254,7 +257,8 @@ impl<'a, T: UdpCopyRemoteSend + ?Sized> UdpCopySend for RemoteSend<'a, T> {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send_packets(
&mut self,

View file

@ -23,7 +23,8 @@ use thiserror::Error;
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use super::UdpCopyPacket;
@ -58,7 +59,8 @@ pub trait UdpCopyRemoteRecv {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv_packets(
&mut self,
@ -79,7 +81,8 @@ pub trait UdpCopyRemoteSend {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send_packets(
&mut self,

View file

@ -23,7 +23,8 @@ use std::task::{ready, Context, Poll};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use nix::sys::socket::{recvmmsg, sendmmsg, MultiHeaders};
use nix::sys::socket::{recvmsg, sendmsg, MsgFlags, SockaddrStorage};
@ -97,7 +98,8 @@ pub trait UdpSocketExt {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_batch_sendmsg<const C: usize>(
&self,
@ -109,7 +111,8 @@ pub trait UdpSocketExt {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_batch_recvmsg<const C: usize>(
&self,
@ -130,7 +133,9 @@ impl UdpSocketExt for UdpSocket {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "dragonfly",
target_os = "netbsd",
target_os = "openbsd",
))]
let flags: MsgFlags = MsgFlags::MSG_DONTWAIT | MsgFlags::MSG_NOSIGNAL;
#[cfg(target_os = "macos")]
@ -194,7 +199,8 @@ impl UdpSocketExt for UdpSocket {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_batch_sendmsg<const C: usize>(
&self,
@ -230,7 +236,8 @@ impl UdpSocketExt for UdpSocket {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_batch_recvmsg<const C: usize>(
&self,

View file

@ -27,7 +27,8 @@ use tokio::time::{Instant, Sleep};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use super::{RecvMsgBuf, RecvMsgHdr};
use crate::limit::{DatagramLimitInfo, DatagramLimitResult};
@ -46,7 +47,8 @@ pub trait AsyncUdpRecv {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_batch_recvmsg(
&mut self,
@ -156,7 +158,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_batch_recvmsg(
&mut self,

View file

@ -25,7 +25,8 @@ use g3_types::net::UpstreamAddr;
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use super::UdpRelayPacket;
@ -62,7 +63,8 @@ pub trait UdpRelayClientRecv {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv_packets(
&mut self,
@ -84,7 +86,8 @@ pub trait UdpRelayClientSend {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send_packets(
&mut self,

View file

@ -145,7 +145,8 @@ impl<'a, T: UdpRelayClientRecv + ?Sized> UdpRelayRecv for ClientRecv<'a, T> {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv_packets(
&mut self,
@ -180,7 +181,8 @@ impl<'a, T: UdpRelayRemoteRecv + ?Sized> UdpRelayRecv for RemoteRecv<'a, T> {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv_packets(
&mut self,
@ -240,7 +242,8 @@ impl<'a, T: UdpRelayClientSend + ?Sized> UdpRelaySend for ClientSend<'a, T> {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send_packets(
&mut self,
@ -270,7 +273,8 @@ impl<'a, T: UdpRelayRemoteSend + ?Sized> UdpRelaySend for RemoteSend<'a, T> {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send_packets(
&mut self,

View file

@ -27,7 +27,8 @@ use g3_types::net::UpstreamAddr;
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use super::UdpRelayPacket;
@ -72,7 +73,8 @@ pub trait UdpRelayRemoteRecv {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv_packets(
&mut self,
@ -94,7 +96,8 @@ pub trait UdpRelayRemoteSend {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send_packets(
&mut self,

View file

@ -27,7 +27,8 @@ use tokio::time::{Instant, Sleep};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use super::SendMsgHdr;
use crate::limit::{DatagramLimitInfo, DatagramLimitResult};
@ -54,7 +55,8 @@ pub trait AsyncUdpSend {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_batch_sendmsg<const C: usize>(
&mut self,
@ -190,7 +192,8 @@ where
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_batch_sendmsg<const C: usize>(
&mut self,

View file

@ -20,7 +20,8 @@ use std::fmt;
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use std::io::IoSliceMut;
use std::io::{self, IoSlice};
@ -36,7 +37,8 @@ use super::{AsyncUdpRecv, AsyncUdpSend, UdpSocketExt};
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
use super::{RecvMsgBuf, RecvMsgHdr, SendMsgHdr};
@ -113,7 +115,8 @@ impl AsyncUdpSend for SendHalf {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_batch_sendmsg<const C: usize>(
&mut self,
@ -155,7 +158,8 @@ impl AsyncUdpRecv for RecvHalf {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_batch_recvmsg(
&mut self,

View file

@ -73,7 +73,8 @@ impl UnaidedRuntimeConfig {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "dragonfly",
target_os = "netbsd",
))]
pub fn set_mapped_sched_affinity(&mut self) -> anyhow::Result<()> {
let n = self.num_threads();

View file

@ -128,7 +128,9 @@ fn new_tcp_socket(family: AddressFamily) -> io::Result<Socket> {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "dragonfly",
target_os = "netbsd",
target_os = "openbsd",
))]
fn new_tcp_socket(family: AddressFamily) -> io::Result<Socket> {
Socket::new(Domain::from(family), Type::STREAM.nonblocking(), None)

View file

@ -212,7 +212,9 @@ fn new_nonblocking_udp_socket(family: AddressFamily) -> io::Result<Socket> {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "dragonfly",
target_os = "netbsd",
target_os = "openbsd",
))]
fn new_nonblocking_udp_socket(family: AddressFamily) -> io::Result<Socket> {
Socket::new(Domain::from(family), Type::DGRAM.nonblocking(), None)

View file

@ -180,7 +180,8 @@ impl AsyncUdpSocket for Socks5UdpSocket {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_send(
&self,
@ -266,7 +267,8 @@ impl AsyncUdpSocket for Socks5UdpSocket {
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd",
))]
fn poll_recv(
&self,

View file

@ -45,7 +45,8 @@ pub fn as_unaided_runtime_config(v: &Yaml) -> anyhow::Result<UnaidedRuntimeConfi
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "dragonfly",
target_os = "netbsd",
))]
let cpu = crate::value::as_cpu_set(iv)
.context(format!("invalid cpu set value for {k}/{id}"))?;

View file

@ -22,7 +22,8 @@ use g3_compat::CpuAffinity;
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
target_os = "dragonfly",
target_os = "netbsd",
))]
pub fn as_cpu_set(v: &Yaml) -> anyhow::Result<CpuAffinity> {
use anyhow::{anyhow, Context};