pub struct NetConfig {
pub mac: [u8; 6],
pub queue_pairs: u16,
}Expand description
Configuration for the virtio-net device attached to the VM.
Default::default() produces a working device with a deterministic
locally-administered MAC. Override the MAC with Self::mac to
pin a value across runs (useful for log correlation against
AF_PACKET captures).
Fields§
§mac: [u8; 6]MAC address advertised to the guest via VIRTIO_NET_F_MAC.
The locally-administered bit (0x02) is set in the default to
avoid collisions with real-hardware OUIs; operators that
override the MAC are responsible for the bit themselves.
queue_pairs: u16Number of virtio-net queue-pairs (one RX + one TX virtqueue per
pair) the device offers. Default 1 — a single queue-pair,
byte-identical to a device with no multiqueue support (no
VIRTIO_NET_F_MQ, no control virtqueue).
Multiqueue is offered only when queue_pairs > 1 AND the transport
carries MSI-X (the x86_64 PCI NIC). On a non-MSI-X transport — the
aarch64 MMIO NIC, or PCI without MSI-X — the device stays single-pair
regardless of this value (no VIRTIO_NET_F_MQ, no control vq,
max_virtqueue_pairs = 0): per-queue IRQ steering, the point of
multiqueue, needs the distinct MSI-X vectors that transport lacks.
When multiqueue IS offered, the device advertises VIRTIO_NET_F_MQ +
the control virtqueue (VIRTIO_NET_F_CTRL_VQ) and reports
max_virtqueue_pairs in config space; the guest brings up
min(num_online_cpus, queue_pairs) pairs and spreads its RX/TX across
them.
Clamped to [1, 256] at construction: 0 becomes 1 (the spec
minimum, VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN) and values above 256
(MAX_QUEUE_PAIRS) are clamped down.
Implementations§
Source§impl NetConfig
impl NetConfig
Sourcepub const DEFAULT: NetConfig
pub const DEFAULT: NetConfig
Const default — MAC 02:00:00:00:00:01. The leading 0x02 sets
the locally-administered bit per IEEE 802 (bit 1 of the first
octet), keeping the address out of the IEEE OUI namespace; the
trailing 0x01 is the conventional first-NIC suffix — multi-NIC
tests give each element a distinct MAC via Self::mac. const
so it can seed a const NetConfig for the
#[ktstr_test(networks = [...])] attribute, matching
super::disk_config::DiskConfig’s DEFAULT.
Sourcepub const fn mac(self, mac: [u8; 6]) -> Self
pub const fn mac(self, mac: [u8; 6]) -> Self
Override the advertised MAC. Returns self for chained
configuration. const fn so a const NetConfig can be built via
NetConfig::DEFAULT.mac(...), matching DiskConfig’s const-fn
builder style.
Sourcepub const fn queue_pairs(self, pairs: u16) -> Self
pub const fn queue_pairs(self, pairs: u16) -> Self
Set the number of queue-pairs the device offers (see
Self::queue_pairs). Returns self for chained configuration.
const fn so a const NetConfig can be built via
NetConfig::DEFAULT.queue_pairs(...), matching Self::mac.
Trait Implementations§
Source§impl Default for NetConfig
impl Default for NetConfig
Source§fn default() -> Self
fn default() -> Self
Delegates to Self::DEFAULT (MAC 02:00:00:00:00:01).
Source§impl<'de> Deserialize<'de> for NetConfig
impl<'de> Deserialize<'de> for NetConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Copy for NetConfig
impl Eq for NetConfig
impl StructuralPartialEq for NetConfig
Auto Trait Implementations§
impl Freeze for NetConfig
impl RefUnwindSafe for NetConfig
impl Send for NetConfig
impl Sync for NetConfig
impl Unpin for NetConfig
impl UnwindSafe for NetConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more