From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer v3 05/15] common: setup: simplify network address list serialization
Date: Tue, 11 Nov 2025 14:59:55 +0100 [thread overview]
Message-ID: <20251111140014.1443471-6-c.heiss@proxmox.com> (raw)
In-Reply-To: <20251111140014.1443471-1-c.heiss@proxmox.com>
Option<Vec<..>> is redundant in combination with #[serde(default)],
as the latter already defaults to an empty Vec<..> if the key does not
exist.
No functional changes.
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
Changes v2 -> v3:
* rebased
Changes v1 -> v2:
* no changes
proxmox-installer-common/src/options.rs | 47 ++++++++++++-------------
proxmox-installer-common/src/setup.rs | 6 ++--
2 files changed, 25 insertions(+), 28 deletions(-)
diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs
index 263bcfb..fa91060 100644
--- a/proxmox-installer-common/src/options.rs
+++ b/proxmox-installer-common/src/options.rs
@@ -514,26 +514,24 @@ impl NetworkOptions {
}
if let Some(routes) = &network.routes {
- let mut filled = false;
if let Some(gw) = &routes.gateway4
- && let Some(iface) = network.interfaces.get(&gw.dev) {
- this.ifname.clone_from(&iface.name);
- if let Some(addresses) = &iface.addresses
- && let Some(addr) = addresses.iter().find(|addr| addr.is_ipv4()) {
- this.gateway = gw.gateway;
- this.address = addr.clone();
- filled = true;
- }
+ && let Some(iface) = network.interfaces.get(&gw.dev)
+ {
+ // we got some ipv4 connectivity, so use that
+ this.ifname.clone_from(&iface.name);
+ if let Some(addr) = iface.addresses.iter().find(|addr| addr.is_ipv4()) {
+ this.gateway = gw.gateway;
+ this.address = addr.clone();
}
- if !filled
- && let Some(gw) = &routes.gateway6
- && let Some(iface) = network.interfaces.get(&gw.dev)
- && let Some(addresses) = &iface.addresses
- && let Some(addr) = addresses.iter().find(|addr| addr.is_ipv6()) {
- this.ifname.clone_from(&iface.name);
- this.gateway = gw.gateway;
- this.address = addr.clone();
- }
+ } else if let Some(gw) = &routes.gateway6
+ && let Some(iface) = network.interfaces.get(&gw.dev)
+ && let Some(addr) = iface.addresses.iter().find(|addr| addr.is_ipv6())
+ {
+ // no ipv4, but ipv6 connectivity
+ this.ifname.clone_from(&iface.name);
+ this.gateway = gw.gateway;
+ this.address = addr.clone();
+ }
}
// In case no there are no routes defined at all (e.g. no DHCP lease),
@@ -541,9 +539,10 @@ impl NetworkOptions {
// NIC should always be present here, as the installation will abort
// earlier in that case, so use the first one enumerated.
if this.ifname.is_empty()
- && let Some(iface) = network.interfaces.values().min_by_key(|v| v.index) {
- this.ifname.clone_from(&iface.name);
- }
+ && let Some(iface) = network.interfaces.values().min_by_key(|v| v.index)
+ {
+ this.ifname.clone_from(&iface.name);
+ }
this
}
@@ -672,9 +671,7 @@ mod tests {
state: InterfaceState::Up,
driver: "dummy".to_owned(),
mac: "01:23:45:67:89:ab".to_owned(),
- addresses: Some(vec![
- CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
- ]),
+ addresses: vec![CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap()],
},
);
@@ -800,7 +797,7 @@ mod tests {
state: InterfaceState::Up,
driver: "dummy".to_owned(),
mac: "01:23:45:67:89:ab".to_owned(),
- addresses: None,
+ addresses: vec![],
},
);
diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs
index 4fda39d..4873fff 100644
--- a/proxmox-installer-common/src/setup.rs
+++ b/proxmox-installer-common/src/setup.rs
@@ -321,7 +321,7 @@ where
.collect())
}
-fn deserialize_cidr_list<'de, D>(deserializer: D) -> Result<Option<Vec<CidrAddress>>, D::Error>
+fn deserialize_cidr_list<'de, D>(deserializer: D) -> Result<Vec<CidrAddress>, D::Error>
where
D: Deserializer<'de>,
{
@@ -347,7 +347,7 @@ where
);
}
- Ok(Some(result))
+ Ok(result)
}
fn serialize_as_display<S, T>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
@@ -478,7 +478,7 @@ pub struct Interface {
#[serde(default)]
#[serde(deserialize_with = "deserialize_cidr_list")]
- pub addresses: Option<Vec<CidrAddress>>,
+ pub addresses: Vec<CidrAddress>,
}
impl Interface {
--
2.51.0
_______________________________________________
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-11-11 13:59 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-11 13:59 [pve-devel] [PATCH installer v3 00/15] support network interface name pinning Christoph Heiss
2025-11-11 13:59 ` [pve-devel] [PATCH installer v3 01/15] test: parse-kernel-cmdline: fix module import statement Christoph Heiss
2025-11-11 13:59 ` [pve-devel] [PATCH installer v3 02/15] install: add support for network interface name pinning Christoph Heiss
2025-11-11 13:59 ` [pve-devel] [PATCH installer v3 03/15] run env: network: add kernel driver name to network interface info Christoph Heiss
2025-11-11 13:59 ` [pve-devel] [PATCH installer v3 04/15] common: utils: fix clippy warnings Christoph Heiss
2025-11-11 13:59 ` Christoph Heiss [this message]
2025-11-11 13:59 ` [pve-devel] [PATCH installer v3 06/15] common: implement support for `network_interface_pin_map` config Christoph Heiss
2025-11-11 13:59 ` [pve-devel] [PATCH installer v3 07/15] auto: add support for pinning network interface names Christoph Heiss
2025-11-11 13:59 ` [pve-devel] [PATCH installer v3 08/15] assistant: verify network settings in `validate-answer` subcommand Christoph Heiss
2025-11-11 13:59 ` [pve-devel] [PATCH installer v3 09/15] post-hook: avoid redundant Option<bool> for (de-)serialization Christoph Heiss
2025-11-11 14:00 ` [pve-devel] [PATCH installer v3 10/15] post-hook: add network interface name and pinning status Christoph Heiss
2025-11-11 14:00 ` [pve-devel] [PATCH installer v3 11/15] tui: views: move network options view to own module Christoph Heiss
2025-11-11 14:00 ` [pve-devel] [PATCH installer v3 12/15] tui: views: form: allow attaching user-defined data to children Christoph Heiss
2025-11-11 14:00 ` [pve-devel] [PATCH installer v3 13/15] tui: add support for pinning network interface names Christoph Heiss
2025-11-11 14:00 ` [pve-devel] [PATCH installer v3 14/15] ui: gtk3: allow passing of dialog parent window Christoph Heiss
2025-11-11 14:00 ` [pve-devel] [PATCH installer v3 15/15] gui: add support for pinning network interface names Christoph Heiss
2025-11-11 16:49 ` Stoiko Ivanov
2025-11-11 15:04 ` [pve-devel] [PATCH installer v3 00/15] support network interface name pinning Thomas Lamprecht
2025-11-12 12:00 ` Christoph Heiss
2025-11-11 17:12 ` Stoiko Ivanov
2025-11-12 7:13 ` [pve-devel] applied: " Thomas Lamprecht
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=20251111140014.1443471-6-c.heiss@proxmox.com \
--to=c.heiss@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox