Skip to content

Commit 15d2415

Browse files
committed
add support for OpenBSD/pf
1 parent a04e92c commit 15d2415

File tree

9 files changed

+17145
-29
lines changed

9 files changed

+17145
-29
lines changed

crates/shadowsocks-service/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ bson = { version = "2.12.0", optional = true }
208208
shadowsocks = { version = "1.20.2", path = "../shadowsocks", default-features = false }
209209

210210
# Just for the ioctl call macro
211-
[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd"))'.dependencies]
211+
[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "openbsd"))'.dependencies]
212212
nix = { version = "0.29", features = ["ioctl"] }
213213

214214
[target.'cfg(windows)'.dependencies]

crates/shadowsocks-service/src/config.rs

+27
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ cfg_if! {
480480
/// Document: <https://www.freebsd.org/doc/handbook/firewalls-pf.html>
481481
#[cfg(any(
482482
target_os = "freebsd",
483+
target_os = "openbsd",
483484
target_os = "macos",
484485
target_os = "ios"
485486
))]
@@ -544,6 +545,30 @@ cfg_if! {
544545
const AVAILABLE_TYPES: &[&str] = &[RedirType::PacketFilter.name(), RedirType::IpFirewall.name()];
545546
AVAILABLE_TYPES
546547
}
548+
} else if #[cfg(target_os = "openbsd")] {
549+
/// Default TCP transparent proxy solution on this platform
550+
pub fn tcp_default() -> RedirType {
551+
RedirType::PacketFilter
552+
}
553+
554+
/// Available TCP transparent proxy types
555+
#[doc(hidden)]
556+
pub fn tcp_available_types() -> &'static [&'static str] {
557+
const AVAILABLE_TYPES: &[&str] = &[RedirType::PacketFilter.name()];
558+
AVAILABLE_TYPES
559+
}
560+
561+
/// Default UDP transparent proxy solution on this platform
562+
pub fn udp_default() -> RedirType {
563+
RedirType::PacketFilter
564+
}
565+
566+
/// Available UDP transparent proxy types
567+
#[doc(hidden)]
568+
pub const fn udp_available_types() -> &'static [&'static str] {
569+
const AVAILABLE_TYPES: &[&str] = &[RedirType::PacketFilter.name()];
570+
AVAILABLE_TYPES
571+
}
547572
} else if #[cfg(any(target_os = "macos", target_os = "ios"))] {
548573
/// Default TCP transparent proxy solution on this platform
549574
pub fn tcp_default() -> RedirType {
@@ -614,6 +639,7 @@ cfg_if! {
614639

615640
#[cfg(any(
616641
target_os = "freebsd",
642+
target_os = "openbsd",
617643
target_os = "macos",
618644
target_os = "ios"
619645
))]
@@ -654,6 +680,7 @@ cfg_if! {
654680

655681
#[cfg(any(
656682
target_os = "freebsd",
683+
target_os = "openbsd",
657684
target_os = "macos",
658685
target_os = "ios",
659686
))]

crates/shadowsocks-service/src/local/redir/sys/unix/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@ cfg_if! {
2020
#[allow(dead_code, non_upper_case_globals, non_snake_case, non_camel_case_types)]
2121
#[allow(clippy::useless_transmute, clippy::too_many_arguments, clippy::unnecessary_cast)]
2222
mod pfvar;
23+
} else if #[cfg(target_os = "openbsd")] {
24+
#[path = "pfvar_bindgen_openbsd.rs"]
25+
#[allow(dead_code, non_upper_case_globals, non_snake_case, non_camel_case_types)]
26+
#[allow(clippy::useless_transmute, clippy::too_many_arguments, clippy::unnecessary_cast)]
27+
mod pfvar;
2328
}
2429
}

0 commit comments

Comments
 (0)