[pve-devel] [PATCH ve-rs 2/2] firewall: correctly return errors when parsing icmpv6 types and codes.
Gabriel Goller
g.goller at proxmox.com
Tue Sep 16 11:31:11 CEST 2025
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 at 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
More information about the pve-devel
mailing list