From d629d57a7e84baf09e0d08cf9e61d3bc62ae4cbf Mon Sep 17 00:00:00 2001 From: ppom Date: Thu, 12 Feb 2026 12:00:00 +0100 Subject: [PATCH] Change ipset version option from 4/6/46 to ipv4/ipv6/ip --- plugins/reaction-plugin-ipset/src/action.rs | 40 ++++++++++----------- plugins/reaction-plugin-ipset/src/tests.rs | 16 +++++---- tests/test-conf/test-ipset.jsonnet | 2 +- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/plugins/reaction-plugin-ipset/src/action.rs b/plugins/reaction-plugin-ipset/src/action.rs index 96fd352..8522717 100644 --- a/plugins/reaction-plugin-ipset/src/action.rs +++ b/plugins/reaction-plugin-ipset/src/action.rs @@ -8,13 +8,13 @@ use crate::ipset::{CreateSet, IpSet, Order, SetChain, Version}; #[derive(Default, Serialize, Deserialize, PartialEq, Eq, Clone, Copy)] pub enum IpVersion { - #[serde(rename = "4")] - V4, - #[serde(rename = "6")] - V6, - #[serde(rename = "46")] #[default] - V46, + #[serde(rename = "ip")] + Ip, + #[serde(rename = "ipv4")] + Ipv4, + #[serde(rename = "ipv6")] + Ipv6, } impl Debug for IpVersion { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -22,9 +22,9 @@ impl Debug for IpVersion { f, "{}", match self { - IpVersion::V4 => "4", - IpVersion::V6 => "6", - IpVersion::V46 => "46", + IpVersion::Ipv4 => "ipv4", + IpVersion::Ipv6 => "ipv6", + IpVersion::Ip => "ip", } ) } @@ -84,9 +84,9 @@ impl ActionOptions { pub struct SetOptions { /// The IP type. /// Defaults to `46`. - /// If `4`: creates an IPv4 set with this name - /// If `6`: creates an IPv6 set with this name - /// If `46`: creates an IPv4 set with its name suffixed by 'v4' AND an IPv6 set with its name suffixed by 'v6' + /// If `ipv4`: creates an IPv4 set with this name + /// If `ipv6`: creates an IPv6 set with this name + /// If `ip`: creates an IPv4 set with its name suffixed by 'v4' AND an IPv6 set with its name suffixed by 'v6' /// *Merged set-wise*. #[serde(default)] version: Option, @@ -242,14 +242,14 @@ impl SetNames { pub fn new(name: String, version: Option) -> Self { Self { ipv4: match version { - Some(IpVersion::V4) => Some(name.clone()), - Some(IpVersion::V6) => None, - None | Some(IpVersion::V46) => Some(format!("{}v4", name)), + Some(IpVersion::Ipv4) => Some(name.clone()), + Some(IpVersion::Ipv6) => None, + None | Some(IpVersion::Ip) => Some(format!("{}v4", name)), }, ipv6: match version { - Some(IpVersion::V4) => None, - Some(IpVersion::V6) => Some(name), - None | Some(IpVersion::V46) => Some(format!("{}v6", name)), + Some(IpVersion::Ipv4) => None, + Some(IpVersion::Ipv6) => Some(name), + None | Some(IpVersion::Ip) => Some(format!("{}v6", name)), }, } } @@ -359,7 +359,7 @@ mod tests { target: None, }; let s2 = SetOptions { - version: Some(IpVersion::V4), + version: Some(IpVersion::Ipv4), chains: Some(vec!["INPUT".into()]), timeout: Some("3h".into()), timeout_u32: Some(3 * 3600), @@ -397,7 +397,7 @@ mod tests { for s3 in [ SetOptions { - version: Some(IpVersion::V6), + version: Some(IpVersion::Ipv6), ..Default::default() }, SetOptions { diff --git a/plugins/reaction-plugin-ipset/src/tests.rs b/plugins/reaction-plugin-ipset/src/tests.rs index f1cef9e..09ce6cf 100644 --- a/plugins/reaction-plugin-ipset/src/tests.rs +++ b/plugins/reaction-plugin-ipset/src/tests.rs @@ -34,7 +34,7 @@ async fn conf_action_standalone() { (true, json!({ "set": "test" }), &p), // missing set key (false, json!({}), &p), - (false, json!({ "version": 4 }), &p), + (false, json!({ "version": "ipv4" }), &p), // unknown key (false, json!({ "set": "test", "unknown": "yes" }), &p), (false, json!({ "set": "test", "ip_index": 1 }), &p), @@ -66,14 +66,18 @@ async fn conf_action_standalone() { (false, json!({ "set": "test", "action": 1 }), &p), // ip version // // ok - (true, json!({ "set": "test", "version": "4" }), &p), - (true, json!({ "set": "test", "version": "6" }), &p), - (true, json!({ "set": "test", "version": "46" }), &p), + (true, json!({ "set": "test", "version": "ipv4" }), &p), + (true, json!({ "set": "test", "version": "ipv6" }), &p), + (true, json!({ "set": "test", "version": "ip" }), &p), // unknown version (false, json!({ "set": "test", "version": 4 }), &p), (false, json!({ "set": "test", "version": 6 }), &p), (false, json!({ "set": "test", "version": 46 }), &p), (false, json!({ "set": "test", "version": "5" }), &p), + (false, json!({ "set": "test", "version": "ipv5" }), &p), + (false, json!({ "set": "test", "version": "4" }), &p), + (false, json!({ "set": "test", "version": "6" }), &p), + (false, json!({ "set": "test", "version": "46" }), &p), // bad type (false, json!({ "set": "test", "version": true }), &p), // chains // @@ -167,7 +171,7 @@ async fn conf_action_merge() { config: json!({ "set": "test", "target": "DROP", - "version": "46", + "version": "ip", "action": "add", }) .into(), @@ -206,7 +210,7 @@ async fn conf_action_merge() { config: json!({ "set": "test2", "target": "target1", - "version": "6", + "version": "ipv6", }) .into(), patterns: vec!["ip".into()], diff --git a/tests/test-conf/test-ipset.jsonnet b/tests/test-conf/test-ipset.jsonnet index 12ce0c8..7232547 100644 --- a/tests/test-conf/test-ipset.jsonnet +++ b/tests/test-conf/test-ipset.jsonnet @@ -30,7 +30,7 @@ options: { set: 'reactiontest', // pattern: 'ip', - // version: 46, + // version: 'ip', // chains: ['INPUT', 'FORWARD'], // target: 'DROP', // action: 'add',