Skip to content

Commit 1e36869

Browse files
committed
依存関係をアップデート
1 parent bac35f7 commit 1e36869

14 files changed

Lines changed: 57813 additions & 240 deletions

File tree

local_proxy/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ hyper = { version = "1", features = ["full"] }
1313
http-body-util = "0.1"
1414
hyper-util = { version = "0.1", features = ["full"] }
1515
once_cell = "1"
16-
base64 = "0.21"
16+
base64 = "0.22"
1717
async-trait = "0.1"
18-
tokio-rustls = "0.24"
19-
rustls-native-certs = "0.6"
18+
tokio-rustls = "0.26"
19+
rustls-native-certs = "0.8"
2020
serde = { version = "1", features = ["derive"] }
2121
json5 = "0.4"
2222
dns-parser = "0.8"

local_proxy/src/outbound/layer/tls.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ use tokio_rustls::{rustls, TlsConnector};
1111
static CONNECTOR: Lazy<TlsConnector> = Lazy::new(|| {
1212
let mut certs = rustls::RootCertStore::empty();
1313
for cert in rustls_native_certs::load_native_certs().unwrap() {
14-
let _ = certs.add(&rustls::Certificate(cert.0));
14+
let _ = certs.add(cert);
1515
}
1616

1717
let config = rustls::ClientConfig::builder()
18-
.with_safe_defaults()
1918
.with_root_certificates(certs)
2019
.with_no_client_auth();
2120

@@ -36,10 +35,7 @@ impl Layer for TlsClient {
3635
where
3736
RW: AsyncRead + AsyncWrite + Unpin + Send + 'static,
3837
{
39-
Ok(Box::new(
40-
CONNECTOR
41-
.connect(addr.hostname.to_string().as_str().try_into()?, stream)
42-
.await?,
43-
))
38+
let addr = addr.hostname.to_string();
39+
Ok(Box::new(CONNECTOR.connect(addr.try_into()?, stream).await?))
4440
}
4541
}

tproxy_tokio/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9+
log = "0.4"
910
cfg-if = "1"
1011
async-trait = "0.1"
1112
tokio = { version = "1", features = ["full"] }
13+
socket2 = { version = "0.5", features = ["all"] }
1214
libc = "0.2"
13-
socket2 = "0.5"
1415
once_cell = "1"
1516

16-
[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))'.dependencies]
17-
nix = { version = "0.27", features = ["ioctl"] }
17+
# Just for the ioctl call macro
18+
[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "openbsd"))'.dependencies]
19+
nix = { version = "0.29", features = ["ioctl"] }

tproxy_tokio/src/lib.rs

Lines changed: 105 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,38 @@ pub enum RedirType {
1717
/// For not supported platforms
1818
NotSupported,
1919

20-
/// For Linux-like systems' Netfilter `REDIRECT`. Only for TCP connections.
21-
/// This is supported from Linux 2.4 Kernel. Document: <https://www.netfilter.org/documentation/index.html#documentation-howto>
22-
/// NOTE: Filter rule `REDIRECT` can only be applied to TCP connections.
20+
/// For Linux-like systems' Netfilter `REDIRECT`. Only for TCP connections.
21+
///
22+
/// This is supported from Linux 2.4 Kernel. Document: <https://www.netfilter.org/documentation/index.html#documentation-howto>
23+
///
24+
/// NOTE: Filter rule `REDIRECT` can only be applied to TCP connections.
2325
#[cfg(any(target_os = "linux", target_os = "android"))]
2426
Redirect,
2527

26-
/// For Linux-like systems' Netfilter TPROXY rule.
27-
/// NOTE: Filter rule `TPROXY` can be applied to TCP and UDP connections.
28+
/// For Linux-like systems' Netfilter TPROXY rule.
29+
///
30+
/// NOTE: Filter rule `TPROXY` can be applied to TCP and UDP connections.
2831
#[cfg(any(target_os = "linux", target_os = "android"))]
2932
TProxy,
3033

31-
/// Packet Filter (pf)
32-
/// Supported by OpenBSD 3.0+, FreeBSD 5.3+, NetBSD 3.0+, Solaris 11.3+, macOS 10.7+, iOS, QNX
33-
/// Document: <https://www.freebsd.org/doc/handbook/firewalls-pf.html>
34+
/// Packet Filter (pf)
35+
///
36+
/// Supported by OpenBSD 3.0+, FreeBSD 5.3+, NetBSD 3.0+, Solaris 11.3+, macOS 10.7+, iOS, QNX
37+
///
38+
/// Document: <https://www.freebsd.org/doc/handbook/firewalls-pf.html>
3439
#[cfg(any(
35-
target_os = "openbsd",
3640
target_os = "freebsd",
37-
target_os = "netbsd",
41+
target_os = "openbsd",
3842
target_os = "macos",
3943
target_os = "ios"
4044
))]
4145
PacketFilter,
4246

43-
/// IPFW
44-
/// Supported by FreeBSD, macOS 10.6- (Have been removed completely on macOS 10.10)
45-
/// Document: https://www.freebsd.org/doc/handbook/firewalls-ipfw.html
47+
/// IPFW
48+
///
49+
/// Supported by FreeBSD, macOS 10.6- (Have been removed completely on macOS 10.10)
50+
///
51+
/// Document: https://www.freebsd.org/doc/handbook/firewalls-ipfw.html
4652
#[cfg(any(target_os = "freebsd", target_os = "macos", target_os = "ios"))]
4753
IpFirewall,
4854
}
@@ -56,46 +62,127 @@ impl RedirType {
5662
}
5763

5864
/// Available TCP transparent proxy types
65+
#[doc(hidden)]
5966
pub fn tcp_available_types() -> &'static [&'static str] {
6067
const AVAILABLE_TYPES: &[&str] = &[RedirType::Redirect.name(), RedirType::TProxy.name()];
6168
AVAILABLE_TYPES
6269
}
63-
} else if #[cfg(any(target_os = "openbsd", target_os = "freebsd"))] {
70+
71+
/// Default UDP transparent proxy solution on this platform
72+
pub const fn udp_default() -> RedirType {
73+
RedirType::TProxy
74+
}
75+
76+
/// Available UDP transparent proxy types
77+
#[doc(hidden)]
78+
pub fn udp_available_types() -> &'static [&'static str] {
79+
const AVAILABLE_TYPES: &[&str] = &[RedirType::TProxy.name()];
80+
AVAILABLE_TYPES
81+
}
82+
} else if #[cfg(any(target_os = "freebsd"))] {
6483
/// Default TCP transparent proxy solution on this platform
6584
pub fn tcp_default() -> RedirType {
6685
RedirType::PacketFilter
6786
}
6887

6988
/// Available TCP transparent proxy types
89+
#[doc(hidden)]
7090
pub fn tcp_available_types() -> &'static [&'static str] {
7191
const AVAILABLE_TYPES: &[&str] = &[RedirType::PacketFilter.name(), RedirType::IpFirewall.name()];
7292
AVAILABLE_TYPES
7393
}
74-
} else if #[cfg(any(target_os = "netbsd", target_os = "macos", target_os = "ios"))] {
94+
95+
/// Default UDP transparent proxy solution on this platform
96+
pub fn udp_default() -> RedirType {
97+
RedirType::PacketFilter
98+
}
99+
100+
/// Available UDP transparent proxy types
101+
#[doc(hidden)]
102+
pub const fn udp_available_types() -> &'static [&'static str] {
103+
const AVAILABLE_TYPES: &[&str] = &[RedirType::PacketFilter.name(), RedirType::IpFirewall.name()];
104+
AVAILABLE_TYPES
105+
}
106+
} else if #[cfg(target_os = "openbsd")] {
75107
/// Default TCP transparent proxy solution on this platform
76108
pub fn tcp_default() -> RedirType {
77109
RedirType::PacketFilter
78110
}
79111

80112
/// Available TCP transparent proxy types
113+
#[doc(hidden)]
114+
pub fn tcp_available_types() -> &'static [&'static str] {
115+
const AVAILABLE_TYPES: &[&str] = &[RedirType::PacketFilter.name()];
116+
AVAILABLE_TYPES
117+
}
118+
119+
/// Default UDP transparent proxy solution on this platform
120+
pub fn udp_default() -> RedirType {
121+
RedirType::PacketFilter
122+
}
123+
124+
/// Available UDP transparent proxy types
125+
#[doc(hidden)]
126+
pub const fn udp_available_types() -> &'static [&'static str] {
127+
const AVAILABLE_TYPES: &[&str] = &[RedirType::PacketFilter.name()];
128+
AVAILABLE_TYPES
129+
}
130+
} else if #[cfg(any(target_os = "macos", target_os = "ios"))] {
131+
/// Default TCP transparent proxy solution on this platform
132+
pub fn tcp_default() -> RedirType {
133+
RedirType::PacketFilter
134+
}
135+
136+
/// Available TCP transparent proxy types
137+
#[doc(hidden)]
81138
pub const fn tcp_available_types() -> &'static [&'static str] {
82139
const AVAILABLE_TYPES: &[&str] = &[RedirType::PacketFilter.name(), RedirType::IpFirewall.name()];
83140
AVAILABLE_TYPES
84141
}
142+
143+
/// Default UDP transparent proxy solution on this platform
144+
pub fn udp_default() -> RedirType {
145+
RedirType::PacketFilter
146+
}
147+
148+
/// Available UDP transparent proxy types
149+
#[doc(hidden)]
150+
pub const fn udp_available_types() -> &'static [&'static str] {
151+
const AVAILABLE_TYPES: &[&str] = &[RedirType::PacketFilter.name()];
152+
AVAILABLE_TYPES
153+
}
85154
} else {
86155
/// Default TCP transparent proxy solution on this platform
87156
pub fn tcp_default() -> RedirType {
88157
RedirType::NotSupported
89158
}
90159

91160
/// Available TCP transparent proxy types
161+
#[doc(hidden)]
92162
pub const fn tcp_available_types() -> &'static [&'static str] {
93163
const AVAILABLE_TYPES: &[&str] = &[];
94164
AVAILABLE_TYPES
95165
}
166+
167+
/// Default UDP transparent proxy solution on this platform
168+
pub fn udp_default() -> RedirType {
169+
RedirType::NotSupported
170+
}
171+
172+
/// Available UDP transparent proxy types
173+
#[doc(hidden)]
174+
pub const fn udp_available_types() -> &'static [&'static str] {
175+
const AVAILABLE_TYPES: &[&str] = &[];
176+
AVAILABLE_TYPES
177+
}
96178
}
97179
}
98180

181+
/// Check if transparent proxy is supported on this platform
182+
pub fn is_supported(self) -> bool {
183+
self != RedirType::NotSupported
184+
}
185+
99186
/// Name of redirect type (transparent proxy type)
100187
pub const fn name(self) -> &'static str {
101188
match self {
@@ -109,9 +196,8 @@ impl RedirType {
109196
RedirType::TProxy => "tproxy",
110197

111198
#[cfg(any(
112-
target_os = "openbsd",
113199
target_os = "freebsd",
114-
target_os = "netbsd",
200+
target_os = "openbsd",
115201
target_os = "macos",
116202
target_os = "ios"
117203
))]
@@ -153,21 +239,14 @@ impl FromStr for RedirType {
153239
"tproxy" => Ok(RedirType::TProxy),
154240

155241
#[cfg(any(
156-
target_os = "openbsd",
157242
target_os = "freebsd",
158-
target_os = "netbsd",
159-
target_os = "solaris",
243+
target_os = "openbsd",
160244
target_os = "macos",
161245
target_os = "ios",
162246
))]
163247
"pf" => Ok(RedirType::PacketFilter),
164248

165-
#[cfg(any(
166-
target_os = "freebsd",
167-
target_os = "macos",
168-
target_os = "ios",
169-
target_os = "dragonfly"
170-
))]
249+
#[cfg(any(target_os = "freebsd", target_os = "macos", target_os = "ios",))]
171250
"ipfw" => Ok(RedirType::IpFirewall),
172251

173252
_ => Err(InvalidRedirType),

tproxy_tokio/src/tcp/bsd/mod.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,24 @@ use socket2::Protocol;
1313

1414
#[async_trait]
1515
impl TcpListenerRedirExt for TcpListener {
16-
async fn bind_redir(ty: RedirType, addr: SocketAddr) -> Result<TcpListener, Error> {
16+
async fn bind_redir(ty: RedirType, addr: SocketAddr) -> io::Result<TcpListener> {
1717
match ty {
1818
#[cfg(any(
19-
target_os = "openbsd",
2019
target_os = "freebsd",
21-
target_os = "netbsd",
20+
target_os = "openbsd",
2221
target_os = "macos",
23-
target_os = "ios",
22+
target_os = "ios"
2423
))]
2524
RedirType::PacketFilter => {}
2625

27-
#[cfg(any(target_os = "freebsd", target_os = "macos", target_os = "ios",))]
26+
#[cfg(any(target_os = "freebsd", target_os = "macos", target_os = "ios"))]
2827
RedirType::IpFirewall => {}
2928

3029
_ => {
3130
return Err(Error::new(
3231
ErrorKind::InvalidInput,
3332
"not supported tcp transparent proxy type",
34-
))
33+
));
3534
}
3635
}
3736

@@ -45,30 +44,26 @@ impl TcpListenerRedirExt for TcpListener {
4544
impl TcpStreamRedirExt for TcpStream {
4645
fn destination_addr(&self, ty: RedirType) -> io::Result<SocketAddr> {
4746
match ty {
48-
#[cfg(any(
49-
target_os = "openbsd",
50-
target_os = "freebsd",
51-
target_os = "netbsd",
52-
target_os = "macos",
53-
target_os = "ios",
54-
))]
55-
RedirType::Redirect => {
47+
#[cfg(any(target_os = "freebsd", target_os = "macos", target_os = "ios"))]
48+
RedirType::PacketFilter => {
5649
let peer_addr = self.peer_addr()?;
5750
let bind_addr = self.local_addr()?;
5851

5952
pf::PF.natlook(&bind_addr, &peer_addr, Protocol::TCP)
6053
}
61-
62-
#[cfg(any(target_os = "freebsd", target_os = "macos", target_os = "ios",))]
54+
#[cfg(target_os = "openbsd")]
55+
// in OpenBSD, we can get TCP destination address with getsockname()
56+
RedirType::PacketFilter => self.local_addr(),
57+
#[cfg(any(target_os = "freebsd", target_os = "macos", target_os = "ios"))]
6358
RedirType::IpFirewall => {
59+
// ## IPFW
60+
//
6461
// For IPFW, uses getsockname() to retrieve destination address
62+
//
6563
// FreeBSD: https://www.freebsd.org/doc/handbook/firewalls-ipfw.html
6664
self.local_addr()
6765
}
68-
_ => Err(Error::new(
69-
ErrorKind::InvalidInput,
70-
"not supported tcp transparent proxy type",
71-
)),
66+
_ => unreachable!("not supported tcp transparent proxy type"),
7267
}
7368
}
7469
}

0 commit comments

Comments
 (0)