mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
net_util: add support for IPv6 addresses on tap interfaces
Allow tap interfaces to be configured with an IPv6 address. The change is fairly straightforward: we need to update the API types and CLI parsing to accept either an IPv6 or IPv4 and then match on the IP address type when the tap device is configured. For IPv6 addresses, the netmask (prefix) must be provided at the same time as the address itself (in the SIOCSIFADDR ioctl). They cannot be configured separately. So we remove the separate "set_netmask" function and convert "set_ip_addr" to also accept a netmask. For IPv4 addresses, the IP address and netmask were already always set together, so this should have no functional impact for users of IPv4 addresses. Signed-off-by: Gregory Anders <ganders@cloudflare.com>
This commit is contained in:
committed by
Rob Bradford
parent
1454d39b28
commit
dce82a34d0
@@ -6,7 +6,7 @@
|
||||
//
|
||||
// SPDX-License-Identifier: (Apache-2.0 AND BSD-3-Clause)
|
||||
|
||||
use std::net::Ipv4Addr;
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
use std::ops::Deref;
|
||||
use std::os::unix::io::{AsRawFd, RawFd};
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
@@ -118,9 +118,9 @@ pub struct VhostUserNetBackend {
|
||||
impl VhostUserNetBackend {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn new(
|
||||
ip_addr: Ipv4Addr,
|
||||
ip_addr: IpAddr,
|
||||
host_mac: MacAddr,
|
||||
netmask: Ipv4Addr,
|
||||
netmask: IpAddr,
|
||||
mtu: Option<u16>,
|
||||
num_queues: usize,
|
||||
queue_size: u16,
|
||||
@@ -271,9 +271,9 @@ impl VhostUserBackendMut for VhostUserNetBackend {
|
||||
}
|
||||
|
||||
pub struct VhostUserNetBackendConfig {
|
||||
pub ip: Ipv4Addr,
|
||||
pub ip: IpAddr,
|
||||
pub host_mac: MacAddr,
|
||||
pub mask: Ipv4Addr,
|
||||
pub mask: IpAddr,
|
||||
pub mtu: Option<u16>,
|
||||
pub socket: String,
|
||||
pub num_queues: usize,
|
||||
@@ -303,7 +303,7 @@ impl VhostUserNetBackendConfig {
|
||||
let ip = parser
|
||||
.convert("ip")
|
||||
.map_err(Error::FailedConfigParse)?
|
||||
.unwrap_or_else(|| Ipv4Addr::new(192, 168, 100, 1));
|
||||
.unwrap_or_else(|| IpAddr::V4(Ipv4Addr::new(192, 168, 100, 1)));
|
||||
let host_mac = parser
|
||||
.convert("host_mac")
|
||||
.map_err(Error::FailedConfigParse)?
|
||||
@@ -311,7 +311,7 @@ impl VhostUserNetBackendConfig {
|
||||
let mask = parser
|
||||
.convert("mask")
|
||||
.map_err(Error::FailedConfigParse)?
|
||||
.unwrap_or_else(|| Ipv4Addr::new(255, 255, 255, 0));
|
||||
.unwrap_or_else(|| IpAddr::V4(Ipv4Addr::new(255, 255, 255, 0)));
|
||||
let mtu = parser.convert("mtu").map_err(Error::FailedConfigParse)?;
|
||||
let queue_size = parser
|
||||
.convert("queue_size")
|
||||
|
||||
Reference in New Issue
Block a user