Struct pfctl::PfCtl

source ·
pub struct PfCtl { /* private fields */ }
Expand description

Struct communicating with the PF firewall.

Implementations§

source§

impl PfCtl

source

pub fn new() -> Result<Self>

Returns a new PfCtl if opening the PF device file succeeded.

source

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.

source

pub fn try_enable(&mut self) -> Result<()>

Same as enable, but StateAlreadyActive errors are supressed and exchanged for Ok(()).

source

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.

source

pub fn try_disable(&mut self) -> Result<()>

Same as disable, but StateAlreadyActive errors are supressed and exchanged for Ok(()).

source

pub fn is_enabled(&mut self) -> Result<bool>

Tries to determine if PF is enabled or not.

source

pub fn add_anchor(&mut self, name: &str, kind: AnchorKind) -> Result<()>

source

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(()).

source

pub fn remove_anchor(&mut self, name: &str, kind: AnchorKind) -> Result<()>

source

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(()).

source

pub fn add_rule(&mut self, anchor: &str, rule: &FilterRule) -> Result<()>

source

pub fn set_rules(&mut self, anchor: &str, change: AnchorChange) -> Result<()>

source

pub fn add_redirect_rule( &mut self, anchor: &str, rule: &RedirectRule ) -> Result<()>

source

pub fn flush_rules(&mut self, anchor: &str, kind: RulesetKind) -> Result<()>

source

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.

source

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

Auto Trait Implementations§

§

impl Freeze for PfCtl

§

impl RefUnwindSafe for PfCtl

§

impl Send for PfCtl

§

impl Sync for PfCtl

§

impl Unpin for PfCtl

§

impl UnwindSafe for PfCtl

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.