Skip to content

Commit

Permalink
Merge branch 'remove-one-more-duct'
Browse files Browse the repository at this point in the history
  • Loading branch information
raksooo committed Dec 20, 2024
2 parents 7301123 + ee78a49 commit e73a827
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions talpid-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ duct = "0.13"

[target.'cfg(target_os = "macos")'.dependencies]
async-trait = "0.1"
duct = "0.13"
pfctl = "0.6.1"
subslice = "0.2"
system-configuration = "0.5.1"
hickory-proto = { workspace = true }
hickory-server = { workspace = true, features = ["resolver"] }
Expand Down
23 changes: 7 additions & 16 deletions talpid-core/src/firewall/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::sync::LazyLock;
use ipnetwork::IpNetwork;
use libc::{c_int, sysctlbyname};
use pfctl::{DropAction, FilterRuleAction, Ip, RedirectRule, Uid};
use subslice::SubsliceExt;
use talpid_types::net::{
AllowedEndpoint, AllowedTunnelTraffic, TransportProtocol, ALLOWED_LAN_MULTICAST_NETS,
ALLOWED_LAN_NETS,
Expand Down Expand Up @@ -936,21 +935,13 @@ impl Firewall {
self.pf.try_enable()
}

fn is_enabled(&self) -> bool {
let cmd = duct::cmd!("/sbin/pfctl", "-s", "info")
.stderr_null()
.stdout_capture();
const EXPECTED_OUTPUT: &[u8] = b"Status: Enabled";
match cmd.run() {
Ok(output) => output.stdout.as_slice().find(EXPECTED_OUTPUT).is_some(),
Err(err) => {
log::error!(
"Failed to execute pfctl, assuming pf is not enabled: {}",
err
);
false
}
}
fn is_enabled(&mut self) -> bool {
// If we can't know for sure whether pf is enabled or not, err on the side of caution and
// return false.
self.pf
.is_enabled()
.inspect_err(|err| log::error!("Unable to determine if pf is enabled: {err}"))
.unwrap_or(false)
}

fn restore_state(&mut self) -> Result<()> {
Expand Down

0 comments on commit e73a827

Please sign in to comment.