Skip to content

Commit 3d0799f

Browse files
author
Russell Bryant
committed
fix(cni): satisfy Rust 1.95 clippy lints in the CNI plugin
The toolchain bump on main surfaced four lints in the chained CNI plugin: a needless borrow of an already-borrowed nft path, a collapsible nested if in verify_rules, a bare OPENSHELL_OUTPUT in a doc comment, and an unnecessary Result wrap on cleanup_rules. The cleanup_rules Result is kept and explicitly allowed so the signature stays symmetric with its non-Linux twin, which already carries the same allow. Signed-off-by: Russell Bryant <rbryant@rbryant-thinkpadt14sgen2i.rmtussc.csb>
1 parent b9a43fa commit 3d0799f

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

  • crates/openshell-cni/src

‎crates/openshell-cni/src/lib.rs‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ fn install_nft_rules(netns: &Path, proxy_uid: u32, nft: &str) -> Result<()> {
11511151
let body = generate_sidecar_bypass_ruleset(proxy_uid, Some("openshell:cni-sidecar:"));
11521152
let ruleset =
11531153
format!("table inet {OPENSHELL_TABLE} {{}}\ndelete table inet {OPENSHELL_TABLE}\n{body}");
1154-
run_nft_ruleset_in_netns(netns, &nft, &ruleset)
1154+
run_nft_ruleset_in_netns(netns, nft, &ruleset)
11551155
}
11561156

11571157
/// Read-only check that the bypass-prevention rules are present AND structurally
@@ -1162,12 +1162,11 @@ fn install_nft_rules(netns: &Path, proxy_uid: u32, nft: &str) -> Result<()> {
11621162
/// and TCP/UDP rejection on both address families.
11631163
#[cfg(target_os = "linux")]
11641164
fn verify_rules(netns: &Path, proxy_uid: u32) -> Result<()> {
1165-
if let Some(nft) = find_nft() {
1166-
if let Ok(dump) =
1165+
if let Some(nft) = find_nft()
1166+
&& let Ok(dump) =
11671167
run_command_capture_in_netns(netns, &nft, &["list", "table", "inet", OPENSHELL_TABLE])
1168-
{
1169-
return verify_nft_ruleset(&dump, proxy_uid);
1170-
}
1168+
{
1169+
return verify_nft_ruleset(&dump, proxy_uid);
11711170
}
11721171
if let Some(iptables) = find_iptables() {
11731172
return verify_iptables_rules(netns, &iptables, proxy_uid);
@@ -1219,7 +1218,7 @@ fn verify_iptables_rules(netns: &Path, backend: &IptablesBackend, proxy_uid: u32
12191218
Ok(())
12201219
}
12211220

1222-
/// Confirms the OUTPUT chain jumps to OPENSHELL_OUTPUT and that chain contains the
1221+
/// Confirms the OUTPUT chain jumps to `OPENSHELL_OUTPUT` and that chain contains the
12231222
/// proxy-UID exemption plus TCP and UDP rejection, for one iptables family.
12241223
#[cfg(target_os = "linux")]
12251224
fn verify_iptables_family(
@@ -1336,7 +1335,11 @@ pub fn netns_probe_ipv6() -> Result<()> {
13361335
}
13371336
}
13381337

1338+
// Best-effort teardown: both backends swallow their own failures because CNI DEL
1339+
// must stay idempotent. The Result is kept so the signature matches the non-Linux
1340+
// twin and DEL can grow fallible cleanup later.
13391341
#[cfg(target_os = "linux")]
1342+
#[allow(clippy::unnecessary_wraps)]
13401343
fn cleanup_rules(netns: &Path) -> Result<()> {
13411344
if let Some(nft) = find_nft() {
13421345
let _ = cleanup_nft_rules(netns, &nft);

0 commit comments

Comments
 (0)