Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 // In the name of Allah
2
3 //! Provides bindings for [iptables](https://www.netfilter.org/projects/iptables/index.html) application in Linux.
4 //! This crate uses iptables binary to manipulate chains and tables.
5 //! This source code is licensed under MIT license that can be found in the LICENSE file.
6 //!
7 //! # Example
8 //! ```
9 //! let ipt = iptables::new(false).unwrap();
10 //! assert!(ipt.new_chain("nat", "NEWCHAINNAME").is_ok());
11 //! assert!(ipt.append("nat", "NEWCHAINNAME", "-j ACCEPT").is_ok());
12 //! assert!(ipt.exists("nat", "NEWCHAINNAME", "-j ACCEPT").unwrap());
13 //! assert!(ipt.delete("nat", "NEWCHAINNAME", "-j ACCEPT").is_ok());
14 //! assert!(ipt.delete_chain("nat", "NEWCHAINNAME").is_ok());
15 //! ```
16
17 pub mod errorrust-analyzer cargo iptables 0.6.0 error/;
18
19 use errorrust-analyzer cargo iptables 0.6.0 error/::IptablesErrorrust-analyzer cargo iptables 0.6.0 error/IptablesError#;
20 use lazy_staticrust-analyzer cargo lazy_static 1.5.0 crate/::lazy_staticrust-analyzer cargo lazy_static 1.5.0 lazy_static!;
21 use regexrust-analyzer cargo regex 1.11.1 crate/::{Matchrust-analyzer cargo regex 1.11.1 regex/string/Match#, Regexrust-analyzer cargo regex 1.11.1 regex/string/Regex#};
22 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#;
23 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#;
24 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#;
25 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::{Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#, Outputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#};
26 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#;
27
28 // List of built-in chains taken from: man 8 iptables
29 const BUILTIN_CHAINS_FILTERrust-analyzer cargo iptables 0.6.0 BUILTIN_CHAINS_FILTER.: &[&str] = &["INPUT", "FORWARD", "OUTPUT"];
30 const BUILTIN_CHAINS_MANGLErust-analyzer cargo iptables 0.6.0 BUILTIN_CHAINS_MANGLE.: &[&str] = &["PREROUTING", "OUTPUT", "INPUT", "FORWARD", "POSTROUTING"];
31 const BUILTIN_CHAINS_NATrust-analyzer cargo iptables 0.6.0 BUILTIN_CHAINS_NAT.: &[&str] = &["PREROUTING", "POSTROUTING", "OUTPUT"];
32 const BUILTIN_CHAINS_RAWrust-analyzer cargo iptables 0.6.0 BUILTIN_CHAINS_RAW.: &[&str] = &["PREROUTING", "OUTPUT"];
33 const BUILTIN_CHAINS_SECURITYrust-analyzer cargo iptables 0.6.0 BUILTIN_CHAINS_SECURITY.: &[&str] = &["INPUT", "OUTPUT", "FORWARD"];
34
35 lazy_staticrust-analyzer cargo lazy_static 1.5.0 lazy_static!! {
36 static ref RE_SPLITrust-analyzer cargo iptables 0.6.0 RE_SPLIT#: Regexrust-analyzer cargo regex 1.11.1 regex/string/Regex# = Regexrust-analyzer cargo regex 1.11.1 regex/string/Regex#::newrust-analyzer cargo regex 1.11.1 regex/string/impl#[Regex]new().(r#"["'].+?["']|[^ ]+"#).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
37 }
38
39 trait SplitQuotedrust-analyzer cargo iptables 0.6.0 SplitQuoted# {
40 fn split_quotedrust-analyzer cargo iptables 0.6.0 SplitQuoted#split_quoted().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str>;
41 }
42
43 impl SplitQuotedrust-analyzer cargo iptables 0.6.0 SplitQuoted# for str {
44 fn split_quotedrust-analyzer cargo iptables 0.6.0 impl#[str][SplitQuoted]split_quoted().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str> {
45 RE_SPLITrust-analyzer cargo iptables 0.6.0 RE_SPLIT.
46 // Iterate over matched segments
47 .find_iterrust-analyzer cargo regex 1.11.1 regex/string/impl#[Regex]find_iter().(self)
48 // Get match as str
49 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|m| Matchrust-analyzer cargo regex 1.11.1 regex/string/Match#::as_strrust-analyzer cargo regex 1.11.1 regex/string/impl#[`Match<'h>`]as_str().(&m))
50 // Remove any surrounding quotes (they will be reinserted by `Command`)
51 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| s.trim_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_matches().(|c| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'"' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\''))
52 // Collect
53 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()
54 }
55 }
56
57 fn error_from_strrust-analyzer cargo iptables 0.6.0 error_from_str().(msg: &str) -> Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#> {
58 msg.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
59 }
60
61 fn output_to_resultrust-analyzer cargo iptables 0.6.0 output_to_result().(output: Outputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
62 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().output.statusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#status..successrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]success().() {
63 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(IptablesErrorrust-analyzer cargo iptables 0.6.0 error/IptablesError#::fromrust-analyzer cargo iptables 0.6.0 error/impl#[IptablesError][`From<Output>`]from().(output)));
64 }
65 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
66 }
67
68 fn get_builtin_chainsrust-analyzer cargo iptables 0.6.0 get_builtin_chains().(table: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&[&str], Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
69 match table {
70 "filter" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(BUILTIN_CHAINS_FILTERrust-analyzer cargo iptables 0.6.0 BUILTIN_CHAINS_FILTER.),
71 "mangle" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(BUILTIN_CHAINS_MANGLErust-analyzer cargo iptables 0.6.0 BUILTIN_CHAINS_MANGLE.),
72 "nat" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(BUILTIN_CHAINS_NATrust-analyzer cargo iptables 0.6.0 BUILTIN_CHAINS_NAT.),
73 "raw" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(BUILTIN_CHAINS_RAWrust-analyzer cargo iptables 0.6.0 BUILTIN_CHAINS_RAW.),
74 "security" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(BUILTIN_CHAINS_SECURITYrust-analyzer cargo iptables 0.6.0 BUILTIN_CHAINS_SECURITY.),
75 _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error_from_strrust-analyzer cargo iptables 0.6.0 error_from_str().("given table is not supported by iptables")),
76 }
77 }
78
79 /// Contains the iptables command and shows if it supports -w and -C options.
80 /// Use `new` method to create a new instance of this struct.
81 pub struct IPTablesrust-analyzer cargo iptables 0.6.0 IPTables# {
82 /// The utility command which must be 'iptables' or 'ip6tables'.
83 pub cmdrust-analyzer cargo iptables 0.6.0 IPTables#cmd.: &'static str,
84
85 /// Indicates if iptables has -C (--check) option
86 pub has_checkrust-analyzer cargo iptables 0.6.0 IPTables#has_check.: bool,
87
88 /// Indicates if iptables has -w (--wait) option
89 pub has_waitrust-analyzer cargo iptables 0.6.0 IPTables#has_wait.: bool,
90
91 /// Indicates if iptables will be run with -n (--numeric) option
92 pub is_numericrust-analyzer cargo iptables 0.6.0 IPTables#is_numeric.: bool,
93 }
94
95 /// Returns `None` because iptables only works on linux
96 #[cfg(not(target_os = "linux"))]
97 pub fn new(is_ipv6: bool) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IPTablesrust-analyzer cargo iptables 0.6.0 IPTables#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
98 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error_from_strrust-analyzer cargo iptables 0.6.0 error_from_str().("iptables only works on Linux"))
99 }
100
101 /// Creates a new `IPTables` Result with the command of 'iptables' if `is_ipv6` is `false`, otherwise the command is 'ip6tables'.
102 #[cfg(target_os = "linux")]
103 pub fn newrust-analyzer cargo iptables 0.6.0 new().(is_ipv6: bool) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IPTablesrust-analyzer cargo iptables 0.6.0 IPTables#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
104 let cmd = if is_ipv6 { "ip6tables" } else { "iptables" };
105
106 let version_output = Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().(cmd).argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("--version").outputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]output().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
107 let re = Regexrust-analyzer cargo regex 1.11.1 regex/string/Regex#::newrust-analyzer cargo regex 1.11.1 regex/string/impl#[Regex]new().(r"v(\d+)\.(\d+)\.(\d+)")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
108 let version_string = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(version_output.stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout..as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().());
109 let versions = re
110 .capturesrust-analyzer cargo regex 1.11.1 regex/string/impl#[Regex]captures().(&version_string)
111 .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("invalid version number")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
112 let v_major = versions
113 .getrust-analyzer cargo regex 1.11.1 regex/string/impl#[`Captures<'h>`]get().(1)
114 .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("unable to get major version number")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
115 .as_strrust-analyzer cargo regex 1.11.1 regex/string/impl#[`Match<'h>`]as_str().()
116 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<i32>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
117 let v_minor = versions
118 .getrust-analyzer cargo regex 1.11.1 regex/string/impl#[`Captures<'h>`]get().(2)
119 .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("unable to get minor version number")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
120 .as_strrust-analyzer cargo regex 1.11.1 regex/string/impl#[`Match<'h>`]as_str().()
121 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<i32>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
122 let v_patch = versions
123 .getrust-analyzer cargo regex 1.11.1 regex/string/impl#[`Captures<'h>`]get().(3)
124 .ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().("unable to get patch version number")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
125 .as_strrust-analyzer cargo regex 1.11.1 regex/string/impl#[`Match<'h>`]as_str().()
126 .parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<i32>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
127
128 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IPTablesrust-analyzer cargo iptables 0.6.0 IPTables# {
129 cmdrust-analyzer cargo iptables 0.6.0 IPTables#cmd.,
130 has_checkrust-analyzer cargo iptables 0.6.0 IPTables#has_check.: (v_major rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().1)
131 || (v_major rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().1 && v_minor rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().4)
132 || (v_major rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().1 && v_minor rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().4 && v_patch rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().10),
133 has_waitrust-analyzer cargo iptables 0.6.0 IPTables#has_wait.: (v_major rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().1)
134 || (v_major rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().1 && v_minor rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().4)
135 || (v_major rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().1 && v_minor rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().4 && v_patch rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().19),
136 is_numericrust-analyzer cargo iptables 0.6.0 IPTables#is_numeric.: false,
137 })
138 }
139
140 impl IPTablesrust-analyzer cargo iptables 0.6.0 IPTables# {
141 /// Get the default policy for a table/chain.
142 pub fn get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().(&self, table: &str, chain: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
143 let builtin_chains = get_builtin_chainsrust-analyzer cargo iptables 0.6.0 get_builtin_chains().(table)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
144 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().builtin_chains.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().as_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`]as_slice().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&chain) {
145 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error_from_strrust-analyzer cargo iptables 0.6.0 error_from_str().(
146 "given chain is not a default chain in the given table, can't get policy",
147 ));
148 }
149
150 let stdout = match self.is_numericrust-analyzer cargo iptables 0.6.0 IPTables#is_numeric. {
151 false => self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&["-t", table, "-L", chain])?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout.,
152 true => self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&["-t", table, "-L", chain, "-n"])?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout.,
153 };
154 let output = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(stdout.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().());
155 for item in output.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('\n') {
156 let fields = item.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(' ').collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str>>();
157 if fields.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1 && fields[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."Chain" && fields[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().chain {
158 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(fields[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().3]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(")", ""));
159 }
160 }
161 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error_from_strrust-analyzer cargo iptables 0.6.0 error_from_str().(
162 "could not find the default policy for table and chain",
163 ))
164 }
165
166 /// Set the default policy for a table/chain.
167 pub fn set_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]set_policy().(&self, table: &str, chain: &str, policy: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
168 let builtin_chains = get_builtin_chainsrust-analyzer cargo iptables 0.6.0 get_builtin_chains().(table)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
169 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().builtin_chains.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().as_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`]as_slice().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&chain) {
170 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error_from_strrust-analyzer cargo iptables 0.6.0 error_from_str().(
171 "given chain is not a default chain in the given table, can't set policy",
172 ));
173 }
174
175 self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&["-t", table, "-P", chain, policy])
176 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(output_to_resultrust-analyzer cargo iptables 0.6.0 output_to_result().)
177 }
178
179 /// Executes a given `command` on the chain.
180 /// Returns the command output if successful.
181 pub fn executerust-analyzer cargo iptables 0.6.0 impl#[IPTables]execute().(&self, table: &str, command: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Outputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
182 self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&[&["-t", table], command.split_quotedrust-analyzer cargo iptables 0.6.0 impl#[str][SplitQuoted]split_quoted().().as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().()].concatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]concat().())
183 }
184
185 /// Checks for the existence of the `rule` in the table/chain.
186 /// Returns true if the rule exists.
187 #[cfg(target_os = "linux")]
188 pub fn existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists().(&self, table: &str, chain: &str, rule: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
189 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.has_checkrust-analyzer cargo iptables 0.6.0 IPTables#has_check. {
190 return self.exists_old_versionrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists_old_version().(table, chain, rule);
191 }
192
193 self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&[&["-t", table, "-C", chain], rule.split_quotedrust-analyzer cargo iptables 0.6.0 impl#[str][SplitQuoted]split_quoted().().as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().()].concatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]concat().())
194 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|output| output.statusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#status..successrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]success().())
195 }
196
197 /// Checks for the existence of the `chain` in the table.
198 /// Returns true if the chain exists.
199 #[cfg(target_os = "linux")]
200 pub fn chain_existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]chain_exists().(&self, table: &str, chain: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
201 match self.is_numericrust-analyzer cargo iptables 0.6.0 IPTables#is_numeric. {
202 false => self
203 .runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&["-t", table, "-L", chain])
204 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|output| output.statusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#status..successrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]success().()),
205 true => self
206 .runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&["-t", table, "-L", chain, "-n"])
207 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|output| output.statusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#status..successrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]success().()),
208 }
209 }
210
211 fn exists_old_versionrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists_old_version().(
212 &self,
213 table: &str,
214 chain: &str,
215 rule: &str,
216 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
217 match self.is_numericrust-analyzer cargo iptables 0.6.0 IPTables#is_numeric. {
218 false => self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&["-t", table, "-S"]).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|output| {
219 Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&output.stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout.).containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("-A {} {}", chain, rule))
220 }),
221 true => self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&["-t", table, "-S", "-n"]).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|output| {
222 Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&output.stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout.).containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("-A {} {}", chain, rule))
223 }),
224 }
225 }
226
227 /// Inserts `rule` in the `position` to the table/chain.
228 pub fn insertrust-analyzer cargo iptables 0.6.0 impl#[IPTables]insert().(
229 &self,
230 table: &str,
231 chain: &str,
232 rule: &str,
233 position: i32,
234 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
235 self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(
236 &[
237 &["-t", table, "-I", chain, &position.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()],
238 rule.split_quotedrust-analyzer cargo iptables 0.6.0 impl#[str][SplitQuoted]split_quoted().().as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().(),
239 ]
240 .concatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]concat().(),
241 )
242 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(output_to_resultrust-analyzer cargo iptables 0.6.0 output_to_result().)
243 }
244
245 /// Inserts `rule` in the `position` to the table/chain if it does not exist.
246 pub fn insert_uniquerust-analyzer cargo iptables 0.6.0 impl#[IPTables]insert_unique().(
247 &self,
248 table: &str,
249 chain: &str,
250 rule: &str,
251 position: i32,
252 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
253 if self.existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists().(table, chain, rule)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
254 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error_from_strrust-analyzer cargo iptables 0.6.0 error_from_str().("the rule exists in the table/chain"));
255 }
256
257 self.insertrust-analyzer cargo iptables 0.6.0 impl#[IPTables]insert().(table, chain, rule, position)
258 }
259
260 /// Replaces `rule` in the `position` to the table/chain.
261 pub fn replacerust-analyzer cargo iptables 0.6.0 impl#[IPTables]replace().(
262 &self,
263 table: &str,
264 chain: &str,
265 rule: &str,
266 position: i32,
267 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
268 self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(
269 &[
270 &["-t", table, "-R", chain, &position.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()],
271 rule.split_quotedrust-analyzer cargo iptables 0.6.0 impl#[str][SplitQuoted]split_quoted().().as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().(),
272 ]
273 .concatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]concat().(),
274 )
275 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(output_to_resultrust-analyzer cargo iptables 0.6.0 output_to_result().)
276 }
277
278 /// Appends `rule` to the table/chain.
279 pub fn appendrust-analyzer cargo iptables 0.6.0 impl#[IPTables]append().(&self, table: &str, chain: &str, rule: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
280 self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&[&["-t", table, "-A", chain], rule.split_quotedrust-analyzer cargo iptables 0.6.0 impl#[str][SplitQuoted]split_quoted().().as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().()].concatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]concat().())
281 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(output_to_resultrust-analyzer cargo iptables 0.6.0 output_to_result().)
282 }
283
284 /// Appends `rule` to the table/chain if it does not exist.
285 pub fn append_uniquerust-analyzer cargo iptables 0.6.0 impl#[IPTables]append_unique().(
286 &self,
287 table: &str,
288 chain: &str,
289 rule: &str,
290 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
291 if self.existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists().(table, chain, rule)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
292 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error_from_strrust-analyzer cargo iptables 0.6.0 error_from_str().("the rule exists in the table/chain"));
293 }
294
295 self.appendrust-analyzer cargo iptables 0.6.0 impl#[IPTables]append().(table, chain, rule)
296 }
297
298 /// Appends or replaces `rule` to the table/chain if it does not exist.
299 pub fn append_replacerust-analyzer cargo iptables 0.6.0 impl#[IPTables]append_replace().(
300 &self,
301 table: &str,
302 chain: &str,
303 rule: &str,
304 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
305 if self.existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists().(table, chain, rule)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
306 self.deleterust-analyzer cargo iptables 0.6.0 impl#[IPTables]delete().(table, chain, rule)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
307 }
308
309 self.appendrust-analyzer cargo iptables 0.6.0 impl#[IPTables]append().(table, chain, rule)
310 }
311
312 /// Deletes `rule` from the table/chain.
313 pub fn deleterust-analyzer cargo iptables 0.6.0 impl#[IPTables]delete().(&self, table: &str, chain: &str, rule: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
314 self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&[&["-t", table, "-D", chain], rule.split_quotedrust-analyzer cargo iptables 0.6.0 impl#[str][SplitQuoted]split_quoted().().as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().()].concatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]concat().())
315 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(output_to_resultrust-analyzer cargo iptables 0.6.0 output_to_result().)
316 }
317
318 /// Deletes all repetition of the `rule` from the table/chain.
319 pub fn delete_allrust-analyzer cargo iptables 0.6.0 impl#[IPTables]delete_all().(&self, table: &str, chain: &str, rule: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
320 while self.existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists().(table, chain, rule)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
321 self.deleterust-analyzer cargo iptables 0.6.0 impl#[IPTables]delete().(table, chain, rule)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
322 }
323
324 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
325 }
326
327 /// Lists rules in the table/chain.
328 pub fn listrust-analyzer cargo iptables 0.6.0 impl#[IPTables]list().(&self, table: &str, chain: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
329 match self.is_numericrust-analyzer cargo iptables 0.6.0 IPTables#is_numeric. {
330 false => self.get_listrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_list().(&["-t", table, "-S", chain]),
331 true => self.get_listrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_list().(&["-t", table, "-S", chain, "-n"]),
332 }
333 }
334
335 /// Lists rules in the table.
336 pub fn list_tablerust-analyzer cargo iptables 0.6.0 impl#[IPTables]list_table().(&self, table: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
337 match self.is_numericrust-analyzer cargo iptables 0.6.0 IPTables#is_numeric. {
338 false => self.get_listrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_list().(&["-t", table, "-S"]),
339 true => self.get_listrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_list().(&["-t", table, "-S", "-n"]),
340 }
341 }
342
343 /// Lists the name of each chain in the table.
344 pub fn list_chainsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]list_chains().(&self, table: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
345 let mut list = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
346 let stdout = self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&["-t", table, "-S"])?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout.;
347 let output = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(stdout.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().());
348 for item in output.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('\n') {
349 let fields = item.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(' ').collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str>>();
350 if fields.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1 && (fields[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."-P" || fields[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."-N") {
351 list.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(fields[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
352 }
353 }
354 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(list)
355 }
356
357 /// Creates a new user-defined chain.
358 pub fn new_chainrust-analyzer cargo iptables 0.6.0 impl#[IPTables]new_chain().(&self, table: &str, chain: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
359 self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&["-t", table, "-N", chain])
360 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(output_to_resultrust-analyzer cargo iptables 0.6.0 output_to_result().)
361 }
362
363 /// Flushes (deletes all rules) a chain.
364 pub fn flush_chainrust-analyzer cargo iptables 0.6.0 impl#[IPTables]flush_chain().(&self, table: &str, chain: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
365 self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&["-t", table, "-F", chain])
366 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(output_to_resultrust-analyzer cargo iptables 0.6.0 output_to_result().)
367 }
368
369 /// Renames a chain in the table.
370 pub fn rename_chainrust-analyzer cargo iptables 0.6.0 impl#[IPTables]rename_chain().(
371 &self,
372 table: &str,
373 old_chain: &str,
374 new_chain: &str,
375 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
376 self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&["-t", table, "-E", old_chain, new_chain])
377 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(output_to_resultrust-analyzer cargo iptables 0.6.0 output_to_result().)
378 }
379
380 /// Deletes a user-defined chain in the table.
381 pub fn delete_chainrust-analyzer cargo iptables 0.6.0 impl#[IPTables]delete_chain().(&self, table: &str, chain: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
382 self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&["-t", table, "-X", chain])
383 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(output_to_resultrust-analyzer cargo iptables 0.6.0 output_to_result().)
384 }
385
386 /// Flushes all chains in a table.
387 pub fn flush_tablerust-analyzer cargo iptables 0.6.0 impl#[IPTables]flush_table().(&self, table: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
388 self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(&["-t", table, "-F"]).and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]and_then().(output_to_resultrust-analyzer cargo iptables 0.6.0 output_to_result().)
389 }
390
391 fn get_listrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_list().<S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#>>(&self, args: &[S]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
392 let stdout = self.runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().(args)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout.;
393 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(stdout.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().())
394 .trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().()
395 .splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('\n')
396 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().)
397 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().())
398 }
399
400 /// Set whether iptables is called with the -n (--numeric) option,
401 /// to avoid host name and port name lookups
402 pub fn set_numericrust-analyzer cargo iptables 0.6.0 impl#[IPTables]set_numeric().(&mut self, numeric: bool) {
403 self.is_numericrust-analyzer cargo iptables 0.6.0 IPTables#is_numeric. = numeric;
404 }
405
406 fn runrust-analyzer cargo iptables 0.6.0 impl#[IPTables]run().<S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#>>(&self, args: &[S]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Outputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#, Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> {
407 let mut output_cmd = Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().(self.cmdrust-analyzer cargo iptables 0.6.0 IPTables#cmd.);
408 let output;
409
410 if self.has_waitrust-analyzer cargo iptables 0.6.0 IPTables#has_wait. {
411 output = output_cmd.argsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]args().(args).argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("--wait").outputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]output().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
412 } else {
413 output = output_cmd.argsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]args().(args).outputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]output().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
414 }
415
416 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(output)
417 }
418 }