pub struct PfCtl { /* private fields */ }Expand description
Struct communicating with the PF firewall.
Implementations§
Source§impl PfCtl
impl PfCtl
Sourcepub fn enable(&mut self) -> Result<()>
pub fn enable(&mut self) -> Result<()>
Tries to enable PF. If the firewall is already enabled it will return an
StateAlreadyActive error. If there is some other error it will return an IoctlError.
Sourcepub fn try_enable(&mut self) -> Result<()>
pub fn try_enable(&mut self) -> Result<()>
Same as enable, but StateAlreadyActive errors are supressed and exchanged for
Ok(()).
Sourcepub fn disable(&mut self) -> Result<()>
pub fn disable(&mut self) -> Result<()>
Tries to disable PF. If the firewall is already disabled it will return an
StateAlreadyActive error. If there is some other error it will return an IoctlError.
Sourcepub fn try_disable(&mut self) -> Result<()>
pub fn try_disable(&mut self) -> Result<()>
Same as disable, but StateAlreadyActive errors are supressed and exchanged for
Ok(()).
Sourcepub fn is_enabled(&mut self) -> Result<bool>
pub fn is_enabled(&mut self) -> Result<bool>
Tries to determine if PF is enabled or not.
pub fn add_anchor(&mut self, name: &str, kind: AnchorKind) -> Result<()>
Sourcepub fn try_add_anchor(&mut self, name: &str, kind: AnchorKind) -> Result<()>
pub fn try_add_anchor(&mut self, name: &str, kind: AnchorKind) -> Result<()>
Same as add_anchor, but StateAlreadyActive errors are supressed and exchanged for
Ok(()).
pub fn remove_anchor(&mut self, name: &str, kind: AnchorKind) -> Result<()>
Sourcepub fn try_remove_anchor(&mut self, name: &str, kind: AnchorKind) -> Result<()>
pub fn try_remove_anchor(&mut self, name: &str, kind: AnchorKind) -> Result<()>
Same as remove_anchor, but AnchorDoesNotExist errors are supressed and exchanged for
Ok(()).
pub fn add_rule(&mut self, anchor: &str, rule: &FilterRule) -> Result<()>
pub fn set_rules(&mut self, anchor: &str, change: AnchorChange) -> Result<()>
pub fn add_nat_rule(&mut self, anchor: &str, rule: &NatRule) -> Result<()>
pub fn add_redirect_rule( &mut self, anchor: &str, rule: &RedirectRule, ) -> Result<()>
pub fn add_scrub_rule(&mut self, anchor: &str, rule: &ScrubRule) -> Result<()>
pub fn flush_rules(&mut self, anchor: &str, kind: RulesetKind) -> Result<()>
Sourcepub fn clear_states(
&mut self,
anchor_name: &str,
kind: AnchorKind,
) -> Result<u32>
pub fn clear_states( &mut self, anchor_name: &str, kind: AnchorKind, ) -> Result<u32>
Clear states created by rules in anchor. Returns total number of removed states upon success, otherwise ErrorKind::AnchorDoesNotExist if anchor does not exist.
Sourcepub fn clear_interface_states(&mut self, interface: Interface) -> Result<u32>
pub fn clear_interface_states(&mut self, interface: Interface) -> Result<u32>
Clear states belonging to a given interface Returns total number of removed states upon success
Sourcepub fn get_states(&mut self) -> Result<Vec<State>>
pub fn get_states(&mut self) -> Result<Vec<State>>
Get all states created by stateful rules
Sourcepub fn kill_state(&mut self, state: &State) -> Result<()>
pub fn kill_state(&mut self, state: &State) -> Result<()>
Remove the specified state.
All current states can be obtained via [get_states].
Sourcepub fn set_interface_flag(
&mut self,
interface: Interface,
flags: InterfaceFlags,
) -> Result<()>
pub fn set_interface_flag( &mut self, interface: Interface, flags: InterfaceFlags, ) -> Result<()>
Set the given interface flags for an interface.
These flags can be viewed with ‘pfctl -sI -v -i
Sourcepub fn clear_interface_flag(
&mut self,
interface: Interface,
flags: InterfaceFlags,
) -> Result<()>
pub fn clear_interface_flag( &mut self, interface: Interface, flags: InterfaceFlags, ) -> Result<()>
Clear the given interface flags for an interface.
https://man.freebsd.org/cgi/man.cgi?pf(4)