Struct IPTables

Source
pub struct IPTables {
    pub cmd: &'static str,
    pub has_check: bool,
    pub has_wait: bool,
    pub is_numeric: bool,
}
Expand description

Contains the iptables command and shows if it supports -w and -C options. Use new method to create a new instance of this struct.

Fields§

§cmd: &'static str

The utility command which must be ‘iptables’ or ‘ip6tables’.

§has_check: bool

Indicates if iptables has -C (–check) option

§has_wait: bool

Indicates if iptables has -w (–wait) option

§is_numeric: bool

Indicates if iptables will be run with -n (–numeric) option

Implementations§

Source§

impl IPTables

Source

pub fn get_policy( &self, table: &str, chain: &str, ) -> Result<String, Box<dyn Error>>

Get the default policy for a table/chain.

Source

pub fn set_policy( &self, table: &str, chain: &str, policy: &str, ) -> Result<(), Box<dyn Error>>

Set the default policy for a table/chain.

Source

pub fn execute( &self, table: &str, command: &str, ) -> Result<Output, Box<dyn Error>>

Executes a given command on the chain. Returns the command output if successful.

Source

pub fn exists( &self, table: &str, chain: &str, rule: &str, ) -> Result<bool, Box<dyn Error>>

Checks for the existence of the rule in the table/chain. Returns true if the rule exists.

Source

pub fn chain_exists( &self, table: &str, chain: &str, ) -> Result<bool, Box<dyn Error>>

Checks for the existence of the chain in the table. Returns true if the chain exists.

Source

pub fn insert( &self, table: &str, chain: &str, rule: &str, position: i32, ) -> Result<(), Box<dyn Error>>

Inserts rule in the position to the table/chain.

Source

pub fn insert_unique( &self, table: &str, chain: &str, rule: &str, position: i32, ) -> Result<(), Box<dyn Error>>

Inserts rule in the position to the table/chain if it does not exist.

Source

pub fn replace( &self, table: &str, chain: &str, rule: &str, position: i32, ) -> Result<(), Box<dyn Error>>

Replaces rule in the position to the table/chain.

Source

pub fn append( &self, table: &str, chain: &str, rule: &str, ) -> Result<(), Box<dyn Error>>

Appends rule to the table/chain.

Source

pub fn append_unique( &self, table: &str, chain: &str, rule: &str, ) -> Result<(), Box<dyn Error>>

Appends rule to the table/chain if it does not exist.

Source

pub fn append_replace( &self, table: &str, chain: &str, rule: &str, ) -> Result<(), Box<dyn Error>>

Appends or replaces rule to the table/chain if it does not exist.

Source

pub fn delete( &self, table: &str, chain: &str, rule: &str, ) -> Result<(), Box<dyn Error>>

Deletes rule from the table/chain.

Source

pub fn delete_all( &self, table: &str, chain: &str, rule: &str, ) -> Result<(), Box<dyn Error>>

Deletes all repetition of the rule from the table/chain.

Source

pub fn list( &self, table: &str, chain: &str, ) -> Result<Vec<String>, Box<dyn Error>>

Lists rules in the table/chain.

Source

pub fn list_table(&self, table: &str) -> Result<Vec<String>, Box<dyn Error>>

Lists rules in the table.

Source

pub fn list_chains(&self, table: &str) -> Result<Vec<String>, Box<dyn Error>>

Lists the name of each chain in the table.

Source

pub fn new_chain(&self, table: &str, chain: &str) -> Result<(), Box<dyn Error>>

Creates a new user-defined chain.

Source

pub fn flush_chain( &self, table: &str, chain: &str, ) -> Result<(), Box<dyn Error>>

Flushes (deletes all rules) a chain.

Source

pub fn rename_chain( &self, table: &str, old_chain: &str, new_chain: &str, ) -> Result<(), Box<dyn Error>>

Renames a chain in the table.

Source

pub fn delete_chain( &self, table: &str, chain: &str, ) -> Result<(), Box<dyn Error>>

Deletes a user-defined chain in the table.

Source

pub fn flush_table(&self, table: &str) -> Result<(), Box<dyn Error>>

Flushes all chains in a table.

Source

pub fn set_numeric(&mut self, numeric: bool)

Set whether iptables is called with the -n (–numeric) option, to avoid host name and port name lookups

Auto Trait Implementations§

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>,

Source§

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>,

Source§

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.