From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id B2F1120EC88 for ; Thu, 25 Apr 2024 19:16:34 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CF5371FA85; Thu, 25 Apr 2024 19:16:41 +0200 (CEST) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Date: Thu, 25 Apr 2024 19:16:08 +0200 Message-Id: <20240425171608.638909-1-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.269 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Subject: [pve-devel] [PATCH proxmox-firewall] config: nftables: add support for icmp-type any X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" We support any as wildcard for matching all icmp types. Implement parsing logic for parsing the any value and support converting the any value into an nftables expression. Signed-off-by: Stefan Hanreich --- proxmox-nftables/src/expression.rs | 2 ++ proxmox-ve-config/src/firewall/types/rule_match.rs | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/proxmox-nftables/src/expression.rs b/proxmox-nftables/src/expression.rs index 20559e8..18b92d4 100644 --- a/proxmox-nftables/src/expression.rs +++ b/proxmox-nftables/src/expression.rs @@ -185,6 +185,7 @@ impl From<&IcmpType> for Expression { match value { IcmpType::Numeric(id) => Expression::from(*id), IcmpType::Named(name) => Expression::from(*name), + IcmpType::Any => Expression::Range(Box::new((u8::MIN.into(), u8::MAX.into()))), } } } @@ -205,6 +206,7 @@ impl From<&Icmpv6Type> for Expression { match value { Icmpv6Type::Numeric(id) => Expression::from(*id), Icmpv6Type::Named(name) => Expression::from(*name), + Icmpv6Type::Any => Expression::Range(Box::new((u8::MIN.into(), u8::MAX.into()))), } } } diff --git a/proxmox-ve-config/src/firewall/types/rule_match.rs b/proxmox-ve-config/src/firewall/types/rule_match.rs index 948b426..94d8624 100644 --- a/proxmox-ve-config/src/firewall/types/rule_match.rs +++ b/proxmox-ve-config/src/firewall/types/rule_match.rs @@ -511,6 +511,7 @@ impl FromStr for Icmp { pub enum IcmpType { Numeric(u8), Named(&'static str), + Any, } #[sortable] @@ -536,6 +537,10 @@ impl std::str::FromStr for IcmpType { type Err = Error; fn from_str(s: &str) -> Result { + if s.eq_ignore_ascii_case("any") { + return Ok(Self::Any); + } + if let Ok(ty) = s.trim().parse::() { return Ok(Self::Numeric(ty)); } @@ -553,6 +558,7 @@ impl fmt::Display for IcmpType { match self { IcmpType::Numeric(ty) => write!(f, "{ty}"), IcmpType::Named(ty) => write!(f, "{ty}"), + IcmpType::Any => write!(f, "any"), } } } @@ -664,6 +670,7 @@ impl FromStr for Icmpv6 { pub enum Icmpv6Type { Numeric(u8), Named(&'static str), + Any, } #[sortable] @@ -693,6 +700,10 @@ impl std::str::FromStr for Icmpv6Type { type Err = Error; fn from_str(s: &str) -> Result { + if s.eq_ignore_ascii_case("any") { + return Ok(Self::Any); + } + if let Ok(ty) = s.trim().parse::() { return Ok(Self::Numeric(ty)); } @@ -710,6 +721,7 @@ impl fmt::Display for Icmpv6Type { match self { Icmpv6Type::Numeric(ty) => write!(f, "{ty}"), Icmpv6Type::Named(ty) => write!(f, "{ty}"), + Icmpv6Type::Any => write!(f, "any"), } } } -- 2.39.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel