mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-22 19:32:20 +00:00
net_util: Consolidate vnet_hdr_len() functions
As a result of refactoring this function was duplicated so consolidate into the top level. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
48faf3abac
commit
7f3e40e0cf
@ -70,6 +70,11 @@ fn create_socket() -> Result<net::UdpSocket> {
|
|||||||
Ok(unsafe { net::UdpSocket::from_raw_fd(sock) })
|
Ok(unsafe { net::UdpSocket::from_raw_fd(sock) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn vnet_hdr_len() -> usize {
|
||||||
|
use virtio_bindings::bindings::virtio_net::virtio_net_hdr_v1;
|
||||||
|
std::mem::size_of::<virtio_net_hdr_v1>()
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -2,12 +2,10 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
||||||
|
|
||||||
use super::TapError;
|
use super::{vnet_hdr_len, MacAddr, Tap, TapError};
|
||||||
use super::{MacAddr, Tap};
|
|
||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::{fs, io};
|
use std::{fs, io};
|
||||||
use virtio_bindings::bindings::virtio_net::virtio_net_hdr_v1;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
@ -39,10 +37,6 @@ pub enum Error {
|
|||||||
|
|
||||||
type Result<T> = std::result::Result<T, Error>;
|
type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
fn vnet_hdr_len() -> usize {
|
|
||||||
std::mem::size_of::<virtio_net_hdr_v1>()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_mq_support(if_name: &Option<&str>, queue_pairs: usize) -> Result<()> {
|
fn check_mq_support(if_name: &Option<&str>, queue_pairs: usize) -> Result<()> {
|
||||||
if let Some(tap_name) = if_name {
|
if let Some(tap_name) = if_name {
|
||||||
let mq = queue_pairs > 1;
|
let mq = queue_pairs > 1;
|
||||||
|
@ -2,13 +2,12 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
||||||
|
|
||||||
use super::Tap;
|
use super::{vnet_hdr_len, Tap};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::num::Wrapping;
|
use std::num::Wrapping;
|
||||||
use vm_memory::{Bytes, GuestAddress, GuestMemoryMmap};
|
use vm_memory::{Bytes, GuestAddress, GuestMemoryMmap};
|
||||||
use vm_virtio::{DescriptorChain, Queue};
|
use vm_virtio::{DescriptorChain, Queue};
|
||||||
use virtio_bindings::bindings::virtio_net::virtio_net_hdr_v1
|
|
||||||
|
|
||||||
/// The maximum buffer size when segmentation offload is enabled. This
|
/// The maximum buffer size when segmentation offload is enabled. This
|
||||||
/// includes the 12-byte virtio net header.
|
/// includes the 12-byte virtio net header.
|
||||||
@ -183,7 +182,3 @@ impl RxVirtio {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vnet_hdr_len() -> usize {
|
|
||||||
std::mem::size_of::<virtio_net_hdr_v1>()
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user