vmm: allow net devices without ip and mask

This change enables easier integration with third-party
tools by removing the requirement for a dummy IP address
when configuring tap devices. The modification applies to
both CLI and API interactions.

Previously, cloud-hypervisor would automatically set a
default static IP address (192.168.249.1) if none was provided.

This could lead to:

* multiple devices without explicit IP configurations
  would end up with the same default IP
* unnecessary inclusion of this IP in firewall rules
* the IP address could clash with host networking and
  routing

This introduces a new constraint:
When providing an IP, the mask must also be provided.

Removes warnings introduced in #7179.
Closes issue #7083.

Signed-off-by: Maximilian Güntner <code@mguentner.de>
This commit is contained in:
Maximilian Güntner
2025-09-22 10:43:03 +02:00
committed by Rob Bradford
parent d28d9eb34e
commit 66aa0743f0
5 changed files with 58 additions and 51 deletions
+3 -19
View File
@@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: Apache-2.0
//
use std::net::{IpAddr, Ipv4Addr};
use std::net::IpAddr;
use std::path::{Path, PathBuf};
#[cfg(feature = "fw_cfg")]
use std::str::FromStr;
@@ -303,10 +303,8 @@ pub fn default_diskconfig_queue_size() -> u16 {
pub struct NetConfig {
#[serde(default = "default_netconfig_tap")]
pub tap: Option<String>,
#[serde(default = "default_netconfig_ip")]
pub ip: IpAddr,
#[serde(default = "default_netconfig_mask")]
pub mask: IpAddr,
pub ip: Option<IpAddr>,
pub mask: Option<IpAddr>,
#[serde(default = "default_netconfig_mac")]
pub mac: MacAddr,
#[serde(default)]
@@ -352,20 +350,6 @@ pub fn default_netconfig_tap() -> Option<String> {
None
}
pub fn default_netconfig_ip() -> IpAddr {
warn!(
"Deprecation warning: No IP address provided. A default IP address is assigned. This behavior will be deprecated soon."
);
IpAddr::V4(Ipv4Addr::new(192, 168, 249, 1))
}
pub fn default_netconfig_mask() -> IpAddr {
warn!(
"Deprecation warning: No network mask provided. A default network mask is assigned. This behavior will be deprecated soon."
);
IpAddr::V4(Ipv4Addr::new(255, 255, 255, 0))
}
pub fn default_netconfig_mac() -> MacAddr {
MacAddr::local_random()
}