Skip to content

Commit c71ce90

Browse files
committed
add support for OpenBSD/pf
1 parent 1a83e0e commit c71ce90

File tree

9 files changed

+16930
-27
lines changed

9 files changed

+16930
-27
lines changed

crates/shadowsocks-service/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ bson = { version = "2.10.0", optional = true }
206206
shadowsocks = { version = "1.20.1", path = "../shadowsocks", default-features = false }
207207

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

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

crates/shadowsocks-service/src/config.rs

+27
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ cfg_if! {
487487
/// Document: <https://www.freebsd.org/doc/handbook/firewalls-pf.html>
488488
#[cfg(any(
489489
target_os = "freebsd",
490+
target_os = "openbsd",
490491
target_os = "macos",
491492
target_os = "ios"
492493
))]
@@ -551,6 +552,30 @@ cfg_if! {
551552
const AVAILABLE_TYPES: &[&str] = &[RedirType::PacketFilter.name(), RedirType::IpFirewall.name()];
552553
AVAILABLE_TYPES
553554
}
555+
} else if #[cfg(target_os = "openbsd")] {
556+
/// Default TCP transparent proxy solution on this platform
557+
pub fn tcp_default() -> RedirType {
558+
RedirType::PacketFilter
559+
}
560+
561+
/// Available TCP transparent proxy types
562+
#[doc(hidden)]
563+
pub fn tcp_available_types() -> &'static [&'static str] {
564+
const AVAILABLE_TYPES: &[&str] = &[RedirType::PacketFilter.name()];
565+
AVAILABLE_TYPES
566+
}
567+
568+
/// Default UDP transparent proxy solution on this platform
569+
pub fn udp_default() -> RedirType {
570+
RedirType::PacketFilter
571+
}
572+
573+
/// Available UDP transparent proxy types
574+
#[doc(hidden)]
575+
pub const fn udp_available_types() -> &'static [&'static str] {
576+
const AVAILABLE_TYPES: &[&str] = &[RedirType::PacketFilter.name()];
577+
AVAILABLE_TYPES
578+
}
554579
} else if #[cfg(any(target_os = "macos", target_os = "ios"))] {
555580
/// Default TCP transparent proxy solution on this platform
556581
pub fn tcp_default() -> RedirType {
@@ -621,6 +646,7 @@ cfg_if! {
621646

622647
#[cfg(any(
623648
target_os = "freebsd",
649+
target_os = "openbsd",
624650
target_os = "macos",
625651
target_os = "ios"
626652
))]
@@ -661,6 +687,7 @@ cfg_if! {
661687

662688
#[cfg(any(
663689
target_os = "freebsd",
690+
target_os = "openbsd",
664691
target_os = "macos",
665692
target_os = "ios",
666693
))]

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)