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
impl IPTables
Sourcepub fn get_policy(
&self,
table: &str,
chain: &str,
) -> Result<String, Box<dyn Error>>
pub fn get_policy( &self, table: &str, chain: &str, ) -> Result<String, Box<dyn Error>>
Get the default policy for a table/chain.
Sourcepub fn set_policy(
&self,
table: &str,
chain: &str,
policy: &str,
) -> Result<(), Box<dyn Error>>
pub fn set_policy( &self, table: &str, chain: &str, policy: &str, ) -> Result<(), Box<dyn Error>>
Set the default policy for a table/chain.
Sourcepub fn execute(
&self,
table: &str,
command: &str,
) -> Result<Output, Box<dyn Error>>
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.
Sourcepub fn exists(
&self,
table: &str,
chain: &str,
rule: &str,
) -> Result<bool, Box<dyn Error>>
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.
Sourcepub fn chain_exists(
&self,
table: &str,
chain: &str,
) -> Result<bool, Box<dyn Error>>
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.
Sourcepub fn insert(
&self,
table: &str,
chain: &str,
rule: &str,
position: i32,
) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn insert_unique(
&self,
table: &str,
chain: &str,
rule: &str,
position: i32,
) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn replace(
&self,
table: &str,
chain: &str,
rule: &str,
position: i32,
) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn append(
&self,
table: &str,
chain: &str,
rule: &str,
) -> Result<(), Box<dyn Error>>
pub fn append( &self, table: &str, chain: &str, rule: &str, ) -> Result<(), Box<dyn Error>>
Appends rule
to the table/chain.
Sourcepub fn append_unique(
&self,
table: &str,
chain: &str,
rule: &str,
) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn append_replace(
&self,
table: &str,
chain: &str,
rule: &str,
) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn delete(
&self,
table: &str,
chain: &str,
rule: &str,
) -> Result<(), Box<dyn Error>>
pub fn delete( &self, table: &str, chain: &str, rule: &str, ) -> Result<(), Box<dyn Error>>
Deletes rule
from the table/chain.
Sourcepub fn delete_all(
&self,
table: &str,
chain: &str,
rule: &str,
) -> Result<(), Box<dyn Error>>
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.
Sourcepub fn list(
&self,
table: &str,
chain: &str,
) -> Result<Vec<String>, Box<dyn Error>>
pub fn list( &self, table: &str, chain: &str, ) -> Result<Vec<String>, Box<dyn Error>>
Lists rules in the table/chain.
Sourcepub fn list_table(&self, table: &str) -> Result<Vec<String>, Box<dyn Error>>
pub fn list_table(&self, table: &str) -> Result<Vec<String>, Box<dyn Error>>
Lists rules in the table.
Sourcepub fn list_chains(&self, table: &str) -> Result<Vec<String>, Box<dyn Error>>
pub fn list_chains(&self, table: &str) -> Result<Vec<String>, Box<dyn Error>>
Lists the name of each chain in the table.
Sourcepub fn new_chain(&self, table: &str, chain: &str) -> Result<(), Box<dyn Error>>
pub fn new_chain(&self, table: &str, chain: &str) -> Result<(), Box<dyn Error>>
Creates a new user-defined chain.
Sourcepub fn flush_chain(
&self,
table: &str,
chain: &str,
) -> Result<(), Box<dyn Error>>
pub fn flush_chain( &self, table: &str, chain: &str, ) -> Result<(), Box<dyn Error>>
Flushes (deletes all rules) a chain.
Sourcepub fn rename_chain(
&self,
table: &str,
old_chain: &str,
new_chain: &str,
) -> Result<(), Box<dyn Error>>
pub fn rename_chain( &self, table: &str, old_chain: &str, new_chain: &str, ) -> Result<(), Box<dyn Error>>
Renames a chain in the table.
Sourcepub fn delete_chain(
&self,
table: &str,
chain: &str,
) -> Result<(), Box<dyn Error>>
pub fn delete_chain( &self, table: &str, chain: &str, ) -> Result<(), Box<dyn Error>>
Deletes a user-defined chain in the table.
Sourcepub fn flush_table(&self, table: &str) -> Result<(), Box<dyn Error>>
pub fn flush_table(&self, table: &str) -> Result<(), Box<dyn Error>>
Flushes all chains in a table.
Sourcepub fn set_numeric(&mut self, numeric: bool)
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