Skip to content

Commit db9e5c0

Browse files
vsilentCopilot
andcommitted
fix: resolve clippy errors in Linux-only firewall modules
- Remove unused imports in nftables.rs, quarantine.rs - Replace inherent to_string() with Display trait for NfTable - Remove needless borrows in .args() calls (iptables.rs, nftables.rs) - Prefix unused variables with underscore (response.rs) - Add error() getter to ResponseLog Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent cc4a9b2 commit db9e5c0

4 files changed

Lines changed: 25 additions & 19 deletions

File tree

src/firewall/iptables.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl IptablesBackend {
7272
/// Create a chain
7373
pub fn create_chain(&self, chain: &IptChain) -> Result<()> {
7474
let output = Command::new("iptables")
75-
.args(&["-t", &chain.table, "-N", &chain.name])
75+
.args(["-t", &chain.table, "-N", &chain.name])
7676
.output()
7777
.context("Failed to create iptables chain")?;
7878

@@ -89,7 +89,7 @@ impl IptablesBackend {
8989
/// Delete a chain
9090
pub fn delete_chain(&self, chain: &IptChain) -> Result<()> {
9191
let output = Command::new("iptables")
92-
.args(&["-t", &chain.table, "-X", &chain.name])
92+
.args(["-t", &chain.table, "-X", &chain.name])
9393
.output()
9494
.context("Failed to delete iptables chain")?;
9595

@@ -148,7 +148,7 @@ impl IptablesBackend {
148148
/// Flush a chain
149149
pub fn flush_chain(&self, chain: &IptChain) -> Result<()> {
150150
let output = Command::new("iptables")
151-
.args(&["-t", &chain.table, "-F", &chain.name])
151+
.args(["-t", &chain.table, "-F", &chain.name])
152152
.output()
153153
.context("Failed to flush iptables chain")?;
154154

@@ -165,7 +165,7 @@ impl IptablesBackend {
165165
/// List rules in a chain
166166
pub fn list_rules(&self, chain: &IptChain) -> Result<Vec<String>> {
167167
let output = Command::new("iptables")
168-
.args(&["-t", &chain.table, "-L", &chain.name, "-n"])
168+
.args(["-t", &chain.table, "-L", &chain.name, "-n"])
169169
.output()
170170
.context("Failed to list iptables rules")?;
171171

src/firewall/nftables.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use anyhow::{Context, Result};
66
use std::process::Command;
77

8-
use crate::firewall::backend::{FirewallBackend, FirewallChain, FirewallRule, FirewallTable};
8+
use crate::firewall::backend::FirewallBackend;
99

1010
/// nftables table
1111
#[derive(Debug, Clone)]
@@ -21,9 +21,11 @@ impl NfTable {
2121
name: name.into(),
2222
}
2323
}
24+
}
2425

25-
fn to_string(&self) -> String {
26-
format!("{} {}", self.family, self.name)
26+
impl std::fmt::Display for NfTable {
27+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28+
write!(f, "{} {}", self.family, self.name)
2729
}
2830
}
2931

@@ -94,7 +96,7 @@ impl NfTablesBackend {
9496
/// Create a table
9597
pub fn create_table(&self, table: &NfTable) -> Result<()> {
9698
let output = Command::new("nft")
97-
.args(&["add", "table", &table.to_string()])
99+
.args(["add", "table", &table.to_string()])
98100
.output()
99101
.context("Failed to create nftables table")?;
100102

@@ -111,7 +113,7 @@ impl NfTablesBackend {
111113
/// Delete a table
112114
pub fn delete_table(&self, table: &NfTable) -> Result<()> {
113115
let output = Command::new("nft")
114-
.args(&["delete", "table", &table.to_string()])
116+
.args(["delete", "table", &table.to_string()])
115117
.output()
116118
.context("Failed to delete nftables table")?;
117119

@@ -135,7 +137,7 @@ impl NfTablesBackend {
135137
);
136138

137139
let output = Command::new("nft")
138-
.args(&["-c", &cmd])
140+
.args(["-c", &cmd])
139141
.output()
140142
.context("Failed to create nftables chain")?;
141143

@@ -154,7 +156,7 @@ impl NfTablesBackend {
154156
let cmd = format!("delete chain {} {}", chain.table.to_string(), chain.name);
155157

156158
let output = Command::new("nft")
157-
.args(&["-c", &cmd])
159+
.args(["-c", &cmd])
158160
.output()
159161
.context("Failed to delete nftables chain")?;
160162

@@ -178,7 +180,7 @@ impl NfTablesBackend {
178180
);
179181

180182
let output = Command::new("nft")
181-
.args(&["-c", &cmd])
183+
.args(["-c", &cmd])
182184
.output()
183185
.context("Failed to add nftables rule")?;
184186

@@ -202,7 +204,7 @@ impl NfTablesBackend {
202204
);
203205

204206
let output = Command::new("nft")
205-
.args(&["-c", &cmd])
207+
.args(["-c", &cmd])
206208
.output()
207209
.context("Failed to delete nftables rule")?;
208210

@@ -229,7 +231,7 @@ impl NfTablesBackend {
229231
let cmd = format!("flush chain {} {}", chain.table.to_string(), chain.name);
230232

231233
let output = Command::new("nft")
232-
.args(&["-c", &cmd])
234+
.args(["-c", &cmd])
233235
.output()
234236
.context("Failed to flush nftables chain")?;
235237

@@ -248,7 +250,7 @@ impl NfTablesBackend {
248250
let cmd = format!("list chain {} {}", chain.table.to_string(), chain.name);
249251

250252
let output = Command::new("nft")
251-
.args(&["-c", &cmd])
253+
.args(["-c", &cmd])
252254
.output()
253255
.context("Failed to list nftables rules")?;
254256

src/firewall/quarantine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
//!
33
//! Isolates compromised containers
44
5-
use anyhow::{Context, Result};
5+
use anyhow::Result;
66
use chrono::{DateTime, Utc};
77
use std::collections::HashMap;
88
use std::sync::{Arc, RwLock};
99

10-
use crate::firewall::nftables::{NfChain, NfRule, NfTable, NfTablesBackend};
10+
use crate::firewall::nftables::{NfChain, NfTable, NfTablesBackend};
1111

1212
/// Quarantine state
1313
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

src/firewall/response.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ impl ResponseExecutor {
215215

216216
/// Execute a response action
217217
pub fn execute(&mut self, action: &ResponseAction) -> Result<()> {
218-
let start = Utc::now();
218+
let _start = Utc::now();
219219
let result = action.execute();
220-
let end = Utc::now();
220+
let _end = Utc::now();
221221

222222
// Log the execution
223223
let log_entry = ResponseLog::new(
@@ -286,6 +286,10 @@ impl ResponseLog {
286286
self.success
287287
}
288288

289+
pub fn error(&self) -> Option<&str> {
290+
self.error.as_deref()
291+
}
292+
289293
pub fn timestamp(&self) -> DateTime<Utc> {
290294
self.timestamp
291295
}

0 commit comments

Comments
 (0)