From: Gabriel Goller <g.goller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH ve-rs 2/2] firewall: correctly return errors when parsing icmpv6 types and codes.
Date: Tue, 16 Sep 2025 11:31:11 +0200 [thread overview]
Message-ID: <20250916093116.114942-3-g.goller@proxmox.com> (raw)
In-Reply-To: <20250916093116.114942-1-g.goller@proxmox.com>
Correctly capture and output the error when parsing a icmpv6 type or
code. This makes it easier to debug icmpv6 parsing errors.
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
.../src/firewall/types/rule_match.rs | 56 ++++++++++++-------
1 file changed, 36 insertions(+), 20 deletions(-)
diff --git a/proxmox-ve-config/src/firewall/types/rule_match.rs b/proxmox-ve-config/src/firewall/types/rule_match.rs
index 8202cda57895..28d3e16b27ba 100644
--- a/proxmox-ve-config/src/firewall/types/rule_match.rs
+++ b/proxmox-ve-config/src/firewall/types/rule_match.rs
@@ -493,17 +493,25 @@ impl FromStr for Icmp {
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut this = Self::default();
- if let Ok(ty) = s.parse() {
- this.ty = Some(ty);
- return Ok(this);
- }
-
- if let Ok(code) = s.parse() {
- this.code = Some(code);
- return Ok(this);
+ match s.parse::<IcmpType>() {
+ Ok(ty) => {
+ this.ty = Some(ty);
+ Ok(this)
+ }
+ Err(type_error) => match s.parse::<IcmpCode>() {
+ Ok(code) => {
+ this.code = Some(code);
+ Ok(this)
+ }
+ Err(code_error) => {
+ bail!(
+ "supplied string is neither a valid icmp type nor code: {:?} - {:?}",
+ type_error,
+ code_error,
+ );
+ }
+ },
}
-
- bail!("supplied string is neither a valid icmp type nor code");
}
}
@@ -652,17 +660,25 @@ impl FromStr for Icmpv6 {
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut this = Self::default();
- if let Ok(ty) = s.parse() {
- this.ty = Some(ty);
- return Ok(this);
- }
-
- if let Ok(code) = s.parse() {
- this.code = Some(code);
- return Ok(this);
+ match s.parse::<Icmpv6Type>() {
+ Ok(ty) => {
+ this.ty = Some(ty);
+ Ok(this)
+ }
+ Err(type_error) => match s.parse::<Icmpv6Code>() {
+ Ok(code) => {
+ this.code = Some(code);
+ Ok(this)
+ }
+ Err(code_error) => {
+ bail!(
+ "supplied string is neither a valid icmpv6 type nor code: {:?} - {:?}",
+ type_error,
+ code_error,
+ );
+ }
+ },
}
-
- bail!("supplied string is neither a valid icmpv6 type nor code");
}
}
--
2.47.3
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-09-16 9:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-16 9:31 [pve-devel] [PATCH proxmox-firewall/ve-rs 0/3] Fix ICMPv6 types in nftables Gabriel Goller
2025-09-16 9:31 ` [pve-devel] [PATCH ve-rs 1/2] fix: firewall: introduce iptables to nftables mapping for icmpv6-types Gabriel Goller
2025-09-16 9:31 ` Gabriel Goller [this message]
2025-09-16 9:31 ` [pve-devel] [PATCH proxmox-firewall 1/1] tests: add icmpv6 type mapping test Gabriel Goller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250916093116.114942-3-g.goller@proxmox.com \
--to=g.goller@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.