rust-iptables icon indicating copy to clipboard operation
rust-iptables copied to clipboard

Add `flush_tables`

Open Sable-20 opened this issue 10 months ago • 0 comments

Flush tables via iptables -F command without requiring specific tables.

A more drastic measure that can be taken instead of adding a function can be used:

pub fn flush_table(&self, table: Option<&str>) -> Result<(), Box<dyn Error>> {
    if table.is_none() {
        return self.run(&["-F"]).and_then(output_to_result);
    }
    self.run(&["-t", table, "-F"]).and_then(output_to_result)
}

While a breaking change this would require people to memorize one less function, this would also be a fairly trivial fix for people to wrap table in their calls to flush_table with Some().

// new call
ipt.flush_table(Some("table"));

Sable-20 avatar Apr 04 '24 11:04 Sable-20